Skip to content

Commit

Permalink
Language fallback improvement
Browse files Browse the repository at this point in the history
- Changes for following best practice for CI4 localization
- Norwegian and Urdu languages now working again
- Sort languages by alphabet in config
  • Loading branch information
BudsieBuds authored and jekkos committed May 18, 2024
1 parent bfbccc9 commit 235845d
Show file tree
Hide file tree
Showing 318 changed files with 61 additions and 58 deletions.
29 changes: 15 additions & 14 deletions app/Config/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class App extends BaseConfig
* strings (like currency markers, numbers, etc), that your program
* should run under for this request.
*/
public string $defaultLocale = 'en-US';
public string $defaultLocale = 'en';

/**
* --------------------------------------------------------------------------
Expand Down Expand Up @@ -159,44 +159,45 @@ class App extends BaseConfig
public array $supportedLocales = [
'ar-EG',
'ar-LB',
'az-AZ',
'az',
'bg',
'bs-BA',
'bs',
'cs',
'da',
'de',
'de-CH',
'de-DE',
'el',
'en',
'en-GB',
'en-US',
'es',
'fa_IR',
'es-ES',
'es-MX',
'fa',
'fr',
'he',
'hr-HR',
'hu-HU',
'hu',
'hy',
'id',
'it',
'km',
'lo',
'ml',
'nb_NO',
'nl',
'nb',
'nl-BE',
'nl-NL',
'pl',
'pt-BR',
'ro',
'ru',
'sv',
'ta',
'th',
'tl-PH',
'tl',
'tr',
'uk-UA',
'ur-PK',
'uk',
'ur',
'vi',
'zh-HANS',
'zh-Hans',
'zh-Hant',
];

Expand Down
2 changes: 1 addition & 1 deletion app/Config/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,4 @@
const MAX_PRECISION = 1e14;
const DEFAULT_PRECISION = 2;
const DEFAULT_LANGUAGE = 'english';
const DEFAULT_LANGUAGE_CODE = 'en-US';
const DEFAULT_LANGUAGE_CODE = 'en';
2 changes: 1 addition & 1 deletion app/Database/tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ INSERT INTO `ospos_app_config` (`key`, `value`) VALUES
('theme', 'flatly'),
('statistics', '1'),
('language', 'english'),
('language_code', 'en-US');
('language_code', 'en');


-- --------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion app/Events/Load_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function load_config(): void
if(current_language_code() == null || current_language() == null || !$language_exists) //TODO: current_language() is undefined
{
$config->language = 'english';
$config->language_code = 'en-US';
$config->language_code = 'en';
}

$language = Services::language();
Expand Down
42 changes: 22 additions & 20 deletions app/Helpers/locale_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,50 +58,52 @@ function current_language(bool $load_system_language = false): string
*/
function get_languages(): array
{
return [
$languages = [
'ar-EG:arabic' => 'Arabic (Egypt)',
'ar-LB:arabic' => 'Arabic (Lebanon)',
'az-AZ:azerbaijani' => 'Azerbaijani (Azerbaijan)',
'az:azerbaijani' => 'Azerbaijani',
'bg:bulgarian' => 'Bulgarian',
'bs-BA:bosnian' => 'Bosnian',
'bs:bosnian' => 'Bosnian',
'cs:czech' => 'Czech',
'da:danish' => 'Danish',
'de:german' => 'German (Germany)',
'de-CH:german' => 'German (Swiss)',
'de-CH:german' => 'German (Switzerland)',
'de-DE:german' => 'German (Germany)',
'el:greek' => 'Greek',
'en-GB:english' => 'English (Great Britain)',
'en-US:english' => 'English (United States)',
'es:spanish' => 'Spanish',
'en:english' => 'English (United States)',
'en-GB:english' => 'English (United Kingdom)',
'es-ES:spanish' => 'Spanish (Spain)',
'es-MX:spanish' => 'Spanish (Mexico)',
'fa:persian' => 'Persian',
'fr:french' => 'French',
'fa-IR:persian' => 'Farsi (Iran)',
'he:english' => 'Hebrew',
'he:hebrew' => 'Hebrew',
'hr-HR:croatian' => 'Croatian (Croatia)',
'hu-HU:hungarian' => 'Hungarian (Hungary)',
'hu:hungarian' => 'Hungarian',
'hy:armenian' => 'Armenian',
'id:indonesian' => 'Indonesian',
'it:italian' => 'Italian',
'km:khmer' => 'Central Khmer (Cambodia)',
'lo:lao' => 'Lao (Laos)',
'ml:malay' => 'Malay',
'km:centralkhmer' => 'Central Khmer',
'lo:lao' => 'Lao',
'ml:malayalam' => 'Malayalam',
'nb:norwegian' => 'Norwegian',
'nl:dutch' => 'Dutch',
'nl-BE:dutch' => 'Dutch (Belgium)',
'nl-NL:dutch' => 'Dutch (Netherlands)',
'pl:polish' => 'Polish',
'pt-BR:portuguese' => 'Portuguese (Brazil)',
'ro:romanian' => 'Romanian',
'ru:russian' => 'Russian',
'sv:swedish' => 'Swedish',
'ta:tamil' => 'Tamil',
'th:thai' => 'Thai',
'tl-PH:talong' => 'Tagalog (Philippines)',
'tl:tagalog' => 'Tagalog',
'tr:turkish' => 'Turkish',
'uk-UA:ukrainian' => 'Ukrainian',
'ur-PK:urdu' => 'Urdu (Islamic Republic of Pakistan)',
'uk:ukrainian' => 'Ukrainian',
'ur:urdu' => 'Urdu',
'vi:vietnamese' => 'Vietnamese',
'zh-Hans:simplified-chinese' => 'Chinese Simplified Script',
'zh-Hant:traditional-chinese' => 'Chinese Traditional Script'
'zh-Hans:simplified-chinese' => 'Chinese (Simplified)',
'zh-Hant:traditional-chinese' => 'Chinese (Traditional)'
];
asort($languages);
return $languages;
}

/**
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 11 additions & 11 deletions app/Language/es/index.html → app/Language/es-ES/index.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>403 Prohibido</title>
</head>
<body>

<p>El acceso a los directorios está prohibido.</p>

</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>403 Prohibido</title>
</head>
<body>

<p>El acceso a los directorios está prohibido.</p>

</body>
</html>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 10 additions & 10 deletions app/Language/uk-UA/index.html → app/Language/uk/index.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>

<p>Directory access is forbidden.</p>

</body>
<!DOCTYPE html>
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>

<p>Directory access is forbidden.</p>

</body>
</html>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 235845d

Please sign in to comment.