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

support localised labels for CLDR overrides #10703

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions scripts/language_names.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,21 @@

let referencedScripts = [];

function getLangNamesInNativeLang() {
/**
* @returns {{
* [code: string]: {
* base?: string;
* script?: string;
* nativeName?: string;
* names?: { [code: string]: string };
* }
* }}
*/
function getCLDROverrides() {
// manually add languages we want that aren't in CLDR
// see for example https://github.com/openstreetmap/iD/pull/9241/
let unordered = {
return {
aer: { nativeName: 'Arrernte' },

Check failure on line 32 in scripts/language_names.js

View workflow job for this annotation

GitHub Actions / Check for spelling errors

aer ==> are

Check failure on line 32 in scripts/language_names.js

View workflow job for this annotation

GitHub Actions / Check for spelling errors

aer ==> are
aoi: { nativeName: 'Anindilyakwa' },
aus: { nativeName: 'Australian Aboriginal Languages' },
bdy: { nativeName: 'Yugambeh–Bandjalangic' },
Expand All @@ -32,7 +42,7 @@
'brh': {
nativeName: 'براہوئی'
},
coa: { nativeName: 'Basa Pulu Kokos' },
coa: { nativeName: 'Basa Pulu Kokos', names: { en: 'Cocos Malay' } },
'cdo': {
nativeName: '閩東語'
},
Expand Down Expand Up @@ -157,7 +167,7 @@
'oc': {
nativeName: 'Occitan'
},
pih: { nativeName: 'Pitkern–Norfuk' },
pih: { nativeName: 'Pitkern–Norfuk', names: { en: 'Pitcairn-Norfolk', ty: 'Pitcairnais' } },
piu: { nativeName: 'Pintupi' },
pjt: { nativeName: 'Pitjantjatjara' },
'pnb': {
Expand All @@ -174,7 +184,7 @@
'skr': {
nativeName: 'سرائیکی'
},
tcs: { nativeName: 'Yumplatok' },
tcs: { nativeName: 'Yumplatok', names: { en: 'Torres Strait Creole' } },
tiw: { nativeName: 'Tiwi' },
'trw': {
nativeName: 'توروالی'
Expand All @@ -198,11 +208,11 @@
nativeName: '吳語(正體)'
},
wrh: { nativeName: 'Wiradjuri' },
wth: { nativeName: 'Wathawurrung' },

Check failure on line 211 in scripts/language_names.js

View workflow job for this annotation

GitHub Actions / Check for spelling errors

wth ==> with

Check failure on line 211 in scripts/language_names.js

View workflow job for this annotation

GitHub Actions / Check for spelling errors

wth ==> with
wyi: { nativeName: 'Woiwurrung' },
xdk: { nativeName: 'Dharug' },
xni: { nativeName: 'Ngarigo' },
xph: { nativeName: 'Tyerrernotepanner' },
xph: { nativeName: 'Tyerrernotepanner', names: { en: 'North Midlands Tasmanian' } },
xrd: { nativeName: 'Gundungurra' },
'yue-Hans': {
base: 'yue',
Expand All @@ -221,6 +231,13 @@
},
zku: { nativeName: 'Kaurna' },
};
}

function getLangNamesInNativeLang() {
const unordered = getCLDROverrides();
for (const key in unordered) {
delete unordered[key].names; // this is added later
}

let langDirectoryPaths = fs.readdirSync(cldrMainDir);
langDirectoryPaths.forEach(code => {
Expand Down Expand Up @@ -274,11 +291,20 @@
exports.languageNamesInLanguageOf = function(code) {
if (rematchCodes[code]) code = rematchCodes[code];

const { language } = new Intl.Locale(code);

let languageFilePath = `${cldrMainDir}${code}/languages.json`;
if (!fs.existsSync(languageFilePath)) return null;

let translatedLangsByCode = JSON.parse(fs.readFileSync(languageFilePath, 'utf8')).main[code].localeDisplayNames.languages;

// add any overrides that have translated names
for (const [key, value] of Object.entries(getCLDROverrides())) {
if (value.names?.[language]) {
translatedLangsByCode[key] ||= value.names?.[language];
}
}

// ignore codes for non-languages
codesToSkip.forEach(skipCode => {
delete translatedLangsByCode[skipCode];
Expand Down
Loading