Skip to content

Translations GetText - Fallback from language with country code to language without a country code not working #90677

@AlixBarreaux

Description

@AlixBarreaux

Tested versions

Reproducible in:
Godot Engine v4.2.1.stable.official.b09f793f5
Godot Engine v4.1.3.stable.official.f06b6836a

System information

Godot v4.2.1.stable - Debian GNU/Linux 12 (bookworm) 12 - X11 - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1060 6GB (nvidia) - 12th Gen Intel(R) Core(TM) i5-12600K (16 Threads)

Issue description

When setting a locale fr with a country code CH this locale + country code combination fr_CH in the TranslationServer works if the .mo file for fr_CH is present.

However if it's not present but the .mo files for fr_CA AND fr (without a country code) are present it will fall back to fr_CA or whatever fr_ + a country code.
This is not what I expect.

I expect the locale + country code fr_CH (CH in this case but it can be any country code) to fall back to the same locale without any country code appended to it, just fr
If the .mo file for fr is not found then it should take the first .mo file for fr + whatever country code.
If none is found it should fall back to the fallback set in project settings. (locale + country code)

Steps to reproduce

Create a label scene, set its text in English in the editor.
Attach a script to it and in the _ready() function put this in: print("Locale used: ", TranslationServer.get_locale())
Go in Project Settings and toggle advanced settings.
Then:
Project Settings -> Localization -> POT Generation -> Generate POT

Outside of Godot with Poedit (or whatever you want) create the getText translation files for:
French, French (Belgium), French (Canadian) .
In the newly opened window, fill in the text value with something related to the file to distinguish which specific language you are using when running the game later on.
Save it.

Project Settings -> Localization -> Translations -> Add -> Add your .mo files you just created.
Project Settings -> Internationalization -> Locale -> test -> This field should be empty by default.
Launch the label scene.
The text in the label should be your English text you have initially set in the editor and the print statement says: Language used: en_US
Project Settings -> Internationalization -> Locale -> test -> set it to fr_CH (You should NOT have created the getText files for French (Switzerland), it must not be imported into the project)
The text in the label is the value from the French Canadian (fr_CA) .mo file, instead of the expected one which is French French Switzerland (fr_CH) and the print statement says: Language used: fr_CH

Minimal reproduction project (MRP)

language-fallback.zip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions