From 7eca61f41502c88f050134dec6d8184688b7750a Mon Sep 17 00:00:00 2001 From: TheNewSound Date: Mon, 13 Apr 2020 02:34:41 +0200 Subject: [PATCH 01/13] create autodetector --- .../Commands/LangJsCommand.php | 28 +++++++++++++ .../Generators/LangJsGenerator.php | 42 +++++++++++++++++++ .../LaravelJsLocalizationServiceProvider.php | 3 +- src/config/config.php | 15 +++++++ 4 files changed, 87 insertions(+), 1 deletion(-) diff --git a/src/Mariuzzo/LaravelJsLocalization/Commands/LangJsCommand.php b/src/Mariuzzo/LaravelJsLocalization/Commands/LangJsCommand.php index b98111c..b600166 100644 --- a/src/Mariuzzo/LaravelJsLocalization/Commands/LangJsCommand.php +++ b/src/Mariuzzo/LaravelJsLocalization/Commands/LangJsCommand.php @@ -67,8 +67,25 @@ public function handle() 'no-lib' => $this->option('no-lib'), 'source' => $this->option('source'), 'no-sort' => $this->option('no-sort'), + 'autodetect' => $this->option('autodetect'), ]; + + if ($options['autodetect']) { + $this->info('Autodetect enabled... If this takes too long, edit the glob\'s in config/js-localization.php to be more specific'); + $usageSearchFiles = $this->generator->usageSearchFiles($this->getUsageSearchFiles()); + $this->info(print_r($usageSearchFiles,true)); + $bar = $this->output->createProgressBar(count($usageSearchFiles)); + $bar->start(); + foreach ($usageSearchFiles as $file){ + $this->generator->usageSearch($file); + $bar->advance(); + } + $bar->finish(); + + $this->info(print_r($this->generator->keepMessages,true)); + } + if ($this->generator->generate($target, $options)) { $this->info("Created: {$target}"); @@ -100,6 +117,16 @@ protected function getDefaultPath() return Config::get('localization-js.path', public_path('messages.js')); } + /** + * Return the path to use when no path is specified. + * + * @return string + */ + protected function getUsageSearchFiles() + { + return Config::get('localization-js.usageSearchFiles', []); + } + /** * Return all command options. * @@ -113,6 +140,7 @@ protected function getOptions() ['json', 'j', InputOption::VALUE_NONE, 'Only output the messages json.', null], ['source', 's', InputOption::VALUE_REQUIRED, 'Specifying a custom source folder', null], ['no-sort', 'ns', InputOption::VALUE_NONE, 'Do not sort the messages', null], + ['autodetect', 'a', InputOption::VALUE_NONE, 'Autodetect which messages to include', null], ]; } } diff --git a/src/Mariuzzo/LaravelJsLocalization/Generators/LangJsGenerator.php b/src/Mariuzzo/LaravelJsLocalization/Generators/LangJsGenerator.php index d756989..a71db72 100644 --- a/src/Mariuzzo/LaravelJsLocalization/Generators/LangJsGenerator.php +++ b/src/Mariuzzo/LaravelJsLocalization/Generators/LangJsGenerator.php @@ -35,6 +35,14 @@ class LangJsGenerator */ protected $messagesIncluded = []; + + /** + * List of files/folders the autodetector should search through. + * TODO make protected + * @var array + */ + public $keepMessages = []; + /** * Name of the domain in which all string-translation should be stored under. * More about string-translation: https://laravel.com/docs/master/localization#retrieving-translation-strings @@ -48,6 +56,7 @@ class LangJsGenerator * * @param File $file The file service instance. * @param string $sourcePath The source path of the language files. + * @param array $messagesIncluded List of messages should be included in build. */ public function __construct(File $file, $sourcePath, $messagesIncluded = []) { @@ -71,6 +80,9 @@ public function generate($target, $options) } $messages = $this->getMessages($options['no-sort']); + if ($options['autodetect']) { + $messages = array_intersect_key($messages, $this->keepMessages); + } $this->prepareTarget($target); if ($options['no-lib']) { @@ -108,6 +120,36 @@ protected function sortMessages(&$messages) } } + /** + * Search usage. + * + */ + public function usageSearchFiles($globs) + { + $files = []; + foreach ($globs as $glob) { + $files += $this->file->glob($this->sourcePath.'../../'.$glob); + } + return $files; + } + + public function usageSearch($file) + { + $matches = []; + $content = $this->file->get($file); + preg_match_all("/Lang\.(?:get|has|choice|trans|transChoice)\(['\"]([^'\"]+)/", $content, $matches); + foreach($matches as $match){ + $chain = []; + $ref = &$chain; + foreach(explode(".",$match[1]) as $value){ + $ref[$value]=[]; + $ref = &$ref[$value]; + } + $this->keepMessages = array_merge_recursive($this->keepMessages, $chain); + $this->keepMessages[$this->stringsDomain][] = $match[1]; + } + } + /** * Return all language messages. * diff --git a/src/Mariuzzo/LaravelJsLocalization/LaravelJsLocalizationServiceProvider.php b/src/Mariuzzo/LaravelJsLocalization/LaravelJsLocalizationServiceProvider.php index eab4548..bda9142 100644 --- a/src/Mariuzzo/LaravelJsLocalization/LaravelJsLocalizationServiceProvider.php +++ b/src/Mariuzzo/LaravelJsLocalization/LaravelJsLocalizationServiceProvider.php @@ -76,7 +76,8 @@ public function register() $langs = $app['path.base'].'/resources/lang'; } $messages = $app['config']->get('localization-js.messages'); - $generator = new Generators\LangJsGenerator($files, $langs, $messages); + $usageSearchFiles = $app['config']->get('localization-js.usageSearchFiles'); + $generator = new Generators\LangJsGenerator($files, $langs, $messages, $usageSearchFiles); return new Commands\LangJsCommand($generator); }); diff --git a/src/config/config.php b/src/config/config.php index 77d5500..55060ab 100644 --- a/src/config/config.php +++ b/src/config/config.php @@ -19,4 +19,19 @@ * The default path to use for the generated javascript. */ 'path' => public_path('messages.js'), + + /* + * Specify the files you want the autodetector to search through. + * Use glob format. + * + * 'usageSearchFiles' => [ + * 'validation', + * 'forum/thread', + * ], + */ + 'usageSearchFiles' => [ + 'public/**/.js', + 'resources/assets/**/*.js', + 'resources/views/**/*', + ], ]; From e71655d1d6935cff5ee16e65650ece81c105a6b2 Mon Sep 17 00:00:00 2001 From: TheNewSound Date: Mon, 13 Apr 2020 02:37:14 +0200 Subject: [PATCH 02/13] create autodetector #2 --- .../LaravelJsLocalizationServiceProvider.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Mariuzzo/LaravelJsLocalization/LaravelJsLocalizationServiceProvider.php b/src/Mariuzzo/LaravelJsLocalization/LaravelJsLocalizationServiceProvider.php index bda9142..eab4548 100644 --- a/src/Mariuzzo/LaravelJsLocalization/LaravelJsLocalizationServiceProvider.php +++ b/src/Mariuzzo/LaravelJsLocalization/LaravelJsLocalizationServiceProvider.php @@ -76,8 +76,7 @@ public function register() $langs = $app['path.base'].'/resources/lang'; } $messages = $app['config']->get('localization-js.messages'); - $usageSearchFiles = $app['config']->get('localization-js.usageSearchFiles'); - $generator = new Generators\LangJsGenerator($files, $langs, $messages, $usageSearchFiles); + $generator = new Generators\LangJsGenerator($files, $langs, $messages); return new Commands\LangJsCommand($generator); }); From 68f20159741428b4057512772c68d633167d244e Mon Sep 17 00:00:00 2001 From: TheNewSound Date: Mon, 13 Apr 2020 17:18:37 +0200 Subject: [PATCH 03/13] create autodetector V1.0 --- .../Commands/LangJsCommand.php | 14 ++-- .../Generators/LangJsGenerator.php | 80 +++++++++++++++---- src/config/config.php | 8 +- 3 files changed, 73 insertions(+), 29 deletions(-) diff --git a/src/Mariuzzo/LaravelJsLocalization/Commands/LangJsCommand.php b/src/Mariuzzo/LaravelJsLocalization/Commands/LangJsCommand.php index b600166..389c270 100644 --- a/src/Mariuzzo/LaravelJsLocalization/Commands/LangJsCommand.php +++ b/src/Mariuzzo/LaravelJsLocalization/Commands/LangJsCommand.php @@ -74,7 +74,6 @@ public function handle() if ($options['autodetect']) { $this->info('Autodetect enabled... If this takes too long, edit the glob\'s in config/js-localization.php to be more specific'); $usageSearchFiles = $this->generator->usageSearchFiles($this->getUsageSearchFiles()); - $this->info(print_r($usageSearchFiles,true)); $bar = $this->output->createProgressBar(count($usageSearchFiles)); $bar->start(); foreach ($usageSearchFiles as $file){ @@ -82,8 +81,7 @@ public function handle() $bar->advance(); } $bar->finish(); - - $this->info(print_r($this->generator->keepMessages,true)); + $this->info("\n"); } if ($this->generator->generate($target, $options)) { @@ -118,13 +116,17 @@ protected function getDefaultPath() } /** - * Return the path to use when no path is specified. + * Return the glob's to search. * - * @return string + * @return array */ protected function getUsageSearchFiles() { - return Config::get('localization-js.usageSearchFiles', []); + return Config::get('localization-js.usageSearchFiles', [ + 'public/**/*.js', + 'resources/assets/**/*.js', + 'resources/views/**/*', + ]); } /** diff --git a/src/Mariuzzo/LaravelJsLocalization/Generators/LangJsGenerator.php b/src/Mariuzzo/LaravelJsLocalization/Generators/LangJsGenerator.php index a71db72..76224d6 100644 --- a/src/Mariuzzo/LaravelJsLocalization/Generators/LangJsGenerator.php +++ b/src/Mariuzzo/LaravelJsLocalization/Generators/LangJsGenerator.php @@ -2,6 +2,7 @@ namespace Mariuzzo\LaravelJsLocalization\Generators; +use Illuminate\Contracts\Filesystem\FileNotFoundException; use InvalidArgumentException; use Illuminate\Filesystem\Filesystem as File; use Illuminate\Support\Str; @@ -38,10 +39,10 @@ class LangJsGenerator /** * List of files/folders the autodetector should search through. - * TODO make protected + * * @var array */ - public $keepMessages = []; + protected $keepMessages = []; /** * Name of the domain in which all string-translation should be stored under. @@ -81,7 +82,7 @@ public function generate($target, $options) $messages = $this->getMessages($options['no-sort']); if ($options['autodetect']) { - $messages = array_intersect_key($messages, $this->keepMessages); + $this->filterKeepMessages($messages,$this->keepMessages); } $this->prepareTarget($target); @@ -121,32 +122,77 @@ protected function sortMessages(&$messages) } /** - * Search usage. - * + * Returns array of filenames from input glob's. + * @param $globs Globs to parse + * @return array */ public function usageSearchFiles($globs) { $files = []; foreach ($globs as $glob) { - $files += $this->file->glob($this->sourcePath.'../../'.$glob); + $files += $this->file->glob($this->sourcePath.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.$glob); } return $files; } + /** + * Searches a file for Lang.get / Lang.has / Lang.choice etc. occurances. + * @param $file Absolute path of file to open + * @return void + */ public function usageSearch($file) { - $matches = []; - $content = $this->file->get($file); - preg_match_all("/Lang\.(?:get|has|choice|trans|transChoice)\(['\"]([^'\"]+)/", $content, $matches); - foreach($matches as $match){ - $chain = []; - $ref = &$chain; - foreach(explode(".",$match[1]) as $value){ - $ref[$value]=[]; - $ref = &$ref[$value]; + try { + $content = $this->file->get($file); + preg_match_all("/Lang\.(?:get|has|choice|trans|transChoice)\(['\"]([^'\"]+)/", $content, $matches); + foreach ($matches[1] as $match) { + $chain = []; + $ref = &$chain; + foreach (explode(".", $match) as $value) { + $ref[$value] = []; + $ref = &$ref[$value]; + } + $this->keepMessages = array_merge_recursive($this->keepMessages, $chain); + $this->keepMessages[$this->stringsDomain][$match] = ""; + } + } catch (\Exception $exception) { + return; + } + } + + /** + * Recursively executes array_intersect_key($array1, $array2); + * @param $array1 Array of master keys + * @param $array2 Array to check keys against + * @see array_intersect_key() + * @return array + */ + protected function array_intersect_key_recursive( $array1, $array2 ) { + $array1 = array_intersect_key( $array1, $array2 ); + foreach ( $array1 as $key => $value ) { + if ( is_array( $value ) && is_array( $array2[ $key ] ) ) { + $array1[ $key ] = $this->array_intersect_key_recursive( $value, $array2[ $key ] ); + } + } + return $array1; + } + + /** + * Filters language keys in $messages to only keep keys in $this->keepMessages; + * @param &$messages Array of master keys + * @param &$keep Array of keys to keep + * @return void + */ + protected function filterKeepMessages(&$messages, &$keep){ + $messages = array_filter($messages,function($key) use ($keep) { + if(array_key_exists($key,$keep)||array_key_exists(substr(strstr($key, '.'),1),$keep)){ + return true; } - $this->keepMessages = array_merge_recursive($this->keepMessages, $chain); - $this->keepMessages[$this->stringsDomain][] = $match[1]; + return false; + },ARRAY_FILTER_USE_KEY); + foreach($messages as $key=>$array){ + $skey = substr(strstr($key, '.'),1); + $messages[$key] = $this->array_intersect_key_recursive($array,$keep[$skey]); } } diff --git a/src/config/config.php b/src/config/config.php index 55060ab..4040d9d 100644 --- a/src/config/config.php +++ b/src/config/config.php @@ -22,12 +22,8 @@ /* * Specify the files you want the autodetector to search through. - * Use glob format. - * - * 'usageSearchFiles' => [ - * 'validation', - * 'forum/thread', - * ], + * The autodetector looks for Lang.get / Lang.has / Lang.choice usages in your Javascript files. + * Use glob format. https://en.wikipedia.org/wiki/Glob_(programming) */ 'usageSearchFiles' => [ 'public/**/.js', From dae40edec018c2c6fa2c55af76944f9fa2ee4231 Mon Sep 17 00:00:00 2001 From: TheNewSound Date: Mon, 13 Apr 2020 17:38:19 +0200 Subject: [PATCH 04/13] create autodetector V1.0.1 --- .../Generators/LangJsGenerator.php | 17 +++++++++-------- src/config/config.php | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/Mariuzzo/LaravelJsLocalization/Generators/LangJsGenerator.php b/src/Mariuzzo/LaravelJsLocalization/Generators/LangJsGenerator.php index 76224d6..05d3095 100644 --- a/src/Mariuzzo/LaravelJsLocalization/Generators/LangJsGenerator.php +++ b/src/Mariuzzo/LaravelJsLocalization/Generators/LangJsGenerator.php @@ -2,7 +2,6 @@ namespace Mariuzzo\LaravelJsLocalization\Generators; -use Illuminate\Contracts\Filesystem\FileNotFoundException; use InvalidArgumentException; use Illuminate\Filesystem\Filesystem as File; use Illuminate\Support\Str; @@ -42,7 +41,7 @@ class LangJsGenerator * * @var array */ - protected $keepMessages = []; + public $keepMessages = []; /** * Name of the domain in which all string-translation should be stored under. @@ -82,6 +81,7 @@ public function generate($target, $options) $messages = $this->getMessages($options['no-sort']); if ($options['autodetect']) { + print_r($this->keepMessages); $this->filterKeepMessages($messages,$this->keepMessages); } $this->prepareTarget($target); @@ -123,7 +123,7 @@ protected function sortMessages(&$messages) /** * Returns array of filenames from input glob's. - * @param $globs Globs to parse + * @param array $globs Globs to parse * @return array */ public function usageSearchFiles($globs) @@ -137,7 +137,8 @@ public function usageSearchFiles($globs) /** * Searches a file for Lang.get / Lang.has / Lang.choice etc. occurances. - * @param $file Absolute path of file to open + * Stores an occurence in $this->keepMessages; + * @param string $file Absolute path of file to open * @return void */ public function usageSearch($file) @@ -162,8 +163,8 @@ public function usageSearch($file) /** * Recursively executes array_intersect_key($array1, $array2); - * @param $array1 Array of master keys - * @param $array2 Array to check keys against + * @param array $array1 Array of master keys + * @param array $array2 Array to check keys against * @see array_intersect_key() * @return array */ @@ -179,8 +180,8 @@ protected function array_intersect_key_recursive( $array1, $array2 ) { /** * Filters language keys in $messages to only keep keys in $this->keepMessages; - * @param &$messages Array of master keys - * @param &$keep Array of keys to keep + * @param array &$messages Array of master keys + * @param array &$keep Array of keys to keep * @return void */ protected function filterKeepMessages(&$messages, &$keep){ diff --git a/src/config/config.php b/src/config/config.php index 4040d9d..9220bcc 100644 --- a/src/config/config.php +++ b/src/config/config.php @@ -26,7 +26,7 @@ * Use glob format. https://en.wikipedia.org/wiki/Glob_(programming) */ 'usageSearchFiles' => [ - 'public/**/.js', + 'public/**/*.js', 'resources/assets/**/*.js', 'resources/views/**/*', ], From 97ca0b6b44df971ae810d715d81a76209190744b Mon Sep 17 00:00:00 2001 From: TheNewSound Date: Mon, 13 Apr 2020 17:40:29 +0200 Subject: [PATCH 05/13] create autodetector V1.0.2 --- .../LaravelJsLocalization/Generators/LangJsGenerator.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Mariuzzo/LaravelJsLocalization/Generators/LangJsGenerator.php b/src/Mariuzzo/LaravelJsLocalization/Generators/LangJsGenerator.php index 05d3095..9a01b05 100644 --- a/src/Mariuzzo/LaravelJsLocalization/Generators/LangJsGenerator.php +++ b/src/Mariuzzo/LaravelJsLocalization/Generators/LangJsGenerator.php @@ -81,7 +81,6 @@ public function generate($target, $options) $messages = $this->getMessages($options['no-sort']); if ($options['autodetect']) { - print_r($this->keepMessages); $this->filterKeepMessages($messages,$this->keepMessages); } $this->prepareTarget($target); From 925752b1b98fcd6a4cfc99653449813f4aec82e3 Mon Sep 17 00:00:00 2001 From: TheNewSound Date: Thu, 16 Apr 2020 02:57:10 +0200 Subject: [PATCH 06/13] create autodetector V1.0.3 --- lib/lang.min.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/lang.min.js b/lib/lang.min.js index e77de10..ebe5f1c 100644 --- a/lib/lang.min.js +++ b/lib/lang.min.js @@ -6,4 +6,8 @@ * @site https://github.com/rmariuzzo/Lang.js * @author Rubens Mariuzzo */ -(function(root,factory){"use strict";if(typeof define==="function"&&define.amd){define([],factory)}else if(typeof exports==="object"){module.exports=factory()}else{root.Lang=factory()}})(this,function(){"use strict";function inferLocale(){if(typeof document!=="undefined"&&document.documentElement){return document.documentElement.lang}}function convertNumber(str){if(str==="-Inf"){return-Infinity}else if(str==="+Inf"||str==="Inf"||str==="*"){return Infinity}return parseInt(str,10)}var intervalRegexp=/^({\s*(\-?\d+(\.\d+)?[\s*,\s*\-?\d+(\.\d+)?]*)\s*})|([\[\]])\s*(-Inf|\*|\-?\d+(\.\d+)?)\s*,\s*(\+?Inf|\*|\-?\d+(\.\d+)?)\s*([\[\]])$/;var anyIntervalRegexp=/({\s*(\-?\d+(\.\d+)?[\s*,\s*\-?\d+(\.\d+)?]*)\s*})|([\[\]])\s*(-Inf|\*|\-?\d+(\.\d+)?)\s*,\s*(\+?Inf|\*|\-?\d+(\.\d+)?)\s*([\[\]])/;var defaults={locale:"en"};var Lang=function(options){options=options||{};this.locale=options.locale||inferLocale()||defaults.locale;this.fallback=options.fallback;this.messages=options.messages};Lang.prototype.setMessages=function(messages){this.messages=messages};Lang.prototype.getLocale=function(){return this.locale||this.fallback};Lang.prototype.setLocale=function(locale){this.locale=locale};Lang.prototype.getFallback=function(){return this.fallback};Lang.prototype.setFallback=function(fallback){this.fallback=fallback};Lang.prototype.has=function(key,locale){if(typeof key!=="string"||!this.messages){return false}return this._getMessage(key,locale)!==null};Lang.prototype.get=function(key,replacements,locale){if(!this.has(key,locale)){return key}var message=this._getMessage(key,locale);if(message===null){return key}if(replacements){message=this._applyReplacements(message,replacements)}return message};Lang.prototype.trans=function(key,replacements){return this.get(key,replacements)};Lang.prototype.choice=function(key,number,replacements,locale){replacements=typeof replacements!=="undefined"?replacements:{};replacements.count=number;var message=this.get(key,replacements,locale);if(message===null||message===undefined){return message}var messageParts=message.split("|");var explicitRules=[];for(var i=0;i=leftNumber:count>leftNumber)&&(rightDelimiter==="]"?count<=rightNumber:count=2&&count%10<=4&&(count%100<10||count%100>=20)?1:2;case"cs":case"sk":return count==1?0:count>=2&&count<=4?1:2;case"ga":return count==1?0:count==2?1:2;case"lt":return count%10==1&&count%100!=11?0:count%10>=2&&(count%100<10||count%100>=20)?1:2;case"sl":return count%100==1?0:count%100==2?1:count%100==3||count%100==4?2:3;case"mk":return count%10==1?0:1;case"mt":return count==1?0:count===0||count%100>1&&count%100<11?1:count%100>10&&count%100<20?2:3;case"lv":return count===0?0:count%10==1&&count%100!=11?1:2;case"pl":return count==1?0:count%10>=2&&count%10<=4&&(count%100<12||count%100>14)?1:2;case"cy":return count==1?0:count==2?1:count==8||count==11?2:3;case"ro":return count==1?0:count===0||count%100>0&&count%100<20?1:2;case"ar":return count===0?0:count==1?1:count==2?2:count%100>=3&&count%100<=10?3:count%100>=11&&count%100<=99?4:5;default:return 0}};return Lang}); \ No newline at end of file +(function(root,factory){"use strict";if(typeof define==="function"&&define.amd){define([],factory)}else if(typeof exports==="object"){module.exports=factory()}else{root.Lang=factory()}})(this,function(){"use strict";function inferLocale(){if(typeof document!=="undefined"&&document.documentElement){return document.documentElement.lang}}function convertNumber(str){if(str==="-Inf"){return-Infinity}else if(str==="+Inf"||str==="Inf"||str==="*"){return Infinity}return parseInt(str,10)}var intervalRegexp=/^({\s*(\-?\d+(\.\d+)?[\s*,\s*\-?\d+(\.\d+)?]*)\s*})|([\[\]])\s*(-Inf|\*|\-?\d+(\.\d+)?)\s*,\s*(\+?Inf|\*|\-?\d+(\.\d+)?)\s*([\[\]])$/;var anyIntervalRegexp=/({\s*(\-?\d+(\.\d+)?[\s*,\s*\-?\d+(\.\d+)?]*)\s*})|([\[\]])\s*(-Inf|\*|\-?\d+(\.\d+)?)\s*,\s*(\+?Inf|\*|\-?\d+(\.\d+)?)\s*([\[\]])/;var defaults={locale:"en"};var Lang=function(options){options=options||{};this.locale=options.locale||inferLocale()||defaults.locale;this.fallback=options.fallback;this.messages=options.messages};Lang.prototype.setMessages=function(messages){this.messages=messages};Lang.prototype.getLocale=function(){return this.locale||this.fallback};Lang.prototype.setLocale=function(locale){this.locale=locale};Lang.prototype.getFallback=function(){return this.fallback};Lang.prototype.setFallback=function(fallback){this.fallback=fallback};Lang.prototype.has=function(key,locale){if(typeof key!=="string"||!this.messages){return false}return this._getMessage(key,locale)!==null};Lang.prototype.get=function(key,replacements,locale){if(!this.has(key,locale)){return key}var message=this._getMessage(key,locale);if(message===null){return key}if(replacements){message=this._applyReplacements(message,replacements)}return message};Lang.prototype.trans=function(key,replacements){return this.get(key,replacements)};Lang.prototype.choice=function(key,number,replacements,locale){replacements=typeof replacements!=="undefined"?replacements:{};replacements.count=number;var message=this.get(key,replacements,locale);if(message===null||message===undefined){return message}var messageParts=message.split("|");var explicitRules=[];for(var i=0;i=leftNumber:count>leftNumber)&&(rightDelimiter==="]"?count<=rightNumber:count=2&&count%10<=4&&(count%100<10||count%100>=20)?1:2;case"cs":case"sk":return count==1?0:count>=2&&count<=4?1:2;case"ga":return count==1?0:count==2?1:2;case"lt":return count%10==1&&count%100!=11?0:count%10>=2&&(count%100<10||count%100>=20)?1:2;case"sl":return count%100==1?0:count%100==2?1:count%100==3||count%100==4?2:3;case"mk":return count%10==1?0:1;case"mt":return count==1?0:count===0||count%100>1&&count%100<11?1:count%100>10&&count%100<20?2:3;case"lv":return count===0?0:count%10==1&&count%100!=11?1:2;case"pl":return count==1?0:count%10>=2&&count%10<=4&&(count%100<12||count%100>14)?1:2;case"cy":return count==1?0:count==2?1:count==8||count==11?2:3;case"ro":return count==1?0:count===0||count%100>0&&count%100<20?1:2;case"ar":return count===0?0:count==1?1:count==2?2:count%100>=3&&count%100<=10?3:count%100>=11&&count%100<=99?4:5;default:return 0}};return Lang}); From 5bbd3f3116aee895e2b5756f9b55a9d358d0b471 Mon Sep 17 00:00:00 2001 From: TheNewSound Date: Thu, 16 Apr 2020 03:10:46 +0200 Subject: [PATCH 07/13] create autodetector V1.0.5 --- lib/lang.min.js | 4 ++-- .../LaravelJsLocalization/Generators/LangJsGenerator.php | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/lang.min.js b/lib/lang.min.js index ebe5f1c..646b599 100644 --- a/lib/lang.min.js +++ b/lib/lang.min.js @@ -7,7 +7,7 @@ * @author Rubens Mariuzzo */ (function(root,factory){"use strict";if(typeof define==="function"&&define.amd){define([],factory)}else if(typeof exports==="object"){module.exports=factory()}else{root.Lang=factory()}})(this,function(){"use strict";function inferLocale(){if(typeof document!=="undefined"&&document.documentElement){return document.documentElement.lang}}function convertNumber(str){if(str==="-Inf"){return-Infinity}else if(str==="+Inf"||str==="Inf"||str==="*"){return Infinity}return parseInt(str,10)}var intervalRegexp=/^({\s*(\-?\d+(\.\d+)?[\s*,\s*\-?\d+(\.\d+)?]*)\s*})|([\[\]])\s*(-Inf|\*|\-?\d+(\.\d+)?)\s*,\s*(\+?Inf|\*|\-?\d+(\.\d+)?)\s*([\[\]])$/;var anyIntervalRegexp=/({\s*(\-?\d+(\.\d+)?[\s*,\s*\-?\d+(\.\d+)?]*)\s*})|([\[\]])\s*(-Inf|\*|\-?\d+(\.\d+)?)\s*,\s*(\+?Inf|\*|\-?\d+(\.\d+)?)\s*([\[\]])/;var defaults={locale:"en"};var Lang=function(options){options=options||{};this.locale=options.locale||inferLocale()||defaults.locale;this.fallback=options.fallback;this.messages=options.messages};Lang.prototype.setMessages=function(messages){this.messages=messages};Lang.prototype.getLocale=function(){return this.locale||this.fallback};Lang.prototype.setLocale=function(locale){this.locale=locale};Lang.prototype.getFallback=function(){return this.fallback};Lang.prototype.setFallback=function(fallback){this.fallback=fallback};Lang.prototype.has=function(key,locale){if(typeof key!=="string"||!this.messages){return false}return this._getMessage(key,locale)!==null};Lang.prototype.get=function(key,replacements,locale){if(!this.has(key,locale)){return key}var message=this._getMessage(key,locale);if(message===null){return key}if(replacements){message=this._applyReplacements(message,replacements)}return message};Lang.prototype.trans=function(key,replacements){return this.get(key,replacements)};Lang.prototype.choice=function(key,number,replacements,locale){replacements=typeof replacements!=="undefined"?replacements:{};replacements.count=number;var message=this.get(key,replacements,locale);if(message===null||message===undefined){return message}var messageParts=message.split("|");var explicitRules=[];for(var i=0;i=leftNumber:count>leftNumber)&&(rightDelimiter==="]"?count<=rightNumber:count=2&&count%10<=4&&(count%100<10||count%100>=20)?1:2;case"cs":case"sk":return count==1?0:count>=2&&count<=4?1:2;case"ga":return count==1?0:count==2?1:2;case"lt":return count%10==1&&count%100!=11?0:count%10>=2&&(count%100<10||count%100>=20)?1:2;case"sl":return count%100==1?0:count%100==2?1:count%100==3||count%100==4?2:3;case"mk":return count%10==1?0:1;case"mt":return count==1?0:count===0||count%100>1&&count%100<11?1:count%100>10&&count%100<20?2:3;case"lv":return count===0?0:count%10==1&&count%100!=11?1:2;case"pl":return count==1?0:count%10>=2&&count%10<=4&&(count%100<12||count%100>14)?1:2;case"cy":return count==1?0:count==2?1:count==8||count==11?2:3;case"ro":return count==1?0:count===0||count%100>0&&count%100<20?1:2;case"ar":return count===0?0:count==1?1:count==2?2:count%100>=3&&count%100<=10?3:count%100>=11&&count%100<=99?4:5;default:return 0}};return Lang}); diff --git a/src/Mariuzzo/LaravelJsLocalization/Generators/LangJsGenerator.php b/src/Mariuzzo/LaravelJsLocalization/Generators/LangJsGenerator.php index 9a01b05..b53f989 100644 --- a/src/Mariuzzo/LaravelJsLocalization/Generators/LangJsGenerator.php +++ b/src/Mariuzzo/LaravelJsLocalization/Generators/LangJsGenerator.php @@ -152,8 +152,12 @@ public function usageSearch($file) $ref[$value] = []; $ref = &$ref[$value]; } - $this->keepMessages = array_merge_recursive($this->keepMessages, $chain); - $this->keepMessages[$this->stringsDomain][$match] = ""; + if(array_key_exists($this->stringsDomain,$chain)){ + $this->keepMessages[$this->stringsDomain][substr($match, strlen($this->stringsDomain)+1)] = ""; + }else { + $this->keepMessages = array_merge_recursive($this->keepMessages, $chain); + $this->keepMessages[$this->stringsDomain][$match] = ""; + } } } catch (\Exception $exception) { return; From 312a0fb524f420567349f20b7e694dd9a5d57242 Mon Sep 17 00:00:00 2001 From: TheNewSound Date: Thu, 16 Apr 2020 03:14:41 +0200 Subject: [PATCH 08/13] create autodetector V1.1.0 --- lib/lang.min.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/lang.min.js b/lib/lang.min.js index 646b599..d2b24bb 100644 --- a/lib/lang.min.js +++ b/lib/lang.min.js @@ -6,8 +6,4 @@ * @site https://github.com/rmariuzzo/Lang.js * @author Rubens Mariuzzo */ -(function(root,factory){"use strict";if(typeof define==="function"&&define.amd){define([],factory)}else if(typeof exports==="object"){module.exports=factory()}else{root.Lang=factory()}})(this,function(){"use strict";function inferLocale(){if(typeof document!=="undefined"&&document.documentElement){return document.documentElement.lang}}function convertNumber(str){if(str==="-Inf"){return-Infinity}else if(str==="+Inf"||str==="Inf"||str==="*"){return Infinity}return parseInt(str,10)}var intervalRegexp=/^({\s*(\-?\d+(\.\d+)?[\s*,\s*\-?\d+(\.\d+)?]*)\s*})|([\[\]])\s*(-Inf|\*|\-?\d+(\.\d+)?)\s*,\s*(\+?Inf|\*|\-?\d+(\.\d+)?)\s*([\[\]])$/;var anyIntervalRegexp=/({\s*(\-?\d+(\.\d+)?[\s*,\s*\-?\d+(\.\d+)?]*)\s*})|([\[\]])\s*(-Inf|\*|\-?\d+(\.\d+)?)\s*,\s*(\+?Inf|\*|\-?\d+(\.\d+)?)\s*([\[\]])/;var defaults={locale:"en"};var Lang=function(options){options=options||{};this.locale=options.locale||inferLocale()||defaults.locale;this.fallback=options.fallback;this.messages=options.messages};Lang.prototype.setMessages=function(messages){this.messages=messages};Lang.prototype.getLocale=function(){return this.locale||this.fallback};Lang.prototype.setLocale=function(locale){this.locale=locale};Lang.prototype.getFallback=function(){return this.fallback};Lang.prototype.setFallback=function(fallback){this.fallback=fallback};Lang.prototype.has=function(key,locale){if(typeof key!=="string"||!this.messages){return false}return this._getMessage(key,locale)!==null};Lang.prototype.get=function(key,replacements,locale){if(!this.has(key,locale)){return key}var message=this._getMessage(key,locale);if(message===null){return key}if(replacements){message=this._applyReplacements(message,replacements)}return message};Lang.prototype.trans=function(key,replacements){return this.get(key,replacements)};Lang.prototype.choice=function(key,number,replacements,locale){replacements=typeof replacements!=="undefined"?replacements:{};replacements.count=number;var message=this.get(key,replacements,locale);if(message===null||message===undefined){return message}var messageParts=message.split("|");var explicitRules=[];for(var i=0;i=leftNumber:count>leftNumber)&&(rightDelimiter==="]"?count<=rightNumber:count=2&&count%10<=4&&(count%100<10||count%100>=20)?1:2;case"cs":case"sk":return count==1?0:count>=2&&count<=4?1:2;case"ga":return count==1?0:count==2?1:2;case"lt":return count%10==1&&count%100!=11?0:count%10>=2&&(count%100<10||count%100>=20)?1:2;case"sl":return count%100==1?0:count%100==2?1:count%100==3||count%100==4?2:3;case"mk":return count%10==1?0:1;case"mt":return count==1?0:count===0||count%100>1&&count%100<11?1:count%100>10&&count%100<20?2:3;case"lv":return count===0?0:count%10==1&&count%100!=11?1:2;case"pl":return count==1?0:count%10>=2&&count%10<=4&&(count%100<12||count%100>14)?1:2;case"cy":return count==1?0:count==2?1:count==8||count==11?2:3;case"ro":return count==1?0:count===0||count%100>0&&count%100<20?1:2;case"ar":return count===0?0:count==1?1:count==2?2:count%100>=3&&count%100<=10?3:count%100>=11&&count%100<=99?4:5;default:return 0}};return Lang}); +(function(root,factory){"use strict";if(typeof define==="function"&&define.amd){define([],factory)}else if(typeof exports==="object"){module.exports=factory()}else{root.Lang=factory()}})(this,function(){"use strict";function inferLocale(){if(typeof document!=="undefined"&&document.documentElement){return document.documentElement.lang}}function convertNumber(str){if(str==="-Inf"){return-Infinity}else if(str==="+Inf"||str==="Inf"||str==="*"){return Infinity}return parseInt(str,10)}var intervalRegexp=/^({\s*(\-?\d+(\.\d+)?[\s*,\s*\-?\d+(\.\d+)?]*)\s*})|([\[\]])\s*(-Inf|\*|\-?\d+(\.\d+)?)\s*,\s*(\+?Inf|\*|\-?\d+(\.\d+)?)\s*([\[\]])$/;var anyIntervalRegexp=/({\s*(\-?\d+(\.\d+)?[\s*,\s*\-?\d+(\.\d+)?]*)\s*})|([\[\]])\s*(-Inf|\*|\-?\d+(\.\d+)?)\s*,\s*(\+?Inf|\*|\-?\d+(\.\d+)?)\s*([\[\]])/;var defaults={locale:"en"};var Lang=function(options){options=options||{};this.locale=options.locale||inferLocale()||defaults.locale;this.fallback=options.fallback;this.messages=options.messages};Lang.prototype.setMessages=function(messages){this.messages=messages};Lang.prototype.getLocale=function(){return this.locale||this.fallback};Lang.prototype.setLocale=function(locale){this.locale=locale};Lang.prototype.getFallback=function(){return this.fallback};Lang.prototype.setFallback=function(fallback){this.fallback=fallback};Lang.prototype.has=function(key,locale){if(typeof key!=="string"||!this.messages){return false}return this._getMessage(key,locale)!==null};Lang.prototype.get=function(key,replacements,locale){if(!this.has(key,locale)){return key}var message=this._getMessage(key,locale);if(message===null){return key}if(replacements){message=this._applyReplacements(message,replacements)}return message};Lang.prototype.trans=function(key,replacements){return this.get(key,replacements)};Lang.prototype.choice=function(key,number,replacements,locale){replacements=typeof replacements!=="undefined"?replacements:{};replacements.count=number;var message=this.get(key,replacements,locale);if(message===null||message===undefined){return message}var messageParts=message.split("|");var explicitRules=[];for(var i=0;i=leftNumber:count>leftNumber)&&(rightDelimiter==="]"?count<=rightNumber:count=2&&count%10<=4&&(count%100<10||count%100>=20)?1:2;case"cs":case"sk":return count==1?0:count>=2&&count<=4?1:2;case"ga":return count==1?0:count==2?1:2;case"lt":return count%10==1&&count%100!=11?0:count%10>=2&&(count%100<10||count%100>=20)?1:2;case"sl":return count%100==1?0:count%100==2?1:count%100==3||count%100==4?2:3;case"mk":return count%10==1?0:1;case"mt":return count==1?0:count===0||count%100>1&&count%100<11?1:count%100>10&&count%100<20?2:3;case"lv":return count===0?0:count%10==1&&count%100!=11?1:2;case"pl":return count==1?0:count%10>=2&&count%10<=4&&(count%100<12||count%100>14)?1:2;case"cy":return count==1?0:count==2?1:count==8||count==11?2:3;case"ro":return count==1?0:count===0||count%100>0&&count%100<20?1:2;case"ar":return count===0?0:count==1?1:count==2?2:count%100>=3&&count%100<=10?3:count%100>=11&&count%100<=99?4:5;default:return 0}};return Lang}); From 9d946a65786d1228255410b8f5eb35dc28ec4dd9 Mon Sep 17 00:00:00 2001 From: TheNewSound Date: Thu, 16 Apr 2020 03:30:24 +0200 Subject: [PATCH 09/13] create autodetector V1.1.1 --- lib/lang.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/lang.min.js b/lib/lang.min.js index d2b24bb..ab8db5c 100644 --- a/lib/lang.min.js +++ b/lib/lang.min.js @@ -6,4 +6,4 @@ * @site https://github.com/rmariuzzo/Lang.js * @author Rubens Mariuzzo */ -(function(root,factory){"use strict";if(typeof define==="function"&&define.amd){define([],factory)}else if(typeof exports==="object"){module.exports=factory()}else{root.Lang=factory()}})(this,function(){"use strict";function inferLocale(){if(typeof document!=="undefined"&&document.documentElement){return document.documentElement.lang}}function convertNumber(str){if(str==="-Inf"){return-Infinity}else if(str==="+Inf"||str==="Inf"||str==="*"){return Infinity}return parseInt(str,10)}var intervalRegexp=/^({\s*(\-?\d+(\.\d+)?[\s*,\s*\-?\d+(\.\d+)?]*)\s*})|([\[\]])\s*(-Inf|\*|\-?\d+(\.\d+)?)\s*,\s*(\+?Inf|\*|\-?\d+(\.\d+)?)\s*([\[\]])$/;var anyIntervalRegexp=/({\s*(\-?\d+(\.\d+)?[\s*,\s*\-?\d+(\.\d+)?]*)\s*})|([\[\]])\s*(-Inf|\*|\-?\d+(\.\d+)?)\s*,\s*(\+?Inf|\*|\-?\d+(\.\d+)?)\s*([\[\]])/;var defaults={locale:"en"};var Lang=function(options){options=options||{};this.locale=options.locale||inferLocale()||defaults.locale;this.fallback=options.fallback;this.messages=options.messages};Lang.prototype.setMessages=function(messages){this.messages=messages};Lang.prototype.getLocale=function(){return this.locale||this.fallback};Lang.prototype.setLocale=function(locale){this.locale=locale};Lang.prototype.getFallback=function(){return this.fallback};Lang.prototype.setFallback=function(fallback){this.fallback=fallback};Lang.prototype.has=function(key,locale){if(typeof key!=="string"||!this.messages){return false}return this._getMessage(key,locale)!==null};Lang.prototype.get=function(key,replacements,locale){if(!this.has(key,locale)){return key}var message=this._getMessage(key,locale);if(message===null){return key}if(replacements){message=this._applyReplacements(message,replacements)}return message};Lang.prototype.trans=function(key,replacements){return this.get(key,replacements)};Lang.prototype.choice=function(key,number,replacements,locale){replacements=typeof replacements!=="undefined"?replacements:{};replacements.count=number;var message=this.get(key,replacements,locale);if(message===null||message===undefined){return message}var messageParts=message.split("|");var explicitRules=[];for(var i=0;i=leftNumber:count>leftNumber)&&(rightDelimiter==="]"?count<=rightNumber:count=2&&count%10<=4&&(count%100<10||count%100>=20)?1:2;case"cs":case"sk":return count==1?0:count>=2&&count<=4?1:2;case"ga":return count==1?0:count==2?1:2;case"lt":return count%10==1&&count%100!=11?0:count%10>=2&&(count%100<10||count%100>=20)?1:2;case"sl":return count%100==1?0:count%100==2?1:count%100==3||count%100==4?2:3;case"mk":return count%10==1?0:1;case"mt":return count==1?0:count===0||count%100>1&&count%100<11?1:count%100>10&&count%100<20?2:3;case"lv":return count===0?0:count%10==1&&count%100!=11?1:2;case"pl":return count==1?0:count%10>=2&&count%10<=4&&(count%100<12||count%100>14)?1:2;case"cy":return count==1?0:count==2?1:count==8||count==11?2:3;case"ro":return count==1?0:count===0||count%100>0&&count%100<20?1:2;case"ar":return count===0?0:count==1?1:count==2?2:count%100>=3&&count%100<=10?3:count%100>=11&&count%100<=99?4:5;default:return 0}};return Lang}); +(function(root,factory){"use strict";if(typeof define==="function"&&define.amd){define([],factory)}else if(typeof exports==="object"){module.exports=factory()}else{root.Lang=factory()}})(this,function(){"use strict";function inferLocale(){if(typeof document!=="undefined"&&document.documentElement){return document.documentElement.lang}}function convertNumber(str){if(str==="-Inf"){return-Infinity}else if(str==="+Inf"||str==="Inf"||str==="*"){return Infinity}return parseInt(str,10)}var intervalRegexp=/^({\s*(\-?\d+(\.\d+)?[\s*,\s*\-?\d+(\.\d+)?]*)\s*})|([\[\]])\s*(-Inf|\*|\-?\d+(\.\d+)?)\s*,\s*(\+?Inf|\*|\-?\d+(\.\d+)?)\s*([\[\]])$/;var anyIntervalRegexp=/({\s*(\-?\d+(\.\d+)?[\s*,\s*\-?\d+(\.\d+)?]*)\s*})|([\[\]])\s*(-Inf|\*|\-?\d+(\.\d+)?)\s*,\s*(\+?Inf|\*|\-?\d+(\.\d+)?)\s*([\[\]])/;var defaults={locale:"en"};var Lang=function(options){options=options||{};this.locale=options.locale||inferLocale()||defaults.locale;this.fallback=options.fallback;this.messages=options.messages};Lang.prototype.setMessages=function(messages){this.messages=messages};Lang.prototype.getLocale=function(){return this.locale||this.fallback};Lang.prototype.setLocale=function(locale){this.locale=locale};Lang.prototype.getFallback=function(){return this.fallback};Lang.prototype.setFallback=function(fallback){this.fallback=fallback};Lang.prototype.has=function(key,locale){if(typeof key!=="string"||!this.messages){return false}return this._getMessage(key,locale)!==null};Lang.prototype.get=function(key,replacements,locale){if(!this.has(key,locale)){return key}var message=this._getMessage(key,locale);if(message===null){return key}if(replacements){message=this._applyReplacements(message,replacements)}return message};Lang.prototype.trans=function(key,replacements){return this.get(key,replacements)};Lang.prototype.choice=function(key,number,replacements,locale){replacements=typeof replacements!=="undefined"?replacements:{};replacements.count=number;var message=this.get(key,replacements,locale);if(message===null||message===undefined){return message}var messageParts=message.split("|");var explicitRules=[];for(var i=0;i=leftNumber:count>leftNumber)&&(rightDelimiter==="]"?count<=rightNumber:count=2&&count%10<=4&&(count%100<10||count%100>=20)?1:2;case"cs":case"sk":return count==1?0:count>=2&&count<=4?1:2;case"ga":return count==1?0:count==2?1:2;case"lt":return count%10==1&&count%100!=11?0:count%10>=2&&(count%100<10||count%100>=20)?1:2;case"sl":return count%100==1?0:count%100==2?1:count%100==3||count%100==4?2:3;case"mk":return count%10==1?0:1;case"mt":return count==1?0:count===0||count%100>1&&count%100<11?1:count%100>10&&count%100<20?2:3;case"lv":return count===0?0:count%10==1&&count%100!=11?1:2;case"pl":return count==1?0:count%10>=2&&count%10<=4&&(count%100<12||count%100>14)?1:2;case"cy":return count==1?0:count==2?1:count==8||count==11?2:3;case"ro":return count==1?0:count===0||count%100>0&&count%100<20?1:2;case"ar":return count===0?0:count==1?1:count==2?2:count%100>=3&&count%100<=10?3:count%100>=11&&count%100<=99?4:5;default:return 0}};return Lang}); From ac0762e172ebf5b3edd5afc3e231481dc1b50fae Mon Sep 17 00:00:00 2001 From: TheNewSound Date: Thu, 16 Apr 2020 03:58:11 +0200 Subject: [PATCH 10/13] create autodetector V1.1.1 --- lib/lang.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/lang.min.js b/lib/lang.min.js index ab8db5c..8b4417e 100644 --- a/lib/lang.min.js +++ b/lib/lang.min.js @@ -6,4 +6,4 @@ * @site https://github.com/rmariuzzo/Lang.js * @author Rubens Mariuzzo */ -(function(root,factory){"use strict";if(typeof define==="function"&&define.amd){define([],factory)}else if(typeof exports==="object"){module.exports=factory()}else{root.Lang=factory()}})(this,function(){"use strict";function inferLocale(){if(typeof document!=="undefined"&&document.documentElement){return document.documentElement.lang}}function convertNumber(str){if(str==="-Inf"){return-Infinity}else if(str==="+Inf"||str==="Inf"||str==="*"){return Infinity}return parseInt(str,10)}var intervalRegexp=/^({\s*(\-?\d+(\.\d+)?[\s*,\s*\-?\d+(\.\d+)?]*)\s*})|([\[\]])\s*(-Inf|\*|\-?\d+(\.\d+)?)\s*,\s*(\+?Inf|\*|\-?\d+(\.\d+)?)\s*([\[\]])$/;var anyIntervalRegexp=/({\s*(\-?\d+(\.\d+)?[\s*,\s*\-?\d+(\.\d+)?]*)\s*})|([\[\]])\s*(-Inf|\*|\-?\d+(\.\d+)?)\s*,\s*(\+?Inf|\*|\-?\d+(\.\d+)?)\s*([\[\]])/;var defaults={locale:"en"};var Lang=function(options){options=options||{};this.locale=options.locale||inferLocale()||defaults.locale;this.fallback=options.fallback;this.messages=options.messages};Lang.prototype.setMessages=function(messages){this.messages=messages};Lang.prototype.getLocale=function(){return this.locale||this.fallback};Lang.prototype.setLocale=function(locale){this.locale=locale};Lang.prototype.getFallback=function(){return this.fallback};Lang.prototype.setFallback=function(fallback){this.fallback=fallback};Lang.prototype.has=function(key,locale){if(typeof key!=="string"||!this.messages){return false}return this._getMessage(key,locale)!==null};Lang.prototype.get=function(key,replacements,locale){if(!this.has(key,locale)){return key}var message=this._getMessage(key,locale);if(message===null){return key}if(replacements){message=this._applyReplacements(message,replacements)}return message};Lang.prototype.trans=function(key,replacements){return this.get(key,replacements)};Lang.prototype.choice=function(key,number,replacements,locale){replacements=typeof replacements!=="undefined"?replacements:{};replacements.count=number;var message=this.get(key,replacements,locale);if(message===null||message===undefined){return message}var messageParts=message.split("|");var explicitRules=[];for(var i=0;i=leftNumber:count>leftNumber)&&(rightDelimiter==="]"?count<=rightNumber:count=2&&count%10<=4&&(count%100<10||count%100>=20)?1:2;case"cs":case"sk":return count==1?0:count>=2&&count<=4?1:2;case"ga":return count==1?0:count==2?1:2;case"lt":return count%10==1&&count%100!=11?0:count%10>=2&&(count%100<10||count%100>=20)?1:2;case"sl":return count%100==1?0:count%100==2?1:count%100==3||count%100==4?2:3;case"mk":return count%10==1?0:1;case"mt":return count==1?0:count===0||count%100>1&&count%100<11?1:count%100>10&&count%100<20?2:3;case"lv":return count===0?0:count%10==1&&count%100!=11?1:2;case"pl":return count==1?0:count%10>=2&&count%10<=4&&(count%100<12||count%100>14)?1:2;case"cy":return count==1?0:count==2?1:count==8||count==11?2:3;case"ro":return count==1?0:count===0||count%100>0&&count%100<20?1:2;case"ar":return count===0?0:count==1?1:count==2?2:count%100>=3&&count%100<=10?3:count%100>=11&&count%100<=99?4:5;default:return 0}};return Lang}); +(function(root,factory){"use strict";if(typeof define==="function"&&define.amd){define([],factory)}else if(typeof exports==="object"){module.exports=factory()}else{root.Lang=factory()}})(this,function(){"use strict";function inferLocale(){if(typeof document!=="undefined"&&document.documentElement){return document.documentElement.lang}}function convertNumber(str){if(str==="-Inf"){return-Infinity}else if(str==="+Inf"||str==="Inf"||str==="*"){return Infinity}return parseInt(str,10)}var intervalRegexp=/^({\s*(\-?\d+(\.\d+)?[\s*,\s*\-?\d+(\.\d+)?]*)\s*})|([\[\]])\s*(-Inf|\*|\-?\d+(\.\d+)?)\s*,\s*(\+?Inf|\*|\-?\d+(\.\d+)?)\s*([\[\]])$/;var anyIntervalRegexp=/({\s*(\-?\d+(\.\d+)?[\s*,\s*\-?\d+(\.\d+)?]*)\s*})|([\[\]])\s*(-Inf|\*|\-?\d+(\.\d+)?)\s*,\s*(\+?Inf|\*|\-?\d+(\.\d+)?)\s*([\[\]])/;var defaults={locale:"en"};var Lang=function(options){options=options||{};this.locale=options.locale||inferLocale()||defaults.locale;this.fallback=options.fallback;this.messages=options.messages};Lang.prototype.setMessages=function(messages){this.messages=messages};Lang.prototype.getLocale=function(){return this.locale||this.fallback};Lang.prototype.setLocale=function(locale){this.locale=locale};Lang.prototype.getFallback=function(){return this.fallback};Lang.prototype.setFallback=function(fallback){this.fallback=fallback};Lang.prototype.has=function(key,locale){if(typeof key!=="string"||!this.messages){return false}return this._getMessage(key,locale)!==null};Lang.prototype.get=function(key,replacements,locale){if(!this.has(key,locale)){return key}var message=this._getMessage(key,locale);if(message===null){return key}if(replacements){message=this._applyReplacements(message,replacements)}return message};Lang.prototype.trans=function(key,replacements){return this.get(key,replacements)};Lang.prototype.choice=function(key,number,replacements,locale){replacements=typeof replacements!=="undefined"?replacements:{};replacements.count=number;var message=this.get(key,replacements,locale);if(message===null||message===undefined){return message}var messageParts=message.split("|");var explicitRules=[];for(var i=0;i=leftNumber:count>leftNumber)&&(rightDelimiter==="]"?count<=rightNumber:count=2&&count%10<=4&&(count%100<10||count%100>=20)?1:2;case"cs":case"sk":return count==1?0:count>=2&&count<=4?1:2;case"ga":return count==1?0:count==2?1:2;case"lt":return count%10==1&&count%100!=11?0:count%10>=2&&(count%100<10||count%100>=20)?1:2;case"sl":return count%100==1?0:count%100==2?1:count%100==3||count%100==4?2:3;case"mk":return count%10==1?0:1;case"mt":return count==1?0:count===0||count%100>1&&count%100<11?1:count%100>10&&count%100<20?2:3;case"lv":return count===0?0:count%10==1&&count%100!=11?1:2;case"pl":return count==1?0:count%10>=2&&count%10<=4&&(count%100<12||count%100>14)?1:2;case"cy":return count==1?0:count==2?1:count==8||count==11?2:3;case"ro":return count==1?0:count===0||count%100>0&&count%100<20?1:2;case"ar":return count===0?0:count==1?1:count==2?2:count%100>=3&&count%100<=10?3:count%100>=11&&count%100<=99?4:5;default:return 0}};return Lang}); From c848266c584e06a01497cc84d3340656c4157c5a Mon Sep 17 00:00:00 2001 From: TheNewSound Date: Thu, 16 Apr 2020 03:59:33 +0200 Subject: [PATCH 11/13] create autodetector V1.1.2 --- lib/lang.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/lang.min.js b/lib/lang.min.js index 8b4417e..90806e5 100644 --- a/lib/lang.min.js +++ b/lib/lang.min.js @@ -6,4 +6,4 @@ * @site https://github.com/rmariuzzo/Lang.js * @author Rubens Mariuzzo */ -(function(root,factory){"use strict";if(typeof define==="function"&&define.amd){define([],factory)}else if(typeof exports==="object"){module.exports=factory()}else{root.Lang=factory()}})(this,function(){"use strict";function inferLocale(){if(typeof document!=="undefined"&&document.documentElement){return document.documentElement.lang}}function convertNumber(str){if(str==="-Inf"){return-Infinity}else if(str==="+Inf"||str==="Inf"||str==="*"){return Infinity}return parseInt(str,10)}var intervalRegexp=/^({\s*(\-?\d+(\.\d+)?[\s*,\s*\-?\d+(\.\d+)?]*)\s*})|([\[\]])\s*(-Inf|\*|\-?\d+(\.\d+)?)\s*,\s*(\+?Inf|\*|\-?\d+(\.\d+)?)\s*([\[\]])$/;var anyIntervalRegexp=/({\s*(\-?\d+(\.\d+)?[\s*,\s*\-?\d+(\.\d+)?]*)\s*})|([\[\]])\s*(-Inf|\*|\-?\d+(\.\d+)?)\s*,\s*(\+?Inf|\*|\-?\d+(\.\d+)?)\s*([\[\]])/;var defaults={locale:"en"};var Lang=function(options){options=options||{};this.locale=options.locale||inferLocale()||defaults.locale;this.fallback=options.fallback;this.messages=options.messages};Lang.prototype.setMessages=function(messages){this.messages=messages};Lang.prototype.getLocale=function(){return this.locale||this.fallback};Lang.prototype.setLocale=function(locale){this.locale=locale};Lang.prototype.getFallback=function(){return this.fallback};Lang.prototype.setFallback=function(fallback){this.fallback=fallback};Lang.prototype.has=function(key,locale){if(typeof key!=="string"||!this.messages){return false}return this._getMessage(key,locale)!==null};Lang.prototype.get=function(key,replacements,locale){if(!this.has(key,locale)){return key}var message=this._getMessage(key,locale);if(message===null){return key}if(replacements){message=this._applyReplacements(message,replacements)}return message};Lang.prototype.trans=function(key,replacements){return this.get(key,replacements)};Lang.prototype.choice=function(key,number,replacements,locale){replacements=typeof replacements!=="undefined"?replacements:{};replacements.count=number;var message=this.get(key,replacements,locale);if(message===null||message===undefined){return message}var messageParts=message.split("|");var explicitRules=[];for(var i=0;i=leftNumber:count>leftNumber)&&(rightDelimiter==="]"?count<=rightNumber:count=2&&count%10<=4&&(count%100<10||count%100>=20)?1:2;case"cs":case"sk":return count==1?0:count>=2&&count<=4?1:2;case"ga":return count==1?0:count==2?1:2;case"lt":return count%10==1&&count%100!=11?0:count%10>=2&&(count%100<10||count%100>=20)?1:2;case"sl":return count%100==1?0:count%100==2?1:count%100==3||count%100==4?2:3;case"mk":return count%10==1?0:1;case"mt":return count==1?0:count===0||count%100>1&&count%100<11?1:count%100>10&&count%100<20?2:3;case"lv":return count===0?0:count%10==1&&count%100!=11?1:2;case"pl":return count==1?0:count%10>=2&&count%10<=4&&(count%100<12||count%100>14)?1:2;case"cy":return count==1?0:count==2?1:count==8||count==11?2:3;case"ro":return count==1?0:count===0||count%100>0&&count%100<20?1:2;case"ar":return count===0?0:count==1?1:count==2?2:count%100>=3&&count%100<=10?3:count%100>=11&&count%100<=99?4:5;default:return 0}};return Lang}); +(function(root,factory){"use strict";if(typeof define==="function"&&define.amd){define([],factory)}else if(typeof exports==="object"){module.exports=factory()}else{root.Lang=factory()}})(this,function(){"use strict";function inferLocale(){if(typeof document!=="undefined"&&document.documentElement){return document.documentElement.lang}}function convertNumber(str){if(str==="-Inf"){return-Infinity}else if(str==="+Inf"||str==="Inf"||str==="*"){return Infinity}return parseInt(str,10)}var intervalRegexp=/^({\s*(\-?\d+(\.\d+)?[\s*,\s*\-?\d+(\.\d+)?]*)\s*})|([\[\]])\s*(-Inf|\*|\-?\d+(\.\d+)?)\s*,\s*(\+?Inf|\*|\-?\d+(\.\d+)?)\s*([\[\]])$/;var anyIntervalRegexp=/({\s*(\-?\d+(\.\d+)?[\s*,\s*\-?\d+(\.\d+)?]*)\s*})|([\[\]])\s*(-Inf|\*|\-?\d+(\.\d+)?)\s*,\s*(\+?Inf|\*|\-?\d+(\.\d+)?)\s*([\[\]])/;var defaults={locale:"en"};var Lang=function(options){options=options||{};this.locale=options.locale||inferLocale()||defaults.locale;this.fallback=options.fallback;this.messages=options.messages};Lang.prototype.setMessages=function(messages){this.messages=messages};Lang.prototype.getLocale=function(){return this.locale||this.fallback};Lang.prototype.setLocale=function(locale){this.locale=locale};Lang.prototype.getFallback=function(){return this.fallback};Lang.prototype.setFallback=function(fallback){this.fallback=fallback};Lang.prototype.has=function(key,locale){if(typeof key!=="string"||!this.messages){return false}return this._getMessage(key,locale)!==null};Lang.prototype.get=function(key,replacements,locale){if(!this.has(key,locale)){return key}var message=this._getMessage(key,locale);if(message===null){return key}if(replacements){message=this._applyReplacements(message,replacements)}return message};Lang.prototype.trans=function(key,replacements){return this.get(key,replacements)};Lang.prototype.choice=function(key,number,replacements,locale){replacements=typeof replacements!=="undefined"?replacements:{};replacements.count=number;var message=this.get(key,replacements,locale);if(message===null||message===undefined){return message}var messageParts=message.split("|");var explicitRules=[];for(var i=0;i=leftNumber:count>leftNumber)&&(rightDelimiter==="]"?count<=rightNumber:count=2&&count%10<=4&&(count%100<10||count%100>=20)?1:2;case"cs":case"sk":return count==1?0:count>=2&&count<=4?1:2;case"ga":return count==1?0:count==2?1:2;case"lt":return count%10==1&&count%100!=11?0:count%10>=2&&(count%100<10||count%100>=20)?1:2;case"sl":return count%100==1?0:count%100==2?1:count%100==3||count%100==4?2:3;case"mk":return count%10==1?0:1;case"mt":return count==1?0:count===0||count%100>1&&count%100<11?1:count%100>10&&count%100<20?2:3;case"lv":return count===0?0:count%10==1&&count%100!=11?1:2;case"pl":return count==1?0:count%10>=2&&count%10<=4&&(count%100<12||count%100>14)?1:2;case"cy":return count==1?0:count==2?1:count==8||count==11?2:3;case"ro":return count==1?0:count===0||count%100>0&&count%100<20?1:2;case"ar":return count===0?0:count==1?1:count==2?2:count%100>=3&&count%100<=10?3:count%100>=11&&count%100<=99?4:5;default:return 0}};return Lang}); From 70eb2287ba5d089090a01a34f5adda8da95156ec Mon Sep 17 00:00:00 2001 From: TheNewSound Date: Thu, 16 Apr 2020 04:09:55 +0200 Subject: [PATCH 12/13] create autodetector final v1.3 --- lib/lang.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/lang.min.js b/lib/lang.min.js index 90806e5..ab27d21 100644 --- a/lib/lang.min.js +++ b/lib/lang.min.js @@ -6,4 +6,4 @@ * @site https://github.com/rmariuzzo/Lang.js * @author Rubens Mariuzzo */ -(function(root,factory){"use strict";if(typeof define==="function"&&define.amd){define([],factory)}else if(typeof exports==="object"){module.exports=factory()}else{root.Lang=factory()}})(this,function(){"use strict";function inferLocale(){if(typeof document!=="undefined"&&document.documentElement){return document.documentElement.lang}}function convertNumber(str){if(str==="-Inf"){return-Infinity}else if(str==="+Inf"||str==="Inf"||str==="*"){return Infinity}return parseInt(str,10)}var intervalRegexp=/^({\s*(\-?\d+(\.\d+)?[\s*,\s*\-?\d+(\.\d+)?]*)\s*})|([\[\]])\s*(-Inf|\*|\-?\d+(\.\d+)?)\s*,\s*(\+?Inf|\*|\-?\d+(\.\d+)?)\s*([\[\]])$/;var anyIntervalRegexp=/({\s*(\-?\d+(\.\d+)?[\s*,\s*\-?\d+(\.\d+)?]*)\s*})|([\[\]])\s*(-Inf|\*|\-?\d+(\.\d+)?)\s*,\s*(\+?Inf|\*|\-?\d+(\.\d+)?)\s*([\[\]])/;var defaults={locale:"en"};var Lang=function(options){options=options||{};this.locale=options.locale||inferLocale()||defaults.locale;this.fallback=options.fallback;this.messages=options.messages};Lang.prototype.setMessages=function(messages){this.messages=messages};Lang.prototype.getLocale=function(){return this.locale||this.fallback};Lang.prototype.setLocale=function(locale){this.locale=locale};Lang.prototype.getFallback=function(){return this.fallback};Lang.prototype.setFallback=function(fallback){this.fallback=fallback};Lang.prototype.has=function(key,locale){if(typeof key!=="string"||!this.messages){return false}return this._getMessage(key,locale)!==null};Lang.prototype.get=function(key,replacements,locale){if(!this.has(key,locale)){return key}var message=this._getMessage(key,locale);if(message===null){return key}if(replacements){message=this._applyReplacements(message,replacements)}return message};Lang.prototype.trans=function(key,replacements){return this.get(key,replacements)};Lang.prototype.choice=function(key,number,replacements,locale){replacements=typeof replacements!=="undefined"?replacements:{};replacements.count=number;var message=this.get(key,replacements,locale);if(message===null||message===undefined){return message}var messageParts=message.split("|");var explicitRules=[];for(var i=0;i=leftNumber:count>leftNumber)&&(rightDelimiter==="]"?count<=rightNumber:count=2&&count%10<=4&&(count%100<10||count%100>=20)?1:2;case"cs":case"sk":return count==1?0:count>=2&&count<=4?1:2;case"ga":return count==1?0:count==2?1:2;case"lt":return count%10==1&&count%100!=11?0:count%10>=2&&(count%100<10||count%100>=20)?1:2;case"sl":return count%100==1?0:count%100==2?1:count%100==3||count%100==4?2:3;case"mk":return count%10==1?0:1;case"mt":return count==1?0:count===0||count%100>1&&count%100<11?1:count%100>10&&count%100<20?2:3;case"lv":return count===0?0:count%10==1&&count%100!=11?1:2;case"pl":return count==1?0:count%10>=2&&count%10<=4&&(count%100<12||count%100>14)?1:2;case"cy":return count==1?0:count==2?1:count==8||count==11?2:3;case"ro":return count==1?0:count===0||count%100>0&&count%100<20?1:2;case"ar":return count===0?0:count==1?1:count==2?2:count%100>=3&&count%100<=10?3:count%100>=11&&count%100<=99?4:5;default:return 0}};return Lang}); +(function(root,factory){"use strict";if(typeof define==="function"&&define.amd){define([],factory)}else if(typeof exports==="object"){module.exports=factory()}else{root.Lang=factory()}})(this,function(){"use strict";function inferLocale(){if(typeof document!=="undefined"&&document.documentElement){return document.documentElement.lang}}function convertNumber(str){if(str==="-Inf"){return-Infinity}else if(str==="+Inf"||str==="Inf"||str==="*"){return Infinity}return parseInt(str,10)}var intervalRegexp=/^({\s*(\-?\d+(\.\d+)?[\s*,\s*\-?\d+(\.\d+)?]*)\s*})|([\[\]])\s*(-Inf|\*|\-?\d+(\.\d+)?)\s*,\s*(\+?Inf|\*|\-?\d+(\.\d+)?)\s*([\[\]])$/;var anyIntervalRegexp=/({\s*(\-?\d+(\.\d+)?[\s*,\s*\-?\d+(\.\d+)?]*)\s*})|([\[\]])\s*(-Inf|\*|\-?\d+(\.\d+)?)\s*,\s*(\+?Inf|\*|\-?\d+(\.\d+)?)\s*([\[\]])/;var defaults={locale:"en"};var Lang=function(options){options=options||{};this.locale=options.locale||inferLocale()||defaults.locale;this.fallback=options.fallback;this.messages=options.messages};Lang.prototype.setMessages=function(messages){this.messages=messages};Lang.prototype.getLocale=function(){return this.locale||this.fallback};Lang.prototype.setLocale=function(locale){this.locale=locale};Lang.prototype.getFallback=function(){return this.fallback};Lang.prototype.setFallback=function(fallback){this.fallback=fallback};Lang.prototype.has=function(key,locale){if(typeof key!=="string"||!this.messages){return false}return this._getMessage(key,locale)!==null};Lang.prototype.get=function(key,replacements,locale){if(!this.has(key,locale)){return key}var message=this._getMessage(key,locale);if(message===null){return key}if(replacements){message=this._applyReplacements(message,replacements)}return message};Lang.prototype.trans=function(key,replacements){return this.get(key,replacements)};Lang.prototype.choice=function(key,number,replacements,locale){replacements=typeof replacements!=="undefined"?replacements:{};replacements.count=number;var message=this.get(key,replacements,locale);if(message===null||message===undefined){return message}var messageParts=message.split("|");var explicitRules=[];for(var i=0;i=leftNumber:count>leftNumber)&&(rightDelimiter==="]"?count<=rightNumber:count=2&&count%10<=4&&(count%100<10||count%100>=20)?1:2;case"cs":case"sk":return count==1?0:count>=2&&count<=4?1:2;case"ga":return count==1?0:count==2?1:2;case"lt":return count%10==1&&count%100!=11?0:count%10>=2&&(count%100<10||count%100>=20)?1:2;case"sl":return count%100==1?0:count%100==2?1:count%100==3||count%100==4?2:3;case"mk":return count%10==1?0:1;case"mt":return count==1?0:count===0||count%100>1&&count%100<11?1:count%100>10&&count%100<20?2:3;case"lv":return count===0?0:count%10==1&&count%100!=11?1:2;case"pl":return count==1?0:count%10>=2&&count%10<=4&&(count%100<12||count%100>14)?1:2;case"cy":return count==1?0:count==2?1:count==8||count==11?2:3;case"ro":return count==1?0:count===0||count%100>0&&count%100<20?1:2;case"ar":return count===0?0:count==1?1:count==2?2:count%100>=3&&count%100<=10?3:count%100>=11&&count%100<=99?4:5;default:return 0}};return Lang}); From ba512962153854747c1120122491a767cd834cc9 Mon Sep 17 00:00:00 2001 From: TheNewSound Date: Thu, 16 Apr 2020 04:13:35 +0200 Subject: [PATCH 13/13] create autodetector final v1.3 --- lib/lang.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/lang.min.js b/lib/lang.min.js index ab27d21..316c4ba 100644 --- a/lib/lang.min.js +++ b/lib/lang.min.js @@ -6,4 +6,4 @@ * @site https://github.com/rmariuzzo/Lang.js * @author Rubens Mariuzzo */ -(function(root,factory){"use strict";if(typeof define==="function"&&define.amd){define([],factory)}else if(typeof exports==="object"){module.exports=factory()}else{root.Lang=factory()}})(this,function(){"use strict";function inferLocale(){if(typeof document!=="undefined"&&document.documentElement){return document.documentElement.lang}}function convertNumber(str){if(str==="-Inf"){return-Infinity}else if(str==="+Inf"||str==="Inf"||str==="*"){return Infinity}return parseInt(str,10)}var intervalRegexp=/^({\s*(\-?\d+(\.\d+)?[\s*,\s*\-?\d+(\.\d+)?]*)\s*})|([\[\]])\s*(-Inf|\*|\-?\d+(\.\d+)?)\s*,\s*(\+?Inf|\*|\-?\d+(\.\d+)?)\s*([\[\]])$/;var anyIntervalRegexp=/({\s*(\-?\d+(\.\d+)?[\s*,\s*\-?\d+(\.\d+)?]*)\s*})|([\[\]])\s*(-Inf|\*|\-?\d+(\.\d+)?)\s*,\s*(\+?Inf|\*|\-?\d+(\.\d+)?)\s*([\[\]])/;var defaults={locale:"en"};var Lang=function(options){options=options||{};this.locale=options.locale||inferLocale()||defaults.locale;this.fallback=options.fallback;this.messages=options.messages};Lang.prototype.setMessages=function(messages){this.messages=messages};Lang.prototype.getLocale=function(){return this.locale||this.fallback};Lang.prototype.setLocale=function(locale){this.locale=locale};Lang.prototype.getFallback=function(){return this.fallback};Lang.prototype.setFallback=function(fallback){this.fallback=fallback};Lang.prototype.has=function(key,locale){if(typeof key!=="string"||!this.messages){return false}return this._getMessage(key,locale)!==null};Lang.prototype.get=function(key,replacements,locale){if(!this.has(key,locale)){return key}var message=this._getMessage(key,locale);if(message===null){return key}if(replacements){message=this._applyReplacements(message,replacements)}return message};Lang.prototype.trans=function(key,replacements){return this.get(key,replacements)};Lang.prototype.choice=function(key,number,replacements,locale){replacements=typeof replacements!=="undefined"?replacements:{};replacements.count=number;var message=this.get(key,replacements,locale);if(message===null||message===undefined){return message}var messageParts=message.split("|");var explicitRules=[];for(var i=0;i=leftNumber:count>leftNumber)&&(rightDelimiter==="]"?count<=rightNumber:count=2&&count%10<=4&&(count%100<10||count%100>=20)?1:2;case"cs":case"sk":return count==1?0:count>=2&&count<=4?1:2;case"ga":return count==1?0:count==2?1:2;case"lt":return count%10==1&&count%100!=11?0:count%10>=2&&(count%100<10||count%100>=20)?1:2;case"sl":return count%100==1?0:count%100==2?1:count%100==3||count%100==4?2:3;case"mk":return count%10==1?0:1;case"mt":return count==1?0:count===0||count%100>1&&count%100<11?1:count%100>10&&count%100<20?2:3;case"lv":return count===0?0:count%10==1&&count%100!=11?1:2;case"pl":return count==1?0:count%10>=2&&count%10<=4&&(count%100<12||count%100>14)?1:2;case"cy":return count==1?0:count==2?1:count==8||count==11?2:3;case"ro":return count==1?0:count===0||count%100>0&&count%100<20?1:2;case"ar":return count===0?0:count==1?1:count==2?2:count%100>=3&&count%100<=10?3:count%100>=11&&count%100<=99?4:5;default:return 0}};return Lang}); +(function(root,factory){"use strict";if(typeof define==="function"&&define.amd){define([],factory)}else if(typeof exports==="object"){module.exports=factory()}else{root.Lang=factory()}})(this,function(){"use strict";function inferLocale(){if(typeof document!=="undefined"&&document.documentElement){return document.documentElement.lang}}function convertNumber(str){if(str==="-Inf"){return-Infinity}else if(str==="+Inf"||str==="Inf"||str==="*"){return Infinity}return parseInt(str,10)}var intervalRegexp=/^({\s*(\-?\d+(\.\d+)?[\s*,\s*\-?\d+(\.\d+)?]*)\s*})|([\[\]])\s*(-Inf|\*|\-?\d+(\.\d+)?)\s*,\s*(\+?Inf|\*|\-?\d+(\.\d+)?)\s*([\[\]])$/;var anyIntervalRegexp=/({\s*(\-?\d+(\.\d+)?[\s*,\s*\-?\d+(\.\d+)?]*)\s*})|([\[\]])\s*(-Inf|\*|\-?\d+(\.\d+)?)\s*,\s*(\+?Inf|\*|\-?\d+(\.\d+)?)\s*([\[\]])/;var defaults={locale:"en"};var Lang=function(options){options=options||{};this.locale=options.locale||inferLocale()||defaults.locale;this.fallback=options.fallback;this.messages=options.messages};Lang.prototype.setMessages=function(messages){this.messages=messages};Lang.prototype.getLocale=function(){return this.locale||this.fallback};Lang.prototype.setLocale=function(locale){this.locale=locale};Lang.prototype.getFallback=function(){return this.fallback};Lang.prototype.setFallback=function(fallback){this.fallback=fallback};Lang.prototype.has=function(key,locale){if(typeof key!=="string"||!this.messages){return false}return this._getMessage(key,locale)!==null};Lang.prototype.get=function(key,replacements,locale){if(!this.has(key,locale)){return key}var message=this._getMessage(key,locale);if(message===null){return key}if(replacements){message=this._applyReplacements(message,replacements)}return message};Lang.prototype.trans=function(key,replacements){return this.get(key,replacements)};Lang.prototype.choice=function(key,number,replacements,locale){replacements=typeof replacements!=="undefined"?replacements:{};replacements.count=number;var message=this.get(key,replacements,locale);if(message===null||message===undefined){return message}var messageParts=message.split("|");var explicitRules=[];for(var i=0;i=leftNumber:count>leftNumber)&&(rightDelimiter==="]"?count<=rightNumber:count=2&&count%10<=4&&(count%100<10||count%100>=20)?1:2;case"cs":case"sk":return count==1?0:count>=2&&count<=4?1:2;case"ga":return count==1?0:count==2?1:2;case"lt":return count%10==1&&count%100!=11?0:count%10>=2&&(count%100<10||count%100>=20)?1:2;case"sl":return count%100==1?0:count%100==2?1:count%100==3||count%100==4?2:3;case"mk":return count%10==1?0:1;case"mt":return count==1?0:count===0||count%100>1&&count%100<11?1:count%100>10&&count%100<20?2:3;case"lv":return count===0?0:count%10==1&&count%100!=11?1:2;case"pl":return count==1?0:count%10>=2&&count%10<=4&&(count%100<12||count%100>14)?1:2;case"cy":return count==1?0:count==2?1:count==8||count==11?2:3;case"ro":return count==1?0:count===0||count%100>0&&count%100<20?1:2;case"ar":return count===0?0:count==1?1:count==2?2:count%100>=3&&count%100<=10?3:count%100>=11&&count%100<=99?4:5;default:return 0}};return Lang});