Comparing locales can have surprising outcomes since it standardizes
locales with defaults. For example, zh and zh_CN result in an exact
match since the defaults change them both to zh_Hans_CN. Expose the
add_default parameter publicly with a default of false so the fully
standardized locale can be inspected.
Since 9456454109, country specific locales are always preferred over
country-less locales even when the OS locale country doesn't match. For
example, running the Godot editor with locale es_ES will result in the
es_AR locale being chosen even though the es locale would be better.
The change happened because the score of the es_AR locale and the es
locale are the same when comparing to es_ES. Change this by parsing
locale strings into a Locale structure and decreasing the score when
script, country or variant are set in both but not matched. For the
es_ES case, this causes the es_AR score to be decreased since the
countries don't match. On the other hand, the es locale is not decreased
since it doesn't specify a country.
This change avoids the problem known as 'Static Initialization Order Fiasco' (SIOF).
See the following PR for more explanation: https://github.com/godotengine/godot/pull/94683
Co-authored-by: Gabor Koncz <gabor.koncz@migeran.com>
How editor plugins use this feature:
1. Pick a unique translation domain name.
2. `_enter_tree()`: load translations into that translation domain.
3. Call `set_translation_domain()` for its root UI node.
4. `_exit_tree()`: remove that translation domain.
Plugins can also set the translation domain to `godot.editor` for
nested nodes that should use editor translations. `EditorFileDialog`
automatically does this.