Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

language name localization #1007

Merged
merged 4 commits into from
Jan 28, 2024
Merged

language name localization #1007

merged 4 commits into from
Jan 28, 2024

Conversation

oxygen-dioxide
Copy link
Contributor

After this change, OpenUtau will show localized name for each singing language it supports when selecting phonemizer.
image

The localized names of each language come from https://github.com/symfony/symfony, and are converted to openutau format using the following script:

#symfony repo contains the names of one language in different languages
#https://github.com/symfony/symfony
#This script converts them to openutau's localization file format.

#Before running this script, please run the following commands:
#git clone https://github.com/symfony/symfony
#git clone https://github.com/stakira/OpenUtau
#pip install py_linq

from   typing  import List, Dict, Tuple
import pathlib
from   py_linq import Enumerable
from   OpenUtau.Misc.sync_strings import file_to_dict, dict_to_file

oRoot = pathlib.Path("OpenUtau")
sRoot = pathlib.Path("symfony")

oLangsFolder = oRoot / "OpenUtau" / "Strings"
sLangsFolder = sRoot / "src" / "Symfony" / "Component" / "Intl" / "Resources" / "data" / "languages"

uiLangMapping = {
    "axaml": "en",
    "zh-TW": "zh_Hant",
}

singingLangMapping = {
    "zh-yue": "yue",
}

#Singing languages supported by OpenUtau
keys = [
    "de",
    "en",
    "es",
    "fr",
    "it",
    "ja",
    "ko",
    "pl",
    "pt",
    "ru",
    "vi",
    "zh",
    "zh-yue",
]

def uiOLangToSLang(oLang: str) -> str:
    if(oLang in uiLangMapping):
        return uiLangMapping[oLang]
    else:
        return oLang.split("-")[0]

def singingOLangToSLang(oLang: str) -> str:
    if(oLang in singingLangMapping):
        return singingLangMapping[oLang]
    else:
        return oLang.split("-")[0]

def loadSymfonyLangs(filepath: pathlib.Path) -> Dict[str, str]:
    with open(filepath, "r", encoding="utf-8") as f:
        return Enumerable(f.readlines())\
            .where(lambda line: "' => '" in line)\
            .select(lambda line: line.split("'"))\
            .to_dictionary(lambda parts: parts[1], lambda parts: parts[3])

def main():
    for oLangFile in oLangsFolder.iterdir():
        oLang = file_to_dict(oLangFile)
        if(oLangFile.name == "Strings.axaml"):
            oLangEn = {}
        else:
            oLangEn = file_to_dict(oLangsFolder / "Strings.axaml")
        to_add = set(oLangEn.keys()) - set(oLang.keys())
        [oLang.update({k: oLangEn[k]}) for k in to_add]
        sLangFile = sLangsFolder / f"{uiOLangToSLang(oLangFile.name.split('.')[1])}.php"
        print(sLangFile, "\n", oLangFile, "\n")
        sLang = loadSymfonyLangs(sLangFile)
        for key in keys:
            sKey = singingOLangToSLang(key)
            if(sKey in sLang):
                oLang[f"languages.{key}"] = ("String", sLang[sKey])
        dict_to_file(oLangFile, oLang, oLangEn)

if(__name__ == "__main__"):
    main()

@stakira
Copy link
Owner

stakira commented Jan 25, 2024

Oops, conflict.

@stakira stakira merged commit 56ad46c into stakira:master Jan 28, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants