Ejemplo n.º 1
0
def properties_to_xwiki_properties(file_path, path_prefix, base_file_name, lang):
    """Convert a java properties file to an XWiki java properties 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]
    lang_delimiter_index = file_name.rfind("_" + lang)
    if lang_delimiter_index > 0:
        file_name = file_name[:lang_delimiter_index]

    # 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())

    # Use the base translation file as template
    base_properties = PropertiesFile()
    with open(path_prefix + base_file_name, "r") as f_properties:
        base_properties.load(f_properties.read())

    # Replace keys with the current translation
    base_properties.replace_with(properties)
    base_properties.filter_export()

    base_properties.write(path_prefix + file_path)
Ejemplo n.º 2
0
def properties_to_xwiki_properties(file_path, path_prefix, base_file_name, lang):
    """Convert a java properties file to an XWiki java properties 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]
    lang_delimiter_index = file_name.rfind("_" + lang)
    if lang_delimiter_index > 0:
        file_name = file_name[:lang_delimiter_index]

    # 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())

    if not properties.is_empty():
        # Use the base translation file as template
        base_properties = PropertiesFile()
        with open(path_prefix + base_file_name, "r") as f_properties:
            base_properties.load(f_properties.read())

        # Replace keys with the current translation
        base_properties.replace_with(properties)
        base_properties.filter_export()

        base_properties.write(path_prefix + file_path)
    else:
        print "Warning: {} translation is empty. Skipping it.".format(properties_path)
Ejemplo n.º 3
0
def xwiki_xml_properties_to_properties(path, path_prefix, lang):
    """Convert an XWiki XML file with properties to a java properties file"""
    relative_dir_path = os.path.dirname(path)
    file_name = os.path.basename(path).split(".")[0]

    properties = PropertiesFile()
    xml_file = XmlFile(path_prefix + path)
    content = xml_file.get_tag_content("content")
    properties.load(content)

    properties_path = "{}.translation/{}_{}.properties".format(
        path_prefix, relative_dir_path + "/" + file_name, lang)
    properties.write(properties_path)
Ejemplo n.º 4
0
def xwiki_xml_to_properties(path, path_prefix, lang):
    """Convert an XWiki XML file to a java properties file"""
    relative_dir_path = os.path.dirname(path)
    file_name = os.path.basename(path).split(".")[0]

    properties = PropertiesFile()
    xml_file = XmlFile(path_prefix + path)
    properties.set_value("{}.title".format(file_name),
                         xml_file.get_tag_content("title"))
    properties.set_value("{}.content".format(file_name),
                         xml_file.get_tag_content("content"))

    properties_path = "{}.translation/{}_{}.properties".format(
        path_prefix, relative_dir_path + "/" + file_name, lang)
    properties.write(properties_path)
Ejemplo n.º 5
0
def xwiki_properties_to_properties(path, path_prefix, lang):
    """Convert an XWiki properties file to a java properties file"""
    relative_dir_path = os.path.dirname(path)
    file_name = os.path.basename(path).split(".")[0]
    lang_delimiter_index = file_name.rfind("_")
    if lang_delimiter_index > 0:
        file_name = file_name[:lang_delimiter_index]

    properties = PropertiesFile()
    with open(path_prefix + path, "r") as f_properties:
        properties.load(f_properties.read())

    properties_path = "{}.translation/{}_{}.properties".format(
        path_prefix, relative_dir_path + "/" + file_name, lang)
    properties.write(properties_path)
Ejemplo n.º 6
0
def xwiki_xml_properties_to_properties(file_path, path_prefix, lang):
    """Convert an XWiki XML file with properties to a java properties 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()

    xml_file = XmlFile()
    xml_file.load(path_prefix + file_path)
    content = xml_file.get_tag_content("content")
    properties.load(content)
    properties.filter_import()

    properties.write(properties_path)
Ejemplo n.º 7
0
def xwiki_xml_to_properties(file_path, path_prefix, lang):
    """Convert an XWiki XML file to a java properties 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()

    xml_file = XmlFile()
    xml_file.load(path_prefix + file_path)
    properties.set_value("{}.title".format(file_name), xml_file.get_tag_content("title"))
    properties.set_value("{}.content".format(file_name),
                         xml_file.get_tag_content("content", ['xwikidoc']))

    properties.write(properties_path)
Ejemplo n.º 8
0
def xwiki_properties_to_properties(file_path, path_prefix, lang):
    """Convert an XWiki properties file to a java properties 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]
    lang_delimiter_index = file_name.rfind("_" + lang)
    if lang_delimiter_index > 0:
        file_name = file_name[:lang_delimiter_index]

    # Weblate translation file
    properties_path = "{}_{}.properties".format(
        path_prefix + TRANSLATION_PREFIX + relative_dir_path + "/" + file_name, lang)
    properties = PropertiesFile()

    with open(path_prefix + file_path, "r") as f_properties:
        properties.load(f_properties.read())
        properties.filter_import()

    properties.write(properties_path)