Skip to content

Commit 3aee0d0

Browse files
committed
MOBILE-3456 lang: Check parent lang from langname
1 parent ca4dc72 commit 3aee0d0

File tree

23 files changed

+21
-28
lines changed

23 files changed

+21
-28
lines changed

scripts/lang_functions.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,6 @@ function add_langs_to_config($langs, $config) {
120120
function get_langfolder($lang) {
121121
$folder = LANGPACKSFOLDER.'/'.str_replace('-', '_', $lang);
122122
if (!is_dir($folder) || !is_file($folder.'/langconfig.php')) {
123-
echo "Cannot translate $folder, folder not found";
124-
125123
return false;
126124
}
127125

@@ -173,6 +171,8 @@ function reset_translations_strings() {
173171
function build_lang($lang, $keys) {
174172
$langfoldername = get_langfolder($lang);
175173
if (!$langfoldername) {
174+
echo "Cannot translate $lang, folder not found";
175+
176176
return false;
177177
}
178178

@@ -182,15 +182,18 @@ function build_lang($lang, $keys) {
182182
$override_langfolder = false;
183183
}
184184

185-
$total = count ($keys);
185+
$total = count($keys);
186186
$local = 0;
187187

188-
$string = get_translation_strings($langfoldername, 'langconfig');
189-
$parent = isset($string['parentlanguage']) ? $string['parentlanguage'] : "";
188+
$langparts = explode('-', $lang, 2);
189+
$parentname = $langparts[0] ?? "";
190+
$parent = "";
190191

191192
echo "Processing $lang";
192-
if ($parent != "" && $parent != $lang) {
193-
echo " ($parent)";
193+
// Check parent language exists.
194+
if ($parentname != $lang && get_langfolder($parentname)) {
195+
echo " ($parentname)";
196+
$parent = $parentname;
194197
}
195198

196199
$langFile = false;
@@ -247,6 +250,12 @@ function build_lang($lang, $keys) {
247250
$translations[$key] = html_entity_decode($text);
248251
}
249252

253+
if (!empty($parent)) {
254+
$translations['core.parentlanguage'] = $parent;
255+
} else if (isset($translations['core.parentlanguage'])) {
256+
unset($translations['core.parentlanguage']);
257+
}
258+
250259
// Sort and save.
251260
ksort($translations);
252261
file_put_contents(ASSETSPATH.$lang.'.json', str_replace('\/', '/', json_encode($translations, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)));
@@ -275,6 +284,8 @@ function progressbar($percentage) {
275284
function detect_lang($lang, $keys) {
276285
$langfoldername = get_langfolder($lang);
277286
if (!$langfoldername) {
287+
echo "Cannot translate $lang, folder not found";
288+
278289
return false;
279290
}
280291

src/assets/lang/ca.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1913,7 +1913,6 @@
19131913
"core.openmodinbrowser": "Obre {{$a}} al navegador",
19141914
"core.othergroups": "Altres grups",
19151915
"core.pagea": "Pàgina {{$a}}",
1916-
"core.parentlanguage": "",
19171916
"core.paymentinstant": "Utilitzeu el botó de baix per pagar i inscriure-us.",
19181917
"core.percentagenumber": "{{$a}}%",
19191918
"core.phone": "Telèfon",

src/assets/lang/cs.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1909,7 +1909,6 @@
19091909
"core.openmodinbrowser": "Otevřít {{$a}} v prohlížeči",
19101910
"core.othergroups": "Další skupiny",
19111911
"core.pagea": "Stránka {{$a}}",
1912-
"core.parentlanguage": "",
19131912
"core.paymentinstant": "Pomocí tlačítka níže můžete provést platbu a během několika minut se zapsat do kurzu!",
19141913
"core.percentagenumber": "{{$a}}%",
19151914
"core.phone": "Telefon",

src/assets/lang/da.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1752,7 +1752,6 @@
17521752
"core.openinbrowser": "Åben i browser",
17531753
"core.othergroups": "Andre grupper",
17541754
"core.pagea": "Side {{$a}}",
1755-
"core.parentlanguage": "",
17561755
"core.paymentinstant": "Brug knappen forneden til at betale og blive tilmeldt umiddelbart derefter.",
17571756
"core.percentagenumber": "{{$a}}%",
17581757
"core.phone": "Telefon",

src/assets/lang/el.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1841,7 +1841,6 @@
18411841
"core.openinbrowser": "Ανοίξτε στον περιηγητή.",
18421842
"core.othergroups": "Άλλες ομάδες",
18431843
"core.pagea": "Σελίδα {{$a}}",
1844-
"core.parentlanguage": "",
18451844
"core.paymentinstant": "Χρησιμοποιήστε το παρακάτω πλήκτρο για να πληρώσετε και να εγγραφείτε μέσα σε λίγα λεπτά!",
18461845
"core.percentagenumber": "{{$a}}%",
18471846
"core.phone": "Τηλέφωνο",

src/assets/lang/en-us.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"core.listsep": ",",
1515
"core.login.loginsteps": "For full access to this site, you first need to create an account.",
1616
"core.notenrolledprofile": "This profile is not available because this user is not enrolled in this course.",
17+
"core.parentlanguage": "en",
1718
"core.paymentinstant": "Use the button below to pay and be enrolled within minutes!",
1819
"core.settings.license": "License",
1920
"core.strftimedate": "%B %d, %Y",

src/assets/lang/en.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1913,7 +1913,6 @@
19131913
"core.openmodinbrowser": "Open {{$a}} in browser",
19141914
"core.othergroups": "Other groups",
19151915
"core.pagea": "Page {{$a}}",
1916-
"core.parentlanguage": "",
19171916
"core.paymentinstant": "Use the button below to pay and be enrolled within minutes!",
19181917
"core.percentagenumber": "{{$a}}%",
19191918
"core.phone": "Phone",

src/assets/lang/es-mx.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1913,7 +1913,7 @@
19131913
"core.openmodinbrowser": "Abrir {{$a}} en navegador",
19141914
"core.othergroups": "Otros grupos",
19151915
"core.pagea": "Página {{$a}}",
1916-
"core.parentlanguage": "",
1916+
"core.parentlanguage": "es",
19171917
"core.paymentinstant": "¡Utilice el botón de abajo para pagar y poder inscribirse en minutos!",
19181918
"core.percentagenumber": "{{$a}}%",
19191919
"core.phone": "Teléfono",

src/assets/lang/es.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1913,7 +1913,6 @@
19131913
"core.openmodinbrowser": "Abrir {{$a}} en el navegador",
19141914
"core.othergroups": "Otros grupos",
19151915
"core.pagea": "Página {{$a}}",
1916-
"core.parentlanguage": "",
19171916
"core.paymentinstant": "¡Utilice el botón de abajo para pagar y poder matricularse en minutos!",
19181917
"core.percentagenumber": "{{$a}}%",
19191918
"core.phone": "Teléfono",

src/assets/lang/fr.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1875,7 +1875,6 @@
18751875
"core.openinbrowser": "Ouvrir dans le navigateur",
18761876
"core.othergroups": "Autres groupes",
18771877
"core.pagea": "Page {{$a}}",
1878-
"core.parentlanguage": "",
18791878
"core.paymentinstant": "Le bouton ci-dessous vous permet de payer et de vous inscrire en quelques minutes !",
18801879
"core.percentagenumber": "{{$a}} %",
18811880
"core.phone": "Téléphone",

0 commit comments

Comments
 (0)