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(-) 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(+) 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 de59300aafe33f9a026360baa3e921992864ec73 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Fri, 12 Oct 2018 23:51:01 +0200 Subject: Update js_strings.tpl --- view/tpl/js_strings.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/view/tpl/js_strings.tpl b/view/tpl/js_strings.tpl index 01fc3f993..f7425ba98 100755 --- a/view/tpl/js_strings.tpl +++ b/view/tpl/js_strings.tpl @@ -34,7 +34,7 @@ 'name_ok1' : "{{$name_ok1}}", 'name_ok2' : "{{$name_ok2}}", - + 'plural_func' : "{{$plural_func}}", 't01' : "{{$t01}}", 't02' : "{{$t02}}", -- 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(-) 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 3dfe604ba0f6cba394095ae7e4500410faf927f3 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Sat, 13 Oct 2018 00:15:48 +0200 Subject: Update main.js --- view/js/main.js | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/view/js/main.js b/view/js/main.js index 48277f5cc..3e81ba0e4 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -44,25 +44,28 @@ $(document).ready(function() { $(document).on('click', '.conversation-settings-link', getConversationSettings); $(document).on('click', '#settings_module_ajax_submit', postConversationSettings); - jQuery.timeago.settings.strings = { - prefixAgo : aStr['t01'], - prefixFromNow : aStr['t02'], - suffixAgo : aStr['t03'], - suffixFromNow : aStr['t04'], - seconds : aStr['t05'], - minute : aStr['t06'], - minutes : aStr['t07'], - hour : aStr['t08'], - hours : aStr['t09'], - day : aStr['t10'], - days : aStr['t11'], - month : aStr['t12'], - months : aStr['t13'], - year : aStr['t14'], - years : aStr['t15'], - wordSeparator : aStr['t16'], - numbers : aStr['t17'], - }; + var tf = new Function('n', aStr['plural_func']); + + jQuery.timeago.settings.strings = { + prefixAgo : aStr['t01'], + prefixFromNow : aStr['t02'], + suffixAgo : aStr['t03'], + suffixFromNow : aStr['t04'], + seconds : aStr['t05'], + minute : aStr['t06'], + minutes : function(value){return aStr['t07'].split("/")[tf(value)];}, + hour : aStr['t08'], + hours : function(value){return aStr['t09'].split("/")[tf(value)];}, + day : aStr['t10'], + days : function(value){return aStr['t11'].split("/")[tf(value)];}, + month : aStr['t12'], + months : function(value){return aStr['t13'].split("/")[tf(value)];}, + year : aStr['t14'], + years : function(value){return aStr['t15'].split("/")[tf(value)];}, + wordSeparator : aStr['t16'], + numbers : aStr['t17'], + }; + //mod_mail only $(".mail-conv-detail .autotime").timeago(); -- 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(-) 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(-) 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(-) 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(-) 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(-) 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(-) 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(-) 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(-) 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