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

Feature labels are based on generic name:zh tag when using Traditional or Simplified Chinese locale #10219

Open
SteveLz opened this issue Apr 23, 2024 · 1 comment
Labels
bug A bug - let's fix this! localization Adapting iD across languages, regions, and cultures

Comments

@SteveLz
Copy link

SteveLz commented Apr 23, 2024

Description

Currently, neither name:zh-Hant nor name:zh-Hans are supported to be displayed on the map, but only the ambiguous name:zh, which is either traditional or simplified, is displayed.

Screenshots

No response

@1ec5
Copy link
Collaborator

1ec5 commented Apr 23, 2024

The labeling code prefers whatever the localizer module considers to be the current language code, which is for the localization that iD’s UI is being displayed in:

iD/modules/util/util.js

Lines 183 to 184 in 25d98b1

var localizedNameKey = 'name:' + localizer.languageCode().toLowerCase();
var name = entity.tags[localizedNameKey] || entity.tags.name || '';

The code to choose a UI localization is a bit convoluted:

let requestedLocales = (_preferredLocaleCodes || [])
.concat(utilDetect().browserLocales) // List of locales preferred by the browser in priority order.
.concat(['en']); // fallback to English since it's the only guaranteed complete language
_localeCodes = localesToUseFrom(requestedLocales);
_localeCode = _localeCodes[0]; // Run iD in the highest-priority locale; the rest are fallbacks
let loadStringsPromises = [];
indexes.forEach((index, i) => {
// Will always return the index for `en` if nothing else
const fullCoverageIndex = _localeCodes.findIndex(function(locale) {
return index[locale] && index[locale].pct === 1;
});
// We only need to load locales up until we find one with full coverage
_localeCodes.slice(0, fullCoverageIndex + 1).forEach(function(code) {
let scopeId = Object.keys(localeDirs)[i];
let directory = Object.values(localeDirs)[i];
if (index[code]) loadStringsPromises.push(localizer.loadLocale(code, scopeId, directory));
});
});

But one thing we seem to have overlooked is that modern browsers generally report locale codes such as zh-Hans-CN and zh-Hant-TW based on CLDR, whereas this repository and the corresponding Transifex project only maintain zh, zh-CN, zh-HK, and zh-TW localizations. If your language preference is any of these four codes verbatim, iD will load the correct localization, but if it differs in any way, such as zh-Hant-TW or zh-Hant, then it’ll fall back to just zh.

Compounding the matter, the labeling code above only chooses the name:* subkey that matches the language part of the locale code. So when iD uses the zh-TW localization, for example, it only labels features based on name:zh, because it’s calling localizer.languageCode() rather than localizer.localeCode(). Even if it were to match the whole locale code, zh-TW is quite rare compared to zh-Hant.

We could add some special cases to both these areas of the codebase, though more robust language code matching would help not only Chinese but also other languages that frequently use more complex locale codes in the database, such as Serbian and Portuguese.

/ref #8739

@1ec5 1ec5 added bug A bug - let's fix this! localization Adapting iD across languages, regions, and cultures labels Apr 23, 2024
@1ec5 1ec5 changed the title Map language Traditional and Simplified Chinese is not supported Feature labels are based on generic name:zh tag when using Traditional or Simplified Chinese locale Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug - let's fix this! localization Adapting iD across languages, regions, and cultures
Projects
None yet
Development

No branches or pull requests

2 participants