serge-community / serge

Continuous localization platform
https://serge.io/
Other
236 stars 52 forks source link

Serge localize behavior with untranslated strings. #107

Closed zhukic closed 5 years ago

zhukic commented 5 years ago

Hi. I use Serge in my Android-project. So at first I'm trying to run serge-import to create initial translation memory database. After that I run serge localize and as the result of that untranslated strings appear in the output file with source translation. For example if I have a source file:

<resources>
    <string name="hello">Hello</string>
    <string name="world">World</string>
    <string name="today">Today</string>
</resources>

And initial output file:

<resources>
    <string name="hello">Привет</string>
    <string name="world">Мир</string>
</resources>

After serge localize untranslated string appears in English:

<resources>
    <string name="hello">Hello</string>
    <string name="world">World</string>
    <string name="today">Today</string>
</resources>

Is it possible to prevent that because Android system can use default string from source file if there is no corresponding translated string? My config file:

jobs
{
    {
        id                          localize_android_strings

        source_dir                  ./app/src/main/res/values
        source_process_subdirs      NO
        source_match                ^strings.xml$

        debug                       YES

        parser
        {
            plugin                  parse_android
        }
        ts_file_path                ./po/%LANG%/%FILE%.po
        output_file_path            ./app/src/main/res/values-%LOCALE:ANDROID%/%NAME%.%EXT%

        source_language             en
        destination_languages       ru de es fr it

        db_source                   DBI:SQLite:dbname=./translate.db3
        db_namespace                android_project
    }

}

Thanks.

iafan commented 5 years ago

The first step here is to use leave_untranslated_blank YES option in your job config plus a replace_strings plugin that will clean up empty nodes from localized files.

There's one test in Serge that does just that, so you can use it as a recipe: https://github.com/evernote/serge/tree/master/t/data/engine/parse_android/01-cleanup-untranslated

The approach above uses regular expressions to clean up the localized files and can be applied not only to Android XML resource files. As of recently, we also got an apply_xslt plugin that can change the shape of XML files to achieve the same result. One of its tests also shows how to remove untranslated strings from Android resource files: https://github.com/evernote/serge/tree/master/t/data/engine/apply_xslt/02

zhukic commented 5 years ago

Everything works fine! @iafan, thanks a lot for the quick response and your help.

Also thanks for such amazing tool!