From 5f2c3f607eae07958e9c5ecc8b6166d29e00136f Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Fri, 12 Oct 2018 23:43:38 +0200 Subject: Add plurals translation at browser side (JS) --- include/js_strings.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/js_strings.php b/include/js_strings.php index d9038e838..5ad7c072a 100644 --- a/include/js_strings.php +++ b/include/js_strings.php @@ -38,6 +38,15 @@ function js_strings() { // using the defaults set below if left untranslated, empty strings if // translated to "NONE" and the corresponding language strings // if translated to anything else + 'minutes' => tt('%d minutes', '%d minutes', '%d'), + 'hours' => tt('about %d hours', 'about %d hours', '%d'), + 'days' => tt('%d days', '%d days', '%d'), + 'months' => tt('%d months', '%d months', '%d'), + 'years' => tt('%d years', '%d years', '%d'), + + // get plural function code + 'plural_func' => tf(), + '$t01' => ((t('timeago.prefixAgo') == 'timeago.prefixAgo') ? '' : ((t('timeago.prefixAgo') == 'NONE') ? '' : t('timeago.prefixAgo'))), '$t02' => ((t('timeago.prefixFromNow') == 'timeago.prefixFromNow') ? '' : ((t('timeago.prefixFromNow') == 'NONE') ? '' : t('timeago.prefixFromNow'))), '$t03' => ((t('timeago.suffixAgo') == 'timeago.suffixAgo') ? 'ago' : ((t('timeago.suffixAgo') == 'NONE') ? '' : t('timeago.suffixAgo'))), @@ -46,15 +55,15 @@ function js_strings() { // translatable main strings for jquery.timeago '$t05' => t('less than a minute'), '$t06' => t('about a minute'), - '$t07' => t('%d minutes'), + '$t07' => ta('%d minutes'), '$t08' => t('about an hour'), - '$t09' => t('about %d hours'), + '$t09' => ta('about %d hours'), '$t10' => t('a day'), - '$t11' => t('%d days'), + '$t11' => ta('%d days'), '$t12' => t('about a month'), - '$t13' => t('%d months'), + '$t13' => ta('%d months'), '$t14' => t('about a year'), - '$t15' => t('%d years'), + '$t15' => ta('%d years'), '$t16' => t(' '), // wordSeparator '$t17' => ((t('timeago.numbers') != 'timeago.numbers') ? t('timeago.numbers') : '[]'), -- cgit v1.2.3 From 8cb05a91ab45e9cc572199cd3ab732e41f0b61b8 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Fri, 12 Oct 2018 23:45:52 +0200 Subject: Update language.php --- include/language.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'include') diff --git a/include/language.php b/include/language.php index 69a7e3004..556752cf9 100644 --- a/include/language.php +++ b/include/language.php @@ -254,6 +254,37 @@ function tt($singular, $plural, $count, $ctx = ''){ } } +/** + * @brief Return slash separated string of plurals translation form + * + * @param string $k key in translations array + * @return string + */ +function ta($k){ + + $t = App::$strings[$k]; + if (is_array($t)) { + return implode("/", $t); + } else { + return $k; + } +} + +/** + * @brief Return string_plural_select_xx function code + * + * @return string + */ +function tf() { + + $r = ''; + $lang = str_replace('-', '_', App::$language); + if(function_exists('string_plural_select_'.$lang)) { + $r = trim(shell_exec("sed -n '5p' view/".$lang."/hstrings.php | tr -d '$'")); + } + return $r; +} + /** * @brief Provide a fallback which will not collide with a function defined in * any language file. -- cgit v1.2.3 From 3e19c4ddae0a07bece54b9a4240431e5261bfcc3 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Sat, 13 Oct 2018 00:12:17 +0200 Subject: Update language.php --- include/language.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/language.php b/include/language.php index 556752cf9..72ceb67b0 100644 --- a/include/language.php +++ b/include/language.php @@ -277,12 +277,12 @@ function ta($k){ */ function tf() { - $r = ''; + $r = ""; $lang = str_replace('-', '_', App::$language); - if(function_exists('string_plural_select_'.$lang)) { - $r = trim(shell_exec("sed -n '5p' view/".$lang."/hstrings.php | tr -d '$'")); - } - return $r; + $file = "view/$lang/hstrings.php"; + if(file_exists($file)) + $r = trim(shell_exec("sed -n '5p' ".$file." | tr -d '$'")); + return $r != "" ? $r : "return 0;"; } /** -- cgit v1.2.3 From ae7873260e41640a4d6f3b9181ac1e68eced4176 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Sat, 13 Oct 2018 00:20:23 +0200 Subject: Update language.php --- include/language.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/language.php b/include/language.php index 72ceb67b0..0d3afd494 100644 --- a/include/language.php +++ b/include/language.php @@ -255,7 +255,7 @@ function tt($singular, $plural, $count, $ctx = ''){ } /** - * @brief Return slash separated string of plurals translation form + * @brief Return slash separated string of plurals translation forms * * @param string $k key in translations array * @return string -- cgit v1.2.3 From 5cd9540d5fb156534aff69f572e817e9607d80bb Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Sat, 13 Oct 2018 00:24:04 +0200 Subject: Update language.php --- include/language.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/language.php b/include/language.php index 0d3afd494..ca3aee6c7 100644 --- a/include/language.php +++ b/include/language.php @@ -266,7 +266,7 @@ function ta($k){ if (is_array($t)) { return implode("/", $t); } else { - return $k; + return $t; } } -- cgit v1.2.3 From 16b6b765076336df21dfa06596c436be5a3098d9 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Sat, 13 Oct 2018 00:25:57 +0200 Subject: Update language.php --- include/language.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/language.php b/include/language.php index ca3aee6c7..ef994cbd8 100644 --- a/include/language.php +++ b/include/language.php @@ -264,10 +264,8 @@ function ta($k){ $t = App::$strings[$k]; if (is_array($t)) { - return implode("/", $t); - } else { - return $t; - } + $t = implode("/", $t); + return $t; } /** -- cgit v1.2.3 From 3641ab8c7dfdffb7fdb16013eb6a96128a1bc23a Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Sat, 13 Oct 2018 00:28:12 +0200 Subject: Update language.php --- include/language.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'include') diff --git a/include/language.php b/include/language.php index ef994cbd8..395d92ef1 100644 --- a/include/language.php +++ b/include/language.php @@ -276,8 +276,7 @@ function ta($k){ function tf() { $r = ""; - $lang = str_replace('-', '_', App::$language); - $file = "view/$lang/hstrings.php"; + $file = "view/".str_replace('-', '_', App::$language)."/hstrings.php"; if(file_exists($file)) $r = trim(shell_exec("sed -n '5p' ".$file." | tr -d '$'")); return $r != "" ? $r : "return 0;"; -- cgit v1.2.3 From 137bee9d27c228f6152895a862f3716e4128cb99 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Sat, 13 Oct 2018 00:40:06 +0200 Subject: Update language.php --- include/language.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/language.php b/include/language.php index 395d92ef1..b10e5dde7 100644 --- a/include/language.php +++ b/include/language.php @@ -263,7 +263,7 @@ function tt($singular, $plural, $count, $ctx = ''){ function ta($k){ $t = App::$strings[$k]; - if (is_array($t)) { + if (is_array($t)) $t = implode("/", $t); return $t; } -- cgit v1.2.3 From 0de713ff363cadd706c27606553cc555ddc3a48a Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Sat, 13 Oct 2018 01:08:06 +0200 Subject: Update language.php --- include/language.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/language.php b/include/language.php index b10e5dde7..790c036d3 100644 --- a/include/language.php +++ b/include/language.php @@ -265,7 +265,7 @@ function ta($k){ $t = App::$strings[$k]; if (is_array($t)) $t = implode("/", $t); - return $t; + return ($t == "" ? $k : $t); } /** @@ -279,7 +279,7 @@ function tf() { $file = "view/".str_replace('-', '_', App::$language)."/hstrings.php"; if(file_exists($file)) $r = trim(shell_exec("sed -n '5p' ".$file." | tr -d '$'")); - return $r != "" ? $r : "return 0;"; + return ($r != "" ? $r : "return 0;"); } /** -- cgit v1.2.3 From 8e5189464e59ca1899d7dbd3ee7302d26b25b297 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Sat, 13 Oct 2018 01:36:24 +0200 Subject: Update language.php --- include/language.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/language.php b/include/language.php index 790c036d3..38e38fd69 100644 --- a/include/language.php +++ b/include/language.php @@ -276,9 +276,10 @@ function ta($k){ function tf() { $r = ""; - $file = "view/".str_replace('-', '_', App::$language)."/hstrings.php"; - if(file_exists($file)) - $r = trim(shell_exec("sed -n '5p' ".$file." | tr -d '$'")); + $lang = str_replace('-', '_', App::$language); + $file = "view/$lang/hstrings.php"; + if(function_exists("string_plural_select_".$lang)) + $r = trim(shell_exec("sed -n '5p' ".$file." | grep 'return' | tr -d '$'")); return ($r != "" ? $r : "return 0;"); } -- cgit v1.2.3 From 6ae9ef571ea02aa5b80c575de70ecec1289c21db Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Sat, 13 Oct 2018 02:14:19 +0200 Subject: Update language.php --- include/language.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'include') diff --git a/include/language.php b/include/language.php index 38e38fd69..c56d5acda 100644 --- a/include/language.php +++ b/include/language.php @@ -277,9 +277,8 @@ function tf() { $r = ""; $lang = str_replace('-', '_', App::$language); - $file = "view/$lang/hstrings.php"; if(function_exists("string_plural_select_".$lang)) - $r = trim(shell_exec("sed -n '5p' ".$file." | grep 'return' | tr -d '$'")); + $r = trim(shell_exec("sed -n '5p' view/".$lang."/hstrings.php | grep 'return' | tr -d '$'")); return ($r != "" ? $r : "return 0;"); } -- cgit v1.2.3