KhronosGroup / glTF-Blender-IO

Blender glTF 2.0 importer and exporter
https://docs.blender.org/manual/en/latest/addons/import_export/scene_gltf2.html
Apache License 2.0
1.49k stars 319 forks source link

Export: names of NLA tracks and translation issue #1843

Open scurest opened 1 year ago

scurest commented 1 year ago

The exporter has special behavior when the name of an NLA track starts with "NLATrack" or "[Action Stash]"

https://github.com/KhronosGroup/glTF-Blender-IO/blob/0ff430ced526f0fac7021426f0283571701bce39/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_animations.py#L131-L132

Because these are hard-coded to the English names, English users who stash an action see different behavior than, say, French users (who get "[Pile d’actions]" instead of "[Action Stash]").

To Reproduce

  1. Create an action, switch to the Action Editor, name it something and stash. Export to glTF. If you were using English the animation will be named with the action name.
  2. Switch to French in the prefs, start a new file, and do it again. This time the animation will be named "[Pile d’actions]" instead of the action name.

Solution I'm not very knowledgeable about i18n stuff. One idea is to test both the English and the localized names, which I believe is

def is_default_nla_track_name(name):
    return (
        # names used by default when stashing/creating track
        name.startswith("NlaTrack") or
        name.startswith("[Action Stash]") or
        # translation of those names into current language
        name.startswith(bpy.app.translations.pgettext("NlaTrack")) or
        name.startswith(bpy.app.translations.pgettext("[Action Stash]"))
    )

This would be an improvement, since it would handle anyone working in one language alone, or an English user sending the file to a non-English user. But it still wouldn't handle eg. a French user sending the file to a non-French user.

Also AFAICT a new NLA track is always named "NlaTrack" regardless of language and not translated, so I'm not sure if that actually needs to be checked.

julienduroure commented 1 year ago

Source / to be checked : https://developer.blender.org/T104145

scurest commented 1 year ago

@julienduroure That's what made me think about it, but this did not change in 3.4, it's the same in 3.3 (and probably before).

scurest commented 1 year ago

Another option is to just hardcode all translations of "[Action Stash]". Currently that list is

en_US [Action Stash]
es [Esconder acción]
fr_FR [Pile d’actions]
ja_JP [保留アクション]
sk_SK [Skryť akciu]
vi_VN [Hành Động Cất Chứa]
it_IT [Accantona Azione]
ko_KR [액션 제외]
pt_BR Armazenamento para as ações
pt_PT Armazenamento para as ações
ru_RU [Размещённое действие]
uk_UA [Запас Дій]
pl_PL [Akcja odłożona]

Generated with this rather awkward script

import bpy

ALL_LANGS = [
    'en_US', 'es', 'fr_FR', 'ja_JP', 'sk_SK', 'vi_VN', 'zh_CN', 'cs_CZ',
    'de_DE', 'it_IT', 'ko_KR', 'pt_BR', 'pt_PT', 'ru_RU', 'uk_UA', 'zh_TW',
    'ab', 'ar_EG', 'ca_AD', 'eo', 'eu_EU', 'fa_IR', 'fi_FI', 'ha', 'he_IL',
    'hi_IN', 'hr_HR', 'hu_HU', 'id_ID', 'ka', 'ky_KG', 'nl_NL', 'pl_PL',
    'sr_RS', 'sr_RS@latin', 'sv_SE', 'th_TH', 'tr_TR',
]

def print_all_translations(text, msgctxt=None):
    orig_lang = bpy.context.preferences.view.language
    try:
        for lang in ALL_LANGS:
            bpy.context.preferences.view.language = lang
            trans = bpy.app.translations.pgettext(text, msgctxt)
            if lang == 'en_US' or trans != text:
                print(lang, trans)
    finally:
        bpy.context.preferences.view.language = orig_lang

print_all_translations('[Action Stash]')