Skip to content

Commit

Permalink
Ensure languages are always presented with the name in that language
Browse files Browse the repository at this point in the history
Signed-off-by: John Gomersall <[email protected]>
  • Loading branch information
john-gom committed Aug 18, 2024
1 parent 26e8322 commit aad2d90
Show file tree
Hide file tree
Showing 191 changed files with 35,378 additions and 13 deletions.
21 changes: 11 additions & 10 deletions build-scripts/build_languages.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,21 @@ fetch('https://static.openfoodfacts.org/data/taxonomies/languages.json').then(as
const countries = await (await fetch('https://static.openfoodfacts.org/data/taxonomies/countries.json')).json();

const languageList = {};
mkdirSync(`${themeDir}/messages`, {recursive: true});
for (const [ key, language ] of Object.entries(languages)) {
if (key === 'en:unknown-language') continue;

const code = language.language_code_2.en;
const name = (language.name?.[code] ?? language.name.en ?? key).replaceAll("'","''");
languageList[code] = name;
}
const languageMessages = '\n# The following are obtained from the OFF languages taxonomy\n' +
Object.entries(languageList).map(([key,value]) => `locale_${key}=${value}`).sort().join('\n');

mkdirSync(`${themeDir}/messages`, {recursive: true});
for (const [ key, language ] of Object.entries(languages)) {
if (key === 'en:unknown-language') continue;

const code = language.language_code_2.en;
const countryMessages = [];
for (const [countryId, country ] of Object.entries(countries)) {
if (!country.country_code_2?.en) {
Expand All @@ -31,10 +38,8 @@ fetch('https://static.openfoodfacts.org/data/taxonomies/languages.json').then(as
writeFileSync(`${themeDir}/messages/messages_${code}.properties`,
customMessages.join('/n') +
'\n# The following are obtained from the OFF countries taxonomy\n' +
countryMessages.sort().join('\n') +
'\n');
countryMessages.sort().join('\n') + languageMessages);
}

const countryOptions = {};
const countryList = {};
// Try and sort the country list to avoid excess diffs
Expand All @@ -50,19 +55,15 @@ fetch('https://static.openfoodfacts.org/data/taxonomies/languages.json').then(as
countryList[countryCode] = countryName;
}

const sortedLanguageCodes = Object.entries(languageList).sort((a,b) => a[1].localeCompare(b[1])).map((entry) => entry[0]);
// Currently sort countries by english name until keycloak supports sorting by localized name
const sortedCountryCodes = Object.entries(countryList).sort((a,b) => a[1].localeCompare(b[1])).map((entry) => entry[0]);
const sortedLanguageCodes = Object.entries(languageList).sort((a,b) => a[1].localeCompare(b[1])).map((entry) => entry[0]);
const realmSettings = {
supportedLocales: sortedLanguageCodes
}
writeFileSync(`runtime-scripts/realm_settings.json`,JSON.stringify(realmSettings, undefined, 2));
writeFileSync(`${themeDir}/theme.properties`,`locales=${sortedLanguageCodes.join(',')}\n`);
appendFileSync(`${themeDir}/messages/messages_en.properties`,
'\n# The following are obtained from the OFF languages taxonomy\n' +
Object.entries(languageList).map(([key,value]) => `locale_${key}=${value}`).sort().join('\n') +
'\n');


const userProfile = JSON.parse(readFileSync(`${runtimeDir}/users_profile.json`));
const countryAttribute = userProfile.attributes.find((a) => a.name === 'country');
countryAttribute.validations.options.options = sortedCountryCodes;
Expand Down
17 changes: 17 additions & 0 deletions tests/login.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,23 @@ test("locale selector supports incremental search", async ({ page }) => {
await expect(page.getByRole("button", { name: "Connexion" })).toBeVisible();
});

test("locale selector always shows in same language", async ({ page }) => {
await gotoHome(page);

const localeSelector = page.getByLabel("languages");
await localeSelector.click();
await localeSelector.pressSequentially("fr");
await localeSelector.press("Tab");

await expect(page.getByRole("button", { name: "Connexion" })).toBeVisible();

await localeSelector.click();
await localeSelector.pressSequentially("eng");
await localeSelector.press("Tab");

await expect(page.getByRole("button", { name: "Sign In" })).toBeVisible();
});

test("create account link", async ({ page }) => {
await gotoHome(page);

Expand Down
3 changes: 3 additions & 0 deletions tests/register.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ test("registration page", async ({ page }) => {
const afterHelper = page.locator('.pf-c-form__helper-text-after:has-text("username"):below(#username)');
expect(await matchStyles(afterHelper, HELPER_TEXT)).toBeNull();


// TODO: Drop-down icon visible on country select
// TODO: Countries are sorted by localized value
});
189 changes: 189 additions & 0 deletions theme/off/common/messages/messages_aa.properties
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,192 @@ country_ZA=South Africa
country_ZM=Zambia
country_ZW=Zimbabwe
country_world=World
# The following are obtained from the OFF languages taxonomy
locale_aa=Afar
locale_ab=Аҧсуа бызшәа
locale_ae=Avestan
locale_af=Afrikaans
locale_ak=Akan
locale_am=አማርኛ
locale_an=Idioma aragonés
locale_ar=العربية
locale_as=অসমীয়া ভাষা
locale_av=МагIарул мацI
locale_ay=Aymar aru
locale_az=Azərbaycan dili
locale_ba=Башҡорт теле
locale_be=Беларуская мова
locale_bg=Български език
locale_bh=बिहारी भाषा
locale_bi=Bislama
locale_bm=Bamanankan
locale_bn=বাংলা ভাষা
locale_bo=བོད་སྐད།
locale_br=Brezhoneg
locale_bs=Bosanski jezik
locale_ca=Català
locale_ce=Нохчий мотт
locale_ch=Fino'' Chamoru
locale_co=Lingua corsa
locale_cr=ᐃᔨᔫ ᐊᔨᒧᐎᓐ
locale_cs=Čeština
locale_cu=Црькъвьнословѣньскъ ѩꙁꙑкъ
locale_cv=Чăваш чĕлхи
locale_cy=Cymraeg
locale_da=Dansk
locale_de=Deutsch
locale_dv=ދިވެހި
locale_dz=རྫོང་ཁ་
locale_ee=Eʋegbe
locale_el=Ελληνικά
locale_en=English
locale_eo=Esperanto
locale_es=Español
locale_et=Eesti keel
locale_eu=Euskara
locale_fa=زبان فارسی
locale_ff=Fulfulde
locale_fi=Suomi
locale_fj=Fijian language
locale_fo=Føroyskt mál
locale_fr=Français
locale_fy=Frysk
locale_ga=An Ghaeilge
locale_gd=Gàidhlig na h-Alba
locale_gl=Lingua galega
locale_gn=Avañe''ẽ
locale_gu=ગુજરાતી ભાષા
locale_gv=Gaelg
locale_ha=Hausa
locale_he=עברית
locale_hi=हिन्दी
locale_ho=Hiri Motu
locale_hr=Hrvatski
locale_ht=Kreyòl
locale_hu=Magyar
locale_hy=Հայերեն
locale_hz=Herero
locale_ia=Interlingua
locale_id=Bahasa Indonesia
locale_ie=Interlingue
locale_ig=Asụsụ Igbo
locale_ii=Nuosu language
locale_ik=Iñupiatun
locale_io=Ido
locale_is=Íslenska
locale_it=Italiano
locale_iu=ᐃᓄᒃᑎᑐᑦ
locale_ja=日本語
locale_jv=Basa Jawa
locale_ka=ქართული ენა
locale_kg=Kisikongo
locale_ki=Gĩgĩkũyũ
locale_kj=Kwanyama
locale_kk=Қазақ тілі
locale_kl=Kalaallisut
locale_km=ភាសាខ្មែរ
locale_kn=ಕನ್ನಡ
locale_ko=한국어
locale_kr=Kanuri
locale_ks=کٲشُر زَبان
locale_ku=Zimanê kurdî
locale_kv=Коми кыв
locale_kw=Kernowek
locale_ky=Кыргыз тили
locale_la=Lingua Latina
locale_lb=Lëtzebuergesch
locale_lg=Luganda
locale_li=Limburgs
locale_ln=Lingála
locale_lo=ພາສາລາວ
locale_lt=Lietuvių kalba
locale_lu=Luba-Katanga language
locale_lv=Latviešu valoda
locale_me=Montenegrin
locale_mg=Fiteny malagasy
locale_mh=Kajin M̧ajeļ
locale_mi=Reo Māori
locale_mk=Македонски јазик
locale_ml=മലയാളം
locale_mn=Монгол хэл
locale_mo=Лимба молдовеняскэ
locale_mr=मराठी भाषा
locale_ms=Bahasa Melayu
locale_mt=Malti
locale_my=မြန်မာဘာသာစကား
locale_na=Dorerin Naoero
locale_nb=Bokmål
locale_nd=Northern Ndebele language
locale_ne=नेपाली भाषा
locale_ng=Ndonga
locale_nl=Nederlands
locale_nn=Nynorsk
locale_no=Norsk
locale_nr=Southern Ndebele
locale_nv=Diné bizaad
locale_ny=Chilankhulo cha Chichewa
locale_oc=Occitan
locale_oj=Ojibwe
locale_om=Afaan Oromoo
locale_or=ଓଡ଼ିଆ
locale_os=Ирон æвзаг
locale_pa=ਪੰਜਾਬੀ ਭਾਸ਼ਾ
locale_pi=पालि Pāli
locale_pl=Język polski
locale_ps=پښتو ژبه
locale_pt=Português
locale_qu=Qhichwa simi
locale_rm=Rumantsch dal Grischun
locale_rn=Ikirundi
locale_ro=Limba română
locale_ru=Русский язык
locale_rw=Ikinyarwanda
locale_ry=Rusyn
locale_sa=संस्कृतम्
locale_sc=Limba sarda
locale_sd=سنڌي ٻولي
locale_se=Davvisámegiella
locale_sg=Sängö
locale_sh=Srpskohrvatski jezik
locale_si=සිංහල භාෂාව
locale_sk=Slovenčina
locale_sl=Slovenščina
locale_sm=Gagana fa''a Sāmoa
locale_sn=ChiShona
locale_so=Af-Soomaali
locale_sq=Gjuha shqipe
locale_sr=Српски језик
locale_ss=SiSwati
locale_st=Sesotho
locale_su=Basa Sunda
locale_sv=Svenska
locale_sw=Kiswahili
locale_ta=தமிழ்
locale_te=తెలుగు
locale_tg=Забони тоҷикӣ
locale_th=ภาษาไทย
locale_ti=ትግርኛ ፊደል
locale_tk=Türkmen dili
locale_tl=Wikang Tagalog
locale_tn=Setswana
locale_to=Lea fakatonga
locale_tr=Türkçe
locale_ts=Xitsonga
locale_tt=Татар теле
locale_tw=Twi
locale_ty=Reo tahiti
locale_ug=ئۇيغۇر تىلى
locale_uk=Українська мова
locale_ur=اردو
locale_uz=Oʻzbek tili
locale_ve=TshiVenḓa
locale_vi=Tiếng Việt
locale_vo=Volapük nulik
locale_wa=Walon
locale_wo=Wolof
locale_xh=IsiXhosa
locale_yi=יידיש
locale_yo=Èdè Yorùbá
locale_za=Vahcuengh
locale_zh=汉语
locale_zu=IsiZulu
Loading

0 comments on commit aad2d90

Please sign in to comment.