From 5c0d31873afef00ce7f6a4e1160f50f659f6b8c0 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Sat, 13 Oct 2018 19:48:45 +0200 Subject: Add date/time plurals translation in JavaScript --- include/js_strings.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/js_strings.php b/include/js_strings.php index d9038e838..17de06b31 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'))), -- cgit v1.2.3 From 729d0d536875b503fdc468cc0c9e89f2aa6b577c Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Sat, 13 Oct 2018 19:50:09 +0200 Subject: Update language.php --- include/language.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/include/language.php b/include/language.php index 69a7e3004..18b942bce 100644 --- a/include/language.php +++ b/include/language.php @@ -254,6 +254,32 @@ function tt($singular, $plural, $count, $ctx = ''){ } } +/** + * @brief Return slash separated string of plurals translation forms + * + * @param string $k key in translations array + * @return string + */ +function ta($k){ + + $t = App::$strings[$k]; + if (is_array($t)) + $t = implode("/", $t); + return ($t == "" ? $k : $t); +} + +/** + * @brief Return string_plural_select_xx function code + * + * @return string + */ + +function tf() { + + $s = "plural_function_code"; + return (x(App::$strings, $s) ? App::$strings[$s] : "return 0;"); +} + /** * @brief Provide a fallback which will not collide with a function defined in * any language file. -- cgit v1.2.3 From f68674b35a70bceb4e9d06f47776ae85bfe11652 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Sat, 13 Oct 2018 19:51:33 +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 3ac4337aec929d6cdf12a1645ab142dc5279bd6c Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Sat, 13 Oct 2018 19:52:59 +0200 Subject: Update main.js --- view/js/main.js | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/view/js/main.js b/view/js/main.js index 48277f5cc..0c16d0560 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -44,25 +44,27 @@ $(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){var str=aStr['t07'].split("/")[tf(value)]; return (str ? str : aStr['t07']);}, + hour : aStr['t08'], + hours : function(value){var str=aStr['t09'].split("/")[tf(value)]; return (str ? str : aStr['t09']);}, + day : aStr['t10'], + days : function(value){var str=aStr['t11'].split("/")[tf(value)]; return (str ? str : aStr['t11']);}, + month : aStr['t12'], + months : function(value){var str=aStr['t13'].split("/")[tf(value)]; return (str ? str : aStr['t13']);}, + year : aStr['t14'], + years : function(value){var str=aStr['t15'].split("/")[tf(value)]; return (str ? str : aStr['t15']);}, + wordSeparator : aStr['t16'], + numbers : aStr['t17'], + }; //mod_mail only $(".mail-conv-detail .autotime").timeago(); -- cgit v1.2.3 From e96e3dc6e6fe7e2e0d5131d8168f048e24216962 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Sat, 13 Oct 2018 19:54:13 +0200 Subject: Update po2php.php --- util/po2php.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/util/po2php.php b/util/po2php.php index 50941c062..4aea1c943 100644 --- a/util/po2php.php +++ b/util/po2php.php @@ -58,8 +58,9 @@ function po2php_run($argc,$argv) { $out .= 'function string_plural_select_' . $lang . '($n){'."\n"; $out .= ' return '.$cond.';'."\n"; $out .= '}}'."\n"; - - $out .= 'App::$rtl = ' . intval($rtl) ; + + $out .= 'App::$rtl = ' . intval($rtl) . ";\n" ; + $out .= 'App::$strings["plural_function_code"] = "return ' . str_replace("$", "", $cond) . ';"'; } if ($k!="" && substr($l,0,7)=="msgstr "){ -- cgit v1.2.3 From 54bdf59dde11e5154c696c33719aaf3976b74e6c Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Sat, 13 Oct 2018 19:56:07 +0200 Subject: Update js_strings.php --- include/js_strings.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/js_strings.php b/include/js_strings.php index 17de06b31..c053e5666 100644 --- a/include/js_strings.php +++ b/include/js_strings.php @@ -55,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