예제 #1
0
def properties_to_xwiki_xml(file_path, path_prefix, base_file_name, lang):
    """Convert a java properties file to an XWiki XML file"""
    # Directory of the translation file
    relative_dir_path = os.path.dirname(file_path)
    # Translation file name without the extension
    file_name = os.path.basename(file_path).split(".")[0]

    # Weblate translation file
    properties_path = "{}_{}.properties".format(
        path_prefix + TRANSLATION_PREFIX + relative_dir_path + "/" + file_name, lang)
    properties = PropertiesFile()
    with open(properties_path, "r") as f_properties:
        properties.load(f_properties.read())

    title = properties.get_value("{}.title".format(file_name))
    content = properties.get_value("{}.content".format(file_name))

    if content:
        if not os.path.isfile(path_prefix + file_path):
            # Create the xml translation if it doesn't exists
            XmlFile.create_xml_file(path_prefix + file_path, path_prefix + base_file_name, lang)

        xml_file = XmlFile()
        xml_file.load(path_prefix + file_path)
        xml_file.set_tag_content("title", title)
        xml_file.set_tag_content("content", content, ['xwikidoc'])
        xml_file.write(path_prefix + file_path)
    else:
        print "Warning: {} translation content is empty. Skipping it.".format(properties_path)
예제 #2
0
def properties_to_xwiki_xml(file_path, path_prefix, base_file_name, lang):
    """Convert a java properties file to an XWiki XML file"""
    # Directory of the translation file
    relative_dir_path = os.path.dirname(file_path)
    # Translation file name without the extension
    file_name = os.path.basename(file_path).split(".")[0]

    # Weblate translation file
    properties_path = "{}_{}.properties".format(
        path_prefix + TRANSLATION_PREFIX + relative_dir_path + "/" + file_name,
        lang)
    properties = PropertiesFile()
    with open(properties_path, "r") as f_properties:
        properties.load(f_properties.read())

    title = properties.get_value("{}.title".format(file_name))
    content = properties.get_value("{}.content".format(file_name))

    if content:
        if not os.path.isfile(path_prefix + file_path):
            # Create the xml translation if it doesn't exists
            XmlFile.create_xml_file(path_prefix + file_path,
                                    path_prefix + base_file_name, lang)

        xml_file = XmlFile()
        xml_file.load(path_prefix + file_path)
        xml_file.set_tag_content("title", title)
        xml_file.set_tag_content("content", content, ['xwikidoc'])
        xml_file.write(path_prefix + file_path)
    else:
        print "Warning: {} translation content is empty. Skipping it.".format(
            properties_path)
예제 #3
0
def properties_to_xwiki_xml(path, path_prefix, lang):
    """Convert a java properties file to an XWiki XML file"""
    relative_dir_path = os.path.dirname(path)
    file_name = os.path.basename(path).split(".")[0]

    properties_path = "{}.translation/{}_{}.properties".format(
        path_prefix, relative_dir_path + "/" + file_name, lang)
    properties = PropertiesFile()
    with open(properties_path, "r") as f_properties:
        properties.load(f_properties.read())

    title = properties.get_value("{}.title".format(file_name))
    content = properties.get_value("{}.content".format(file_name))
    xml_file = XmlFile(path_prefix + path)
    xml_file.set_tag_content("title", title)
    xml_file.set_tag_content("content", content)
    xml_file.write()
예제 #4
0
def properties_to_xwiki_xml(file_path, path_prefix, lang):
    """Convert a java properties file to an XWiki XML file"""
    # Directory of the translation file
    relative_dir_path = os.path.dirname(file_path)
    # Translation file name without the extension
    file_name = os.path.basename(file_path).split(".")[0]

    # Weblate translation file
    properties_path = "{}_{}.properties".format(
        path_prefix + TRANSLATION_PREFIX + relative_dir_path + "/" + file_name, lang)
    properties = PropertiesFile()
    with open(properties_path, "r") as f_properties:
        properties.load(f_properties.read())

    title = properties.get_value("{}.title".format(file_name))
    content = properties.get_value("{}.content".format(file_name))
    xml_file = XmlFile()
    xml_file.load(path_prefix + file_path)
    xml_file.set_tag_content("title", title)
    xml_file.set_tag_content("content", content)
    xml_file.write(path_prefix + file_path)