diff --git a/libs/i18next/.npmignore b/libs/i18next/.npmignore new file mode 100644 index 00000000..d7025695 --- /dev/null +++ b/libs/i18next/.npmignore @@ -0,0 +1 @@ +release diff --git a/libs/i18next/CHANGELOG.md b/libs/i18next/CHANGELOG.md new file mode 100644 index 00000000..557719bd --- /dev/null +++ b/libs/i18next/CHANGELOG.md @@ -0,0 +1,241 @@ +### 1.8.2 +- fixes build of commonjs with jquery file + +### 1.8.0 +- [BREAKING] adds custom build for commonjs with jquery...default will be without require for jquery +- fixes issue [issue 360](https://github.com/i18next/i18next/issues/360) +- expose applyReplacement on api +- save resources to localStorage when useLocaleStore is true +- add support on key is a number +- added getResourceBundle to API +- allow multiple post-processors +- fallback to singular if no plural is found fixes issue [issue 356](https://github.com/i18next/i18next/issues/356) +- access localstorage always with try catch fixes issue [issue 353](https://github.com/i18next/i18next/issues/353) + +### 1.7.7 +- fixes issue with stack overflow on t(lng, count) +- fixes empty value fallback when processing secondary ns + +### 1.7.6 +- fixes lng detection (i18next-client on npm) + +### 1.7.5 +- adds option to define defaultOptions, which gets merged into t(options) [issue 307](https://github.com/i18next/i18next/issues/307) +- optimization of size added by plural rules +- handle error on json parse when using internal xhr +- fixes plural/singular on count if going on fallbacks eg. fr --> en +- fixes global leak of sync in amd versions +- apply options.lowerCaseLng to fallbackLng too +- added hasResourceBundle(lng, ns) to check if bundle exists +- added experimental i18n.sync.reload --> resets resStore and reloads resources +- catch issues with localStorage quota +- changes detectlanguage to support whitelist entries + +### 1.7.4 +- add resource bundle gets deep extend flag i18n.addResourceBundle(lng, ns, { 'deep': { 'key2': 'value2' }}, true); +- new functions to add one key value or multiple i18n.addResource(lng, ns, key, value);, i18n.addResources(lng, ns, {'key1': 'value1', 'deep.key2': 'value2'}); +- lngWhitelist merged +- override postMissing function +- allow floats for count +- added indefinite functionality for plurals +- optional set replacing vars to replace member to avoid collision with other options +- experimental optional detectLngFromLocalStorage +- fix for norwegian language + +### 1.7.3 +- solves issue with ie8 not providing .trim function on string -> added to shim +- set data using $(selector).i18n() on data-i18n='[data-someDataAttr]key' +- more bullet proof state handling on failed file load +- corrected latvian plurals based on [issue 231](https://github.com/jamuhl/i18next/issues/231) +- allow array of fallback languages +- allow int in values passed to shortcut sprintf +- setLng to 'cimode' will trigger a CI mode returning 'key' instead of translation + +### 1.7.2 +- introducing option fallbackOnEmpty -> empty string will fallback +- added function removeResourceBundle(lng, ns) -> removes a resource set +- fixed issue with no option passed to setLng +- added ability to prepend, append content with data-i18n attributes +- introducing objectTreeKeyHandler +- fixes issue with i18n.t(null), i18n.t(undefined) throwing exception +- returnObjectTrees does not mangle arrays, functions, and regexps +- optimized structure for bower support + +### 1.7.1 +- fixed some typo +- allow translate to take an array of keys - take first found +- allow numbers in object trees + +### 1.7.0 +- test if initialisation finished before allowing calling t function +- setting option fixLng=true will return t function on init or setLng with the lng fixed for every subsequent call to t +- grab key from content if attr data-i18n has no value +- setting shortcutFunction to 'defaultValue' allows calling i18n.t(key, defaultValue) +- empty string in defaultValue is now valid no longer displaying key +- allow option cookieDomain +- fixes issue #115 out of stack exception in IE8 by recursing _translate in objectTrees + +### 1.6.3 +- option to parse key if missing +- fixes issue where plural don't get translated if language is passed in t options +- fixes issue where key or defaultValue aren't postProcessed with itself as value +- fixes issue with fallbackLng = false in combination with sendMissingTo = fallback +- fixes namespace fallback loop to only loop if array has really a ns in it + +### 1.6.2 +- fixes some var typo +- fixes sendMissing to correct namespace +- fixes sendMissing in combination with fallbackNS + +### 1.6.1 +- PR #106 optionally un/escape interpolated content +- PR #101 automatic gettext like sprintf syntax detection + postprocess injection +- customload will get called on dynamicLoad too +- fixes namespace array settings if loaded resourcebundle or additional namespaces +- lookup of not existend resouces can be fallbacked to other namespaces - see option fallbackNS (array or string if one ns to fallback to) +- defaultValues get postProcessed +- BREAKING: per default null values in resources get translated to fallback. This can be changed by setting option fallbackOnNull to false +- PR #81 added support for passing options to nested resources +- PR #88 added an exists method to check for the existence of a key in the resource store +- fixed issue with null value throws in applyReplacement function +- fixed issue #80 empty string lookup ends in fallback instead of returning result in language +- fixed issue with null value in resources not returning expected value +- optimized tests to use on server (nodejs) too +- allow zepto as drop in replacement for $ +- using testacular as runner +- upgraded to grunt 0.4.0 +- fixed optional interpolation prefix/suffix not used in plural translation cases +- optimized check if there are multiple keys for the data-i18n attribute to parse + +### 1.6.0 +- option to specify target to set attributes with jquery function by using 'data-i18n-target attribute' +- function to set new options for nesting functionality +- function to add resources after init +- option to lookup in default namespace if value is not found in given namespace +- option to change interpolation prefix and suffix via translation options +- fixed issue with using ns/keyseparator on plurals, context,... +- fixed issue with posting missing when not using jquery +- post missing in correct lng if lng is given in translation options +- proper usage of deferred object in init function +- fixed issue replacing values in objectTree + +### 1.5.10 +- BREAKING: fixed plural rules for languages with extended plural forms (more than 2 forms) +- merged pull #61 - custom loader (enables jsonp or other loading custom loading strategies) +- escaping interpolation prefix/suffix for proper regex replace + +### 1.5.9 +- functions to load additional namespaces after init and to set default namespace to something else +- set if you don't want to read defaultValues from content while using jquery fc +- set dataAttribute to different value +- set cookieName to different value +- some smallbugfixes +- typesafe use of console if in debug mode + +### 1.5.8 +- disable cookie usage by setting init option useCookie to false +- accept empty string as translation value +- fixed bug in own ajax implementation not using proper sendType +- fixed bug for returning objTree in combination with namespace +- fixed bug in plurals of romanic lngs + +### 1.5.7 +- pass namespace in t() options +- interpolation nesting +- changable querystring param to look language up from + +### 1.5.6 +- typesafe check for window, document existance +- runnable under rhino +- seperated amd builds with/without jquery + +### 1.5.5 +- __BREAKING__ added all plurals: suffixes will new be same as in gettext usage (number indexes key_plural_0|2|3|4|5|7|8|10|11|20|100), additional if needed signature of addRule has changed +- added sprintf as postprocessor -> postProcess = 'sprintf' and sprintf = obj or array +- set default postProcessor on init +- redone build process with grunt +- drop in replacement for jquery each, extend, ajax +- setting fallbackLng to false will stop loading and looking it up +- option to load only current or unspecific language files + +### v1.5.0 +- pass options to sync._fetchOne, use options for fetching +- support for i18next-webtranslate + +### v1.4.1 +- post processor +- __BREAKING:__ localStorage defaults to false +- added localStorageExpirationTime for better caching control +- few bug fixes + +### v1.4.0 +- preload multiple languages +- translate key to other language than current +- fixed issue with namespace usage in combination with context and plurals +- more options to send missing values +- better amd support + +### v1.3.4 +- set type of ajax request to GET (options sendType: default POST) +- set cookie expiration (options cookieExpirationTime: in minutes) +- read / cache translation options (context, count, ...) in data-attribute (options useDataAttrOptions: default false) + +### v1.3.3 +- optional return an objectTree from translation +- use jquery promises or callback in initialisation +- rewrote all tests with mocha.js + +### v1.3.2 +- options to init i18next sync (options -> getAsync = false) +- replace all occurence of replacement string + +### v1.3.1 +- pass options to selector.i18n() thanks to [@hugojosefson](https://github.com/jamuhl/i18next/pull/10) +- close [issue #8(https://github.com/jamuhl/i18next/issues/8)]: Fail silently when trying to access a path with children +- cleanup +- debug flag (options.debug -> write infos/errors to console) + +### v1.2.5 +- fix for IE8 + +### v1.2.4 +- added indexOf for non ECMA-262 standard compliant browsers (IE < 9) +- calling i28n() on element with data-i18n attribute will localize it now (i18n now not only works on container elements child) + +### v1.2.3 + +- extended detectLng: switch via qs _setLng=_ or cookie _i18next_ +- assert county in locale will be uppercased `en-us` -> `en-US` +- provide option to have locale always lowercased _option lowerCaseLng_ +- set lng cookie when set in init function + +### v1.2 + +- support for translation context +- fixed zero count in plurals +- init without options, callback + +### v1.1 + +- support for multiple plural forms +- common.js enabled (for node.js serverside) +- changes to be less dependent on jquery (override it's functions, add to root if no jquery) +- enable it on serverside with node.js [i18next-node](https://github.com/jamuhl/i18next-node) + +### v1.0 + +- support for other attribute translation via _data-i18n_ attribute +- bug fixes +- tests with qunit and sinon + +### v0.9 + +- multi-namespace support +- loading static files or dynamic route +- jquery function for _data-i18n_ attibute +- post missing translations to the server +- graceful fallback en-US -> en -> fallbackLng +- localstorage support +- support for pluralized strings +- insertion of variables into translations +- translation nesting diff --git a/libs/i18next/Gruntfile.js b/libs/i18next/Gruntfile.js new file mode 100644 index 00000000..51de9dce --- /dev/null +++ b/libs/i18next/Gruntfile.js @@ -0,0 +1,301 @@ +/*global module:false*/ +module.exports = function(grunt) { + + var version = '1.8.2'; + // before release: + // update bower.json, package.json + // after release: + // add tag to repo: git tag -a 1.6.0 -m 'i18next v1.6.0' + // push tag: git push origin 1.6.0 + // npm publish + + grunt.loadNpmTasks('grunt-rigger'); + grunt.loadNpmTasks('grunt-contrib'); + grunt.loadNpmTasks('grunt-shell'); + grunt.loadNpmTasks('gruntacular'); + grunt.loadTasks('buildtasks'); + + // Project configuration. + grunt.initConfig({ + meta: { + version: version, + banner: '// i18next, v<%= meta.version %>\n' + + '// Copyright (c)<%= grunt.template.today("yyyy") %> Jan Mühlemann (jamuhl).\n' + + '// Distributed under MIT license\n' + + '// http://i18next.com\n' + }, + + clean: ['bin'], + + shell: { + /* create phonegap projects */ + maintain: { + command: 'plato -r -d reports/maintain/<%= grunt.template.today("yyyymmdd") %> src', + stdout: true + } + }, + + testacular: { + options: { + configFile: 'testacular.conf.js' + }, + ci: { + singleRun: true, + browsers: ['PhantomJS'] + }, + all: { + singleRun: true, + browsers: ['PhantomJS', 'Chrome', 'Firefox', 'Safari'] + }, + dev: { + reporters: 'dots', + browsers: ['PhantomJS'] + } + }, + + jshint: { + options: { + scripturl: true, + laxcomma: true, + loopfunc: true, + curly: false, + eqeqeq: false, + immed: false, + latedef: true, + newcap: true, + noarg: true, + sub: true, + undef: true, + boss: true, + eqnull: true, + browser: true, + globals: { + jQuery: true, + $: true, + console: true, + ActiveXObject: true, + module: true + } + }, + files: [ 'bin/*.js' ] + }, + + rig: { + options: { + banner: '<%= meta.banner %>' + }, + build: { + src: ['src/i18next.js'], + dest: 'bin/i18next-latest.js' + }, + amd: { + src: ['src/amd.js'], + dest: 'bin/i18next.amd-latest.js' + }, + amdjquery: { + src: ['src/amd.jquery.js'], + dest: 'bin/i18next.amd.withJQuery-latest.js' + }, + commonjsjquery: { + src: ['src/commonjs.jquery.js'], + dest: 'bin/i18next.commonjs.withJQuery-latest.js' + }, + spec: { + src: ['spec/spec.js'], + dest: 'test/test.js' + }, + serverInit: { + src: ['spec/server.init.spec.js'], + dest: 'test/server/i18next.init.spec.js' + }, + serverFunct: { + src: ['spec/server.functions.spec.js'], + dest: 'test/server/i18next.functions.spec.js' + }, + serverTrans: { + src: ['spec/server.translate.spec.js'], + dest: 'test/server/i18next.translate.spec.js' + } + }, + + uglify: { + options: { + banner: '<%= meta.banner %>' + }, + // bin: { + // src: ['bin/i18next-latest.js'], + // dest: 'bin/i18next-<%= meta.version %>.min.js' + // }, + release: { + src: ['bin/i18next-latest.js'], + dest: 'release/i18next-<%= meta.version %>.min.js' + }, + amd: { + src: ['bin/i18next.amd-latest.js'], + dest: 'release/i18next.amd-<%= meta.version %>.min.js' + }, + amdjquery: { + src: ['bin/i18next.amd.withJQuery-latest.js'], + dest: 'release/i18next.amd.withJQuery-<%= meta.version %>.min.js' + }, + commonjsjquery: { + src: ['bin/i18next.commonjs.withJQuery-latest.js'], + dest: 'release/i18next.commonjs.withJQuery-<%= meta.version %>.min.js' + }, + release_latest: { + src: ['bin/i18next-latest.js'], + dest: 'release/i18next-latest.min.js' + }, + amd_latest: { + src: ['bin/i18next.amd-latest.js'], + dest: 'release/i18next.amd-latest.min.js' + }, + amdjquery_latest: { + src: ['bin/i18next.amd.withJQuery-latest.js'], + dest: 'release/i18next.amd.withJQuery-latest.min.js' + }, + commonjsjquery_latest: { + src: ['bin/i18next.commonjs.withJQuery-latest.js'], + dest: 'release/i18next.commonjs.withJQuery-latest.min.js' + }, + release_latest_root: { + src: ['bin/i18next-latest.js'], + dest: './i18next.min.js' + }, + amd_latest_root: { + src: ['bin/i18next.amd-latest.js'], + dest: './i18next.amd.min.js' + }, + amdjquery_latest_root: { + src: ['bin/i18next.amd.withJQuery-latest.js'], + dest: './i18next.amd.withJQuery.min.js' + }, + commonjsjquery_latest_root: { + src: ['bin/i18next.commonjs.withJQuery-latest.js'], + dest: './i18next.commonjs.withJQuery.min.js' + } + }, + + copy: { + js: { + files: [ + { expand: true, cwd: 'bin/', src: ['*.js'], dest: 'release/', + rename: function(dest, src) { console.log(src + ' -> ' + dest); + if (src == 'i18next-latest.js') { + dest += 'i18next-' + version + '.js'; + } + if (src == 'i18next.amd-latest.js') { + dest += 'i18next.amd-' + version + '.js'; + } + if (src == 'i18next.amd.withJQuery-latest.js') { + dest += 'i18next.amd.withJQuery-' + version + '.js'; + } + if (src == 'i18next.commonjs.withJQuery-latest.js') { + dest += 'i18next.commonjs.withJQuery-' + version + '.js'; + } + return dest; + } + }, + { expand: true, cwd: 'bin/', src: ['*.js'], dest: 'release/'}, + { expand: true, cwd: 'bin/', src: ['*.js'], dest: './', + rename: function(dest, src) { console.log(src + ' -> ' + dest); + if (src == 'i18next-latest.js') { + dest += 'i18next.js'; + } + if (src == 'i18next.amd-latest.js') { + dest += 'i18next.amd.js'; + } + if (src == 'i18next.amd.withJQuery-latest.js') { + dest += 'i18next.amd.withJQuery.js'; + } + if (src == 'i18next.commonjs.withJQuery-latest.js') { + dest += 'i18next.commonjs.withJQuery.js'; + } + return dest; + } + } + ] + } + }, + + compress: { + zip: { + options: { + archive: 'release/i18next-<%= meta.version %>.zip', + mode: 'zip', + level: 1 + }, + files: [ + { + expand: true, + flatten: true, + cwd: 'release/', + src: [ + 'i18next-<%= meta.version %>.js', + 'i18next-<%= meta.version %>.min.js' + ], + dest: 'i18next-<%= meta.version %>/' + } + ] + }, + zipamd: { + options: { + archive: 'release/i18next.amd-<%= meta.version %>.zip', + mode: 'zip', + level: 1 + }, + files: [ + { + expand: true, + flatten: true, + cwd: 'release/', + src: [ + 'i18next.amd-<%= meta.version %>.js', + 'i18next.amd-<%= meta.version %>.min.js', + 'i18next.amd.withJQuery-<%= meta.version %>.js', + 'i18next.amd.withJQuery-<%= meta.version %>.min.js' + ], + dest: 'i18next.amd-<%= meta.version %>/' + } + ] + } + }, + + server: { + host: '0.0.0.0', + index: 'test/index.html', + files: { 'test.js': 'test/test.js' }, + + folders: { + 'libs': './test/libs', + 'bin': './bin', + 'locales': './test/locales', + 'sample': './sample/static' + } + }, + + watch: { + lib: { + files: 'src/*.js', + tasks: 'rig:build' + }, + + spec: { + files: 'spec/**/*.js', + tasks: 'rig:spec' + } + } + + }); + + // Default task. + grunt.registerTask('default', ['clean', 'rig']); + grunt.registerTask('release', ['default', 'uglify', 'copy', 'compress']); + + grunt.registerTask('test', ['testacular:dev']); + grunt.registerTask('test:all', ['testacular:all']); + + grunt.registerTask('report', ['shell:maintain', 'testacular:ci']); + + +}; \ No newline at end of file diff --git a/libs/i18next/README.md b/libs/i18next/README.md new file mode 100644 index 00000000..bf6395bf --- /dev/null +++ b/libs/i18next/README.md @@ -0,0 +1,156 @@ +# Searching Contributors + +looking for contributors interested in helping the project (long term): + +- getting stuff fixed faster +- we might start work on a version 2.0.0 (supporting old API - but rewrite to optimize size, drop old browser support, better modularization, ...) +- update docs to be generated out of wiki pages?!? +- creating an icon for i18next organisation on github and the project +- ... + +# Introduction + +Project goal is to provide an easy way to translate a website on clientside: + +- fetch resources from server +- fetch each resource file individually (static) or all once via dynamicRoute +- apply translation to HTML tags with the _data-i18n_ attribute +- post missing key-value pairs to server (for easy development -> just translate the new keys) +- search for key _en-US_ first, then in _en_, then in fallback language (or de-DE, de , fallback) + +Check out the [documentation](http://i18next.com) + +Check [CHANGELOG](https://github.com/i18next/i18next/blob/master/CHANGELOG.md) for changes. + +# Usage + +Assuming we loaded __en-US__, __en__ and __dev__ resources for two namespaces ('ns.special' and 'ns.common'): + + // given loaded and merged dictionaries in i18next.js to: + { + "en_US": { + "ns.special": { + "app": { + "name": "i18n", + "insert": "you are __youAre__", + "child": "__count__ child", + "child_plural": "__count__ children" + } + }, + "ns.common": {} + }, + "en": { + "ns.special": { + "app": { + "area": "Area 51" + } + }, + "ns.common": {} + }, + "dev": { + "ns.common": { + "app": { + "company": { + "name": "my company" + } + }, + "add": "add" + }, + "ns.special": { + "nav": { + "1": "link1", + "2": "link2", + "home": "home" + } + } + } + } + +## you can translate using `$.t(key, [options])` + + $.i18n.init({ + lng: 'en-US', + ns: { namespaces: ['ns.common', 'ns.special'], defaultNs: 'ns.special'} + }, function() { + $.t('app.name'); // -> i18n (from en-US resourcefile) + $.t('app.area'); // -> Area 51 (from en resourcefile) + $.t('ns.common:app.company.name'); // -> my company (from dev resourcefile) + $.t('ns.common:add'); // -> add (from dev resourcefile) + }); + +### insert values into your translation + + $.t('app.insert', {youAre: 'great'}) // -> you are great + +### support for plurals + + $.t('app.child', {count: 1}) // -> 1 child + $.t('app.child', {count: 3}) // -> 3 children + +### support for key priority when you need to try multiple keys, using the first one that exists. + + $.t(['app.missingKey', 'app.existingKey'], {greeting: "hello"}) // -> I am the existing key: hello + +## or you can just `$('.mySelector').i18n()` assuming you have added the `data-i18n="key"` attribute to your elements + + // given + + + // Run the following javascript to translate all elements having the _data-i18n_ attribute: + $.i18n.init({ + lng: 'en-US', + ns: { namespaces: ['ns.common', 'ns.special'], defaultNs: 'ns.special'} + }, function() { + $('.nav').i18n(); + }); + +For missing keys (if the option 'addMissing' is set to true) will be send to server with actual text as defaultValue. + +# Sample usage + +In the folder you find one static sample. + +# serverside integrations + +[i18next-node](https://github.com/jamuhl/i18next-node) is bringing i18next to node.js + +# Inspiration + +- [jsperanto](https://github.com/jpjoyal/jsperanto). + +# Building +To build your own copy of i18next, check out the repository and: + + git clone https://github.com/jamuhl/i18next.git + cd i18next + npm install -g grunt-cli + npm install + grunt + +The grunt command will build i18next into the bin/ and release/ folders. + +# License (MIT) + +Copyright (c) 2011 Jan Mühlemann + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/libs/i18next/bower.json b/libs/i18next/bower.json new file mode 100644 index 00000000..b91d877b --- /dev/null +++ b/libs/i18next/bower.json @@ -0,0 +1,20 @@ +{ + "name": "i18next", + "version": "1.8.2", + "main": "./i18next.js", + "dependencies": {}, + "ignore": [ + "test/", + "release/", + "spec/", + "src/", + "sample/", + "report/", + "buildtasks/", + ".gitignore", + "Gruntfile.js", + "package.json", + "testacular.conf.js", + "**/*.zip" + ] +} diff --git a/libs/i18next/buildtasks/server.js b/libs/i18next/buildtasks/server.js new file mode 100644 index 00000000..2d221b13 --- /dev/null +++ b/libs/i18next/buildtasks/server.js @@ -0,0 +1,104 @@ +/* + * Grunt Task File + * --------------- + * + * Task: Server + * Description: Serve the web application. + * Dependencies: express + * + */ + +module.exports = function(grunt) { + + var _ = grunt.util._; + // Shorthand Grunt functions + var log = grunt.log; + + grunt.registerTask("server", "Run development server.", function(prop) { + var options; + var props = ["server"]; + + // Keep alive + var done = this.async(); + + // If a prop was passed as the argument, use that sub-property of server. + if (prop) { props.push(prop); } + + // Defaults set for server values + options = _.defaults(grunt.config(props) || {}, { + favicon: "./favicon.ico", + index: "./index.html", + + port: process.env.PORT || 8000, + host: process.env.HOST || "127.0.0.1" + }); + + options.folders = options.folders || {}; + + // Ensure folders have correct defaults + options.folders = _.defaults(options.folders, { + app: "./app", + assets: "./assets", + dist: "./dist" + }); + + options.files = options.files || {}; + + // Ensure files have correct defaults + options.files = _.defaults(options.files, { + "app/config.js": "app/config.js" + }); + + // Run the server + listen(options); + + // Fail task if errors were logged + if (grunt.errors) { return false; } + + log.writeln("Listening on http://" + options.host + ":" + options.port); + }); + + function listen(options) { + // Require libraries. + var fs = require("fs"); + var path = require("path"); + var express = require("express"); + + // If the server is already available use it. + var site = options.server ? options.server() : express(); + + // Allow users to override the root. + var root = _.isString(options.root) ? options.root : "/"; + + // Map static folders. + Object.keys(options.folders).sort().reverse().forEach(function(key) { + site.get(root + key + "/*", function(req, res, next) { + // Find filename. + var filename = '/' + req.params[0];//;.slice((root + key).length); console.log(req.params[0]); + + res.sendfile(path.join(options.folders[key] + filename)); + }); + }); + + // Map static files. + if (_.isObject(options.files)) { + Object.keys(options.files).sort().reverse().forEach(function(key) { + site.get(root + key, function(req, res) { + return res.sendfile(options.files[key]); + }); + }); + } + + // Serve favicon.ico. + site.use(express.favicon(options.favicon)); + + // Ensure all routes go home, client side app.. + site.get("*", function(req, res) { + fs.createReadStream(options.index).pipe(res); + }); + + // Actually listen + site.listen(options.port, options.host); + } + +}; \ No newline at end of file diff --git a/libs/i18next/i18next.amd.js b/libs/i18next/i18next.amd.js new file mode 100644 index 00000000..a71b1ce5 --- /dev/null +++ b/libs/i18next/i18next.amd.js @@ -0,0 +1,2176 @@ +// i18next, v1.8.2 +// Copyright (c)2015 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function (root, factory) { + if (typeof exports === 'object') { + + module.exports = factory(); + + } else if (typeof define === 'function' && define.amd) { + + define([], factory); + + } +}(this, function () { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + // Add string trim for IE8. + if (typeof String.prototype.trim !== 'function') { + String.prototype.trim = function() { + return this.replace(/^\s+|\s+$/g, ''); + } + } + + var $ = undefined + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = [] + , initialized = false + , sync = {}; + + sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = f.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + f.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + if ((status && status == 200) || (xhr && xhr.status && xhr.status == 200)) { + // file loaded but invalid json, stop waste time ! + f.error('There is a typo in: ' + url); + } else if ((status && status == 404) || (xhr && xhr.status && xhr.status == 404)) { + f.log('Does not exist: ' + url); + } else { + var theStatus = status ? status : ((xhr && xhr.status) ? xhr.status : null); + f.log(theStatus + ' when loading ' + url); + } + + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback' && o.fallbackLng[0] !== false) { + for (var i = 0; i < o.fallbackLng.length; i++) { + urls.push({lng: o.fallbackLng[i], url: applyReplacement(o.resPostPath, { lng: o.fallbackLng[i], ns: ns })}); + } + } else if (o.sendMissingTo === 'current' || (o.sendMissingTo === 'fallback' && o.fallbackLng[0] === false) ) { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + }, + + reload: reload + }; + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: ['dev'], + fallbackNS: [], + detectLngQS: 'setLng', + detectLngFromLocalStorage: false, + ns: { + namespaces: ['translation'], + defaultNs: 'translation' + }, + fallbackOnNull: true, + fallbackOnEmpty: false, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + defaultVariables: false, + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + indefiniteSuffix: '_indefinite', + indefiniteNotFound: ['indefinite_not_found', Math.random()].join(''), + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + cookieDomain: undefined, + + objectTreeKeyHandler: undefined, + postProcess: undefined, + parseMissingKey: undefined, + missingKeyHandler: sync.postMissing, + + shortcutFunction: 'sprintf' // or: defaultValue + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _deepExtend(target, source) { + for (var prop in source) + if (prop in target) + _deepExtend(target[prop], source[prop]); + else + target[prop] = source[prop]; + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || Object.prototype.toString.apply(object) !== '[object Array]' || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + try { + return JSON.parse(data) + } catch (e) { + f.error('Can not parse JSON. URL: ' + url); + return {}; + } + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + // file: protocol always gives status code 0, so check for data + if (status === 200 || (status === 0 && data.text())) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes,domain) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + domain = (domain)? "domain="+domain+";" : ""; + document.cookie = name+"="+value+expires+";"+domain+"path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes,domain) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + deepExtend: _deepExtend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : (typeof document !== 'undefined' ? _ajax : function() {}), + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + error: function(str) { + if (typeof console !== "undefined") console.error(str); + }, + getCountyIndexOfLng: function(lng) { + var lng_index = 0; + if (lng === 'nb-NO' || lng === 'nn-NO' || lng === 'nb-no' || lng === 'nn-no') lng_index = 1; + return lng_index; + }, + toLanguages: function(lng) { + var log = this.log; + + function applyCase(l) { + var ret = l; + + if (typeof l === 'string' && l.indexOf('-') > -1) { + var parts = l.split('-'); + + ret = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } else { + ret = o.lowerCaseLng ? l.toLowerCase() : l; + } + + return ret; + } + + var languages = []; + var whitelist = o.lngWhitelist || false; + var addLanguage = function(language){ + //reject langs not whitelisted + if(!whitelist || whitelist.indexOf(language) > -1){ + languages.push(language); + }else{ + log('rejecting non-whitelisted language: ' + language); + } + }; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + if (o.load !== 'unspecific') addLanguage(applyCase(lng)); + if (o.load !== 'current') addLanguage(applyCase(parts[this.getCountyIndexOfLng(lng)])); + } else { + addLanguage(applyCase(lng)); + } + + for (var i = 0; i < o.fallbackLng.length; i++) { + if (languages.indexOf(o.fallbackLng[i]) === -1 && o.fallbackLng[i]) languages.push(applyCase(o.fallbackLng[i])); + } + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + }, + regexReplacementEscape: function(strOrFn) { + if (typeof strOrFn === 'string') { + return strOrFn.replace(/\$/g, "$$$$"); + } else { + return strOrFn; + } + }, + localStorage: { + setItem: function(key, value) { + if (window.localStorage) { + try { + window.localStorage.setItem(key, value); + } catch (e) { + f.log('failed to set value for key "' + key + '" to localStorage.'); + } + } + }, + getItem: function(key, value) { + if (window.localStorage) { + try { + return window.localStorage.getItem(key, value); + } catch (e) { + f.log('failed to get value for key "' + key + '" from localStorage.'); + return undefined; + } + } + } + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + delete o.fixLng; /* passed in each time */ + + // override functions: .log(), .detectLanguage(), etc + if (o.functions) { + delete o.functions; + f.extend(f, options.functions); + } + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // fallback languages + if (typeof o.fallbackLng == 'string' || typeof o.fallbackLng == 'boolean') { + o.fallbackLng = [o.fallbackLng]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + if (o.useCookie && f.cookie.read(o.cookieName) !== currentLng){ //cookie is unset or invalid + f.cookie.create(o.cookieName, currentLng, o.cookieExpirationTime, o.cookieDomain); + } + if (o.detectLngFromLocalStorage && typeof document !== 'undefined' && window.localStorage) { + f.localStorage.setItem('i18next_lng', currentLng); + } + + var lngTranslate = translate; + if (options.fixLng) { + lngTranslate = function(key, options) { + options = options || {}; + options.lng = options.lng || lngTranslate.lng; + return translate(key, options); + }; + lngTranslate.lng = currentLng; + } + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + initialized = true; + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + initialized = true; + + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources, deep) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + if (deep) { + f.deepExtend(resStore[lng][ns], resources); + } else { + f.extend(resStore[lng][ns], resources); + } + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function hasResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + var res = resStore[lng][ns] || {}; + + var hasValues = false; + for(var prop in res) { + if (res.hasOwnProperty(prop)) { + hasValues = true; + } + } + + return hasValues; + } + + function getResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + return f.extend({}, resStore[lng][ns]); + } + + function removeResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = {}; + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function addResource(lng, ns, key, value) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + var keys = key.split(o.keyseparator); + var x = 0; + var node = resStore[lng][ns]; + var origRef = node; + + while (keys[x]) { + if (x == keys.length - 1) + node[keys[x]] = value; + else { + if (node[keys[x]] == null) + node[keys[x]] = {}; + + node = node[keys[x]]; + } + x++; + } + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function addResources(lng, ns, resources) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + for (var m in resources) { + if (typeof resources[m] === 'string') addResource(lng, ns, m, resources[m]); + } + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, options, cb) { + if (typeof options === 'function') { + cb = options; + options = {}; + } else if (!options) { + options = {}; + } + + options.lng = lng; + return init(options, cb); + } + + function lng() { + return currentLng; + } + + function reload(cb) { + resStore = {}; + setLng(currentLng, cb); + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else if (attr === 'prepend') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.prepend($.t(key, optionsToUse)); + } else if (attr === 'append') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.append($.t(key, optionsToUse)); + } else if (attr.indexOf("data-") === 0) { + var dataAttr = attr.substr(("data-").length); + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.data(dataAttr) }, options) : options; + var translated = $.t(key, optionsToUse); + //we change into the data cache + ele.data(dataAttr, translated); + //we change into the dom + ele.attr(attr, translated); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key && typeof key !== 'undefined' && key !== false) key = ele.text() || ele.val(); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + var hash = replacementHash.replace && typeof replacementHash.replace === 'object' ? replacementHash.replace : replacementHash; + f.each(hash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), f.regexReplacementEscape(value)); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(f.escape(value))); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(value)); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + if (index_of_end_of_closing <= index_of_opening) { + f.error('there is an missing closing in following translation value', translated); + return ''; + } + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, f.regexReplacementEscape(translated_token)); + } + return translated; + } + + function hasContext(options) { + return (options.context && (typeof options.context == 'string' || typeof options.context == 'number')); + } + + function needsPlural(options, lng) { + return (options.count !== undefined && typeof options.count != 'string'/* && pluralExtensions.needsPlural(lng, options.count)*/); + } + + function needsIndefiniteArticle(options) { + return (options.indefinite_article !== undefined && typeof options.indefinite_article != 'string' && options.indefinite_article); + } + + function exists(key, options) { + options = options || {}; + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + options = options || {}; + + if (!initialized) { + f.log('i18next not finished initialization. you might have called t function before loading resources finished.') + return options.defaultValue || ''; + }; + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _getDefaultValue(key, options) { + return (options.defaultValue !== undefined) ? options.defaultValue : key; + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(potentialKeys, options) { + if (options && typeof options !== 'object') { + if (o.shortcutFunction === 'sprintf') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else if (o.shortcutFunction === 'defaultValue') { + options = { + defaultValue: options + } + } + } else { + options = options || {}; + } + + if (typeof o.defaultVariables === 'object') { + options = f.extend({}, o.defaultVariables, options); + } + + if (potentialKeys === undefined || potentialKeys === null || potentialKeys === '') return ''; + + if (typeof potentialKeys === 'number') { + potentialKeys = String(potentialKeys); + } + + if (typeof potentialKeys === 'string') { + potentialKeys = [potentialKeys]; + } + + var key = potentialKeys[0]; + + if (potentialKeys.length > 1) { + for (var i = 0; i < potentialKeys.length; i++) { + key = potentialKeys[i]; + if (exists(key, options)) { + break; + } + } + } + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng, options.fallbackLng) : languages + , ns = options.ns || o.ns.defaultNs + , parts; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing && typeof o.missingKeyHandler === 'function') { + if (options.lng) { + o.missingKeyHandler(lngs[0], ns, key, notFound, lngs); + } else { + o.missingKeyHandler(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessorsToApply; + if (typeof o.postProcess === 'string' && o.postProcess !== '') { + postProcessorsToApply = [o.postProcess]; + } else if (typeof o.postProcess === 'array' || typeof o.postProcess === 'object') { + postProcessorsToApply = o.postProcess; + } else { + postProcessorsToApply = []; + } + + if (typeof options.postProcess === 'string' && options.postProcess !== '') { + postProcessorsToApply = postProcessorsToApply.concat([options.postProcess]); + } else if (typeof options.postProcess === 'array' || typeof options.postProcess === 'object') { + postProcessorsToApply = postProcessorsToApply.concat(options.postProcess); + } + + if (found !== undefined && postProcessorsToApply.length) { + postProcessorsToApply.forEach(function(postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + }); + } + + // process notFound if function exists + var splitNotFound = notFound; + if (notFound.indexOf(o.nsseparator) > -1) { + parts = notFound.split(o.nsseparator); + splitNotFound = parts[1]; + } + if (splitNotFound === key && o.parseMissingKey) { + notFound = o.parseMissingKey(notFound); + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessorsToApply.length) { + var val = _getDefaultValue(key, options); + postProcessorsToApply.forEach(function(postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](val, key, options); + } + }); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options) { + options = options || {}; + + var optionWithoutCount, translated + , notFound = _getDefaultValue(key, options) + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + // CI mode + if (lngs[0].toLowerCase() === 'cimode') return notFound; + + // passed in lng + if (options.lngs) lngs = options.lngs; + if (options.lng) { + lngs = f.toLanguages(options.lng, options.fallbackLng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options, lngs[0])) { + optionWithoutCount = f.extend({ lngs: [lngs[0]]}, options); + delete optionWithoutCount.count; + optionWithoutCount._origLng = optionWithoutCount._origLng || optionWithoutCount.lng || lngs[0]; + delete optionWithoutCount.lng; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey; + if (!pluralExtensions.needsPlural(lngs[0], options.count)) { + pluralKey = ns + o.nsseparator + key; + } else { + pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(lngs[0], options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + } + + translated = translate(pluralKey, optionWithoutCount); + + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } else if (lngs.length > 1) { + // remove failed lng + var clone = lngs.slice(); + clone.shift(); + options = f.extend(options, { lngs: clone }); + options._origLng = optionWithoutCount._origLng; + delete options.lng; + // retry with fallbacks + translated = translate(ns + o.nsseparator + key, options); + if (translated != o.pluralNotFound) return translated; + } else { + optionWithoutCount.lng = optionWithoutCount._origLng; + delete optionWithoutCount._origLng; + translated = translate(ns + o.nsseparator + key, optionWithoutCount); + + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); + } + } + + if (needsIndefiniteArticle(options)) { + var optionsWithoutIndef = f.extend({}, options); + delete optionsWithoutIndef.indefinite_article; + optionsWithoutIndef.defaultValue = o.indefiniteNotFound; + // If we don't have a count, we want the indefinite, if we do have a count, and needsPlural is false + var indefiniteKey = ns + o.nsseparator + key + (((options.count && !needsPlural(options, lngs[0])) || !options.count) ? o.indefiniteSuffix : ""); + translated = translate(indefiniteKey, optionsWithoutIndef); + if (translated != o.indefiniteNotFound) { + return translated; + } + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + var valueType = Object.prototype.toString.apply(value); + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (valueType === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + if (o.objectTreeKeyHandler && typeof o.objectTreeKeyHandler == 'function') { + value = o.objectTreeKeyHandler(key, value, l, ns, options); + } else { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned an object instead of string.'; + f.log(value); + } + } else if (valueType !== '[object Number]' && valueType !== '[object Function]' && valueType !== '[object RegExp]') { + var copy = (valueType === '[object Array]') ? [] : {}; // apply child translation on a copy + f.each(value, function(m) { + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + }); + value = copy; + } + } + + if (typeof value === 'string' && value.trim() === '' && o.fallbackOnEmpty === true) + value = undefined; + + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length > 0))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found || (found==="" && o.fallbackOnEmpty === false)) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + options.isFallbackLookup = false; + } + + return found; + } + function detectLanguage() { + var detectedLng; + var whitelist = o.lngWhitelist || []; + var userLngChoices = []; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var params = query.split('&'); + for (var i=0; i 0) { + var key = params[i].substring(0,pos); + if (key == o.detectLngQS) { + userLngChoices.push(params[i].substring(pos+1)); + } + } + } + })(); + } + + // get from cookie + if (o.useCookie && typeof document !== 'undefined') { + var c = f.cookie.read(o.cookieName); + if (c) userLngChoices.push(c); + } + + // get from localStorage + if (o.detectLngFromLocalStorage && typeof window !== 'undefined' && window.localStorage) { + userLngChoices.push(f.localStorage.getItem('i18next_lng')); + } + + // get from navigator + if (typeof navigator !== 'undefined') { + if (navigator.languages) { // chrome only; not an array, so can't use .push.apply instead of iterating + for (var i=0;i -1) { + var parts = lng.split('-'); + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } + + if (whitelist.length === 0 || whitelist.indexOf(lng) > -1) { + detectedLng = lng; + break; + } + } + })(); + + //fallback + if (!detectedLng){ + detectedLng = o.fallbackLng[0]; + } + + return detectedLng; + } + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + + /* [code, name, numbers, pluralsType] */ + var _rules = [ + ["ach", "Acholi", [1,2], 1], + ["af", "Afrikaans",[1,2], 2], + ["ak", "Akan", [1,2], 1], + ["am", "Amharic", [1,2], 1], + ["an", "Aragonese",[1,2], 2], + ["ar", "Arabic", [0,1,2,3,11,100],5], + ["arn", "Mapudungun",[1,2], 1], + ["ast", "Asturian", [1,2], 2], + ["ay", "Aymará", [1], 3], + ["az", "Azerbaijani",[1,2],2], + ["be", "Belarusian",[1,2,5],4], + ["bg", "Bulgarian",[1,2], 2], + ["bn", "Bengali", [1,2], 2], + ["bo", "Tibetan", [1], 3], + ["br", "Breton", [1,2], 1], + ["bs", "Bosnian", [1,2,5],4], + ["ca", "Catalan", [1,2], 2], + ["cgg", "Chiga", [1], 3], + ["cs", "Czech", [1,2,5],6], + ["csb", "Kashubian",[1,2,5],7], + ["cy", "Welsh", [1,2,3,8],8], + ["da", "Danish", [1,2], 2], + ["de", "German", [1,2], 2], + ["dev", "Development Fallback", [1,2], 2], + ["dz", "Dzongkha", [1], 3], + ["el", "Greek", [1,2], 2], + ["en", "English", [1,2], 2], + ["eo", "Esperanto",[1,2], 2], + ["es", "Spanish", [1,2], 2], + ["es_ar","Argentinean Spanish", [1,2], 2], + ["et", "Estonian", [1,2], 2], + ["eu", "Basque", [1,2], 2], + ["fa", "Persian", [1], 3], + ["fi", "Finnish", [1,2], 2], + ["fil", "Filipino", [1,2], 1], + ["fo", "Faroese", [1,2], 2], + ["fr", "French", [1,2], 9], + ["fur", "Friulian", [1,2], 2], + ["fy", "Frisian", [1,2], 2], + ["ga", "Irish", [1,2,3,7,11],10], + ["gd", "Scottish Gaelic",[1,2,3,20],11], + ["gl", "Galician", [1,2], 2], + ["gu", "Gujarati", [1,2], 2], + ["gun", "Gun", [1,2], 1], + ["ha", "Hausa", [1,2], 2], + ["he", "Hebrew", [1,2], 2], + ["hi", "Hindi", [1,2], 2], + ["hr", "Croatian", [1,2,5],4], + ["hu", "Hungarian",[1,2], 2], + ["hy", "Armenian", [1,2], 2], + ["ia", "Interlingua",[1,2],2], + ["id", "Indonesian",[1], 3], + ["is", "Icelandic",[1,2], 12], + ["it", "Italian", [1,2], 2], + ["ja", "Japanese", [1], 3], + ["jbo", "Lojban", [1], 3], + ["jv", "Javanese", [0,1], 13], + ["ka", "Georgian", [1], 3], + ["kk", "Kazakh", [1], 3], + ["km", "Khmer", [1], 3], + ["kn", "Kannada", [1,2], 2], + ["ko", "Korean", [1], 3], + ["ku", "Kurdish", [1,2], 2], + ["kw", "Cornish", [1,2,3,4],14], + ["ky", "Kyrgyz", [1], 3], + ["lb", "Letzeburgesch",[1,2],2], + ["ln", "Lingala", [1,2], 1], + ["lo", "Lao", [1], 3], + ["lt", "Lithuanian",[1,2,10],15], + ["lv", "Latvian", [1,2,0],16], + ["mai", "Maithili", [1,2], 2], + ["mfe", "Mauritian Creole",[1,2],1], + ["mg", "Malagasy", [1,2], 1], + ["mi", "Maori", [1,2], 1], + ["mk", "Macedonian",[1,2],17], + ["ml", "Malayalam",[1,2], 2], + ["mn", "Mongolian",[1,2], 2], + ["mnk", "Mandinka", [0,1,2],18], + ["mr", "Marathi", [1,2], 2], + ["ms", "Malay", [1], 3], + ["mt", "Maltese", [1,2,11,20],19], + ["nah", "Nahuatl", [1,2], 2], + ["nap", "Neapolitan",[1,2], 2], + ["nb", "Norwegian Bokmal",[1,2],2], + ["ne", "Nepali", [1,2], 2], + ["nl", "Dutch", [1,2], 2], + ["nn", "Norwegian Nynorsk",[1,2],2], + ["no", "Norwegian",[1,2], 2], + ["nso", "Northern Sotho",[1,2],2], + ["oc", "Occitan", [1,2], 1], + ["or", "Oriya", [2,1], 2], + ["pa", "Punjabi", [1,2], 2], + ["pap", "Papiamento",[1,2], 2], + ["pl", "Polish", [1,2,5],7], + ["pms", "Piemontese",[1,2], 2], + ["ps", "Pashto", [1,2], 2], + ["pt", "Portuguese",[1,2], 2], + ["pt_br","Brazilian Portuguese",[1,2], 2], + ["rm", "Romansh", [1,2], 2], + ["ro", "Romanian", [1,2,20],20], + ["ru", "Russian", [1,2,5],4], + ["sah", "Yakut", [1], 3], + ["sco", "Scots", [1,2], 2], + ["se", "Northern Sami",[1,2], 2], + ["si", "Sinhala", [1,2], 2], + ["sk", "Slovak", [1,2,5],6], + ["sl", "Slovenian",[5,1,2,3],21], + ["so", "Somali", [1,2], 2], + ["son", "Songhay", [1,2], 2], + ["sq", "Albanian", [1,2], 2], + ["sr", "Serbian", [1,2,5],4], + ["su", "Sundanese",[1], 3], + ["sv", "Swedish", [1,2], 2], + ["sw", "Swahili", [1,2], 2], + ["ta", "Tamil", [1,2], 2], + ["te", "Telugu", [1,2], 2], + ["tg", "Tajik", [1,2], 1], + ["th", "Thai", [1], 3], + ["ti", "Tigrinya", [1,2], 1], + ["tk", "Turkmen", [1,2], 2], + ["tr", "Turkish", [1,2], 1], + ["tt", "Tatar", [1], 3], + ["ug", "Uyghur", [1], 3], + ["uk", "Ukrainian",[1,2,5],4], + ["ur", "Urdu", [1,2], 2], + ["uz", "Uzbek", [1,2], 1], + ["vi", "Vietnamese",[1], 3], + ["wa", "Walloon", [1,2], 1], + ["wo", "Wolof", [1], 3], + ["yo", "Yoruba", [1,2], 2], + ["zh", "Chinese", [1], 3] + ]; + + var _rulesPluralsTypes = { + 1: function(n) {return Number(n > 1);}, + 2: function(n) {return Number(n != 1);}, + 3: function(n) {return 0;}, + 4: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 5: function(n) {return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5);}, + 6: function(n) {return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2);}, + 7: function(n) {return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 8: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3);}, + 9: function(n) {return Number(n >= 2);}, + 10: function(n) {return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;}, + 11: function(n) {return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3);}, + 12: function(n) {return Number(n%10!=1 || n%100==11);}, + 13: function(n) {return Number(n !== 0);}, + 14: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3);}, + 15: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 16: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2);}, + 17: function(n) {return Number(n==1 || n%10==1 ? 0 : 1);}, + 18: function(n) {return Number(0 ? 0 : n==1 ? 1 : 2);}, + 19: function(n) {return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3);}, + 20: function(n) {return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2);}, + 21: function(n) {return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }; + + var pluralExtensions = { + + rules: (function () { + var l, rules = {}; + for (l=_rules.length; l-- ;) { + rules[_rules[l][0]] = { + name: _rules[l][1], + numbers: _rules[l][2], + plurals: _rulesPluralsTypes[_rules[l][3]] + } + } + return rules; + }()), + + // you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + needsPlural: function(lng, count) { + var parts = lng.split('-'); + + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[parts[f.getCountyIndexOfLng(lng)]]; + } + + if (ext && ext.numbers.length <= 1) { + return false; + } else { + return this.get(lng, count) !== 1; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i; + if (ext.noAbs) { + i = ext.plurals(c); + } else { + i = ext.plurals(Math.abs(c)); + } + + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[f.getCountyIndexOfLng(lng)], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.hasResourceBundle = hasResourceBundle; + i18n.getResourceBundle = getResourceBundle; + i18n.addResource = addResource; + i18n.addResources = addResources; + i18n.removeResourceBundle = removeResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.applyReplacement = f.applyReplacement; + i18n.options = o; + + return i18n; + +})); \ No newline at end of file diff --git a/libs/i18next/i18next.amd.min.js b/libs/i18next/i18next.amd.min.js new file mode 100644 index 00000000..e91e2051 --- /dev/null +++ b/libs/i18next/i18next.amd.min.js @@ -0,0 +1,5 @@ +// i18next, v1.8.2 +// Copyright (c)2015 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +!function(a,b){"object"==typeof exports?module.exports=b():"function"==typeof define&&define.amd&&define([],b)}(this,function(){function a(a,b){if(!b||"function"==typeof b)return a;for(var c in b)a[c]=b[c];return a}function b(a,c){for(var d in c)d in a?b(a[d],c[d]):a[d]=c[d];return a}function c(a,b,c){var d,e=0,f=a.length,g=void 0===f||"[object Array]"!==Object.prototype.toString.apply(a)||"function"==typeof a;if(c)if(g){for(d in a)if(b.apply(a[d],c)===!1)break}else for(;f>e&&b.apply(a[e++],c)!==!1;);else if(g){for(d in a)if(b.call(a[d],d,a[d])===!1)break}else for(;f>e&&b.call(a[e],e,a[e++])!==!1;);return a}function d(a){return"string"==typeof a?a.replace(/[&<>"'\/]/g,function(a){return P[a]}):a}function e(a){var b=function(a){if(window.XMLHttpRequest)return a(null,new XMLHttpRequest);if(window.ActiveXObject)try{return a(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(b){return a(null,new ActiveXObject("Microsoft.XMLHTTP"))}return a(new Error)},c=function(a){if("string"==typeof a)return a;var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")},d=function(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;cd?b+=String.fromCharCode(d):d>127&&2048>d?(b+=String.fromCharCode(d>>6|192),b+=String.fromCharCode(63&d|128)):(b+=String.fromCharCode(d>>12|224),b+=String.fromCharCode(d>>6&63|128),b+=String.fromCharCode(63&d|128))}return b},e=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";a=d(a);var c,e,f,g,h,i,j,k="",l=0;do c=a.charCodeAt(l++),e=a.charCodeAt(l++),f=a.charCodeAt(l++),g=c>>2,h=(3&c)<<4|e>>4,i=(15&e)<<2|f>>6,j=63&f,isNaN(e)?i=j=64:isNaN(f)&&(j=64),k+=b.charAt(g)+b.charAt(h)+b.charAt(i)+b.charAt(j),c=e=f="",g=h=i=j="";while(l1&&(d+=d.indexOf("?")>-1?"&"+k:"?"+k),e.jsonp){var l=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=d,void l.appendChild(m)}}b(function(b,c){if(b)return h(b);c.open(a,d,e.async);for(var f in j)j.hasOwnProperty(f)&&c.setRequestHeader(f,j[f]);c.onreadystatechange=function(){if(4===c.readyState){var a=c.responseText||"";if(!h)return;h(c.status,{text:function(){return a},json:function(){try{return JSON.parse(a)}catch(b){return S.error("Can not parse JSON. URL: "+d),{}}}})}},c.send(i)})},h={authBasic:function(a,b){g.headers.Authorization="Basic "+e(a+":"+b)},connect:function(a,b,c){return g("CONNECT",a,b,c)},del:function(a,b,c){return g("DELETE",a,b,c)},get:function(a,b,c){return g("GET",a,b,c)},head:function(a,b,c){return g("HEAD",a,b,c)},headers:function(a){g.headers=a||{}},isAllowed:function(a,b,c){this.options(a,function(a,d){c(-1!==d.text().indexOf(b))})},options:function(a,b,c){return g("OPTIONS",a,b,c)},patch:function(a,b,c){return g("PATCH",a,b,c)},post:function(a,b,c){return g("POST",a,b,c)},put:function(a,b,c){return g("PUT",a,b,c)},trace:function(a,b,c){return g("TRACE",a,b,c)}},i=a.type?a.type.toLowerCase():"get";h[i](a.url,a,function(b,c){200===b||0===b&&c.text()?a.success(c.json(),b,null):a.error(c.text(),b,null)})}function f(a,b){"function"==typeof a&&(b=a,a={}),a=a||{},S.extend(O,a),delete O.fixLng,O.functions&&(delete O.functions,S.extend(S,a.functions)),"string"==typeof O.ns&&(O.ns={namespaces:[O.ns],defaultNs:O.ns}),"string"==typeof O.fallbackNS&&(O.fallbackNS=[O.fallbackNS]),("string"==typeof O.fallbackLng||"boolean"==typeof O.fallbackLng)&&(O.fallbackLng=[O.fallbackLng]),O.interpolationPrefixEscaped=S.regexEscape(O.interpolationPrefix),O.interpolationSuffixEscaped=S.regexEscape(O.interpolationSuffix),O.lng||(O.lng=S.detectLanguage()),L=S.toLanguages(O.lng),G=L[0],S.log("currentLng set to: "+G),O.useCookie&&S.cookie.read(O.cookieName)!==G&&S.cookie.create(O.cookieName,G,O.cookieExpirationTime,O.cookieDomain),O.detectLngFromLocalStorage&&"undefined"!=typeof document&&window.localStorage&&S.localStorage.setItem("i18next_lng",G);var c=A;a.fixLng&&(c=function(a,b){return b=b||{},b.lng=b.lng||c.lng,A(a,b)},c.lng=G),V.setCurrentLng(G),H&&O.setJqueryExt&&t();var d;if(H&&H.Deferred&&(d=H.Deferred()),!O.resStore){var e=S.toLanguages(O.lng);"string"==typeof O.preload&&(O.preload=[O.preload]);for(var f=0,g=O.preload.length;g>f;f++)for(var h=S.toLanguages(O.preload[f]),i=0,j=h.length;j>i;i++)e.indexOf(h[i])<0&&e.push(h[i]);return I.sync.load(e,O,function(a,e){J=e,M=!0,b&&b(c),d&&d.resolve(c)}),d?d.promise():void 0}return J=O.resStore,M=!0,b&&b(c),d&&d.resolve(c),d?d.promise():void 0}function g(a,b){"string"==typeof a&&(a=[a]);for(var c=0,d=a.length;d>c;c++)O.preload.indexOf(a[c])<0&&O.preload.push(a[c]);return f(b)}function h(a,b,c,d){"string"!=typeof b?(c=b,b=O.ns.defaultNs):O.ns.namespaces.indexOf(b)<0&&O.ns.namespaces.push(b),J[a]=J[a]||{},J[a][b]=J[a][b]||{},d?S.deepExtend(J[a][b],c):S.extend(J[a][b],c),O.useLocalStorage&&N._storeLocal(J)}function i(a,b){"string"!=typeof b&&(b=O.ns.defaultNs),J[a]=J[a]||{};var c=J[a][b]||{},d=!1;for(var e in c)c.hasOwnProperty(e)&&(d=!0);return d}function j(a,b){return"string"!=typeof b&&(b=O.ns.defaultNs),J[a]=J[a]||{},S.extend({},J[a][b])}function k(a,b){"string"!=typeof b&&(b=O.ns.defaultNs),J[a]=J[a]||{},J[a][b]={},O.useLocalStorage&&N._storeLocal(J)}function l(a,b,c,d){"string"!=typeof b?(resource=b,b=O.ns.defaultNs):O.ns.namespaces.indexOf(b)<0&&O.ns.namespaces.push(b),J[a]=J[a]||{},J[a][b]=J[a][b]||{};for(var e=c.split(O.keyseparator),f=0,g=J[a][b];e[f];)f==e.length-1?g[e[f]]=d:(null==g[e[f]]&&(g[e[f]]={}),g=g[e[f]]),f++;O.useLocalStorage&&N._storeLocal(J)}function m(a,b,c){"string"!=typeof b?(resource=b,b=O.ns.defaultNs):O.ns.namespaces.indexOf(b)<0&&O.ns.namespaces.push(b);for(var d in c)"string"==typeof c[d]&&l(a,b,d,c[d])}function n(a){O.ns.defaultNs=a}function o(a,b){p([a],b)}function p(a,b){var c={dynamicLoad:O.dynamicLoad,resGetPath:O.resGetPath,getAsync:O.getAsync,customLoad:O.customLoad,ns:{namespaces:a,defaultNs:""}},d=S.toLanguages(O.lng);"string"==typeof O.preload&&(O.preload=[O.preload]);for(var e=0,f=O.preload.length;f>e;e++)for(var g=S.toLanguages(O.preload[e]),h=0,i=g.length;i>h;h++)d.indexOf(g[h])<0&&d.push(g[h]);for(var j=[],k=0,l=d.length;l>k;k++){var m=!1,n=J[d[k]];if(n)for(var o=0,p=a.length;p>o;o++)n[a[o]]||(m=!0);else m=!0;m&&j.push(d[k])}j.length?I.sync._fetch(j,c,function(c,d){var e=a.length*j.length;S.each(a,function(a,c){O.ns.namespaces.indexOf(c)<0&&O.ns.namespaces.push(c),S.each(j,function(a,f){J[f]=J[f]||{},J[f][c]=d[f][c],e--,0===e&&b&&(O.useLocalStorage&&I.sync._storeLocal(J),b())})})}):b&&b()}function q(a,b,c){return"function"==typeof b?(c=b,b={}):b||(b={}),b.lng=a,f(b,c)}function r(){return G}function s(a){J={},q(G,a)}function t(){function a(a,b,c){if(0!==b.length){var d="text";if(0===b.indexOf("[")){var e=b.split("]");b=e[1],d=e[0].substr(1,e[0].length-1)}b.indexOf(";")===b.length-1&&(b=b.substr(0,b.length-2));var f;if("html"===d)f=O.defaultValueFromContent?H.extend({defaultValue:a.html()},c):c,a.html(H.t(b,f));else if("text"===d)f=O.defaultValueFromContent?H.extend({defaultValue:a.text()},c):c,a.text(H.t(b,f));else if("prepend"===d)f=O.defaultValueFromContent?H.extend({defaultValue:a.html()},c):c,a.prepend(H.t(b,f));else if("append"===d)f=O.defaultValueFromContent?H.extend({defaultValue:a.html()},c):c,a.append(H.t(b,f));else if(0===d.indexOf("data-")){var g=d.substr("data-".length);f=O.defaultValueFromContent?H.extend({defaultValue:a.data(g)},c):c;var h=H.t(b,f);a.data(g,h),a.attr(d,h)}else f=O.defaultValueFromContent?H.extend({defaultValue:a.attr(d)},c):c,a.attr(d,H.t(b,f))}}function b(b,c){var d=b.attr(O.selectorAttr);if(d||"undefined"==typeof d||d===!1||(d=b.text()||b.val()),d){var e=b,f=b.data("i18n-target");if(f&&(e=b.find(f)||b),c||O.useDataAttrOptions!==!0||(c=b.data("i18n-options")),c=c||{},d.indexOf(";")>=0){var g=d.split(";");H.each(g,function(b,d){""!==d&&a(e,d,c)})}else a(e,d,c);O.useDataAttrOptions===!0&&b.data("i18n-options",c)}}H.t=H.t||A,H.fn.i18n=function(a){return this.each(function(){b(H(this),a);var c=H(this).find("["+O.selectorAttr+"]");c.each(function(){b(H(this),a)})})}}function u(a,b,c,d){if(!a)return a;if(d=d||b,a.indexOf(d.interpolationPrefix||O.interpolationPrefix)<0)return a;var e=d.interpolationPrefix?S.regexEscape(d.interpolationPrefix):O.interpolationPrefixEscaped,f=d.interpolationSuffix?S.regexEscape(d.interpolationSuffix):O.interpolationSuffixEscaped,g="HTML"+f,h=b.replace&&"object"==typeof b.replace?b.replace:b;return S.each(h,function(b,h){var i=c?c+O.keyseparator+b:b;"object"==typeof h&&null!==h?a=u(a,h,i,d):d.escapeInterpolation||O.escapeInterpolation?(a=a.replace(new RegExp([e,i,g].join(""),"g"),S.regexReplacementEscape(h)),a=a.replace(new RegExp([e,i,f].join(""),"g"),S.regexReplacementEscape(S.escape(h)))):a=a.replace(new RegExp([e,i,f].join(""),"g"),S.regexReplacementEscape(h))}),a}function v(a,b){var c=",",d="{",e="}",f=S.extend({},b);for(delete f.postProcess;-1!=a.indexOf(O.reusePrefix)&&(K++,!(K>O.maxRecursion));){var g=a.lastIndexOf(O.reusePrefix),h=a.indexOf(O.reuseSuffix,g)+O.reuseSuffix.length,i=a.substring(g,h),j=i.replace(O.reusePrefix,"").replace(O.reuseSuffix,"");if(g>=h)return S.error("there is an missing closing in following translation value",a),"";if(-1!=j.indexOf(c)){var k=j.indexOf(c);if(-1!=j.indexOf(d,k)&&-1!=j.indexOf(e,k)){var l=j.indexOf(d,k),m=j.indexOf(e,l)+e.length;try{f=S.extend(f,JSON.parse(j.substring(l,m))),j=j.substring(0,k)}catch(n){}}}var o=D(j,f);a=a.replace(i,S.regexReplacementEscape(o))}return a}function w(a){return a.context&&("string"==typeof a.context||"number"==typeof a.context)}function x(a){return void 0!==a.count&&"string"!=typeof a.count}function y(a){return void 0!==a.indefinite_article&&"string"!=typeof a.indefinite_article&&a.indefinite_article}function z(a,b){b=b||{};var c=B(a,b),d=E(a,b);return void 0!==d||d===c}function A(a,b){return b=b||{},M?(K=0,D.apply(null,arguments)):(S.log("i18next not finished initialization. you might have called t function before loading resources finished."),b.defaultValue||"")}function B(a,b){return void 0!==b.defaultValue?b.defaultValue:a}function C(){for(var a=[],b=1;b1)for(var d=0;d-1&&(e=c.split(O.nsseparator),i=e[0],c=e[1]),void 0===g&&O.sendMissing&&"function"==typeof O.missingKeyHandler&&(b.lng?O.missingKeyHandler(h[0],i,c,f,h):O.missingKeyHandler(O.lng,i,c,f,h));var j;j="string"==typeof O.postProcess&&""!==O.postProcess?[O.postProcess]:"array"==typeof O.postProcess||"object"==typeof O.postProcess?O.postProcess:[],"string"==typeof b.postProcess&&""!==b.postProcess?j=j.concat([b.postProcess]):("array"==typeof b.postProcess||"object"==typeof b.postProcess)&&(j=j.concat(b.postProcess)),void 0!==g&&j.length&&j.forEach(function(a){W[a]&&(g=W[a](g,c,b))});var k=f;if(f.indexOf(O.nsseparator)>-1&&(e=f.split(O.nsseparator),k=e[1]),k===c&&O.parseMissingKey&&(f=O.parseMissingKey(f)),void 0===g&&(f=u(f,b),f=v(f,b),j.length)){var l=B(c,b);j.forEach(function(a){W[a]&&(g=W[a](l,c,b))})}return void 0!==g?g:f}function E(a,b){b=b||{};var c,d,e=B(a,b),f=L;if(!J)return e;if("cimode"===f[0].toLowerCase())return e;if(b.lngs&&(f=b.lngs),b.lng&&(f=S.toLanguages(b.lng,b.fallbackLng),!J[f[0]])){var g=O.getAsync;O.getAsync=!1,I.sync.load(f,O,function(a,b){S.extend(J,b),O.getAsync=g})}var h=b.ns||O.ns.defaultNs;if(a.indexOf(O.nsseparator)>-1){var i=a.split(O.nsseparator);h=i[0],a=i[1]}if(w(b)){c=S.extend({},b),delete c.context,c.defaultValue=O.contextNotFound;var j=h+O.nsseparator+a+"_"+b.context;if(d=A(j,c),d!=O.contextNotFound)return u(d,{context:b.context})}if(x(b,f[0])){c=S.extend({lngs:[f[0]]},b),delete c.count,c._origLng=c._origLng||c.lng||f[0],delete c.lng,c.defaultValue=O.pluralNotFound;var k;if(V.needsPlural(f[0],b.count)){k=h+O.nsseparator+a+O.pluralSuffix;var l=V.get(f[0],b.count);l>=0?k=k+"_"+l:1===l&&(k=h+O.nsseparator+a)}else k=h+O.nsseparator+a;if(d=A(k,c),d!=O.pluralNotFound)return u(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix});if(!(f.length>1))return c.lng=c._origLng,delete c._origLng,d=A(h+O.nsseparator+a,c),u(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix});var m=f.slice();if(m.shift(),b=S.extend(b,{lngs:m}),b._origLng=c._origLng,delete b.lng,d=A(h+O.nsseparator+a,b),d!=O.pluralNotFound)return d}if(y(b)){var n=S.extend({},b);delete n.indefinite_article,n.defaultValue=O.indefiniteNotFound;var o=h+O.nsseparator+a+(b.count&&!x(b,f[0])||!b.count?O.indefiniteSuffix:"");if(d=A(o,n),d!=O.indefiniteNotFound)return d}for(var p,q=a.split(O.keyseparator),r=0,s=f.length;s>r&&void 0===p;r++){for(var t=f[r],z=0,C=J[t]&&J[t][h];q[z];)C=C&&C[q[z]],z++;if(void 0!==C){var F=Object.prototype.toString.apply(C);if("string"==typeof C)C=u(C,b),C=v(C,b);else if("[object Array]"!==F||O.returnObjectTrees||b.returnObjectTrees){if(null===C&&O.fallbackOnNull===!0)C=void 0;else if(null!==C)if(O.returnObjectTrees||b.returnObjectTrees){if("[object Number]"!==F&&"[object Function]"!==F&&"[object RegExp]"!==F){var G="[object Array]"===F?[]:{};S.each(C,function(c){G[c]=D(h+O.nsseparator+a+O.keyseparator+c,b)}),C=G}}else O.objectTreeKeyHandler&&"function"==typeof O.objectTreeKeyHandler?C=O.objectTreeKeyHandler(a,C,t,h,b):(C="key '"+h+":"+a+" ("+t+")' returned an object instead of string.",S.log(C))}else C=C.join("\n"),C=u(C,b),C=v(C,b);"string"==typeof C&&""===C.trim()&&O.fallbackOnEmpty===!0&&(C=void 0),p=C}}if(void 0===p&&!b.isFallbackLookup&&(O.fallbackToDefaultNS===!0||O.fallbackNS&&O.fallbackNS.length>0)){if(b.isFallbackLookup=!0,O.fallbackNS.length){for(var H=0,K=O.fallbackNS.length;K>H;H++)if(p=E(O.fallbackNS[H]+O.nsseparator+a,b),p||""===p&&O.fallbackOnEmpty===!1){var M=p.indexOf(O.nsseparator)>-1?p.split(O.nsseparator)[1]:p,N=e.indexOf(O.nsseparator)>-1?e.split(O.nsseparator)[1]:e;if(M!==N)break}}else p=E(a,b);b.isFallbackLookup=!1}return p}function F(){var a,b=O.lngWhitelist||[],c=[];if("undefined"!=typeof window&&!function(){for(var a=window.location.search.substring(1),b=a.split("&"),d=0;d0){var f=b[d].substring(0,e);f==O.detectLngQS&&c.push(b[d].substring(e+1))}}}(),O.useCookie&&"undefined"!=typeof document){var d=S.cookie.read(O.cookieName);d&&c.push(d)}if(O.detectLngFromLocalStorage&&"undefined"!=typeof window&&window.localStorage&&c.push(S.localStorage.getItem("i18next_lng")),"undefined"!=typeof navigator){if(navigator.languages)for(var e=0;e-1){var f=e.split("-");e=O.lowerCaseLng?f[0].toLowerCase()+"-"+f[1].toLowerCase():f[0].toLowerCase()+"-"+f[1].toUpperCase()}if(0===b.length||b.indexOf(e)>-1){a=e;break}}}(),a||(a=O.fallbackLng[0]),a}Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>0&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=c;arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d))));for(var e=d>=0?Math.min(d,c-1):c-Math.abs(d);e>=0;e--)if(e in b&&b[e]===a)return e;return-1}),"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")});var G,H=void 0,I={},J={},K=0,L=[],M=!1,N={};N={load:function(a,b,c){b.useLocalStorage?N._loadLocal(a,b,function(d,e){for(var f=[],g=0,h=a.length;h>g;g++)e[a[g]]||f.push(a[g]);f.length>0?N._fetch(f,b,function(a,b){S.extend(e,b),N._storeLocal(b),c(null,e)}):c(null,e)}):N._fetch(a,b,function(a,b){c(null,b)})},_loadLocal:function(a,b,c){var d={},e=(new Date).getTime();if(window.localStorage){var f=a.length;S.each(a,function(a,g){var h=S.localStorage.getItem("res_"+g);h&&(h=JSON.parse(h),h.i18nStamp&&h.i18nStamp+b.localStorageExpirationTime>e&&(d[g]=h)),f--,0===f&&c(null,d)})}},_storeLocal:function(a){if(window.localStorage)for(var b in a)a[b].i18nStamp=(new Date).getTime(),S.localStorage.setItem("res_"+b,JSON.stringify(a[b]))},_fetch:function(a,b,c){var d=b.ns,e={};if(b.dynamicLoad){var f=function(a,b){c(null,b)};if("function"==typeof b.customLoad)b.customLoad(a,d.namespaces,b,f);else{var g=u(b.resGetPath,{lng:a.join("+"),ns:d.namespaces.join("+")});S.ajax({url:g,success:function(a){S.log("loaded: "+g),f(null,a)},error:function(a,b,c){S.log("failed loading: "+g),f("failed loading resource.json error: "+c)},dataType:"json",async:b.getAsync})}}else{var h,i=d.namespaces.length*a.length;S.each(d.namespaces,function(d,f){S.each(a,function(a,d){var g=function(a,b){a&&(h=h||[],h.push(a)),e[d]=e[d]||{},e[d][f]=b,i--,0===i&&c(h,e)};"function"==typeof b.customLoad?b.customLoad(d,f,b,g):N._fetchOne(d,f,b,g)})})}},_fetchOne:function(a,b,c,d){var e=u(c.resGetPath,{lng:a,ns:b});S.ajax({url:e,success:function(a){S.log("loaded: "+e),d(null,a)},error:function(a,b,c){if(b&&200==b||a&&a.status&&200==a.status)S.error("There is a typo in: "+e);else if(b&&404==b||a&&a.status&&404==a.status)S.log("Does not exist: "+e);else{var f=b?b:a&&a.status?a.status:null;S.log(f+" when loading "+e)}d(c,{})},dataType:"json",async:c.getAsync})},postMissing:function(a,b,c,d,e){var f={};f[c]=d;var g=[];if("fallback"===O.sendMissingTo&&O.fallbackLng[0]!==!1)for(var h=0;hh;h++)g.push({lng:e[h],url:u(O.resPostPath,{lng:e[h],ns:b})});for(var j=0,k=g.length;k>j;j++){var l=g[j];S.ajax({url:l.url,type:O.sendType,data:f,success:function(){S.log("posted missing key '"+c+"' to: "+l.url);for(var a=c.split("."),e=0,f=J[l.lng][b];a[e];)f=f[a[e]]=e===a.length-1?d:f[a[e]]||{},e++},error:function(){S.log("failed posting missing key '"+c+"' to: "+l.url)},dataType:"json",async:O.postAsync})}},reload:s};var O={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:["dev"],fallbackNS:[],detectLngQS:"setLng",detectLngFromLocalStorage:!1,ns:{namespaces:["translation"],defaultNs:"translation"},fallbackOnNull:!0,fallbackOnEmpty:!1,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",defaultVariables:!1,reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,indefiniteSuffix:"_indefinite",indefiniteNotFound:["indefinite_not_found",Math.random()].join(""),setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",cookieDomain:void 0,objectTreeKeyHandler:void 0,postProcess:void 0,parseMissingKey:void 0,missingKeyHandler:N.postMissing,shortcutFunction:"sprintf"},P={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},Q={create:function(a,b,c,d){var e;if(c){var f=new Date;f.setTime(f.getTime()+60*c*1e3),e="; expires="+f.toGMTString()}else e="";d=d?"domain="+d+";":"",document.cookie=a+"="+b+e+";"+d+"path=/"},read:function(a){for(var b=a+"=",c=document.cookie.split(";"),d=0;d-1){var c=a.split("-");b=O.lowerCaseLng?c[0].toLowerCase()+"-"+c[1].toLowerCase():c[0].toLowerCase()+"-"+c[1].toUpperCase()}else b=O.lowerCaseLng?a.toLowerCase():a;return b}var c=this.log,d=[],e=O.lngWhitelist||!1,f=function(a){!e||e.indexOf(a)>-1?d.push(a):c("rejecting non-whitelisted language: "+a)};if("string"==typeof a&&a.indexOf("-")>-1){var g=a.split("-");"unspecific"!==O.load&&f(b(a)),"current"!==O.load&&f(b(g[this.getCountyIndexOfLng(a)]))}else f(b(a));for(var h=0;h1)},2:function(a){return Number(1!=a)},3:function(){return 0},4:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},5:function(a){return Number(0===a?0:1==a?1:2==a?2:a%100>=3&&10>=a%100?3:a%100>=11?4:5)},6:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)},7:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},8:function(a){return Number(1==a?0:2==a?1:8!=a&&11!=a?2:3)},9:function(a){return Number(a>=2)},10:function(a){return Number(1==a?0:2==a?1:7>a?2:11>a?3:4)},11:function(a){return Number(1==a||11==a?0:2==a||12==a?1:a>2&&20>a?2:3)},12:function(a){return Number(a%10!=1||a%100==11)},13:function(a){return Number(0!==a)},14:function(a){return Number(1==a?0:2==a?1:3==a?2:3)},15:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&(10>a%100||a%100>=20)?1:2)},16:function(a){return Number(a%10==1&&a%100!=11?0:0!==a?1:2)},17:function(a){return Number(1==a||a%10==1?0:1)},18:function(a){return Number(1==a?1:2)},19:function(a){return Number(1==a?0:0===a||a%100>1&&11>a%100?1:a%100>10&&20>a%100?2:3)},20:function(a){return Number(1==a?0:0===a||a%100>0&&20>a%100?1:2)},21:function(a){return Number(a%100==1?1:a%100==2?2:a%100==3||a%100==4?3:0)}},V={rules:function(){var a,b={};for(a=T.length;a--;)b[T[a][0]]={name:T[a][1],numbers:T[a][2],plurals:U[T[a][3]]};return b}(),addRule:function(a,b){V.rules[a]=b},setCurrentLng:function(a){if(!V.currentRule||V.currentRule.lng!==a){var b=a.split("-");V.currentRule={lng:a,rule:V.rules[b[0]]}}},needsPlural:function(a,b){var c,d=a.split("-");return c=V.currentRule&&V.currentRule.lng===a?V.currentRule.rule:V.rules[d[S.getCountyIndexOfLng(a)]],c&&c.numbers.length<=1?!1:1!==this.get(a,b)},get:function(a,b){function c(b,c){var d;if(d=V.currentRule&&V.currentRule.lng===a?V.currentRule.rule:V.rules[b]){var e;e=d.plurals(d.noAbs?c:Math.abs(c));var f=d.numbers[e];return 2===d.numbers.length&&1===d.numbers[0]&&(2===f?f=-1:1===f&&(f=1)),f}return 1===c?"1":"-1"}var d=a.split("-");return c(d[S.getCountyIndexOfLng(a)],b)}},W={},X=function(a,b){W[a]=b},Y=function(){function a(a){return Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}function b(a,b){for(var c=[];b>0;c[--b]=a);return c.join("")}var c=function(){return c.cache.hasOwnProperty(arguments[0])||(c.cache[arguments[0]]=c.parse(arguments[0])),c.format.call(null,c.cache[arguments[0]],arguments)};return c.format=function(c,d){var e,f,g,h,i,j,k,l=1,m=c.length,n="",o=[];for(f=0;m>f;f++)if(n=a(c[f]),"string"===n)o.push(c[f]);else if("array"===n){if(h=c[f],h[2])for(e=d[l],g=0;g=0?"+"+e:e,j=h[4]?"0"==h[4]?"0":h[4].charAt(1):" ",k=h[6]-String(e).length,i=h[6]?b(j,k):"",o.push(h[5]?e+i:i+e)}return o.join("")},c.cache={},c.parse=function(a){for(var b=a,c=[],d=[],e=0;b;){if(null!==(c=/^[^\x25]+/.exec(b)))d.push(c[0]);else if(null!==(c=/^\x25{2}/.exec(b)))d.push("%");else{if(null===(c=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(b)))throw"[sprintf] huh?";if(c[2]){e|=1;var f=[],g=c[2],h=[];if(null===(h=/^([a-z_][a-z_\d]*)/i.exec(g)))throw"[sprintf] huh?";for(f.push(h[1]);""!==(g=g.substring(h[0].length));)if(null!==(h=/^\.([a-z_][a-z_\d]*)/i.exec(g)))f.push(h[1]);else{if(null===(h=/^\[(\d+)\]/.exec(g)))throw"[sprintf] huh?";f.push(h[1])}c[2]=f}else e|=2;if(3===e)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";d.push(c)}b=b.substring(c[0].length)}return d},c}(),Z=function(a,b){return b.unshift(a),Y.apply(null,b)};return X("sprintf",function(a,b,c){return c.sprintf?"[object Array]"===Object.prototype.toString.apply(c.sprintf)?Z(a,c.sprintf):"object"==typeof c.sprintf?Y(a,c.sprintf):a:a}),I.init=f,I.setLng=q,I.preload=g,I.addResourceBundle=h,I.hasResourceBundle=i,I.getResourceBundle=j,I.addResource=l,I.addResources=m,I.removeResourceBundle=k,I.loadNamespace=o,I.loadNamespaces=p,I.setDefaultNamespace=n,I.t=A,I.translate=A,I.exists=z,I.detectLanguage=S.detectLanguage,I.pluralExtensions=V,I.sync=N,I.functions=S,I.lng=r,I.addPostProcessor=X,I.applyReplacement=S.applyReplacement,I.options=O,I}); \ No newline at end of file diff --git a/libs/i18next/i18next.amd.withJQuery.js b/libs/i18next/i18next.amd.withJQuery.js new file mode 100644 index 00000000..46e8f4f2 --- /dev/null +++ b/libs/i18next/i18next.amd.withJQuery.js @@ -0,0 +1,2180 @@ +// i18next, v1.8.2 +// Copyright (c)2015 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function (root, factory) { + if (typeof exports === 'object') { + + var jquery = require('jquery'); + + module.exports = factory(jquery); + + } else if (typeof define === 'function' && define.amd) { + + define(['jquery'], factory); + + } +}(this, function ($) { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + // Add string trim for IE8. + if (typeof String.prototype.trim !== 'function') { + String.prototype.trim = function() { + return this.replace(/^\s+|\s+$/g, ''); + } + } + + var i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = [] + , initialized = false + , sync = {}; + + sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = f.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + f.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + if ((status && status == 200) || (xhr && xhr.status && xhr.status == 200)) { + // file loaded but invalid json, stop waste time ! + f.error('There is a typo in: ' + url); + } else if ((status && status == 404) || (xhr && xhr.status && xhr.status == 404)) { + f.log('Does not exist: ' + url); + } else { + var theStatus = status ? status : ((xhr && xhr.status) ? xhr.status : null); + f.log(theStatus + ' when loading ' + url); + } + + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback' && o.fallbackLng[0] !== false) { + for (var i = 0; i < o.fallbackLng.length; i++) { + urls.push({lng: o.fallbackLng[i], url: applyReplacement(o.resPostPath, { lng: o.fallbackLng[i], ns: ns })}); + } + } else if (o.sendMissingTo === 'current' || (o.sendMissingTo === 'fallback' && o.fallbackLng[0] === false) ) { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + }, + + reload: reload + }; + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: ['dev'], + fallbackNS: [], + detectLngQS: 'setLng', + detectLngFromLocalStorage: false, + ns: { + namespaces: ['translation'], + defaultNs: 'translation' + }, + fallbackOnNull: true, + fallbackOnEmpty: false, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + defaultVariables: false, + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + indefiniteSuffix: '_indefinite', + indefiniteNotFound: ['indefinite_not_found', Math.random()].join(''), + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + cookieDomain: undefined, + + objectTreeKeyHandler: undefined, + postProcess: undefined, + parseMissingKey: undefined, + missingKeyHandler: sync.postMissing, + + shortcutFunction: 'sprintf' // or: defaultValue + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _deepExtend(target, source) { + for (var prop in source) + if (prop in target) + _deepExtend(target[prop], source[prop]); + else + target[prop] = source[prop]; + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || Object.prototype.toString.apply(object) !== '[object Array]' || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + try { + return JSON.parse(data) + } catch (e) { + f.error('Can not parse JSON. URL: ' + url); + return {}; + } + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + // file: protocol always gives status code 0, so check for data + if (status === 200 || (status === 0 && data.text())) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes,domain) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + domain = (domain)? "domain="+domain+";" : ""; + document.cookie = name+"="+value+expires+";"+domain+"path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes,domain) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + deepExtend: _deepExtend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : (typeof document !== 'undefined' ? _ajax : function() {}), + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + error: function(str) { + if (typeof console !== "undefined") console.error(str); + }, + getCountyIndexOfLng: function(lng) { + var lng_index = 0; + if (lng === 'nb-NO' || lng === 'nn-NO' || lng === 'nb-no' || lng === 'nn-no') lng_index = 1; + return lng_index; + }, + toLanguages: function(lng) { + var log = this.log; + + function applyCase(l) { + var ret = l; + + if (typeof l === 'string' && l.indexOf('-') > -1) { + var parts = l.split('-'); + + ret = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } else { + ret = o.lowerCaseLng ? l.toLowerCase() : l; + } + + return ret; + } + + var languages = []; + var whitelist = o.lngWhitelist || false; + var addLanguage = function(language){ + //reject langs not whitelisted + if(!whitelist || whitelist.indexOf(language) > -1){ + languages.push(language); + }else{ + log('rejecting non-whitelisted language: ' + language); + } + }; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + if (o.load !== 'unspecific') addLanguage(applyCase(lng)); + if (o.load !== 'current') addLanguage(applyCase(parts[this.getCountyIndexOfLng(lng)])); + } else { + addLanguage(applyCase(lng)); + } + + for (var i = 0; i < o.fallbackLng.length; i++) { + if (languages.indexOf(o.fallbackLng[i]) === -1 && o.fallbackLng[i]) languages.push(applyCase(o.fallbackLng[i])); + } + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + }, + regexReplacementEscape: function(strOrFn) { + if (typeof strOrFn === 'string') { + return strOrFn.replace(/\$/g, "$$$$"); + } else { + return strOrFn; + } + }, + localStorage: { + setItem: function(key, value) { + if (window.localStorage) { + try { + window.localStorage.setItem(key, value); + } catch (e) { + f.log('failed to set value for key "' + key + '" to localStorage.'); + } + } + }, + getItem: function(key, value) { + if (window.localStorage) { + try { + return window.localStorage.getItem(key, value); + } catch (e) { + f.log('failed to get value for key "' + key + '" from localStorage.'); + return undefined; + } + } + } + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + delete o.fixLng; /* passed in each time */ + + // override functions: .log(), .detectLanguage(), etc + if (o.functions) { + delete o.functions; + f.extend(f, options.functions); + } + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // fallback languages + if (typeof o.fallbackLng == 'string' || typeof o.fallbackLng == 'boolean') { + o.fallbackLng = [o.fallbackLng]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + if (o.useCookie && f.cookie.read(o.cookieName) !== currentLng){ //cookie is unset or invalid + f.cookie.create(o.cookieName, currentLng, o.cookieExpirationTime, o.cookieDomain); + } + if (o.detectLngFromLocalStorage && typeof document !== 'undefined' && window.localStorage) { + f.localStorage.setItem('i18next_lng', currentLng); + } + + var lngTranslate = translate; + if (options.fixLng) { + lngTranslate = function(key, options) { + options = options || {}; + options.lng = options.lng || lngTranslate.lng; + return translate(key, options); + }; + lngTranslate.lng = currentLng; + } + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + initialized = true; + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + initialized = true; + + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources, deep) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + if (deep) { + f.deepExtend(resStore[lng][ns], resources); + } else { + f.extend(resStore[lng][ns], resources); + } + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function hasResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + var res = resStore[lng][ns] || {}; + + var hasValues = false; + for(var prop in res) { + if (res.hasOwnProperty(prop)) { + hasValues = true; + } + } + + return hasValues; + } + + function getResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + return f.extend({}, resStore[lng][ns]); + } + + function removeResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = {}; + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function addResource(lng, ns, key, value) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + var keys = key.split(o.keyseparator); + var x = 0; + var node = resStore[lng][ns]; + var origRef = node; + + while (keys[x]) { + if (x == keys.length - 1) + node[keys[x]] = value; + else { + if (node[keys[x]] == null) + node[keys[x]] = {}; + + node = node[keys[x]]; + } + x++; + } + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function addResources(lng, ns, resources) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + for (var m in resources) { + if (typeof resources[m] === 'string') addResource(lng, ns, m, resources[m]); + } + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, options, cb) { + if (typeof options === 'function') { + cb = options; + options = {}; + } else if (!options) { + options = {}; + } + + options.lng = lng; + return init(options, cb); + } + + function lng() { + return currentLng; + } + + function reload(cb) { + resStore = {}; + setLng(currentLng, cb); + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else if (attr === 'prepend') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.prepend($.t(key, optionsToUse)); + } else if (attr === 'append') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.append($.t(key, optionsToUse)); + } else if (attr.indexOf("data-") === 0) { + var dataAttr = attr.substr(("data-").length); + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.data(dataAttr) }, options) : options; + var translated = $.t(key, optionsToUse); + //we change into the data cache + ele.data(dataAttr, translated); + //we change into the dom + ele.attr(attr, translated); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key && typeof key !== 'undefined' && key !== false) key = ele.text() || ele.val(); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + var hash = replacementHash.replace && typeof replacementHash.replace === 'object' ? replacementHash.replace : replacementHash; + f.each(hash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), f.regexReplacementEscape(value)); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(f.escape(value))); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(value)); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + if (index_of_end_of_closing <= index_of_opening) { + f.error('there is an missing closing in following translation value', translated); + return ''; + } + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, f.regexReplacementEscape(translated_token)); + } + return translated; + } + + function hasContext(options) { + return (options.context && (typeof options.context == 'string' || typeof options.context == 'number')); + } + + function needsPlural(options, lng) { + return (options.count !== undefined && typeof options.count != 'string'/* && pluralExtensions.needsPlural(lng, options.count)*/); + } + + function needsIndefiniteArticle(options) { + return (options.indefinite_article !== undefined && typeof options.indefinite_article != 'string' && options.indefinite_article); + } + + function exists(key, options) { + options = options || {}; + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + options = options || {}; + + if (!initialized) { + f.log('i18next not finished initialization. you might have called t function before loading resources finished.') + return options.defaultValue || ''; + }; + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _getDefaultValue(key, options) { + return (options.defaultValue !== undefined) ? options.defaultValue : key; + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(potentialKeys, options) { + if (options && typeof options !== 'object') { + if (o.shortcutFunction === 'sprintf') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else if (o.shortcutFunction === 'defaultValue') { + options = { + defaultValue: options + } + } + } else { + options = options || {}; + } + + if (typeof o.defaultVariables === 'object') { + options = f.extend({}, o.defaultVariables, options); + } + + if (potentialKeys === undefined || potentialKeys === null || potentialKeys === '') return ''; + + if (typeof potentialKeys === 'number') { + potentialKeys = String(potentialKeys); + } + + if (typeof potentialKeys === 'string') { + potentialKeys = [potentialKeys]; + } + + var key = potentialKeys[0]; + + if (potentialKeys.length > 1) { + for (var i = 0; i < potentialKeys.length; i++) { + key = potentialKeys[i]; + if (exists(key, options)) { + break; + } + } + } + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng, options.fallbackLng) : languages + , ns = options.ns || o.ns.defaultNs + , parts; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing && typeof o.missingKeyHandler === 'function') { + if (options.lng) { + o.missingKeyHandler(lngs[0], ns, key, notFound, lngs); + } else { + o.missingKeyHandler(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessorsToApply; + if (typeof o.postProcess === 'string' && o.postProcess !== '') { + postProcessorsToApply = [o.postProcess]; + } else if (typeof o.postProcess === 'array' || typeof o.postProcess === 'object') { + postProcessorsToApply = o.postProcess; + } else { + postProcessorsToApply = []; + } + + if (typeof options.postProcess === 'string' && options.postProcess !== '') { + postProcessorsToApply = postProcessorsToApply.concat([options.postProcess]); + } else if (typeof options.postProcess === 'array' || typeof options.postProcess === 'object') { + postProcessorsToApply = postProcessorsToApply.concat(options.postProcess); + } + + if (found !== undefined && postProcessorsToApply.length) { + postProcessorsToApply.forEach(function(postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + }); + } + + // process notFound if function exists + var splitNotFound = notFound; + if (notFound.indexOf(o.nsseparator) > -1) { + parts = notFound.split(o.nsseparator); + splitNotFound = parts[1]; + } + if (splitNotFound === key && o.parseMissingKey) { + notFound = o.parseMissingKey(notFound); + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessorsToApply.length) { + var val = _getDefaultValue(key, options); + postProcessorsToApply.forEach(function(postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](val, key, options); + } + }); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options) { + options = options || {}; + + var optionWithoutCount, translated + , notFound = _getDefaultValue(key, options) + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + // CI mode + if (lngs[0].toLowerCase() === 'cimode') return notFound; + + // passed in lng + if (options.lngs) lngs = options.lngs; + if (options.lng) { + lngs = f.toLanguages(options.lng, options.fallbackLng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options, lngs[0])) { + optionWithoutCount = f.extend({ lngs: [lngs[0]]}, options); + delete optionWithoutCount.count; + optionWithoutCount._origLng = optionWithoutCount._origLng || optionWithoutCount.lng || lngs[0]; + delete optionWithoutCount.lng; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey; + if (!pluralExtensions.needsPlural(lngs[0], options.count)) { + pluralKey = ns + o.nsseparator + key; + } else { + pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(lngs[0], options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + } + + translated = translate(pluralKey, optionWithoutCount); + + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } else if (lngs.length > 1) { + // remove failed lng + var clone = lngs.slice(); + clone.shift(); + options = f.extend(options, { lngs: clone }); + options._origLng = optionWithoutCount._origLng; + delete options.lng; + // retry with fallbacks + translated = translate(ns + o.nsseparator + key, options); + if (translated != o.pluralNotFound) return translated; + } else { + optionWithoutCount.lng = optionWithoutCount._origLng; + delete optionWithoutCount._origLng; + translated = translate(ns + o.nsseparator + key, optionWithoutCount); + + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); + } + } + + if (needsIndefiniteArticle(options)) { + var optionsWithoutIndef = f.extend({}, options); + delete optionsWithoutIndef.indefinite_article; + optionsWithoutIndef.defaultValue = o.indefiniteNotFound; + // If we don't have a count, we want the indefinite, if we do have a count, and needsPlural is false + var indefiniteKey = ns + o.nsseparator + key + (((options.count && !needsPlural(options, lngs[0])) || !options.count) ? o.indefiniteSuffix : ""); + translated = translate(indefiniteKey, optionsWithoutIndef); + if (translated != o.indefiniteNotFound) { + return translated; + } + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + var valueType = Object.prototype.toString.apply(value); + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (valueType === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + if (o.objectTreeKeyHandler && typeof o.objectTreeKeyHandler == 'function') { + value = o.objectTreeKeyHandler(key, value, l, ns, options); + } else { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned an object instead of string.'; + f.log(value); + } + } else if (valueType !== '[object Number]' && valueType !== '[object Function]' && valueType !== '[object RegExp]') { + var copy = (valueType === '[object Array]') ? [] : {}; // apply child translation on a copy + f.each(value, function(m) { + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + }); + value = copy; + } + } + + if (typeof value === 'string' && value.trim() === '' && o.fallbackOnEmpty === true) + value = undefined; + + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length > 0))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found || (found==="" && o.fallbackOnEmpty === false)) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + options.isFallbackLookup = false; + } + + return found; + } + function detectLanguage() { + var detectedLng; + var whitelist = o.lngWhitelist || []; + var userLngChoices = []; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var params = query.split('&'); + for (var i=0; i 0) { + var key = params[i].substring(0,pos); + if (key == o.detectLngQS) { + userLngChoices.push(params[i].substring(pos+1)); + } + } + } + })(); + } + + // get from cookie + if (o.useCookie && typeof document !== 'undefined') { + var c = f.cookie.read(o.cookieName); + if (c) userLngChoices.push(c); + } + + // get from localStorage + if (o.detectLngFromLocalStorage && typeof window !== 'undefined' && window.localStorage) { + userLngChoices.push(f.localStorage.getItem('i18next_lng')); + } + + // get from navigator + if (typeof navigator !== 'undefined') { + if (navigator.languages) { // chrome only; not an array, so can't use .push.apply instead of iterating + for (var i=0;i -1) { + var parts = lng.split('-'); + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } + + if (whitelist.length === 0 || whitelist.indexOf(lng) > -1) { + detectedLng = lng; + break; + } + } + })(); + + //fallback + if (!detectedLng){ + detectedLng = o.fallbackLng[0]; + } + + return detectedLng; + } + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + + /* [code, name, numbers, pluralsType] */ + var _rules = [ + ["ach", "Acholi", [1,2], 1], + ["af", "Afrikaans",[1,2], 2], + ["ak", "Akan", [1,2], 1], + ["am", "Amharic", [1,2], 1], + ["an", "Aragonese",[1,2], 2], + ["ar", "Arabic", [0,1,2,3,11,100],5], + ["arn", "Mapudungun",[1,2], 1], + ["ast", "Asturian", [1,2], 2], + ["ay", "Aymará", [1], 3], + ["az", "Azerbaijani",[1,2],2], + ["be", "Belarusian",[1,2,5],4], + ["bg", "Bulgarian",[1,2], 2], + ["bn", "Bengali", [1,2], 2], + ["bo", "Tibetan", [1], 3], + ["br", "Breton", [1,2], 1], + ["bs", "Bosnian", [1,2,5],4], + ["ca", "Catalan", [1,2], 2], + ["cgg", "Chiga", [1], 3], + ["cs", "Czech", [1,2,5],6], + ["csb", "Kashubian",[1,2,5],7], + ["cy", "Welsh", [1,2,3,8],8], + ["da", "Danish", [1,2], 2], + ["de", "German", [1,2], 2], + ["dev", "Development Fallback", [1,2], 2], + ["dz", "Dzongkha", [1], 3], + ["el", "Greek", [1,2], 2], + ["en", "English", [1,2], 2], + ["eo", "Esperanto",[1,2], 2], + ["es", "Spanish", [1,2], 2], + ["es_ar","Argentinean Spanish", [1,2], 2], + ["et", "Estonian", [1,2], 2], + ["eu", "Basque", [1,2], 2], + ["fa", "Persian", [1], 3], + ["fi", "Finnish", [1,2], 2], + ["fil", "Filipino", [1,2], 1], + ["fo", "Faroese", [1,2], 2], + ["fr", "French", [1,2], 9], + ["fur", "Friulian", [1,2], 2], + ["fy", "Frisian", [1,2], 2], + ["ga", "Irish", [1,2,3,7,11],10], + ["gd", "Scottish Gaelic",[1,2,3,20],11], + ["gl", "Galician", [1,2], 2], + ["gu", "Gujarati", [1,2], 2], + ["gun", "Gun", [1,2], 1], + ["ha", "Hausa", [1,2], 2], + ["he", "Hebrew", [1,2], 2], + ["hi", "Hindi", [1,2], 2], + ["hr", "Croatian", [1,2,5],4], + ["hu", "Hungarian",[1,2], 2], + ["hy", "Armenian", [1,2], 2], + ["ia", "Interlingua",[1,2],2], + ["id", "Indonesian",[1], 3], + ["is", "Icelandic",[1,2], 12], + ["it", "Italian", [1,2], 2], + ["ja", "Japanese", [1], 3], + ["jbo", "Lojban", [1], 3], + ["jv", "Javanese", [0,1], 13], + ["ka", "Georgian", [1], 3], + ["kk", "Kazakh", [1], 3], + ["km", "Khmer", [1], 3], + ["kn", "Kannada", [1,2], 2], + ["ko", "Korean", [1], 3], + ["ku", "Kurdish", [1,2], 2], + ["kw", "Cornish", [1,2,3,4],14], + ["ky", "Kyrgyz", [1], 3], + ["lb", "Letzeburgesch",[1,2],2], + ["ln", "Lingala", [1,2], 1], + ["lo", "Lao", [1], 3], + ["lt", "Lithuanian",[1,2,10],15], + ["lv", "Latvian", [1,2,0],16], + ["mai", "Maithili", [1,2], 2], + ["mfe", "Mauritian Creole",[1,2],1], + ["mg", "Malagasy", [1,2], 1], + ["mi", "Maori", [1,2], 1], + ["mk", "Macedonian",[1,2],17], + ["ml", "Malayalam",[1,2], 2], + ["mn", "Mongolian",[1,2], 2], + ["mnk", "Mandinka", [0,1,2],18], + ["mr", "Marathi", [1,2], 2], + ["ms", "Malay", [1], 3], + ["mt", "Maltese", [1,2,11,20],19], + ["nah", "Nahuatl", [1,2], 2], + ["nap", "Neapolitan",[1,2], 2], + ["nb", "Norwegian Bokmal",[1,2],2], + ["ne", "Nepali", [1,2], 2], + ["nl", "Dutch", [1,2], 2], + ["nn", "Norwegian Nynorsk",[1,2],2], + ["no", "Norwegian",[1,2], 2], + ["nso", "Northern Sotho",[1,2],2], + ["oc", "Occitan", [1,2], 1], + ["or", "Oriya", [2,1], 2], + ["pa", "Punjabi", [1,2], 2], + ["pap", "Papiamento",[1,2], 2], + ["pl", "Polish", [1,2,5],7], + ["pms", "Piemontese",[1,2], 2], + ["ps", "Pashto", [1,2], 2], + ["pt", "Portuguese",[1,2], 2], + ["pt_br","Brazilian Portuguese",[1,2], 2], + ["rm", "Romansh", [1,2], 2], + ["ro", "Romanian", [1,2,20],20], + ["ru", "Russian", [1,2,5],4], + ["sah", "Yakut", [1], 3], + ["sco", "Scots", [1,2], 2], + ["se", "Northern Sami",[1,2], 2], + ["si", "Sinhala", [1,2], 2], + ["sk", "Slovak", [1,2,5],6], + ["sl", "Slovenian",[5,1,2,3],21], + ["so", "Somali", [1,2], 2], + ["son", "Songhay", [1,2], 2], + ["sq", "Albanian", [1,2], 2], + ["sr", "Serbian", [1,2,5],4], + ["su", "Sundanese",[1], 3], + ["sv", "Swedish", [1,2], 2], + ["sw", "Swahili", [1,2], 2], + ["ta", "Tamil", [1,2], 2], + ["te", "Telugu", [1,2], 2], + ["tg", "Tajik", [1,2], 1], + ["th", "Thai", [1], 3], + ["ti", "Tigrinya", [1,2], 1], + ["tk", "Turkmen", [1,2], 2], + ["tr", "Turkish", [1,2], 1], + ["tt", "Tatar", [1], 3], + ["ug", "Uyghur", [1], 3], + ["uk", "Ukrainian",[1,2,5],4], + ["ur", "Urdu", [1,2], 2], + ["uz", "Uzbek", [1,2], 1], + ["vi", "Vietnamese",[1], 3], + ["wa", "Walloon", [1,2], 1], + ["wo", "Wolof", [1], 3], + ["yo", "Yoruba", [1,2], 2], + ["zh", "Chinese", [1], 3] + ]; + + var _rulesPluralsTypes = { + 1: function(n) {return Number(n > 1);}, + 2: function(n) {return Number(n != 1);}, + 3: function(n) {return 0;}, + 4: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 5: function(n) {return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5);}, + 6: function(n) {return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2);}, + 7: function(n) {return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 8: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3);}, + 9: function(n) {return Number(n >= 2);}, + 10: function(n) {return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;}, + 11: function(n) {return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3);}, + 12: function(n) {return Number(n%10!=1 || n%100==11);}, + 13: function(n) {return Number(n !== 0);}, + 14: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3);}, + 15: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 16: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2);}, + 17: function(n) {return Number(n==1 || n%10==1 ? 0 : 1);}, + 18: function(n) {return Number(0 ? 0 : n==1 ? 1 : 2);}, + 19: function(n) {return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3);}, + 20: function(n) {return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2);}, + 21: function(n) {return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }; + + var pluralExtensions = { + + rules: (function () { + var l, rules = {}; + for (l=_rules.length; l-- ;) { + rules[_rules[l][0]] = { + name: _rules[l][1], + numbers: _rules[l][2], + plurals: _rulesPluralsTypes[_rules[l][3]] + } + } + return rules; + }()), + + // you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + needsPlural: function(lng, count) { + var parts = lng.split('-'); + + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[parts[f.getCountyIndexOfLng(lng)]]; + } + + if (ext && ext.numbers.length <= 1) { + return false; + } else { + return this.get(lng, count) !== 1; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i; + if (ext.noAbs) { + i = ext.plurals(c); + } else { + i = ext.plurals(Math.abs(c)); + } + + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[f.getCountyIndexOfLng(lng)], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.hasResourceBundle = hasResourceBundle; + i18n.getResourceBundle = getResourceBundle; + i18n.addResource = addResource; + i18n.addResources = addResources; + i18n.removeResourceBundle = removeResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.applyReplacement = f.applyReplacement; + i18n.options = o; + + $.i18n = i18n; + $.t = i18n.t; + + return i18n; + +})); \ No newline at end of file diff --git a/libs/i18next/i18next.amd.withJQuery.min.js b/libs/i18next/i18next.amd.withJQuery.min.js new file mode 100644 index 00000000..0f9273f2 --- /dev/null +++ b/libs/i18next/i18next.amd.withJQuery.min.js @@ -0,0 +1,5 @@ +// i18next, v1.8.2 +// Copyright (c)2015 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +!function(a,b){if("object"==typeof exports){var c=require("jquery");module.exports=b(c)}else"function"==typeof define&&define.amd&&define(["jquery"],b)}(this,function(a){function b(a,b){if(!b||"function"==typeof b)return a;for(var c in b)a[c]=b[c];return a}function c(a,b){for(var d in b)d in a?c(a[d],b[d]):a[d]=b[d];return a}function d(a,b,c){var d,e=0,f=a.length,g=void 0===f||"[object Array]"!==Object.prototype.toString.apply(a)||"function"==typeof a;if(c)if(g){for(d in a)if(b.apply(a[d],c)===!1)break}else for(;f>e&&b.apply(a[e++],c)!==!1;);else if(g){for(d in a)if(b.call(a[d],d,a[d])===!1)break}else for(;f>e&&b.call(a[e],e,a[e++])!==!1;);return a}function e(a){return"string"==typeof a?a.replace(/[&<>"'\/]/g,function(a){return P[a]}):a}function f(a){var b=function(a){if(window.XMLHttpRequest)return a(null,new XMLHttpRequest);if(window.ActiveXObject)try{return a(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(b){return a(null,new ActiveXObject("Microsoft.XMLHTTP"))}return a(new Error)},c=function(a){if("string"==typeof a)return a;var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")},d=function(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;cd?b+=String.fromCharCode(d):d>127&&2048>d?(b+=String.fromCharCode(d>>6|192),b+=String.fromCharCode(63&d|128)):(b+=String.fromCharCode(d>>12|224),b+=String.fromCharCode(d>>6&63|128),b+=String.fromCharCode(63&d|128))}return b},e=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";a=d(a);var c,e,f,g,h,i,j,k="",l=0;do c=a.charCodeAt(l++),e=a.charCodeAt(l++),f=a.charCodeAt(l++),g=c>>2,h=(3&c)<<4|e>>4,i=(15&e)<<2|f>>6,j=63&f,isNaN(e)?i=j=64:isNaN(f)&&(j=64),k+=b.charAt(g)+b.charAt(h)+b.charAt(i)+b.charAt(j),c=e=f="",g=h=i=j="";while(l1&&(d+=d.indexOf("?")>-1?"&"+k:"?"+k),e.jsonp){var l=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=d,void l.appendChild(m)}}b(function(b,c){if(b)return h(b);c.open(a,d,e.async);for(var f in j)j.hasOwnProperty(f)&&c.setRequestHeader(f,j[f]);c.onreadystatechange=function(){if(4===c.readyState){var a=c.responseText||"";if(!h)return;h(c.status,{text:function(){return a},json:function(){try{return JSON.parse(a)}catch(b){return S.error("Can not parse JSON. URL: "+d),{}}}})}},c.send(i)})},h={authBasic:function(a,b){g.headers.Authorization="Basic "+e(a+":"+b)},connect:function(a,b,c){return g("CONNECT",a,b,c)},del:function(a,b,c){return g("DELETE",a,b,c)},get:function(a,b,c){return g("GET",a,b,c)},head:function(a,b,c){return g("HEAD",a,b,c)},headers:function(a){g.headers=a||{}},isAllowed:function(a,b,c){this.options(a,function(a,d){c(-1!==d.text().indexOf(b))})},options:function(a,b,c){return g("OPTIONS",a,b,c)},patch:function(a,b,c){return g("PATCH",a,b,c)},post:function(a,b,c){return g("POST",a,b,c)},put:function(a,b,c){return g("PUT",a,b,c)},trace:function(a,b,c){return g("TRACE",a,b,c)}},i=a.type?a.type.toLowerCase():"get";h[i](a.url,a,function(b,c){200===b||0===b&&c.text()?a.success(c.json(),b,null):a.error(c.text(),b,null)})}function g(b,c){"function"==typeof b&&(c=b,b={}),b=b||{},S.extend(O,b),delete O.fixLng,O.functions&&(delete O.functions,S.extend(S,b.functions)),"string"==typeof O.ns&&(O.ns={namespaces:[O.ns],defaultNs:O.ns}),"string"==typeof O.fallbackNS&&(O.fallbackNS=[O.fallbackNS]),("string"==typeof O.fallbackLng||"boolean"==typeof O.fallbackLng)&&(O.fallbackLng=[O.fallbackLng]),O.interpolationPrefixEscaped=S.regexEscape(O.interpolationPrefix),O.interpolationSuffixEscaped=S.regexEscape(O.interpolationSuffix),O.lng||(O.lng=S.detectLanguage()),L=S.toLanguages(O.lng),H=L[0],S.log("currentLng set to: "+H),O.useCookie&&S.cookie.read(O.cookieName)!==H&&S.cookie.create(O.cookieName,H,O.cookieExpirationTime,O.cookieDomain),O.detectLngFromLocalStorage&&"undefined"!=typeof document&&window.localStorage&&S.localStorage.setItem("i18next_lng",H);var d=B;b.fixLng&&(d=function(a,b){return b=b||{},b.lng=b.lng||d.lng,B(a,b)},d.lng=H),V.setCurrentLng(H),a&&O.setJqueryExt&&u();var e;if(a&&a.Deferred&&(e=a.Deferred()),!O.resStore){var f=S.toLanguages(O.lng);"string"==typeof O.preload&&(O.preload=[O.preload]);for(var g=0,h=O.preload.length;h>g;g++)for(var i=S.toLanguages(O.preload[g]),j=0,k=i.length;k>j;j++)f.indexOf(i[j])<0&&f.push(i[j]);return I.sync.load(f,O,function(a,b){J=b,M=!0,c&&c(d),e&&e.resolve(d)}),e?e.promise():void 0}return J=O.resStore,M=!0,c&&c(d),e&&e.resolve(d),e?e.promise():void 0}function h(a,b){"string"==typeof a&&(a=[a]);for(var c=0,d=a.length;d>c;c++)O.preload.indexOf(a[c])<0&&O.preload.push(a[c]);return g(b)}function i(a,b,c,d){"string"!=typeof b?(c=b,b=O.ns.defaultNs):O.ns.namespaces.indexOf(b)<0&&O.ns.namespaces.push(b),J[a]=J[a]||{},J[a][b]=J[a][b]||{},d?S.deepExtend(J[a][b],c):S.extend(J[a][b],c),O.useLocalStorage&&N._storeLocal(J)}function j(a,b){"string"!=typeof b&&(b=O.ns.defaultNs),J[a]=J[a]||{};var c=J[a][b]||{},d=!1;for(var e in c)c.hasOwnProperty(e)&&(d=!0);return d}function k(a,b){return"string"!=typeof b&&(b=O.ns.defaultNs),J[a]=J[a]||{},S.extend({},J[a][b])}function l(a,b){"string"!=typeof b&&(b=O.ns.defaultNs),J[a]=J[a]||{},J[a][b]={},O.useLocalStorage&&N._storeLocal(J)}function m(a,b,c,d){"string"!=typeof b?(resource=b,b=O.ns.defaultNs):O.ns.namespaces.indexOf(b)<0&&O.ns.namespaces.push(b),J[a]=J[a]||{},J[a][b]=J[a][b]||{};for(var e=c.split(O.keyseparator),f=0,g=J[a][b];e[f];)f==e.length-1?g[e[f]]=d:(null==g[e[f]]&&(g[e[f]]={}),g=g[e[f]]),f++;O.useLocalStorage&&N._storeLocal(J)}function n(a,b,c){"string"!=typeof b?(resource=b,b=O.ns.defaultNs):O.ns.namespaces.indexOf(b)<0&&O.ns.namespaces.push(b);for(var d in c)"string"==typeof c[d]&&m(a,b,d,c[d])}function o(a){O.ns.defaultNs=a}function p(a,b){q([a],b)}function q(a,b){var c={dynamicLoad:O.dynamicLoad,resGetPath:O.resGetPath,getAsync:O.getAsync,customLoad:O.customLoad,ns:{namespaces:a,defaultNs:""}},d=S.toLanguages(O.lng);"string"==typeof O.preload&&(O.preload=[O.preload]);for(var e=0,f=O.preload.length;f>e;e++)for(var g=S.toLanguages(O.preload[e]),h=0,i=g.length;i>h;h++)d.indexOf(g[h])<0&&d.push(g[h]);for(var j=[],k=0,l=d.length;l>k;k++){var m=!1,n=J[d[k]];if(n)for(var o=0,p=a.length;p>o;o++)n[a[o]]||(m=!0);else m=!0;m&&j.push(d[k])}j.length?I.sync._fetch(j,c,function(c,d){var e=a.length*j.length;S.each(a,function(a,c){O.ns.namespaces.indexOf(c)<0&&O.ns.namespaces.push(c),S.each(j,function(a,f){J[f]=J[f]||{},J[f][c]=d[f][c],e--,0===e&&b&&(O.useLocalStorage&&I.sync._storeLocal(J),b())})})}):b&&b()}function r(a,b,c){return"function"==typeof b?(c=b,b={}):b||(b={}),b.lng=a,g(b,c)}function s(){return H}function t(a){J={},r(H,a)}function u(){function b(b,c,d){if(0!==c.length){var e="text";if(0===c.indexOf("[")){var f=c.split("]");c=f[1],e=f[0].substr(1,f[0].length-1)}c.indexOf(";")===c.length-1&&(c=c.substr(0,c.length-2));var g;if("html"===e)g=O.defaultValueFromContent?a.extend({defaultValue:b.html()},d):d,b.html(a.t(c,g));else if("text"===e)g=O.defaultValueFromContent?a.extend({defaultValue:b.text()},d):d,b.text(a.t(c,g));else if("prepend"===e)g=O.defaultValueFromContent?a.extend({defaultValue:b.html()},d):d,b.prepend(a.t(c,g));else if("append"===e)g=O.defaultValueFromContent?a.extend({defaultValue:b.html()},d):d,b.append(a.t(c,g));else if(0===e.indexOf("data-")){var h=e.substr("data-".length);g=O.defaultValueFromContent?a.extend({defaultValue:b.data(h)},d):d;var i=a.t(c,g);b.data(h,i),b.attr(e,i)}else g=O.defaultValueFromContent?a.extend({defaultValue:b.attr(e)},d):d,b.attr(e,a.t(c,g))}}function c(c,d){var e=c.attr(O.selectorAttr);if(e||"undefined"==typeof e||e===!1||(e=c.text()||c.val()),e){var f=c,g=c.data("i18n-target");if(g&&(f=c.find(g)||c),d||O.useDataAttrOptions!==!0||(d=c.data("i18n-options")),d=d||{},e.indexOf(";")>=0){var h=e.split(";");a.each(h,function(a,c){""!==c&&b(f,c,d)})}else b(f,e,d);O.useDataAttrOptions===!0&&c.data("i18n-options",d)}}a.t=a.t||B,a.fn.i18n=function(b){return this.each(function(){c(a(this),b);var d=a(this).find("["+O.selectorAttr+"]");d.each(function(){c(a(this),b)})})}}function v(a,b,c,d){if(!a)return a;if(d=d||b,a.indexOf(d.interpolationPrefix||O.interpolationPrefix)<0)return a;var e=d.interpolationPrefix?S.regexEscape(d.interpolationPrefix):O.interpolationPrefixEscaped,f=d.interpolationSuffix?S.regexEscape(d.interpolationSuffix):O.interpolationSuffixEscaped,g="HTML"+f,h=b.replace&&"object"==typeof b.replace?b.replace:b;return S.each(h,function(b,h){var i=c?c+O.keyseparator+b:b;"object"==typeof h&&null!==h?a=v(a,h,i,d):d.escapeInterpolation||O.escapeInterpolation?(a=a.replace(new RegExp([e,i,g].join(""),"g"),S.regexReplacementEscape(h)),a=a.replace(new RegExp([e,i,f].join(""),"g"),S.regexReplacementEscape(S.escape(h)))):a=a.replace(new RegExp([e,i,f].join(""),"g"),S.regexReplacementEscape(h))}),a}function w(a,b){var c=",",d="{",e="}",f=S.extend({},b);for(delete f.postProcess;-1!=a.indexOf(O.reusePrefix)&&(K++,!(K>O.maxRecursion));){var g=a.lastIndexOf(O.reusePrefix),h=a.indexOf(O.reuseSuffix,g)+O.reuseSuffix.length,i=a.substring(g,h),j=i.replace(O.reusePrefix,"").replace(O.reuseSuffix,"");if(g>=h)return S.error("there is an missing closing in following translation value",a),"";if(-1!=j.indexOf(c)){var k=j.indexOf(c);if(-1!=j.indexOf(d,k)&&-1!=j.indexOf(e,k)){var l=j.indexOf(d,k),m=j.indexOf(e,l)+e.length;try{f=S.extend(f,JSON.parse(j.substring(l,m))),j=j.substring(0,k)}catch(n){}}}var o=E(j,f);a=a.replace(i,S.regexReplacementEscape(o))}return a}function x(a){return a.context&&("string"==typeof a.context||"number"==typeof a.context)}function y(a){return void 0!==a.count&&"string"!=typeof a.count}function z(a){return void 0!==a.indefinite_article&&"string"!=typeof a.indefinite_article&&a.indefinite_article}function A(a,b){b=b||{};var c=C(a,b),d=F(a,b);return void 0!==d||d===c}function B(a,b){return b=b||{},M?(K=0,E.apply(null,arguments)):(S.log("i18next not finished initialization. you might have called t function before loading resources finished."),b.defaultValue||"")}function C(a,b){return void 0!==b.defaultValue?b.defaultValue:a}function D(){for(var a=[],b=1;b1)for(var d=0;d-1&&(e=c.split(O.nsseparator),i=e[0],c=e[1]),void 0===g&&O.sendMissing&&"function"==typeof O.missingKeyHandler&&(b.lng?O.missingKeyHandler(h[0],i,c,f,h):O.missingKeyHandler(O.lng,i,c,f,h));var j;j="string"==typeof O.postProcess&&""!==O.postProcess?[O.postProcess]:"array"==typeof O.postProcess||"object"==typeof O.postProcess?O.postProcess:[],"string"==typeof b.postProcess&&""!==b.postProcess?j=j.concat([b.postProcess]):("array"==typeof b.postProcess||"object"==typeof b.postProcess)&&(j=j.concat(b.postProcess)),void 0!==g&&j.length&&j.forEach(function(a){W[a]&&(g=W[a](g,c,b))});var k=f;if(f.indexOf(O.nsseparator)>-1&&(e=f.split(O.nsseparator),k=e[1]),k===c&&O.parseMissingKey&&(f=O.parseMissingKey(f)),void 0===g&&(f=v(f,b),f=w(f,b),j.length)){var l=C(c,b);j.forEach(function(a){W[a]&&(g=W[a](l,c,b))})}return void 0!==g?g:f}function F(a,b){b=b||{};var c,d,e=C(a,b),f=L;if(!J)return e;if("cimode"===f[0].toLowerCase())return e;if(b.lngs&&(f=b.lngs),b.lng&&(f=S.toLanguages(b.lng,b.fallbackLng),!J[f[0]])){var g=O.getAsync;O.getAsync=!1,I.sync.load(f,O,function(a,b){S.extend(J,b),O.getAsync=g})}var h=b.ns||O.ns.defaultNs;if(a.indexOf(O.nsseparator)>-1){var i=a.split(O.nsseparator);h=i[0],a=i[1]}if(x(b)){c=S.extend({},b),delete c.context,c.defaultValue=O.contextNotFound;var j=h+O.nsseparator+a+"_"+b.context;if(d=B(j,c),d!=O.contextNotFound)return v(d,{context:b.context})}if(y(b,f[0])){c=S.extend({lngs:[f[0]]},b),delete c.count,c._origLng=c._origLng||c.lng||f[0],delete c.lng,c.defaultValue=O.pluralNotFound;var k;if(V.needsPlural(f[0],b.count)){k=h+O.nsseparator+a+O.pluralSuffix;var l=V.get(f[0],b.count);l>=0?k=k+"_"+l:1===l&&(k=h+O.nsseparator+a)}else k=h+O.nsseparator+a;if(d=B(k,c),d!=O.pluralNotFound)return v(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix});if(!(f.length>1))return c.lng=c._origLng,delete c._origLng,d=B(h+O.nsseparator+a,c),v(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix});var m=f.slice();if(m.shift(),b=S.extend(b,{lngs:m}),b._origLng=c._origLng,delete b.lng,d=B(h+O.nsseparator+a,b),d!=O.pluralNotFound)return d}if(z(b)){var n=S.extend({},b);delete n.indefinite_article,n.defaultValue=O.indefiniteNotFound;var o=h+O.nsseparator+a+(b.count&&!y(b,f[0])||!b.count?O.indefiniteSuffix:"");if(d=B(o,n),d!=O.indefiniteNotFound)return d}for(var p,q=a.split(O.keyseparator),r=0,s=f.length;s>r&&void 0===p;r++){for(var t=f[r],u=0,A=J[t]&&J[t][h];q[u];)A=A&&A[q[u]],u++;if(void 0!==A){var D=Object.prototype.toString.apply(A);if("string"==typeof A)A=v(A,b),A=w(A,b);else if("[object Array]"!==D||O.returnObjectTrees||b.returnObjectTrees){if(null===A&&O.fallbackOnNull===!0)A=void 0;else if(null!==A)if(O.returnObjectTrees||b.returnObjectTrees){if("[object Number]"!==D&&"[object Function]"!==D&&"[object RegExp]"!==D){var G="[object Array]"===D?[]:{};S.each(A,function(c){G[c]=E(h+O.nsseparator+a+O.keyseparator+c,b)}),A=G}}else O.objectTreeKeyHandler&&"function"==typeof O.objectTreeKeyHandler?A=O.objectTreeKeyHandler(a,A,t,h,b):(A="key '"+h+":"+a+" ("+t+")' returned an object instead of string.",S.log(A))}else A=A.join("\n"),A=v(A,b),A=w(A,b);"string"==typeof A&&""===A.trim()&&O.fallbackOnEmpty===!0&&(A=void 0),p=A}}if(void 0===p&&!b.isFallbackLookup&&(O.fallbackToDefaultNS===!0||O.fallbackNS&&O.fallbackNS.length>0)){if(b.isFallbackLookup=!0,O.fallbackNS.length){for(var H=0,K=O.fallbackNS.length;K>H;H++)if(p=F(O.fallbackNS[H]+O.nsseparator+a,b),p||""===p&&O.fallbackOnEmpty===!1){var M=p.indexOf(O.nsseparator)>-1?p.split(O.nsseparator)[1]:p,N=e.indexOf(O.nsseparator)>-1?e.split(O.nsseparator)[1]:e;if(M!==N)break}}else p=F(a,b);b.isFallbackLookup=!1}return p}function G(){var a,b=O.lngWhitelist||[],c=[];if("undefined"!=typeof window&&!function(){for(var a=window.location.search.substring(1),b=a.split("&"),d=0;d0){var f=b[d].substring(0,e);f==O.detectLngQS&&c.push(b[d].substring(e+1))}}}(),O.useCookie&&"undefined"!=typeof document){var d=S.cookie.read(O.cookieName);d&&c.push(d)}if(O.detectLngFromLocalStorage&&"undefined"!=typeof window&&window.localStorage&&c.push(S.localStorage.getItem("i18next_lng")),"undefined"!=typeof navigator){if(navigator.languages)for(var e=0;e-1){var f=e.split("-");e=O.lowerCaseLng?f[0].toLowerCase()+"-"+f[1].toLowerCase():f[0].toLowerCase()+"-"+f[1].toUpperCase()}if(0===b.length||b.indexOf(e)>-1){a=e;break}}}(),a||(a=O.fallbackLng[0]),a}Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>0&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=c;arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d))));for(var e=d>=0?Math.min(d,c-1):c-Math.abs(d);e>=0;e--)if(e in b&&b[e]===a)return e;return-1}),"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")});var H,I={},J={},K=0,L=[],M=!1,N={};N={load:function(a,b,c){b.useLocalStorage?N._loadLocal(a,b,function(d,e){for(var f=[],g=0,h=a.length;h>g;g++)e[a[g]]||f.push(a[g]);f.length>0?N._fetch(f,b,function(a,b){S.extend(e,b),N._storeLocal(b),c(null,e)}):c(null,e)}):N._fetch(a,b,function(a,b){c(null,b)})},_loadLocal:function(a,b,c){var d={},e=(new Date).getTime();if(window.localStorage){var f=a.length;S.each(a,function(a,g){var h=S.localStorage.getItem("res_"+g);h&&(h=JSON.parse(h),h.i18nStamp&&h.i18nStamp+b.localStorageExpirationTime>e&&(d[g]=h)),f--,0===f&&c(null,d)})}},_storeLocal:function(a){if(window.localStorage)for(var b in a)a[b].i18nStamp=(new Date).getTime(),S.localStorage.setItem("res_"+b,JSON.stringify(a[b]))},_fetch:function(a,b,c){var d=b.ns,e={};if(b.dynamicLoad){var f=function(a,b){c(null,b)};if("function"==typeof b.customLoad)b.customLoad(a,d.namespaces,b,f);else{var g=v(b.resGetPath,{lng:a.join("+"),ns:d.namespaces.join("+")});S.ajax({url:g,success:function(a){S.log("loaded: "+g),f(null,a)},error:function(a,b,c){S.log("failed loading: "+g),f("failed loading resource.json error: "+c)},dataType:"json",async:b.getAsync})}}else{var h,i=d.namespaces.length*a.length;S.each(d.namespaces,function(d,f){S.each(a,function(a,d){var g=function(a,b){a&&(h=h||[],h.push(a)),e[d]=e[d]||{},e[d][f]=b,i--,0===i&&c(h,e)};"function"==typeof b.customLoad?b.customLoad(d,f,b,g):N._fetchOne(d,f,b,g)})})}},_fetchOne:function(a,b,c,d){var e=v(c.resGetPath,{lng:a,ns:b});S.ajax({url:e,success:function(a){S.log("loaded: "+e),d(null,a)},error:function(a,b,c){if(b&&200==b||a&&a.status&&200==a.status)S.error("There is a typo in: "+e);else if(b&&404==b||a&&a.status&&404==a.status)S.log("Does not exist: "+e);else{var f=b?b:a&&a.status?a.status:null;S.log(f+" when loading "+e)}d(c,{})},dataType:"json",async:c.getAsync})},postMissing:function(a,b,c,d,e){var f={};f[c]=d;var g=[];if("fallback"===O.sendMissingTo&&O.fallbackLng[0]!==!1)for(var h=0;hh;h++)g.push({lng:e[h],url:v(O.resPostPath,{lng:e[h],ns:b})});for(var j=0,k=g.length;k>j;j++){var l=g[j];S.ajax({url:l.url,type:O.sendType,data:f,success:function(){S.log("posted missing key '"+c+"' to: "+l.url);for(var a=c.split("."),e=0,f=J[l.lng][b];a[e];)f=f[a[e]]=e===a.length-1?d:f[a[e]]||{},e++},error:function(){S.log("failed posting missing key '"+c+"' to: "+l.url)},dataType:"json",async:O.postAsync})}},reload:t};var O={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:["dev"],fallbackNS:[],detectLngQS:"setLng",detectLngFromLocalStorage:!1,ns:{namespaces:["translation"],defaultNs:"translation"},fallbackOnNull:!0,fallbackOnEmpty:!1,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",defaultVariables:!1,reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,indefiniteSuffix:"_indefinite",indefiniteNotFound:["indefinite_not_found",Math.random()].join(""),setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",cookieDomain:void 0,objectTreeKeyHandler:void 0,postProcess:void 0,parseMissingKey:void 0,missingKeyHandler:N.postMissing,shortcutFunction:"sprintf"},P={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},Q={create:function(a,b,c,d){var e;if(c){var f=new Date;f.setTime(f.getTime()+60*c*1e3),e="; expires="+f.toGMTString()}else e="";d=d?"domain="+d+";":"",document.cookie=a+"="+b+e+";"+d+"path=/"},read:function(a){for(var b=a+"=",c=document.cookie.split(";"),d=0;d-1){var c=a.split("-");b=O.lowerCaseLng?c[0].toLowerCase()+"-"+c[1].toLowerCase():c[0].toLowerCase()+"-"+c[1].toUpperCase()}else b=O.lowerCaseLng?a.toLowerCase():a;return b}var c=this.log,d=[],e=O.lngWhitelist||!1,f=function(a){!e||e.indexOf(a)>-1?d.push(a):c("rejecting non-whitelisted language: "+a)};if("string"==typeof a&&a.indexOf("-")>-1){var g=a.split("-");"unspecific"!==O.load&&f(b(a)),"current"!==O.load&&f(b(g[this.getCountyIndexOfLng(a)]))}else f(b(a));for(var h=0;h1)},2:function(a){return Number(1!=a)},3:function(){return 0},4:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},5:function(a){return Number(0===a?0:1==a?1:2==a?2:a%100>=3&&10>=a%100?3:a%100>=11?4:5)},6:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)},7:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},8:function(a){return Number(1==a?0:2==a?1:8!=a&&11!=a?2:3)},9:function(a){return Number(a>=2)},10:function(a){return Number(1==a?0:2==a?1:7>a?2:11>a?3:4)},11:function(a){return Number(1==a||11==a?0:2==a||12==a?1:a>2&&20>a?2:3)},12:function(a){return Number(a%10!=1||a%100==11)},13:function(a){return Number(0!==a)},14:function(a){return Number(1==a?0:2==a?1:3==a?2:3)},15:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&(10>a%100||a%100>=20)?1:2)},16:function(a){return Number(a%10==1&&a%100!=11?0:0!==a?1:2)},17:function(a){return Number(1==a||a%10==1?0:1)},18:function(a){return Number(1==a?1:2)},19:function(a){return Number(1==a?0:0===a||a%100>1&&11>a%100?1:a%100>10&&20>a%100?2:3)},20:function(a){return Number(1==a?0:0===a||a%100>0&&20>a%100?1:2)},21:function(a){return Number(a%100==1?1:a%100==2?2:a%100==3||a%100==4?3:0)}},V={rules:function(){var a,b={};for(a=T.length;a--;)b[T[a][0]]={name:T[a][1],numbers:T[a][2],plurals:U[T[a][3]]};return b}(),addRule:function(a,b){V.rules[a]=b},setCurrentLng:function(a){if(!V.currentRule||V.currentRule.lng!==a){var b=a.split("-");V.currentRule={lng:a,rule:V.rules[b[0]]}}},needsPlural:function(a,b){var c,d=a.split("-");return c=V.currentRule&&V.currentRule.lng===a?V.currentRule.rule:V.rules[d[S.getCountyIndexOfLng(a)]],c&&c.numbers.length<=1?!1:1!==this.get(a,b)},get:function(a,b){function c(b,c){var d;if(d=V.currentRule&&V.currentRule.lng===a?V.currentRule.rule:V.rules[b]){var e;e=d.plurals(d.noAbs?c:Math.abs(c));var f=d.numbers[e];return 2===d.numbers.length&&1===d.numbers[0]&&(2===f?f=-1:1===f&&(f=1)),f}return 1===c?"1":"-1"}var d=a.split("-");return c(d[S.getCountyIndexOfLng(a)],b)}},W={},X=function(a,b){W[a]=b},Y=function(){function a(a){return Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}function b(a,b){for(var c=[];b>0;c[--b]=a);return c.join("")}var c=function(){return c.cache.hasOwnProperty(arguments[0])||(c.cache[arguments[0]]=c.parse(arguments[0])),c.format.call(null,c.cache[arguments[0]],arguments)};return c.format=function(c,d){var e,f,g,h,i,j,k,l=1,m=c.length,n="",o=[];for(f=0;m>f;f++)if(n=a(c[f]),"string"===n)o.push(c[f]);else if("array"===n){if(h=c[f],h[2])for(e=d[l],g=0;g=0?"+"+e:e,j=h[4]?"0"==h[4]?"0":h[4].charAt(1):" ",k=h[6]-String(e).length,i=h[6]?b(j,k):"",o.push(h[5]?e+i:i+e)}return o.join("")},c.cache={},c.parse=function(a){for(var b=a,c=[],d=[],e=0;b;){if(null!==(c=/^[^\x25]+/.exec(b)))d.push(c[0]);else if(null!==(c=/^\x25{2}/.exec(b)))d.push("%");else{if(null===(c=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(b)))throw"[sprintf] huh?";if(c[2]){e|=1;var f=[],g=c[2],h=[];if(null===(h=/^([a-z_][a-z_\d]*)/i.exec(g)))throw"[sprintf] huh?";for(f.push(h[1]);""!==(g=g.substring(h[0].length));)if(null!==(h=/^\.([a-z_][a-z_\d]*)/i.exec(g)))f.push(h[1]);else{if(null===(h=/^\[(\d+)\]/.exec(g)))throw"[sprintf] huh?";f.push(h[1])}c[2]=f}else e|=2;if(3===e)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";d.push(c)}b=b.substring(c[0].length)}return d},c}(),Z=function(a,b){return b.unshift(a),Y.apply(null,b)};return X("sprintf",function(a,b,c){return c.sprintf?"[object Array]"===Object.prototype.toString.apply(c.sprintf)?Z(a,c.sprintf):"object"==typeof c.sprintf?Y(a,c.sprintf):a:a}),I.init=g,I.setLng=r,I.preload=h,I.addResourceBundle=i,I.hasResourceBundle=j,I.getResourceBundle=k,I.addResource=m,I.addResources=n,I.removeResourceBundle=l,I.loadNamespace=p,I.loadNamespaces=q,I.setDefaultNamespace=o,I.t=B,I.translate=B,I.exists=A,I.detectLanguage=S.detectLanguage,I.pluralExtensions=V,I.sync=N,I.functions=S,I.lng=s,I.addPostProcessor=X,I.applyReplacement=S.applyReplacement,I.options=O,a.i18n=I,a.t=I.t,I}); \ No newline at end of file diff --git a/libs/i18next/i18next.commonjs.withJQuery.js b/libs/i18next/i18next.commonjs.withJQuery.js new file mode 100644 index 00000000..fb96e55b --- /dev/null +++ b/libs/i18next/i18next.commonjs.withJQuery.js @@ -0,0 +1,2186 @@ +// i18next, v1.8.2 +// Copyright (c)2015 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function(root) { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + // Add string trim for IE8. + if (typeof String.prototype.trim !== 'function') { + String.prototype.trim = function() { + return this.replace(/^\s+|\s+$/g, ''); + } + } + + var $ = root.jQuery || root.Zepto + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = [] + , initialized = false + , sync = {}; + + + + // Export the i18next object for **CommonJS**. + // If we're not in CommonJS, add `i18n` to the + // global object or to jquery. + if (typeof module !== 'undefined' && module.exports) { + module.exports = i18n; + if (!$) { + try { + $ = require('jquery'); + } catch(e) { + // just ignore + } + } + + } else { + root.i18n = root.i18n || i18n; + } + + if ($) { + $.i18n = $.i18n || i18n; + } + sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = f.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + f.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + if ((status && status == 200) || (xhr && xhr.status && xhr.status == 200)) { + // file loaded but invalid json, stop waste time ! + f.error('There is a typo in: ' + url); + } else if ((status && status == 404) || (xhr && xhr.status && xhr.status == 404)) { + f.log('Does not exist: ' + url); + } else { + var theStatus = status ? status : ((xhr && xhr.status) ? xhr.status : null); + f.log(theStatus + ' when loading ' + url); + } + + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback' && o.fallbackLng[0] !== false) { + for (var i = 0; i < o.fallbackLng.length; i++) { + urls.push({lng: o.fallbackLng[i], url: applyReplacement(o.resPostPath, { lng: o.fallbackLng[i], ns: ns })}); + } + } else if (o.sendMissingTo === 'current' || (o.sendMissingTo === 'fallback' && o.fallbackLng[0] === false) ) { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + }, + + reload: reload + }; + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: ['dev'], + fallbackNS: [], + detectLngQS: 'setLng', + detectLngFromLocalStorage: false, + ns: { + namespaces: ['translation'], + defaultNs: 'translation' + }, + fallbackOnNull: true, + fallbackOnEmpty: false, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + defaultVariables: false, + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + indefiniteSuffix: '_indefinite', + indefiniteNotFound: ['indefinite_not_found', Math.random()].join(''), + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + cookieDomain: undefined, + + objectTreeKeyHandler: undefined, + postProcess: undefined, + parseMissingKey: undefined, + missingKeyHandler: sync.postMissing, + + shortcutFunction: 'sprintf' // or: defaultValue + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _deepExtend(target, source) { + for (var prop in source) + if (prop in target) + _deepExtend(target[prop], source[prop]); + else + target[prop] = source[prop]; + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || Object.prototype.toString.apply(object) !== '[object Array]' || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + try { + return JSON.parse(data) + } catch (e) { + f.error('Can not parse JSON. URL: ' + url); + return {}; + } + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + // file: protocol always gives status code 0, so check for data + if (status === 200 || (status === 0 && data.text())) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes,domain) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + domain = (domain)? "domain="+domain+";" : ""; + document.cookie = name+"="+value+expires+";"+domain+"path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes,domain) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + deepExtend: _deepExtend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : (typeof document !== 'undefined' ? _ajax : function() {}), + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + error: function(str) { + if (typeof console !== "undefined") console.error(str); + }, + getCountyIndexOfLng: function(lng) { + var lng_index = 0; + if (lng === 'nb-NO' || lng === 'nn-NO' || lng === 'nb-no' || lng === 'nn-no') lng_index = 1; + return lng_index; + }, + toLanguages: function(lng) { + var log = this.log; + + function applyCase(l) { + var ret = l; + + if (typeof l === 'string' && l.indexOf('-') > -1) { + var parts = l.split('-'); + + ret = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } else { + ret = o.lowerCaseLng ? l.toLowerCase() : l; + } + + return ret; + } + + var languages = []; + var whitelist = o.lngWhitelist || false; + var addLanguage = function(language){ + //reject langs not whitelisted + if(!whitelist || whitelist.indexOf(language) > -1){ + languages.push(language); + }else{ + log('rejecting non-whitelisted language: ' + language); + } + }; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + if (o.load !== 'unspecific') addLanguage(applyCase(lng)); + if (o.load !== 'current') addLanguage(applyCase(parts[this.getCountyIndexOfLng(lng)])); + } else { + addLanguage(applyCase(lng)); + } + + for (var i = 0; i < o.fallbackLng.length; i++) { + if (languages.indexOf(o.fallbackLng[i]) === -1 && o.fallbackLng[i]) languages.push(applyCase(o.fallbackLng[i])); + } + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + }, + regexReplacementEscape: function(strOrFn) { + if (typeof strOrFn === 'string') { + return strOrFn.replace(/\$/g, "$$$$"); + } else { + return strOrFn; + } + }, + localStorage: { + setItem: function(key, value) { + if (window.localStorage) { + try { + window.localStorage.setItem(key, value); + } catch (e) { + f.log('failed to set value for key "' + key + '" to localStorage.'); + } + } + }, + getItem: function(key, value) { + if (window.localStorage) { + try { + return window.localStorage.getItem(key, value); + } catch (e) { + f.log('failed to get value for key "' + key + '" from localStorage.'); + return undefined; + } + } + } + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + delete o.fixLng; /* passed in each time */ + + // override functions: .log(), .detectLanguage(), etc + if (o.functions) { + delete o.functions; + f.extend(f, options.functions); + } + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // fallback languages + if (typeof o.fallbackLng == 'string' || typeof o.fallbackLng == 'boolean') { + o.fallbackLng = [o.fallbackLng]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + if (o.useCookie && f.cookie.read(o.cookieName) !== currentLng){ //cookie is unset or invalid + f.cookie.create(o.cookieName, currentLng, o.cookieExpirationTime, o.cookieDomain); + } + if (o.detectLngFromLocalStorage && typeof document !== 'undefined' && window.localStorage) { + f.localStorage.setItem('i18next_lng', currentLng); + } + + var lngTranslate = translate; + if (options.fixLng) { + lngTranslate = function(key, options) { + options = options || {}; + options.lng = options.lng || lngTranslate.lng; + return translate(key, options); + }; + lngTranslate.lng = currentLng; + } + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + initialized = true; + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + initialized = true; + + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources, deep) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + if (deep) { + f.deepExtend(resStore[lng][ns], resources); + } else { + f.extend(resStore[lng][ns], resources); + } + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function hasResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + var res = resStore[lng][ns] || {}; + + var hasValues = false; + for(var prop in res) { + if (res.hasOwnProperty(prop)) { + hasValues = true; + } + } + + return hasValues; + } + + function getResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + return f.extend({}, resStore[lng][ns]); + } + + function removeResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = {}; + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function addResource(lng, ns, key, value) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + var keys = key.split(o.keyseparator); + var x = 0; + var node = resStore[lng][ns]; + var origRef = node; + + while (keys[x]) { + if (x == keys.length - 1) + node[keys[x]] = value; + else { + if (node[keys[x]] == null) + node[keys[x]] = {}; + + node = node[keys[x]]; + } + x++; + } + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function addResources(lng, ns, resources) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + for (var m in resources) { + if (typeof resources[m] === 'string') addResource(lng, ns, m, resources[m]); + } + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, options, cb) { + if (typeof options === 'function') { + cb = options; + options = {}; + } else if (!options) { + options = {}; + } + + options.lng = lng; + return init(options, cb); + } + + function lng() { + return currentLng; + } + + function reload(cb) { + resStore = {}; + setLng(currentLng, cb); + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else if (attr === 'prepend') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.prepend($.t(key, optionsToUse)); + } else if (attr === 'append') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.append($.t(key, optionsToUse)); + } else if (attr.indexOf("data-") === 0) { + var dataAttr = attr.substr(("data-").length); + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.data(dataAttr) }, options) : options; + var translated = $.t(key, optionsToUse); + //we change into the data cache + ele.data(dataAttr, translated); + //we change into the dom + ele.attr(attr, translated); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key && typeof key !== 'undefined' && key !== false) key = ele.text() || ele.val(); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + var hash = replacementHash.replace && typeof replacementHash.replace === 'object' ? replacementHash.replace : replacementHash; + f.each(hash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), f.regexReplacementEscape(value)); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(f.escape(value))); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(value)); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + if (index_of_end_of_closing <= index_of_opening) { + f.error('there is an missing closing in following translation value', translated); + return ''; + } + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, f.regexReplacementEscape(translated_token)); + } + return translated; + } + + function hasContext(options) { + return (options.context && (typeof options.context == 'string' || typeof options.context == 'number')); + } + + function needsPlural(options, lng) { + return (options.count !== undefined && typeof options.count != 'string'/* && pluralExtensions.needsPlural(lng, options.count)*/); + } + + function needsIndefiniteArticle(options) { + return (options.indefinite_article !== undefined && typeof options.indefinite_article != 'string' && options.indefinite_article); + } + + function exists(key, options) { + options = options || {}; + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + options = options || {}; + + if (!initialized) { + f.log('i18next not finished initialization. you might have called t function before loading resources finished.') + return options.defaultValue || ''; + }; + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _getDefaultValue(key, options) { + return (options.defaultValue !== undefined) ? options.defaultValue : key; + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(potentialKeys, options) { + if (options && typeof options !== 'object') { + if (o.shortcutFunction === 'sprintf') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else if (o.shortcutFunction === 'defaultValue') { + options = { + defaultValue: options + } + } + } else { + options = options || {}; + } + + if (typeof o.defaultVariables === 'object') { + options = f.extend({}, o.defaultVariables, options); + } + + if (potentialKeys === undefined || potentialKeys === null || potentialKeys === '') return ''; + + if (typeof potentialKeys === 'number') { + potentialKeys = String(potentialKeys); + } + + if (typeof potentialKeys === 'string') { + potentialKeys = [potentialKeys]; + } + + var key = potentialKeys[0]; + + if (potentialKeys.length > 1) { + for (var i = 0; i < potentialKeys.length; i++) { + key = potentialKeys[i]; + if (exists(key, options)) { + break; + } + } + } + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng, options.fallbackLng) : languages + , ns = options.ns || o.ns.defaultNs + , parts; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing && typeof o.missingKeyHandler === 'function') { + if (options.lng) { + o.missingKeyHandler(lngs[0], ns, key, notFound, lngs); + } else { + o.missingKeyHandler(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessorsToApply; + if (typeof o.postProcess === 'string' && o.postProcess !== '') { + postProcessorsToApply = [o.postProcess]; + } else if (typeof o.postProcess === 'array' || typeof o.postProcess === 'object') { + postProcessorsToApply = o.postProcess; + } else { + postProcessorsToApply = []; + } + + if (typeof options.postProcess === 'string' && options.postProcess !== '') { + postProcessorsToApply = postProcessorsToApply.concat([options.postProcess]); + } else if (typeof options.postProcess === 'array' || typeof options.postProcess === 'object') { + postProcessorsToApply = postProcessorsToApply.concat(options.postProcess); + } + + if (found !== undefined && postProcessorsToApply.length) { + postProcessorsToApply.forEach(function(postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + }); + } + + // process notFound if function exists + var splitNotFound = notFound; + if (notFound.indexOf(o.nsseparator) > -1) { + parts = notFound.split(o.nsseparator); + splitNotFound = parts[1]; + } + if (splitNotFound === key && o.parseMissingKey) { + notFound = o.parseMissingKey(notFound); + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessorsToApply.length) { + var val = _getDefaultValue(key, options); + postProcessorsToApply.forEach(function(postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](val, key, options); + } + }); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options) { + options = options || {}; + + var optionWithoutCount, translated + , notFound = _getDefaultValue(key, options) + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + // CI mode + if (lngs[0].toLowerCase() === 'cimode') return notFound; + + // passed in lng + if (options.lngs) lngs = options.lngs; + if (options.lng) { + lngs = f.toLanguages(options.lng, options.fallbackLng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options, lngs[0])) { + optionWithoutCount = f.extend({ lngs: [lngs[0]]}, options); + delete optionWithoutCount.count; + optionWithoutCount._origLng = optionWithoutCount._origLng || optionWithoutCount.lng || lngs[0]; + delete optionWithoutCount.lng; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey; + if (!pluralExtensions.needsPlural(lngs[0], options.count)) { + pluralKey = ns + o.nsseparator + key; + } else { + pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(lngs[0], options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + } + + translated = translate(pluralKey, optionWithoutCount); + + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } else if (lngs.length > 1) { + // remove failed lng + var clone = lngs.slice(); + clone.shift(); + options = f.extend(options, { lngs: clone }); + options._origLng = optionWithoutCount._origLng; + delete options.lng; + // retry with fallbacks + translated = translate(ns + o.nsseparator + key, options); + if (translated != o.pluralNotFound) return translated; + } else { + optionWithoutCount.lng = optionWithoutCount._origLng; + delete optionWithoutCount._origLng; + translated = translate(ns + o.nsseparator + key, optionWithoutCount); + + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); + } + } + + if (needsIndefiniteArticle(options)) { + var optionsWithoutIndef = f.extend({}, options); + delete optionsWithoutIndef.indefinite_article; + optionsWithoutIndef.defaultValue = o.indefiniteNotFound; + // If we don't have a count, we want the indefinite, if we do have a count, and needsPlural is false + var indefiniteKey = ns + o.nsseparator + key + (((options.count && !needsPlural(options, lngs[0])) || !options.count) ? o.indefiniteSuffix : ""); + translated = translate(indefiniteKey, optionsWithoutIndef); + if (translated != o.indefiniteNotFound) { + return translated; + } + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + var valueType = Object.prototype.toString.apply(value); + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (valueType === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + if (o.objectTreeKeyHandler && typeof o.objectTreeKeyHandler == 'function') { + value = o.objectTreeKeyHandler(key, value, l, ns, options); + } else { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned an object instead of string.'; + f.log(value); + } + } else if (valueType !== '[object Number]' && valueType !== '[object Function]' && valueType !== '[object RegExp]') { + var copy = (valueType === '[object Array]') ? [] : {}; // apply child translation on a copy + f.each(value, function(m) { + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + }); + value = copy; + } + } + + if (typeof value === 'string' && value.trim() === '' && o.fallbackOnEmpty === true) + value = undefined; + + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length > 0))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found || (found==="" && o.fallbackOnEmpty === false)) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + options.isFallbackLookup = false; + } + + return found; + } + function detectLanguage() { + var detectedLng; + var whitelist = o.lngWhitelist || []; + var userLngChoices = []; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var params = query.split('&'); + for (var i=0; i 0) { + var key = params[i].substring(0,pos); + if (key == o.detectLngQS) { + userLngChoices.push(params[i].substring(pos+1)); + } + } + } + })(); + } + + // get from cookie + if (o.useCookie && typeof document !== 'undefined') { + var c = f.cookie.read(o.cookieName); + if (c) userLngChoices.push(c); + } + + // get from localStorage + if (o.detectLngFromLocalStorage && typeof window !== 'undefined' && window.localStorage) { + userLngChoices.push(f.localStorage.getItem('i18next_lng')); + } + + // get from navigator + if (typeof navigator !== 'undefined') { + if (navigator.languages) { // chrome only; not an array, so can't use .push.apply instead of iterating + for (var i=0;i -1) { + var parts = lng.split('-'); + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } + + if (whitelist.length === 0 || whitelist.indexOf(lng) > -1) { + detectedLng = lng; + break; + } + } + })(); + + //fallback + if (!detectedLng){ + detectedLng = o.fallbackLng[0]; + } + + return detectedLng; + } + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + + /* [code, name, numbers, pluralsType] */ + var _rules = [ + ["ach", "Acholi", [1,2], 1], + ["af", "Afrikaans",[1,2], 2], + ["ak", "Akan", [1,2], 1], + ["am", "Amharic", [1,2], 1], + ["an", "Aragonese",[1,2], 2], + ["ar", "Arabic", [0,1,2,3,11,100],5], + ["arn", "Mapudungun",[1,2], 1], + ["ast", "Asturian", [1,2], 2], + ["ay", "Aymará", [1], 3], + ["az", "Azerbaijani",[1,2],2], + ["be", "Belarusian",[1,2,5],4], + ["bg", "Bulgarian",[1,2], 2], + ["bn", "Bengali", [1,2], 2], + ["bo", "Tibetan", [1], 3], + ["br", "Breton", [1,2], 1], + ["bs", "Bosnian", [1,2,5],4], + ["ca", "Catalan", [1,2], 2], + ["cgg", "Chiga", [1], 3], + ["cs", "Czech", [1,2,5],6], + ["csb", "Kashubian",[1,2,5],7], + ["cy", "Welsh", [1,2,3,8],8], + ["da", "Danish", [1,2], 2], + ["de", "German", [1,2], 2], + ["dev", "Development Fallback", [1,2], 2], + ["dz", "Dzongkha", [1], 3], + ["el", "Greek", [1,2], 2], + ["en", "English", [1,2], 2], + ["eo", "Esperanto",[1,2], 2], + ["es", "Spanish", [1,2], 2], + ["es_ar","Argentinean Spanish", [1,2], 2], + ["et", "Estonian", [1,2], 2], + ["eu", "Basque", [1,2], 2], + ["fa", "Persian", [1], 3], + ["fi", "Finnish", [1,2], 2], + ["fil", "Filipino", [1,2], 1], + ["fo", "Faroese", [1,2], 2], + ["fr", "French", [1,2], 9], + ["fur", "Friulian", [1,2], 2], + ["fy", "Frisian", [1,2], 2], + ["ga", "Irish", [1,2,3,7,11],10], + ["gd", "Scottish Gaelic",[1,2,3,20],11], + ["gl", "Galician", [1,2], 2], + ["gu", "Gujarati", [1,2], 2], + ["gun", "Gun", [1,2], 1], + ["ha", "Hausa", [1,2], 2], + ["he", "Hebrew", [1,2], 2], + ["hi", "Hindi", [1,2], 2], + ["hr", "Croatian", [1,2,5],4], + ["hu", "Hungarian",[1,2], 2], + ["hy", "Armenian", [1,2], 2], + ["ia", "Interlingua",[1,2],2], + ["id", "Indonesian",[1], 3], + ["is", "Icelandic",[1,2], 12], + ["it", "Italian", [1,2], 2], + ["ja", "Japanese", [1], 3], + ["jbo", "Lojban", [1], 3], + ["jv", "Javanese", [0,1], 13], + ["ka", "Georgian", [1], 3], + ["kk", "Kazakh", [1], 3], + ["km", "Khmer", [1], 3], + ["kn", "Kannada", [1,2], 2], + ["ko", "Korean", [1], 3], + ["ku", "Kurdish", [1,2], 2], + ["kw", "Cornish", [1,2,3,4],14], + ["ky", "Kyrgyz", [1], 3], + ["lb", "Letzeburgesch",[1,2],2], + ["ln", "Lingala", [1,2], 1], + ["lo", "Lao", [1], 3], + ["lt", "Lithuanian",[1,2,10],15], + ["lv", "Latvian", [1,2,0],16], + ["mai", "Maithili", [1,2], 2], + ["mfe", "Mauritian Creole",[1,2],1], + ["mg", "Malagasy", [1,2], 1], + ["mi", "Maori", [1,2], 1], + ["mk", "Macedonian",[1,2],17], + ["ml", "Malayalam",[1,2], 2], + ["mn", "Mongolian",[1,2], 2], + ["mnk", "Mandinka", [0,1,2],18], + ["mr", "Marathi", [1,2], 2], + ["ms", "Malay", [1], 3], + ["mt", "Maltese", [1,2,11,20],19], + ["nah", "Nahuatl", [1,2], 2], + ["nap", "Neapolitan",[1,2], 2], + ["nb", "Norwegian Bokmal",[1,2],2], + ["ne", "Nepali", [1,2], 2], + ["nl", "Dutch", [1,2], 2], + ["nn", "Norwegian Nynorsk",[1,2],2], + ["no", "Norwegian",[1,2], 2], + ["nso", "Northern Sotho",[1,2],2], + ["oc", "Occitan", [1,2], 1], + ["or", "Oriya", [2,1], 2], + ["pa", "Punjabi", [1,2], 2], + ["pap", "Papiamento",[1,2], 2], + ["pl", "Polish", [1,2,5],7], + ["pms", "Piemontese",[1,2], 2], + ["ps", "Pashto", [1,2], 2], + ["pt", "Portuguese",[1,2], 2], + ["pt_br","Brazilian Portuguese",[1,2], 2], + ["rm", "Romansh", [1,2], 2], + ["ro", "Romanian", [1,2,20],20], + ["ru", "Russian", [1,2,5],4], + ["sah", "Yakut", [1], 3], + ["sco", "Scots", [1,2], 2], + ["se", "Northern Sami",[1,2], 2], + ["si", "Sinhala", [1,2], 2], + ["sk", "Slovak", [1,2,5],6], + ["sl", "Slovenian",[5,1,2,3],21], + ["so", "Somali", [1,2], 2], + ["son", "Songhay", [1,2], 2], + ["sq", "Albanian", [1,2], 2], + ["sr", "Serbian", [1,2,5],4], + ["su", "Sundanese",[1], 3], + ["sv", "Swedish", [1,2], 2], + ["sw", "Swahili", [1,2], 2], + ["ta", "Tamil", [1,2], 2], + ["te", "Telugu", [1,2], 2], + ["tg", "Tajik", [1,2], 1], + ["th", "Thai", [1], 3], + ["ti", "Tigrinya", [1,2], 1], + ["tk", "Turkmen", [1,2], 2], + ["tr", "Turkish", [1,2], 1], + ["tt", "Tatar", [1], 3], + ["ug", "Uyghur", [1], 3], + ["uk", "Ukrainian",[1,2,5],4], + ["ur", "Urdu", [1,2], 2], + ["uz", "Uzbek", [1,2], 1], + ["vi", "Vietnamese",[1], 3], + ["wa", "Walloon", [1,2], 1], + ["wo", "Wolof", [1], 3], + ["yo", "Yoruba", [1,2], 2], + ["zh", "Chinese", [1], 3] + ]; + + var _rulesPluralsTypes = { + 1: function(n) {return Number(n > 1);}, + 2: function(n) {return Number(n != 1);}, + 3: function(n) {return 0;}, + 4: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 5: function(n) {return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5);}, + 6: function(n) {return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2);}, + 7: function(n) {return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 8: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3);}, + 9: function(n) {return Number(n >= 2);}, + 10: function(n) {return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;}, + 11: function(n) {return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3);}, + 12: function(n) {return Number(n%10!=1 || n%100==11);}, + 13: function(n) {return Number(n !== 0);}, + 14: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3);}, + 15: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 16: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2);}, + 17: function(n) {return Number(n==1 || n%10==1 ? 0 : 1);}, + 18: function(n) {return Number(0 ? 0 : n==1 ? 1 : 2);}, + 19: function(n) {return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3);}, + 20: function(n) {return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2);}, + 21: function(n) {return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }; + + var pluralExtensions = { + + rules: (function () { + var l, rules = {}; + for (l=_rules.length; l-- ;) { + rules[_rules[l][0]] = { + name: _rules[l][1], + numbers: _rules[l][2], + plurals: _rulesPluralsTypes[_rules[l][3]] + } + } + return rules; + }()), + + // you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + needsPlural: function(lng, count) { + var parts = lng.split('-'); + + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[parts[f.getCountyIndexOfLng(lng)]]; + } + + if (ext && ext.numbers.length <= 1) { + return false; + } else { + return this.get(lng, count) !== 1; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i; + if (ext.noAbs) { + i = ext.plurals(c); + } else { + i = ext.plurals(Math.abs(c)); + } + + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[f.getCountyIndexOfLng(lng)], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.hasResourceBundle = hasResourceBundle; + i18n.getResourceBundle = getResourceBundle; + i18n.addResource = addResource; + i18n.addResources = addResources; + i18n.removeResourceBundle = removeResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.applyReplacement = f.applyReplacement; + i18n.options = o; + +})(typeof exports === 'undefined' ? window : exports); \ No newline at end of file diff --git a/libs/i18next/i18next.commonjs.withJQuery.min.js b/libs/i18next/i18next.commonjs.withJQuery.min.js new file mode 100644 index 00000000..af364373 --- /dev/null +++ b/libs/i18next/i18next.commonjs.withJQuery.min.js @@ -0,0 +1,5 @@ +// i18next, v1.8.2 +// Copyright (c)2015 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +!function(a){function b(a,b){if(!b||"function"==typeof b)return a;for(var c in b)a[c]=b[c];return a}function c(a,b){for(var d in b)d in a?c(a[d],b[d]):a[d]=b[d];return a}function d(a,b,c){var d,e=0,f=a.length,g=void 0===f||"[object Array]"!==Object.prototype.toString.apply(a)||"function"==typeof a;if(c)if(g){for(d in a)if(b.apply(a[d],c)===!1)break}else for(;f>e&&b.apply(a[e++],c)!==!1;);else if(g){for(d in a)if(b.call(a[d],d,a[d])===!1)break}else for(;f>e&&b.call(a[e],e,a[e++])!==!1;);return a}function e(a){return"string"==typeof a?a.replace(/[&<>"'\/]/g,function(a){return R[a]}):a}function f(a){var b=function(a){if(window.XMLHttpRequest)return a(null,new XMLHttpRequest);if(window.ActiveXObject)try{return a(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(b){return a(null,new ActiveXObject("Microsoft.XMLHTTP"))}return a(new Error)},c=function(a){if("string"==typeof a)return a;var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")},d=function(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;cd?b+=String.fromCharCode(d):d>127&&2048>d?(b+=String.fromCharCode(d>>6|192),b+=String.fromCharCode(63&d|128)):(b+=String.fromCharCode(d>>12|224),b+=String.fromCharCode(d>>6&63|128),b+=String.fromCharCode(63&d|128))}return b},e=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";a=d(a);var c,e,f,g,h,i,j,k="",l=0;do c=a.charCodeAt(l++),e=a.charCodeAt(l++),f=a.charCodeAt(l++),g=c>>2,h=(3&c)<<4|e>>4,i=(15&e)<<2|f>>6,j=63&f,isNaN(e)?i=j=64:isNaN(f)&&(j=64),k+=b.charAt(g)+b.charAt(h)+b.charAt(i)+b.charAt(j),c=e=f="",g=h=i=j="";while(l1&&(d+=d.indexOf("?")>-1?"&"+k:"?"+k),e.jsonp){var l=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=d,void l.appendChild(m)}}b(function(b,c){if(b)return h(b);c.open(a,d,e.async);for(var f in j)j.hasOwnProperty(f)&&c.setRequestHeader(f,j[f]);c.onreadystatechange=function(){if(4===c.readyState){var a=c.responseText||"";if(!h)return;h(c.status,{text:function(){return a},json:function(){try{return JSON.parse(a)}catch(b){return U.error("Can not parse JSON. URL: "+d),{}}}})}},c.send(i)})},h={authBasic:function(a,b){g.headers.Authorization="Basic "+e(a+":"+b)},connect:function(a,b,c){return g("CONNECT",a,b,c)},del:function(a,b,c){return g("DELETE",a,b,c)},get:function(a,b,c){return g("GET",a,b,c)},head:function(a,b,c){return g("HEAD",a,b,c)},headers:function(a){g.headers=a||{}},isAllowed:function(a,b,c){this.options(a,function(a,d){c(-1!==d.text().indexOf(b))})},options:function(a,b,c){return g("OPTIONS",a,b,c)},patch:function(a,b,c){return g("PATCH",a,b,c)},post:function(a,b,c){return g("POST",a,b,c)},put:function(a,b,c){return g("PUT",a,b,c)},trace:function(a,b,c){return g("TRACE",a,b,c)}},i=a.type?a.type.toLowerCase():"get";h[i](a.url,a,function(b,c){200===b||0===b&&c.text()?a.success(c.json(),b,null):a.error(c.text(),b,null)})}function g(a,b){"function"==typeof a&&(b=a,a={}),a=a||{},U.extend(Q,a),delete Q.fixLng,Q.functions&&(delete Q.functions,U.extend(U,a.functions)),"string"==typeof Q.ns&&(Q.ns={namespaces:[Q.ns],defaultNs:Q.ns}),"string"==typeof Q.fallbackNS&&(Q.fallbackNS=[Q.fallbackNS]),("string"==typeof Q.fallbackLng||"boolean"==typeof Q.fallbackLng)&&(Q.fallbackLng=[Q.fallbackLng]),Q.interpolationPrefixEscaped=U.regexEscape(Q.interpolationPrefix),Q.interpolationSuffixEscaped=U.regexEscape(Q.interpolationSuffix),Q.lng||(Q.lng=U.detectLanguage()),M=U.toLanguages(Q.lng),H=M[0],U.log("currentLng set to: "+H),Q.useCookie&&U.cookie.read(Q.cookieName)!==H&&U.cookie.create(Q.cookieName,H,Q.cookieExpirationTime,Q.cookieDomain),Q.detectLngFromLocalStorage&&"undefined"!=typeof document&&window.localStorage&&U.localStorage.setItem("i18next_lng",H);var c=B;a.fixLng&&(c=function(a,b){return b=b||{},b.lng=b.lng||c.lng,B(a,b)},c.lng=H),X.setCurrentLng(H),I&&Q.setJqueryExt&&u();var d;if(I&&I.Deferred&&(d=I.Deferred()),!Q.resStore){var e=U.toLanguages(Q.lng);"string"==typeof Q.preload&&(Q.preload=[Q.preload]);for(var f=0,g=Q.preload.length;g>f;f++)for(var h=U.toLanguages(Q.preload[f]),i=0,j=h.length;j>i;i++)e.indexOf(h[i])<0&&e.push(h[i]);return J.sync.load(e,Q,function(a,e){K=e,N=!0,b&&b(c),d&&d.resolve(c)}),d?d.promise():void 0}return K=Q.resStore,N=!0,b&&b(c),d&&d.resolve(c),d?d.promise():void 0}function h(a,b){"string"==typeof a&&(a=[a]);for(var c=0,d=a.length;d>c;c++)Q.preload.indexOf(a[c])<0&&Q.preload.push(a[c]);return g(b)}function i(a,b,c,d){"string"!=typeof b?(c=b,b=Q.ns.defaultNs):Q.ns.namespaces.indexOf(b)<0&&Q.ns.namespaces.push(b),K[a]=K[a]||{},K[a][b]=K[a][b]||{},d?U.deepExtend(K[a][b],c):U.extend(K[a][b],c),Q.useLocalStorage&&O._storeLocal(K)}function j(a,b){"string"!=typeof b&&(b=Q.ns.defaultNs),K[a]=K[a]||{};var c=K[a][b]||{},d=!1;for(var e in c)c.hasOwnProperty(e)&&(d=!0);return d}function k(a,b){return"string"!=typeof b&&(b=Q.ns.defaultNs),K[a]=K[a]||{},U.extend({},K[a][b])}function l(a,b){"string"!=typeof b&&(b=Q.ns.defaultNs),K[a]=K[a]||{},K[a][b]={},Q.useLocalStorage&&O._storeLocal(K)}function m(a,b,c,d){"string"!=typeof b?(resource=b,b=Q.ns.defaultNs):Q.ns.namespaces.indexOf(b)<0&&Q.ns.namespaces.push(b),K[a]=K[a]||{},K[a][b]=K[a][b]||{};for(var e=c.split(Q.keyseparator),f=0,g=K[a][b];e[f];)f==e.length-1?g[e[f]]=d:(null==g[e[f]]&&(g[e[f]]={}),g=g[e[f]]),f++;Q.useLocalStorage&&O._storeLocal(K)}function n(a,b,c){"string"!=typeof b?(resource=b,b=Q.ns.defaultNs):Q.ns.namespaces.indexOf(b)<0&&Q.ns.namespaces.push(b);for(var d in c)"string"==typeof c[d]&&m(a,b,d,c[d])}function o(a){Q.ns.defaultNs=a}function p(a,b){q([a],b)}function q(a,b){var c={dynamicLoad:Q.dynamicLoad,resGetPath:Q.resGetPath,getAsync:Q.getAsync,customLoad:Q.customLoad,ns:{namespaces:a,defaultNs:""}},d=U.toLanguages(Q.lng);"string"==typeof Q.preload&&(Q.preload=[Q.preload]);for(var e=0,f=Q.preload.length;f>e;e++)for(var g=U.toLanguages(Q.preload[e]),h=0,i=g.length;i>h;h++)d.indexOf(g[h])<0&&d.push(g[h]);for(var j=[],k=0,l=d.length;l>k;k++){var m=!1,n=K[d[k]];if(n)for(var o=0,p=a.length;p>o;o++)n[a[o]]||(m=!0);else m=!0;m&&j.push(d[k])}j.length?J.sync._fetch(j,c,function(c,d){var e=a.length*j.length;U.each(a,function(a,c){Q.ns.namespaces.indexOf(c)<0&&Q.ns.namespaces.push(c),U.each(j,function(a,f){K[f]=K[f]||{},K[f][c]=d[f][c],e--,0===e&&b&&(Q.useLocalStorage&&J.sync._storeLocal(K),b())})})}):b&&b()}function r(a,b,c){return"function"==typeof b?(c=b,b={}):b||(b={}),b.lng=a,g(b,c)}function s(){return H}function t(a){K={},r(H,a)}function u(){function a(a,b,c){if(0!==b.length){var d="text";if(0===b.indexOf("[")){var e=b.split("]");b=e[1],d=e[0].substr(1,e[0].length-1)}b.indexOf(";")===b.length-1&&(b=b.substr(0,b.length-2));var f;if("html"===d)f=Q.defaultValueFromContent?I.extend({defaultValue:a.html()},c):c,a.html(I.t(b,f));else if("text"===d)f=Q.defaultValueFromContent?I.extend({defaultValue:a.text()},c):c,a.text(I.t(b,f));else if("prepend"===d)f=Q.defaultValueFromContent?I.extend({defaultValue:a.html()},c):c,a.prepend(I.t(b,f));else if("append"===d)f=Q.defaultValueFromContent?I.extend({defaultValue:a.html()},c):c,a.append(I.t(b,f));else if(0===d.indexOf("data-")){var g=d.substr("data-".length);f=Q.defaultValueFromContent?I.extend({defaultValue:a.data(g)},c):c;var h=I.t(b,f);a.data(g,h),a.attr(d,h)}else f=Q.defaultValueFromContent?I.extend({defaultValue:a.attr(d)},c):c,a.attr(d,I.t(b,f))}}function b(b,c){var d=b.attr(Q.selectorAttr);if(d||"undefined"==typeof d||d===!1||(d=b.text()||b.val()),d){var e=b,f=b.data("i18n-target");if(f&&(e=b.find(f)||b),c||Q.useDataAttrOptions!==!0||(c=b.data("i18n-options")),c=c||{},d.indexOf(";")>=0){var g=d.split(";");I.each(g,function(b,d){""!==d&&a(e,d,c)})}else a(e,d,c);Q.useDataAttrOptions===!0&&b.data("i18n-options",c)}}I.t=I.t||B,I.fn.i18n=function(a){return this.each(function(){b(I(this),a);var c=I(this).find("["+Q.selectorAttr+"]");c.each(function(){b(I(this),a)})})}}function v(a,b,c,d){if(!a)return a;if(d=d||b,a.indexOf(d.interpolationPrefix||Q.interpolationPrefix)<0)return a;var e=d.interpolationPrefix?U.regexEscape(d.interpolationPrefix):Q.interpolationPrefixEscaped,f=d.interpolationSuffix?U.regexEscape(d.interpolationSuffix):Q.interpolationSuffixEscaped,g="HTML"+f,h=b.replace&&"object"==typeof b.replace?b.replace:b;return U.each(h,function(b,h){var i=c?c+Q.keyseparator+b:b;"object"==typeof h&&null!==h?a=v(a,h,i,d):d.escapeInterpolation||Q.escapeInterpolation?(a=a.replace(new RegExp([e,i,g].join(""),"g"),U.regexReplacementEscape(h)),a=a.replace(new RegExp([e,i,f].join(""),"g"),U.regexReplacementEscape(U.escape(h)))):a=a.replace(new RegExp([e,i,f].join(""),"g"),U.regexReplacementEscape(h))}),a}function w(a,b){var c=",",d="{",e="}",f=U.extend({},b);for(delete f.postProcess;-1!=a.indexOf(Q.reusePrefix)&&(L++,!(L>Q.maxRecursion));){var g=a.lastIndexOf(Q.reusePrefix),h=a.indexOf(Q.reuseSuffix,g)+Q.reuseSuffix.length,i=a.substring(g,h),j=i.replace(Q.reusePrefix,"").replace(Q.reuseSuffix,"");if(g>=h)return U.error("there is an missing closing in following translation value",a),"";if(-1!=j.indexOf(c)){var k=j.indexOf(c);if(-1!=j.indexOf(d,k)&&-1!=j.indexOf(e,k)){var l=j.indexOf(d,k),m=j.indexOf(e,l)+e.length;try{f=U.extend(f,JSON.parse(j.substring(l,m))),j=j.substring(0,k)}catch(n){}}}var o=E(j,f);a=a.replace(i,U.regexReplacementEscape(o))}return a}function x(a){return a.context&&("string"==typeof a.context||"number"==typeof a.context)}function y(a){return void 0!==a.count&&"string"!=typeof a.count}function z(a){return void 0!==a.indefinite_article&&"string"!=typeof a.indefinite_article&&a.indefinite_article}function A(a,b){b=b||{};var c=C(a,b),d=F(a,b);return void 0!==d||d===c}function B(a,b){return b=b||{},N?(L=0,E.apply(null,arguments)):(U.log("i18next not finished initialization. you might have called t function before loading resources finished."),b.defaultValue||"")}function C(a,b){return void 0!==b.defaultValue?b.defaultValue:a}function D(){for(var a=[],b=1;b1)for(var d=0;d-1&&(e=c.split(Q.nsseparator),i=e[0],c=e[1]),void 0===g&&Q.sendMissing&&"function"==typeof Q.missingKeyHandler&&(b.lng?Q.missingKeyHandler(h[0],i,c,f,h):Q.missingKeyHandler(Q.lng,i,c,f,h));var j;j="string"==typeof Q.postProcess&&""!==Q.postProcess?[Q.postProcess]:"array"==typeof Q.postProcess||"object"==typeof Q.postProcess?Q.postProcess:[],"string"==typeof b.postProcess&&""!==b.postProcess?j=j.concat([b.postProcess]):("array"==typeof b.postProcess||"object"==typeof b.postProcess)&&(j=j.concat(b.postProcess)),void 0!==g&&j.length&&j.forEach(function(a){Y[a]&&(g=Y[a](g,c,b))});var k=f;if(f.indexOf(Q.nsseparator)>-1&&(e=f.split(Q.nsseparator),k=e[1]),k===c&&Q.parseMissingKey&&(f=Q.parseMissingKey(f)),void 0===g&&(f=v(f,b),f=w(f,b),j.length)){var l=C(c,b);j.forEach(function(a){Y[a]&&(g=Y[a](l,c,b))})}return void 0!==g?g:f}function F(a,b){b=b||{};var c,d,e=C(a,b),f=M;if(!K)return e;if("cimode"===f[0].toLowerCase())return e;if(b.lngs&&(f=b.lngs),b.lng&&(f=U.toLanguages(b.lng,b.fallbackLng),!K[f[0]])){var g=Q.getAsync;Q.getAsync=!1,J.sync.load(f,Q,function(a,b){U.extend(K,b),Q.getAsync=g})}var h=b.ns||Q.ns.defaultNs;if(a.indexOf(Q.nsseparator)>-1){var i=a.split(Q.nsseparator);h=i[0],a=i[1]}if(x(b)){c=U.extend({},b),delete c.context,c.defaultValue=Q.contextNotFound;var j=h+Q.nsseparator+a+"_"+b.context;if(d=B(j,c),d!=Q.contextNotFound)return v(d,{context:b.context})}if(y(b,f[0])){c=U.extend({lngs:[f[0]]},b),delete c.count,c._origLng=c._origLng||c.lng||f[0],delete c.lng,c.defaultValue=Q.pluralNotFound;var k;if(X.needsPlural(f[0],b.count)){k=h+Q.nsseparator+a+Q.pluralSuffix;var l=X.get(f[0],b.count);l>=0?k=k+"_"+l:1===l&&(k=h+Q.nsseparator+a)}else k=h+Q.nsseparator+a;if(d=B(k,c),d!=Q.pluralNotFound)return v(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix});if(!(f.length>1))return c.lng=c._origLng,delete c._origLng,d=B(h+Q.nsseparator+a,c),v(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix});var m=f.slice();if(m.shift(),b=U.extend(b,{lngs:m}),b._origLng=c._origLng,delete b.lng,d=B(h+Q.nsseparator+a,b),d!=Q.pluralNotFound)return d}if(z(b)){var n=U.extend({},b);delete n.indefinite_article,n.defaultValue=Q.indefiniteNotFound;var o=h+Q.nsseparator+a+(b.count&&!y(b,f[0])||!b.count?Q.indefiniteSuffix:"");if(d=B(o,n),d!=Q.indefiniteNotFound)return d}for(var p,q=a.split(Q.keyseparator),r=0,s=f.length;s>r&&void 0===p;r++){for(var t=f[r],u=0,A=K[t]&&K[t][h];q[u];)A=A&&A[q[u]],u++;if(void 0!==A){var D=Object.prototype.toString.apply(A);if("string"==typeof A)A=v(A,b),A=w(A,b);else if("[object Array]"!==D||Q.returnObjectTrees||b.returnObjectTrees){if(null===A&&Q.fallbackOnNull===!0)A=void 0;else if(null!==A)if(Q.returnObjectTrees||b.returnObjectTrees){if("[object Number]"!==D&&"[object Function]"!==D&&"[object RegExp]"!==D){var G="[object Array]"===D?[]:{};U.each(A,function(c){G[c]=E(h+Q.nsseparator+a+Q.keyseparator+c,b)}),A=G}}else Q.objectTreeKeyHandler&&"function"==typeof Q.objectTreeKeyHandler?A=Q.objectTreeKeyHandler(a,A,t,h,b):(A="key '"+h+":"+a+" ("+t+")' returned an object instead of string.",U.log(A))}else A=A.join("\n"),A=v(A,b),A=w(A,b);"string"==typeof A&&""===A.trim()&&Q.fallbackOnEmpty===!0&&(A=void 0),p=A}}if(void 0===p&&!b.isFallbackLookup&&(Q.fallbackToDefaultNS===!0||Q.fallbackNS&&Q.fallbackNS.length>0)){if(b.isFallbackLookup=!0,Q.fallbackNS.length){for(var H=0,I=Q.fallbackNS.length;I>H;H++)if(p=F(Q.fallbackNS[H]+Q.nsseparator+a,b),p||""===p&&Q.fallbackOnEmpty===!1){var L=p.indexOf(Q.nsseparator)>-1?p.split(Q.nsseparator)[1]:p,N=e.indexOf(Q.nsseparator)>-1?e.split(Q.nsseparator)[1]:e;if(L!==N)break}}else p=F(a,b);b.isFallbackLookup=!1}return p}function G(){var a,b=Q.lngWhitelist||[],c=[];if("undefined"!=typeof window&&!function(){for(var a=window.location.search.substring(1),b=a.split("&"),d=0;d0){var f=b[d].substring(0,e);f==Q.detectLngQS&&c.push(b[d].substring(e+1))}}}(),Q.useCookie&&"undefined"!=typeof document){var d=U.cookie.read(Q.cookieName);d&&c.push(d)}if(Q.detectLngFromLocalStorage&&"undefined"!=typeof window&&window.localStorage&&c.push(U.localStorage.getItem("i18next_lng")),"undefined"!=typeof navigator){if(navigator.languages)for(var e=0;e-1){var f=e.split("-");e=Q.lowerCaseLng?f[0].toLowerCase()+"-"+f[1].toLowerCase():f[0].toLowerCase()+"-"+f[1].toUpperCase()}if(0===b.length||b.indexOf(e)>-1){a=e;break}}}(),a||(a=Q.fallbackLng[0]),a}Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>0&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=c;arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d))));for(var e=d>=0?Math.min(d,c-1):c-Math.abs(d);e>=0;e--)if(e in b&&b[e]===a)return e;return-1}),"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")});var H,I=a.jQuery||a.Zepto,J={},K={},L=0,M=[],N=!1,O={};if("undefined"!=typeof module&&module.exports){if(module.exports=J,!I)try{I=require("jquery")}catch(P){}}else a.i18n=a.i18n||J;I&&(I.i18n=I.i18n||J),O={load:function(a,b,c){b.useLocalStorage?O._loadLocal(a,b,function(d,e){for(var f=[],g=0,h=a.length;h>g;g++)e[a[g]]||f.push(a[g]);f.length>0?O._fetch(f,b,function(a,b){U.extend(e,b),O._storeLocal(b),c(null,e)}):c(null,e)}):O._fetch(a,b,function(a,b){c(null,b)})},_loadLocal:function(a,b,c){var d={},e=(new Date).getTime();if(window.localStorage){var f=a.length;U.each(a,function(a,g){var h=U.localStorage.getItem("res_"+g);h&&(h=JSON.parse(h),h.i18nStamp&&h.i18nStamp+b.localStorageExpirationTime>e&&(d[g]=h)),f--,0===f&&c(null,d)})}},_storeLocal:function(a){if(window.localStorage)for(var b in a)a[b].i18nStamp=(new Date).getTime(),U.localStorage.setItem("res_"+b,JSON.stringify(a[b]))},_fetch:function(a,b,c){var d=b.ns,e={};if(b.dynamicLoad){var f=function(a,b){c(null,b)};if("function"==typeof b.customLoad)b.customLoad(a,d.namespaces,b,f);else{var g=v(b.resGetPath,{lng:a.join("+"),ns:d.namespaces.join("+")});U.ajax({url:g,success:function(a){U.log("loaded: "+g),f(null,a)},error:function(a,b,c){U.log("failed loading: "+g),f("failed loading resource.json error: "+c)},dataType:"json",async:b.getAsync})}}else{var h,i=d.namespaces.length*a.length;U.each(d.namespaces,function(d,f){U.each(a,function(a,d){var g=function(a,b){a&&(h=h||[],h.push(a)),e[d]=e[d]||{},e[d][f]=b,i--,0===i&&c(h,e)};"function"==typeof b.customLoad?b.customLoad(d,f,b,g):O._fetchOne(d,f,b,g)})})}},_fetchOne:function(a,b,c,d){var e=v(c.resGetPath,{lng:a,ns:b});U.ajax({url:e,success:function(a){U.log("loaded: "+e),d(null,a)},error:function(a,b,c){if(b&&200==b||a&&a.status&&200==a.status)U.error("There is a typo in: "+e);else if(b&&404==b||a&&a.status&&404==a.status)U.log("Does not exist: "+e);else{var f=b?b:a&&a.status?a.status:null;U.log(f+" when loading "+e)}d(c,{})},dataType:"json",async:c.getAsync})},postMissing:function(a,b,c,d,e){var f={};f[c]=d;var g=[];if("fallback"===Q.sendMissingTo&&Q.fallbackLng[0]!==!1)for(var h=0;hh;h++)g.push({lng:e[h],url:v(Q.resPostPath,{lng:e[h],ns:b})});for(var j=0,k=g.length;k>j;j++){var l=g[j];U.ajax({url:l.url,type:Q.sendType,data:f,success:function(){U.log("posted missing key '"+c+"' to: "+l.url);for(var a=c.split("."),e=0,f=K[l.lng][b];a[e];)f=f[a[e]]=e===a.length-1?d:f[a[e]]||{},e++},error:function(){U.log("failed posting missing key '"+c+"' to: "+l.url)},dataType:"json",async:Q.postAsync})}},reload:t};var Q={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:["dev"],fallbackNS:[],detectLngQS:"setLng",detectLngFromLocalStorage:!1,ns:{namespaces:["translation"],defaultNs:"translation"},fallbackOnNull:!0,fallbackOnEmpty:!1,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",defaultVariables:!1,reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,indefiniteSuffix:"_indefinite",indefiniteNotFound:["indefinite_not_found",Math.random()].join(""),setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",cookieDomain:void 0,objectTreeKeyHandler:void 0,postProcess:void 0,parseMissingKey:void 0,missingKeyHandler:O.postMissing,shortcutFunction:"sprintf"},R={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},S={create:function(a,b,c,d){var e;if(c){var f=new Date;f.setTime(f.getTime()+60*c*1e3),e="; expires="+f.toGMTString()}else e="";d=d?"domain="+d+";":"",document.cookie=a+"="+b+e+";"+d+"path=/"},read:function(a){for(var b=a+"=",c=document.cookie.split(";"),d=0;d-1){var c=a.split("-");b=Q.lowerCaseLng?c[0].toLowerCase()+"-"+c[1].toLowerCase():c[0].toLowerCase()+"-"+c[1].toUpperCase()}else b=Q.lowerCaseLng?a.toLowerCase():a;return b}var c=this.log,d=[],e=Q.lngWhitelist||!1,f=function(a){!e||e.indexOf(a)>-1?d.push(a):c("rejecting non-whitelisted language: "+a)};if("string"==typeof a&&a.indexOf("-")>-1){var g=a.split("-");"unspecific"!==Q.load&&f(b(a)),"current"!==Q.load&&f(b(g[this.getCountyIndexOfLng(a)]))}else f(b(a));for(var h=0;h1)},2:function(a){return Number(1!=a)},3:function(){return 0},4:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},5:function(a){return Number(0===a?0:1==a?1:2==a?2:a%100>=3&&10>=a%100?3:a%100>=11?4:5)},6:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)},7:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},8:function(a){return Number(1==a?0:2==a?1:8!=a&&11!=a?2:3)},9:function(a){return Number(a>=2)},10:function(a){return Number(1==a?0:2==a?1:7>a?2:11>a?3:4)},11:function(a){return Number(1==a||11==a?0:2==a||12==a?1:a>2&&20>a?2:3)},12:function(a){return Number(a%10!=1||a%100==11)},13:function(a){return Number(0!==a)},14:function(a){return Number(1==a?0:2==a?1:3==a?2:3)},15:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&(10>a%100||a%100>=20)?1:2)},16:function(a){return Number(a%10==1&&a%100!=11?0:0!==a?1:2)},17:function(a){return Number(1==a||a%10==1?0:1)},18:function(a){return Number(1==a?1:2)},19:function(a){return Number(1==a?0:0===a||a%100>1&&11>a%100?1:a%100>10&&20>a%100?2:3)},20:function(a){return Number(1==a?0:0===a||a%100>0&&20>a%100?1:2)},21:function(a){return Number(a%100==1?1:a%100==2?2:a%100==3||a%100==4?3:0)}},X={rules:function(){var a,b={};for(a=V.length;a--;)b[V[a][0]]={name:V[a][1],numbers:V[a][2],plurals:W[V[a][3]]};return b}(),addRule:function(a,b){X.rules[a]=b},setCurrentLng:function(a){if(!X.currentRule||X.currentRule.lng!==a){var b=a.split("-");X.currentRule={lng:a,rule:X.rules[b[0]]}}},needsPlural:function(a,b){var c,d=a.split("-");return c=X.currentRule&&X.currentRule.lng===a?X.currentRule.rule:X.rules[d[U.getCountyIndexOfLng(a)]],c&&c.numbers.length<=1?!1:1!==this.get(a,b)},get:function(a,b){function c(b,c){var d;if(d=X.currentRule&&X.currentRule.lng===a?X.currentRule.rule:X.rules[b]){var e;e=d.plurals(d.noAbs?c:Math.abs(c));var f=d.numbers[e];return 2===d.numbers.length&&1===d.numbers[0]&&(2===f?f=-1:1===f&&(f=1)),f}return 1===c?"1":"-1"}var d=a.split("-");return c(d[U.getCountyIndexOfLng(a)],b)}},Y={},Z=function(a,b){Y[a]=b},$=function(){function a(a){return Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}function b(a,b){for(var c=[];b>0;c[--b]=a);return c.join("")}var c=function(){return c.cache.hasOwnProperty(arguments[0])||(c.cache[arguments[0]]=c.parse(arguments[0])),c.format.call(null,c.cache[arguments[0]],arguments)};return c.format=function(c,d){var e,f,g,h,i,j,k,l=1,m=c.length,n="",o=[];for(f=0;m>f;f++)if(n=a(c[f]),"string"===n)o.push(c[f]);else if("array"===n){if(h=c[f],h[2])for(e=d[l],g=0;g=0?"+"+e:e,j=h[4]?"0"==h[4]?"0":h[4].charAt(1):" ",k=h[6]-String(e).length,i=h[6]?b(j,k):"",o.push(h[5]?e+i:i+e)}return o.join("")},c.cache={},c.parse=function(a){for(var b=a,c=[],d=[],e=0;b;){if(null!==(c=/^[^\x25]+/.exec(b)))d.push(c[0]);else if(null!==(c=/^\x25{2}/.exec(b)))d.push("%");else{if(null===(c=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(b)))throw"[sprintf] huh?";if(c[2]){e|=1;var f=[],g=c[2],h=[];if(null===(h=/^([a-z_][a-z_\d]*)/i.exec(g)))throw"[sprintf] huh?";for(f.push(h[1]);""!==(g=g.substring(h[0].length));)if(null!==(h=/^\.([a-z_][a-z_\d]*)/i.exec(g)))f.push(h[1]);else{if(null===(h=/^\[(\d+)\]/.exec(g)))throw"[sprintf] huh?";f.push(h[1])}c[2]=f}else e|=2;if(3===e)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";d.push(c)}b=b.substring(c[0].length)}return d},c}(),_=function(a,b){return b.unshift(a),$.apply(null,b)};Z("sprintf",function(a,b,c){return c.sprintf?"[object Array]"===Object.prototype.toString.apply(c.sprintf)?_(a,c.sprintf):"object"==typeof c.sprintf?$(a,c.sprintf):a:a}),J.init=g,J.setLng=r,J.preload=h,J.addResourceBundle=i,J.hasResourceBundle=j,J.getResourceBundle=k,J.addResource=m,J.addResources=n,J.removeResourceBundle=l,J.loadNamespace=p,J.loadNamespaces=q,J.setDefaultNamespace=o,J.t=B,J.translate=B,J.exists=A,J.detectLanguage=U.detectLanguage,J.pluralExtensions=X,J.sync=O,J.functions=U,J.lng=s,J.addPostProcessor=Z,J.applyReplacement=U.applyReplacement,J.options=Q}("undefined"==typeof exports?window:exports); \ No newline at end of file diff --git a/libs/i18next/i18next.js b/libs/i18next/i18next.js new file mode 100644 index 00000000..7aab2a78 --- /dev/null +++ b/libs/i18next/i18next.js @@ -0,0 +1,2178 @@ +// i18next, v1.8.2 +// Copyright (c)2015 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function(root) { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + // Add string trim for IE8. + if (typeof String.prototype.trim !== 'function') { + String.prototype.trim = function() { + return this.replace(/^\s+|\s+$/g, ''); + } + } + + var $ = root.jQuery || root.Zepto + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = [] + , initialized = false + , sync = {}; + + + + // Export the i18next object for **CommonJS**. + // If we're not in CommonJS, add `i18n` to the + // global object or to jquery. + if (typeof module !== 'undefined' && module.exports) { + module.exports = i18n; + } else { + if ($) { + $.i18n = $.i18n || i18n; + } + + root.i18n = root.i18n || i18n; + } + sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = f.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + f.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + if ((status && status == 200) || (xhr && xhr.status && xhr.status == 200)) { + // file loaded but invalid json, stop waste time ! + f.error('There is a typo in: ' + url); + } else if ((status && status == 404) || (xhr && xhr.status && xhr.status == 404)) { + f.log('Does not exist: ' + url); + } else { + var theStatus = status ? status : ((xhr && xhr.status) ? xhr.status : null); + f.log(theStatus + ' when loading ' + url); + } + + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback' && o.fallbackLng[0] !== false) { + for (var i = 0; i < o.fallbackLng.length; i++) { + urls.push({lng: o.fallbackLng[i], url: applyReplacement(o.resPostPath, { lng: o.fallbackLng[i], ns: ns })}); + } + } else if (o.sendMissingTo === 'current' || (o.sendMissingTo === 'fallback' && o.fallbackLng[0] === false) ) { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + }, + + reload: reload + }; + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: ['dev'], + fallbackNS: [], + detectLngQS: 'setLng', + detectLngFromLocalStorage: false, + ns: { + namespaces: ['translation'], + defaultNs: 'translation' + }, + fallbackOnNull: true, + fallbackOnEmpty: false, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + defaultVariables: false, + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + indefiniteSuffix: '_indefinite', + indefiniteNotFound: ['indefinite_not_found', Math.random()].join(''), + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + cookieDomain: undefined, + + objectTreeKeyHandler: undefined, + postProcess: undefined, + parseMissingKey: undefined, + missingKeyHandler: sync.postMissing, + + shortcutFunction: 'sprintf' // or: defaultValue + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _deepExtend(target, source) { + for (var prop in source) + if (prop in target) + _deepExtend(target[prop], source[prop]); + else + target[prop] = source[prop]; + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || Object.prototype.toString.apply(object) !== '[object Array]' || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + try { + return JSON.parse(data) + } catch (e) { + f.error('Can not parse JSON. URL: ' + url); + return {}; + } + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + // file: protocol always gives status code 0, so check for data + if (status === 200 || (status === 0 && data.text())) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes,domain) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + domain = (domain)? "domain="+domain+";" : ""; + document.cookie = name+"="+value+expires+";"+domain+"path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes,domain) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + deepExtend: _deepExtend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : (typeof document !== 'undefined' ? _ajax : function() {}), + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + error: function(str) { + if (typeof console !== "undefined") console.error(str); + }, + getCountyIndexOfLng: function(lng) { + var lng_index = 0; + if (lng === 'nb-NO' || lng === 'nn-NO' || lng === 'nb-no' || lng === 'nn-no') lng_index = 1; + return lng_index; + }, + toLanguages: function(lng) { + var log = this.log; + + function applyCase(l) { + var ret = l; + + if (typeof l === 'string' && l.indexOf('-') > -1) { + var parts = l.split('-'); + + ret = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } else { + ret = o.lowerCaseLng ? l.toLowerCase() : l; + } + + return ret; + } + + var languages = []; + var whitelist = o.lngWhitelist || false; + var addLanguage = function(language){ + //reject langs not whitelisted + if(!whitelist || whitelist.indexOf(language) > -1){ + languages.push(language); + }else{ + log('rejecting non-whitelisted language: ' + language); + } + }; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + if (o.load !== 'unspecific') addLanguage(applyCase(lng)); + if (o.load !== 'current') addLanguage(applyCase(parts[this.getCountyIndexOfLng(lng)])); + } else { + addLanguage(applyCase(lng)); + } + + for (var i = 0; i < o.fallbackLng.length; i++) { + if (languages.indexOf(o.fallbackLng[i]) === -1 && o.fallbackLng[i]) languages.push(applyCase(o.fallbackLng[i])); + } + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + }, + regexReplacementEscape: function(strOrFn) { + if (typeof strOrFn === 'string') { + return strOrFn.replace(/\$/g, "$$$$"); + } else { + return strOrFn; + } + }, + localStorage: { + setItem: function(key, value) { + if (window.localStorage) { + try { + window.localStorage.setItem(key, value); + } catch (e) { + f.log('failed to set value for key "' + key + '" to localStorage.'); + } + } + }, + getItem: function(key, value) { + if (window.localStorage) { + try { + return window.localStorage.getItem(key, value); + } catch (e) { + f.log('failed to get value for key "' + key + '" from localStorage.'); + return undefined; + } + } + } + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + delete o.fixLng; /* passed in each time */ + + // override functions: .log(), .detectLanguage(), etc + if (o.functions) { + delete o.functions; + f.extend(f, options.functions); + } + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // fallback languages + if (typeof o.fallbackLng == 'string' || typeof o.fallbackLng == 'boolean') { + o.fallbackLng = [o.fallbackLng]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + if (o.useCookie && f.cookie.read(o.cookieName) !== currentLng){ //cookie is unset or invalid + f.cookie.create(o.cookieName, currentLng, o.cookieExpirationTime, o.cookieDomain); + } + if (o.detectLngFromLocalStorage && typeof document !== 'undefined' && window.localStorage) { + f.localStorage.setItem('i18next_lng', currentLng); + } + + var lngTranslate = translate; + if (options.fixLng) { + lngTranslate = function(key, options) { + options = options || {}; + options.lng = options.lng || lngTranslate.lng; + return translate(key, options); + }; + lngTranslate.lng = currentLng; + } + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + initialized = true; + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + initialized = true; + + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources, deep) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + if (deep) { + f.deepExtend(resStore[lng][ns], resources); + } else { + f.extend(resStore[lng][ns], resources); + } + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function hasResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + var res = resStore[lng][ns] || {}; + + var hasValues = false; + for(var prop in res) { + if (res.hasOwnProperty(prop)) { + hasValues = true; + } + } + + return hasValues; + } + + function getResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + return f.extend({}, resStore[lng][ns]); + } + + function removeResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = {}; + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function addResource(lng, ns, key, value) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + var keys = key.split(o.keyseparator); + var x = 0; + var node = resStore[lng][ns]; + var origRef = node; + + while (keys[x]) { + if (x == keys.length - 1) + node[keys[x]] = value; + else { + if (node[keys[x]] == null) + node[keys[x]] = {}; + + node = node[keys[x]]; + } + x++; + } + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function addResources(lng, ns, resources) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + for (var m in resources) { + if (typeof resources[m] === 'string') addResource(lng, ns, m, resources[m]); + } + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, options, cb) { + if (typeof options === 'function') { + cb = options; + options = {}; + } else if (!options) { + options = {}; + } + + options.lng = lng; + return init(options, cb); + } + + function lng() { + return currentLng; + } + + function reload(cb) { + resStore = {}; + setLng(currentLng, cb); + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else if (attr === 'prepend') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.prepend($.t(key, optionsToUse)); + } else if (attr === 'append') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.append($.t(key, optionsToUse)); + } else if (attr.indexOf("data-") === 0) { + var dataAttr = attr.substr(("data-").length); + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.data(dataAttr) }, options) : options; + var translated = $.t(key, optionsToUse); + //we change into the data cache + ele.data(dataAttr, translated); + //we change into the dom + ele.attr(attr, translated); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key && typeof key !== 'undefined' && key !== false) key = ele.text() || ele.val(); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + var hash = replacementHash.replace && typeof replacementHash.replace === 'object' ? replacementHash.replace : replacementHash; + f.each(hash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), f.regexReplacementEscape(value)); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(f.escape(value))); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(value)); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + if (index_of_end_of_closing <= index_of_opening) { + f.error('there is an missing closing in following translation value', translated); + return ''; + } + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, f.regexReplacementEscape(translated_token)); + } + return translated; + } + + function hasContext(options) { + return (options.context && (typeof options.context == 'string' || typeof options.context == 'number')); + } + + function needsPlural(options, lng) { + return (options.count !== undefined && typeof options.count != 'string'/* && pluralExtensions.needsPlural(lng, options.count)*/); + } + + function needsIndefiniteArticle(options) { + return (options.indefinite_article !== undefined && typeof options.indefinite_article != 'string' && options.indefinite_article); + } + + function exists(key, options) { + options = options || {}; + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + options = options || {}; + + if (!initialized) { + f.log('i18next not finished initialization. you might have called t function before loading resources finished.') + return options.defaultValue || ''; + }; + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _getDefaultValue(key, options) { + return (options.defaultValue !== undefined) ? options.defaultValue : key; + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(potentialKeys, options) { + if (options && typeof options !== 'object') { + if (o.shortcutFunction === 'sprintf') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else if (o.shortcutFunction === 'defaultValue') { + options = { + defaultValue: options + } + } + } else { + options = options || {}; + } + + if (typeof o.defaultVariables === 'object') { + options = f.extend({}, o.defaultVariables, options); + } + + if (potentialKeys === undefined || potentialKeys === null || potentialKeys === '') return ''; + + if (typeof potentialKeys === 'number') { + potentialKeys = String(potentialKeys); + } + + if (typeof potentialKeys === 'string') { + potentialKeys = [potentialKeys]; + } + + var key = potentialKeys[0]; + + if (potentialKeys.length > 1) { + for (var i = 0; i < potentialKeys.length; i++) { + key = potentialKeys[i]; + if (exists(key, options)) { + break; + } + } + } + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng, options.fallbackLng) : languages + , ns = options.ns || o.ns.defaultNs + , parts; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing && typeof o.missingKeyHandler === 'function') { + if (options.lng) { + o.missingKeyHandler(lngs[0], ns, key, notFound, lngs); + } else { + o.missingKeyHandler(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessorsToApply; + if (typeof o.postProcess === 'string' && o.postProcess !== '') { + postProcessorsToApply = [o.postProcess]; + } else if (typeof o.postProcess === 'array' || typeof o.postProcess === 'object') { + postProcessorsToApply = o.postProcess; + } else { + postProcessorsToApply = []; + } + + if (typeof options.postProcess === 'string' && options.postProcess !== '') { + postProcessorsToApply = postProcessorsToApply.concat([options.postProcess]); + } else if (typeof options.postProcess === 'array' || typeof options.postProcess === 'object') { + postProcessorsToApply = postProcessorsToApply.concat(options.postProcess); + } + + if (found !== undefined && postProcessorsToApply.length) { + postProcessorsToApply.forEach(function(postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + }); + } + + // process notFound if function exists + var splitNotFound = notFound; + if (notFound.indexOf(o.nsseparator) > -1) { + parts = notFound.split(o.nsseparator); + splitNotFound = parts[1]; + } + if (splitNotFound === key && o.parseMissingKey) { + notFound = o.parseMissingKey(notFound); + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessorsToApply.length) { + var val = _getDefaultValue(key, options); + postProcessorsToApply.forEach(function(postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](val, key, options); + } + }); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options) { + options = options || {}; + + var optionWithoutCount, translated + , notFound = _getDefaultValue(key, options) + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + // CI mode + if (lngs[0].toLowerCase() === 'cimode') return notFound; + + // passed in lng + if (options.lngs) lngs = options.lngs; + if (options.lng) { + lngs = f.toLanguages(options.lng, options.fallbackLng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options, lngs[0])) { + optionWithoutCount = f.extend({ lngs: [lngs[0]]}, options); + delete optionWithoutCount.count; + optionWithoutCount._origLng = optionWithoutCount._origLng || optionWithoutCount.lng || lngs[0]; + delete optionWithoutCount.lng; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey; + if (!pluralExtensions.needsPlural(lngs[0], options.count)) { + pluralKey = ns + o.nsseparator + key; + } else { + pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(lngs[0], options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + } + + translated = translate(pluralKey, optionWithoutCount); + + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } else if (lngs.length > 1) { + // remove failed lng + var clone = lngs.slice(); + clone.shift(); + options = f.extend(options, { lngs: clone }); + options._origLng = optionWithoutCount._origLng; + delete options.lng; + // retry with fallbacks + translated = translate(ns + o.nsseparator + key, options); + if (translated != o.pluralNotFound) return translated; + } else { + optionWithoutCount.lng = optionWithoutCount._origLng; + delete optionWithoutCount._origLng; + translated = translate(ns + o.nsseparator + key, optionWithoutCount); + + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); + } + } + + if (needsIndefiniteArticle(options)) { + var optionsWithoutIndef = f.extend({}, options); + delete optionsWithoutIndef.indefinite_article; + optionsWithoutIndef.defaultValue = o.indefiniteNotFound; + // If we don't have a count, we want the indefinite, if we do have a count, and needsPlural is false + var indefiniteKey = ns + o.nsseparator + key + (((options.count && !needsPlural(options, lngs[0])) || !options.count) ? o.indefiniteSuffix : ""); + translated = translate(indefiniteKey, optionsWithoutIndef); + if (translated != o.indefiniteNotFound) { + return translated; + } + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + var valueType = Object.prototype.toString.apply(value); + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (valueType === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + if (o.objectTreeKeyHandler && typeof o.objectTreeKeyHandler == 'function') { + value = o.objectTreeKeyHandler(key, value, l, ns, options); + } else { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned an object instead of string.'; + f.log(value); + } + } else if (valueType !== '[object Number]' && valueType !== '[object Function]' && valueType !== '[object RegExp]') { + var copy = (valueType === '[object Array]') ? [] : {}; // apply child translation on a copy + f.each(value, function(m) { + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + }); + value = copy; + } + } + + if (typeof value === 'string' && value.trim() === '' && o.fallbackOnEmpty === true) + value = undefined; + + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length > 0))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found || (found==="" && o.fallbackOnEmpty === false)) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + options.isFallbackLookup = false; + } + + return found; + } + function detectLanguage() { + var detectedLng; + var whitelist = o.lngWhitelist || []; + var userLngChoices = []; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var params = query.split('&'); + for (var i=0; i 0) { + var key = params[i].substring(0,pos); + if (key == o.detectLngQS) { + userLngChoices.push(params[i].substring(pos+1)); + } + } + } + })(); + } + + // get from cookie + if (o.useCookie && typeof document !== 'undefined') { + var c = f.cookie.read(o.cookieName); + if (c) userLngChoices.push(c); + } + + // get from localStorage + if (o.detectLngFromLocalStorage && typeof window !== 'undefined' && window.localStorage) { + userLngChoices.push(f.localStorage.getItem('i18next_lng')); + } + + // get from navigator + if (typeof navigator !== 'undefined') { + if (navigator.languages) { // chrome only; not an array, so can't use .push.apply instead of iterating + for (var i=0;i -1) { + var parts = lng.split('-'); + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } + + if (whitelist.length === 0 || whitelist.indexOf(lng) > -1) { + detectedLng = lng; + break; + } + } + })(); + + //fallback + if (!detectedLng){ + detectedLng = o.fallbackLng[0]; + } + + return detectedLng; + } + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + + /* [code, name, numbers, pluralsType] */ + var _rules = [ + ["ach", "Acholi", [1,2], 1], + ["af", "Afrikaans",[1,2], 2], + ["ak", "Akan", [1,2], 1], + ["am", "Amharic", [1,2], 1], + ["an", "Aragonese",[1,2], 2], + ["ar", "Arabic", [0,1,2,3,11,100],5], + ["arn", "Mapudungun",[1,2], 1], + ["ast", "Asturian", [1,2], 2], + ["ay", "Aymará", [1], 3], + ["az", "Azerbaijani",[1,2],2], + ["be", "Belarusian",[1,2,5],4], + ["bg", "Bulgarian",[1,2], 2], + ["bn", "Bengali", [1,2], 2], + ["bo", "Tibetan", [1], 3], + ["br", "Breton", [1,2], 1], + ["bs", "Bosnian", [1,2,5],4], + ["ca", "Catalan", [1,2], 2], + ["cgg", "Chiga", [1], 3], + ["cs", "Czech", [1,2,5],6], + ["csb", "Kashubian",[1,2,5],7], + ["cy", "Welsh", [1,2,3,8],8], + ["da", "Danish", [1,2], 2], + ["de", "German", [1,2], 2], + ["dev", "Development Fallback", [1,2], 2], + ["dz", "Dzongkha", [1], 3], + ["el", "Greek", [1,2], 2], + ["en", "English", [1,2], 2], + ["eo", "Esperanto",[1,2], 2], + ["es", "Spanish", [1,2], 2], + ["es_ar","Argentinean Spanish", [1,2], 2], + ["et", "Estonian", [1,2], 2], + ["eu", "Basque", [1,2], 2], + ["fa", "Persian", [1], 3], + ["fi", "Finnish", [1,2], 2], + ["fil", "Filipino", [1,2], 1], + ["fo", "Faroese", [1,2], 2], + ["fr", "French", [1,2], 9], + ["fur", "Friulian", [1,2], 2], + ["fy", "Frisian", [1,2], 2], + ["ga", "Irish", [1,2,3,7,11],10], + ["gd", "Scottish Gaelic",[1,2,3,20],11], + ["gl", "Galician", [1,2], 2], + ["gu", "Gujarati", [1,2], 2], + ["gun", "Gun", [1,2], 1], + ["ha", "Hausa", [1,2], 2], + ["he", "Hebrew", [1,2], 2], + ["hi", "Hindi", [1,2], 2], + ["hr", "Croatian", [1,2,5],4], + ["hu", "Hungarian",[1,2], 2], + ["hy", "Armenian", [1,2], 2], + ["ia", "Interlingua",[1,2],2], + ["id", "Indonesian",[1], 3], + ["is", "Icelandic",[1,2], 12], + ["it", "Italian", [1,2], 2], + ["ja", "Japanese", [1], 3], + ["jbo", "Lojban", [1], 3], + ["jv", "Javanese", [0,1], 13], + ["ka", "Georgian", [1], 3], + ["kk", "Kazakh", [1], 3], + ["km", "Khmer", [1], 3], + ["kn", "Kannada", [1,2], 2], + ["ko", "Korean", [1], 3], + ["ku", "Kurdish", [1,2], 2], + ["kw", "Cornish", [1,2,3,4],14], + ["ky", "Kyrgyz", [1], 3], + ["lb", "Letzeburgesch",[1,2],2], + ["ln", "Lingala", [1,2], 1], + ["lo", "Lao", [1], 3], + ["lt", "Lithuanian",[1,2,10],15], + ["lv", "Latvian", [1,2,0],16], + ["mai", "Maithili", [1,2], 2], + ["mfe", "Mauritian Creole",[1,2],1], + ["mg", "Malagasy", [1,2], 1], + ["mi", "Maori", [1,2], 1], + ["mk", "Macedonian",[1,2],17], + ["ml", "Malayalam",[1,2], 2], + ["mn", "Mongolian",[1,2], 2], + ["mnk", "Mandinka", [0,1,2],18], + ["mr", "Marathi", [1,2], 2], + ["ms", "Malay", [1], 3], + ["mt", "Maltese", [1,2,11,20],19], + ["nah", "Nahuatl", [1,2], 2], + ["nap", "Neapolitan",[1,2], 2], + ["nb", "Norwegian Bokmal",[1,2],2], + ["ne", "Nepali", [1,2], 2], + ["nl", "Dutch", [1,2], 2], + ["nn", "Norwegian Nynorsk",[1,2],2], + ["no", "Norwegian",[1,2], 2], + ["nso", "Northern Sotho",[1,2],2], + ["oc", "Occitan", [1,2], 1], + ["or", "Oriya", [2,1], 2], + ["pa", "Punjabi", [1,2], 2], + ["pap", "Papiamento",[1,2], 2], + ["pl", "Polish", [1,2,5],7], + ["pms", "Piemontese",[1,2], 2], + ["ps", "Pashto", [1,2], 2], + ["pt", "Portuguese",[1,2], 2], + ["pt_br","Brazilian Portuguese",[1,2], 2], + ["rm", "Romansh", [1,2], 2], + ["ro", "Romanian", [1,2,20],20], + ["ru", "Russian", [1,2,5],4], + ["sah", "Yakut", [1], 3], + ["sco", "Scots", [1,2], 2], + ["se", "Northern Sami",[1,2], 2], + ["si", "Sinhala", [1,2], 2], + ["sk", "Slovak", [1,2,5],6], + ["sl", "Slovenian",[5,1,2,3],21], + ["so", "Somali", [1,2], 2], + ["son", "Songhay", [1,2], 2], + ["sq", "Albanian", [1,2], 2], + ["sr", "Serbian", [1,2,5],4], + ["su", "Sundanese",[1], 3], + ["sv", "Swedish", [1,2], 2], + ["sw", "Swahili", [1,2], 2], + ["ta", "Tamil", [1,2], 2], + ["te", "Telugu", [1,2], 2], + ["tg", "Tajik", [1,2], 1], + ["th", "Thai", [1], 3], + ["ti", "Tigrinya", [1,2], 1], + ["tk", "Turkmen", [1,2], 2], + ["tr", "Turkish", [1,2], 1], + ["tt", "Tatar", [1], 3], + ["ug", "Uyghur", [1], 3], + ["uk", "Ukrainian",[1,2,5],4], + ["ur", "Urdu", [1,2], 2], + ["uz", "Uzbek", [1,2], 1], + ["vi", "Vietnamese",[1], 3], + ["wa", "Walloon", [1,2], 1], + ["wo", "Wolof", [1], 3], + ["yo", "Yoruba", [1,2], 2], + ["zh", "Chinese", [1], 3] + ]; + + var _rulesPluralsTypes = { + 1: function(n) {return Number(n > 1);}, + 2: function(n) {return Number(n != 1);}, + 3: function(n) {return 0;}, + 4: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 5: function(n) {return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5);}, + 6: function(n) {return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2);}, + 7: function(n) {return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 8: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3);}, + 9: function(n) {return Number(n >= 2);}, + 10: function(n) {return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;}, + 11: function(n) {return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3);}, + 12: function(n) {return Number(n%10!=1 || n%100==11);}, + 13: function(n) {return Number(n !== 0);}, + 14: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3);}, + 15: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 16: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2);}, + 17: function(n) {return Number(n==1 || n%10==1 ? 0 : 1);}, + 18: function(n) {return Number(0 ? 0 : n==1 ? 1 : 2);}, + 19: function(n) {return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3);}, + 20: function(n) {return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2);}, + 21: function(n) {return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }; + + var pluralExtensions = { + + rules: (function () { + var l, rules = {}; + for (l=_rules.length; l-- ;) { + rules[_rules[l][0]] = { + name: _rules[l][1], + numbers: _rules[l][2], + plurals: _rulesPluralsTypes[_rules[l][3]] + } + } + return rules; + }()), + + // you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + needsPlural: function(lng, count) { + var parts = lng.split('-'); + + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[parts[f.getCountyIndexOfLng(lng)]]; + } + + if (ext && ext.numbers.length <= 1) { + return false; + } else { + return this.get(lng, count) !== 1; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i; + if (ext.noAbs) { + i = ext.plurals(c); + } else { + i = ext.plurals(Math.abs(c)); + } + + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[f.getCountyIndexOfLng(lng)], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.hasResourceBundle = hasResourceBundle; + i18n.getResourceBundle = getResourceBundle; + i18n.addResource = addResource; + i18n.addResources = addResources; + i18n.removeResourceBundle = removeResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.applyReplacement = f.applyReplacement; + i18n.options = o; + +})(typeof exports === 'undefined' ? window : exports); \ No newline at end of file diff --git a/libs/i18next/i18next.min.js b/libs/i18next/i18next.min.js new file mode 100644 index 00000000..5ba7b5ba --- /dev/null +++ b/libs/i18next/i18next.min.js @@ -0,0 +1,5 @@ +// i18next, v1.8.2 +// Copyright (c)2015 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +!function(a){function b(a,b){if(!b||"function"==typeof b)return a;for(var c in b)a[c]=b[c];return a}function c(a,b){for(var d in b)d in a?c(a[d],b[d]):a[d]=b[d];return a}function d(a,b,c){var d,e=0,f=a.length,g=void 0===f||"[object Array]"!==Object.prototype.toString.apply(a)||"function"==typeof a;if(c)if(g){for(d in a)if(b.apply(a[d],c)===!1)break}else for(;f>e&&b.apply(a[e++],c)!==!1;);else if(g){for(d in a)if(b.call(a[d],d,a[d])===!1)break}else for(;f>e&&b.call(a[e],e,a[e++])!==!1;);return a}function e(a){return"string"==typeof a?a.replace(/[&<>"'\/]/g,function(a){return Q[a]}):a}function f(a){var b=function(a){if(window.XMLHttpRequest)return a(null,new XMLHttpRequest);if(window.ActiveXObject)try{return a(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(b){return a(null,new ActiveXObject("Microsoft.XMLHTTP"))}return a(new Error)},c=function(a){if("string"==typeof a)return a;var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")},d=function(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;cd?b+=String.fromCharCode(d):d>127&&2048>d?(b+=String.fromCharCode(d>>6|192),b+=String.fromCharCode(63&d|128)):(b+=String.fromCharCode(d>>12|224),b+=String.fromCharCode(d>>6&63|128),b+=String.fromCharCode(63&d|128))}return b},e=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";a=d(a);var c,e,f,g,h,i,j,k="",l=0;do c=a.charCodeAt(l++),e=a.charCodeAt(l++),f=a.charCodeAt(l++),g=c>>2,h=(3&c)<<4|e>>4,i=(15&e)<<2|f>>6,j=63&f,isNaN(e)?i=j=64:isNaN(f)&&(j=64),k+=b.charAt(g)+b.charAt(h)+b.charAt(i)+b.charAt(j),c=e=f="",g=h=i=j="";while(l1&&(d+=d.indexOf("?")>-1?"&"+k:"?"+k),e.jsonp){var l=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=d,void l.appendChild(m)}}b(function(b,c){if(b)return h(b);c.open(a,d,e.async);for(var f in j)j.hasOwnProperty(f)&&c.setRequestHeader(f,j[f]);c.onreadystatechange=function(){if(4===c.readyState){var a=c.responseText||"";if(!h)return;h(c.status,{text:function(){return a},json:function(){try{return JSON.parse(a)}catch(b){return T.error("Can not parse JSON. URL: "+d),{}}}})}},c.send(i)})},h={authBasic:function(a,b){g.headers.Authorization="Basic "+e(a+":"+b)},connect:function(a,b,c){return g("CONNECT",a,b,c)},del:function(a,b,c){return g("DELETE",a,b,c)},get:function(a,b,c){return g("GET",a,b,c)},head:function(a,b,c){return g("HEAD",a,b,c)},headers:function(a){g.headers=a||{}},isAllowed:function(a,b,c){this.options(a,function(a,d){c(-1!==d.text().indexOf(b))})},options:function(a,b,c){return g("OPTIONS",a,b,c)},patch:function(a,b,c){return g("PATCH",a,b,c)},post:function(a,b,c){return g("POST",a,b,c)},put:function(a,b,c){return g("PUT",a,b,c)},trace:function(a,b,c){return g("TRACE",a,b,c)}},i=a.type?a.type.toLowerCase():"get";h[i](a.url,a,function(b,c){200===b||0===b&&c.text()?a.success(c.json(),b,null):a.error(c.text(),b,null)})}function g(a,b){"function"==typeof a&&(b=a,a={}),a=a||{},T.extend(P,a),delete P.fixLng,P.functions&&(delete P.functions,T.extend(T,a.functions)),"string"==typeof P.ns&&(P.ns={namespaces:[P.ns],defaultNs:P.ns}),"string"==typeof P.fallbackNS&&(P.fallbackNS=[P.fallbackNS]),("string"==typeof P.fallbackLng||"boolean"==typeof P.fallbackLng)&&(P.fallbackLng=[P.fallbackLng]),P.interpolationPrefixEscaped=T.regexEscape(P.interpolationPrefix),P.interpolationSuffixEscaped=T.regexEscape(P.interpolationSuffix),P.lng||(P.lng=T.detectLanguage()),M=T.toLanguages(P.lng),H=M[0],T.log("currentLng set to: "+H),P.useCookie&&T.cookie.read(P.cookieName)!==H&&T.cookie.create(P.cookieName,H,P.cookieExpirationTime,P.cookieDomain),P.detectLngFromLocalStorage&&"undefined"!=typeof document&&window.localStorage&&T.localStorage.setItem("i18next_lng",H);var c=B;a.fixLng&&(c=function(a,b){return b=b||{},b.lng=b.lng||c.lng,B(a,b)},c.lng=H),W.setCurrentLng(H),I&&P.setJqueryExt&&u();var d;if(I&&I.Deferred&&(d=I.Deferred()),!P.resStore){var e=T.toLanguages(P.lng);"string"==typeof P.preload&&(P.preload=[P.preload]);for(var f=0,g=P.preload.length;g>f;f++)for(var h=T.toLanguages(P.preload[f]),i=0,j=h.length;j>i;i++)e.indexOf(h[i])<0&&e.push(h[i]);return J.sync.load(e,P,function(a,e){K=e,N=!0,b&&b(c),d&&d.resolve(c)}),d?d.promise():void 0}return K=P.resStore,N=!0,b&&b(c),d&&d.resolve(c),d?d.promise():void 0}function h(a,b){"string"==typeof a&&(a=[a]);for(var c=0,d=a.length;d>c;c++)P.preload.indexOf(a[c])<0&&P.preload.push(a[c]);return g(b)}function i(a,b,c,d){"string"!=typeof b?(c=b,b=P.ns.defaultNs):P.ns.namespaces.indexOf(b)<0&&P.ns.namespaces.push(b),K[a]=K[a]||{},K[a][b]=K[a][b]||{},d?T.deepExtend(K[a][b],c):T.extend(K[a][b],c),P.useLocalStorage&&O._storeLocal(K)}function j(a,b){"string"!=typeof b&&(b=P.ns.defaultNs),K[a]=K[a]||{};var c=K[a][b]||{},d=!1;for(var e in c)c.hasOwnProperty(e)&&(d=!0);return d}function k(a,b){return"string"!=typeof b&&(b=P.ns.defaultNs),K[a]=K[a]||{},T.extend({},K[a][b])}function l(a,b){"string"!=typeof b&&(b=P.ns.defaultNs),K[a]=K[a]||{},K[a][b]={},P.useLocalStorage&&O._storeLocal(K)}function m(a,b,c,d){"string"!=typeof b?(resource=b,b=P.ns.defaultNs):P.ns.namespaces.indexOf(b)<0&&P.ns.namespaces.push(b),K[a]=K[a]||{},K[a][b]=K[a][b]||{};for(var e=c.split(P.keyseparator),f=0,g=K[a][b];e[f];)f==e.length-1?g[e[f]]=d:(null==g[e[f]]&&(g[e[f]]={}),g=g[e[f]]),f++;P.useLocalStorage&&O._storeLocal(K)}function n(a,b,c){"string"!=typeof b?(resource=b,b=P.ns.defaultNs):P.ns.namespaces.indexOf(b)<0&&P.ns.namespaces.push(b);for(var d in c)"string"==typeof c[d]&&m(a,b,d,c[d])}function o(a){P.ns.defaultNs=a}function p(a,b){q([a],b)}function q(a,b){var c={dynamicLoad:P.dynamicLoad,resGetPath:P.resGetPath,getAsync:P.getAsync,customLoad:P.customLoad,ns:{namespaces:a,defaultNs:""}},d=T.toLanguages(P.lng);"string"==typeof P.preload&&(P.preload=[P.preload]);for(var e=0,f=P.preload.length;f>e;e++)for(var g=T.toLanguages(P.preload[e]),h=0,i=g.length;i>h;h++)d.indexOf(g[h])<0&&d.push(g[h]);for(var j=[],k=0,l=d.length;l>k;k++){var m=!1,n=K[d[k]];if(n)for(var o=0,p=a.length;p>o;o++)n[a[o]]||(m=!0);else m=!0;m&&j.push(d[k])}j.length?J.sync._fetch(j,c,function(c,d){var e=a.length*j.length;T.each(a,function(a,c){P.ns.namespaces.indexOf(c)<0&&P.ns.namespaces.push(c),T.each(j,function(a,f){K[f]=K[f]||{},K[f][c]=d[f][c],e--,0===e&&b&&(P.useLocalStorage&&J.sync._storeLocal(K),b())})})}):b&&b()}function r(a,b,c){return"function"==typeof b?(c=b,b={}):b||(b={}),b.lng=a,g(b,c)}function s(){return H}function t(a){K={},r(H,a)}function u(){function a(a,b,c){if(0!==b.length){var d="text";if(0===b.indexOf("[")){var e=b.split("]");b=e[1],d=e[0].substr(1,e[0].length-1)}b.indexOf(";")===b.length-1&&(b=b.substr(0,b.length-2));var f;if("html"===d)f=P.defaultValueFromContent?I.extend({defaultValue:a.html()},c):c,a.html(I.t(b,f));else if("text"===d)f=P.defaultValueFromContent?I.extend({defaultValue:a.text()},c):c,a.text(I.t(b,f));else if("prepend"===d)f=P.defaultValueFromContent?I.extend({defaultValue:a.html()},c):c,a.prepend(I.t(b,f));else if("append"===d)f=P.defaultValueFromContent?I.extend({defaultValue:a.html()},c):c,a.append(I.t(b,f));else if(0===d.indexOf("data-")){var g=d.substr("data-".length);f=P.defaultValueFromContent?I.extend({defaultValue:a.data(g)},c):c;var h=I.t(b,f);a.data(g,h),a.attr(d,h)}else f=P.defaultValueFromContent?I.extend({defaultValue:a.attr(d)},c):c,a.attr(d,I.t(b,f))}}function b(b,c){var d=b.attr(P.selectorAttr);if(d||"undefined"==typeof d||d===!1||(d=b.text()||b.val()),d){var e=b,f=b.data("i18n-target");if(f&&(e=b.find(f)||b),c||P.useDataAttrOptions!==!0||(c=b.data("i18n-options")),c=c||{},d.indexOf(";")>=0){var g=d.split(";");I.each(g,function(b,d){""!==d&&a(e,d,c)})}else a(e,d,c);P.useDataAttrOptions===!0&&b.data("i18n-options",c)}}I.t=I.t||B,I.fn.i18n=function(a){return this.each(function(){b(I(this),a);var c=I(this).find("["+P.selectorAttr+"]");c.each(function(){b(I(this),a)})})}}function v(a,b,c,d){if(!a)return a;if(d=d||b,a.indexOf(d.interpolationPrefix||P.interpolationPrefix)<0)return a;var e=d.interpolationPrefix?T.regexEscape(d.interpolationPrefix):P.interpolationPrefixEscaped,f=d.interpolationSuffix?T.regexEscape(d.interpolationSuffix):P.interpolationSuffixEscaped,g="HTML"+f,h=b.replace&&"object"==typeof b.replace?b.replace:b;return T.each(h,function(b,h){var i=c?c+P.keyseparator+b:b;"object"==typeof h&&null!==h?a=v(a,h,i,d):d.escapeInterpolation||P.escapeInterpolation?(a=a.replace(new RegExp([e,i,g].join(""),"g"),T.regexReplacementEscape(h)),a=a.replace(new RegExp([e,i,f].join(""),"g"),T.regexReplacementEscape(T.escape(h)))):a=a.replace(new RegExp([e,i,f].join(""),"g"),T.regexReplacementEscape(h))}),a}function w(a,b){var c=",",d="{",e="}",f=T.extend({},b);for(delete f.postProcess;-1!=a.indexOf(P.reusePrefix)&&(L++,!(L>P.maxRecursion));){var g=a.lastIndexOf(P.reusePrefix),h=a.indexOf(P.reuseSuffix,g)+P.reuseSuffix.length,i=a.substring(g,h),j=i.replace(P.reusePrefix,"").replace(P.reuseSuffix,"");if(g>=h)return T.error("there is an missing closing in following translation value",a),"";if(-1!=j.indexOf(c)){var k=j.indexOf(c);if(-1!=j.indexOf(d,k)&&-1!=j.indexOf(e,k)){var l=j.indexOf(d,k),m=j.indexOf(e,l)+e.length;try{f=T.extend(f,JSON.parse(j.substring(l,m))),j=j.substring(0,k)}catch(n){}}}var o=E(j,f);a=a.replace(i,T.regexReplacementEscape(o))}return a}function x(a){return a.context&&("string"==typeof a.context||"number"==typeof a.context)}function y(a){return void 0!==a.count&&"string"!=typeof a.count}function z(a){return void 0!==a.indefinite_article&&"string"!=typeof a.indefinite_article&&a.indefinite_article}function A(a,b){b=b||{};var c=C(a,b),d=F(a,b);return void 0!==d||d===c}function B(a,b){return b=b||{},N?(L=0,E.apply(null,arguments)):(T.log("i18next not finished initialization. you might have called t function before loading resources finished."),b.defaultValue||"")}function C(a,b){return void 0!==b.defaultValue?b.defaultValue:a}function D(){for(var a=[],b=1;b1)for(var d=0;d-1&&(e=c.split(P.nsseparator),i=e[0],c=e[1]),void 0===g&&P.sendMissing&&"function"==typeof P.missingKeyHandler&&(b.lng?P.missingKeyHandler(h[0],i,c,f,h):P.missingKeyHandler(P.lng,i,c,f,h));var j;j="string"==typeof P.postProcess&&""!==P.postProcess?[P.postProcess]:"array"==typeof P.postProcess||"object"==typeof P.postProcess?P.postProcess:[],"string"==typeof b.postProcess&&""!==b.postProcess?j=j.concat([b.postProcess]):("array"==typeof b.postProcess||"object"==typeof b.postProcess)&&(j=j.concat(b.postProcess)),void 0!==g&&j.length&&j.forEach(function(a){X[a]&&(g=X[a](g,c,b))});var k=f;if(f.indexOf(P.nsseparator)>-1&&(e=f.split(P.nsseparator),k=e[1]),k===c&&P.parseMissingKey&&(f=P.parseMissingKey(f)),void 0===g&&(f=v(f,b),f=w(f,b),j.length)){var l=C(c,b);j.forEach(function(a){X[a]&&(g=X[a](l,c,b))})}return void 0!==g?g:f}function F(a,b){b=b||{};var c,d,e=C(a,b),f=M;if(!K)return e;if("cimode"===f[0].toLowerCase())return e;if(b.lngs&&(f=b.lngs),b.lng&&(f=T.toLanguages(b.lng,b.fallbackLng),!K[f[0]])){var g=P.getAsync;P.getAsync=!1,J.sync.load(f,P,function(a,b){T.extend(K,b),P.getAsync=g})}var h=b.ns||P.ns.defaultNs;if(a.indexOf(P.nsseparator)>-1){var i=a.split(P.nsseparator);h=i[0],a=i[1]}if(x(b)){c=T.extend({},b),delete c.context,c.defaultValue=P.contextNotFound;var j=h+P.nsseparator+a+"_"+b.context;if(d=B(j,c),d!=P.contextNotFound)return v(d,{context:b.context})}if(y(b,f[0])){c=T.extend({lngs:[f[0]]},b),delete c.count,c._origLng=c._origLng||c.lng||f[0],delete c.lng,c.defaultValue=P.pluralNotFound;var k;if(W.needsPlural(f[0],b.count)){k=h+P.nsseparator+a+P.pluralSuffix;var l=W.get(f[0],b.count);l>=0?k=k+"_"+l:1===l&&(k=h+P.nsseparator+a)}else k=h+P.nsseparator+a;if(d=B(k,c),d!=P.pluralNotFound)return v(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix});if(!(f.length>1))return c.lng=c._origLng,delete c._origLng,d=B(h+P.nsseparator+a,c),v(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix});var m=f.slice();if(m.shift(),b=T.extend(b,{lngs:m}),b._origLng=c._origLng,delete b.lng,d=B(h+P.nsseparator+a,b),d!=P.pluralNotFound)return d}if(z(b)){var n=T.extend({},b);delete n.indefinite_article,n.defaultValue=P.indefiniteNotFound;var o=h+P.nsseparator+a+(b.count&&!y(b,f[0])||!b.count?P.indefiniteSuffix:"");if(d=B(o,n),d!=P.indefiniteNotFound)return d}for(var p,q=a.split(P.keyseparator),r=0,s=f.length;s>r&&void 0===p;r++){for(var t=f[r],u=0,A=K[t]&&K[t][h];q[u];)A=A&&A[q[u]],u++;if(void 0!==A){var D=Object.prototype.toString.apply(A);if("string"==typeof A)A=v(A,b),A=w(A,b);else if("[object Array]"!==D||P.returnObjectTrees||b.returnObjectTrees){if(null===A&&P.fallbackOnNull===!0)A=void 0;else if(null!==A)if(P.returnObjectTrees||b.returnObjectTrees){if("[object Number]"!==D&&"[object Function]"!==D&&"[object RegExp]"!==D){var G="[object Array]"===D?[]:{};T.each(A,function(c){G[c]=E(h+P.nsseparator+a+P.keyseparator+c,b)}),A=G}}else P.objectTreeKeyHandler&&"function"==typeof P.objectTreeKeyHandler?A=P.objectTreeKeyHandler(a,A,t,h,b):(A="key '"+h+":"+a+" ("+t+")' returned an object instead of string.",T.log(A))}else A=A.join("\n"),A=v(A,b),A=w(A,b);"string"==typeof A&&""===A.trim()&&P.fallbackOnEmpty===!0&&(A=void 0),p=A}}if(void 0===p&&!b.isFallbackLookup&&(P.fallbackToDefaultNS===!0||P.fallbackNS&&P.fallbackNS.length>0)){if(b.isFallbackLookup=!0,P.fallbackNS.length){for(var H=0,I=P.fallbackNS.length;I>H;H++)if(p=F(P.fallbackNS[H]+P.nsseparator+a,b),p||""===p&&P.fallbackOnEmpty===!1){var L=p.indexOf(P.nsseparator)>-1?p.split(P.nsseparator)[1]:p,N=e.indexOf(P.nsseparator)>-1?e.split(P.nsseparator)[1]:e;if(L!==N)break}}else p=F(a,b);b.isFallbackLookup=!1}return p}function G(){var a,b=P.lngWhitelist||[],c=[];if("undefined"!=typeof window&&!function(){for(var a=window.location.search.substring(1),b=a.split("&"),d=0;d0){var f=b[d].substring(0,e);f==P.detectLngQS&&c.push(b[d].substring(e+1))}}}(),P.useCookie&&"undefined"!=typeof document){var d=T.cookie.read(P.cookieName);d&&c.push(d)}if(P.detectLngFromLocalStorage&&"undefined"!=typeof window&&window.localStorage&&c.push(T.localStorage.getItem("i18next_lng")),"undefined"!=typeof navigator){if(navigator.languages)for(var e=0;e-1){var f=e.split("-");e=P.lowerCaseLng?f[0].toLowerCase()+"-"+f[1].toLowerCase():f[0].toLowerCase()+"-"+f[1].toUpperCase()}if(0===b.length||b.indexOf(e)>-1){a=e;break}}}(),a||(a=P.fallbackLng[0]),a}Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>0&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=c;arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d))));for(var e=d>=0?Math.min(d,c-1):c-Math.abs(d);e>=0;e--)if(e in b&&b[e]===a)return e;return-1}),"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")});var H,I=a.jQuery||a.Zepto,J={},K={},L=0,M=[],N=!1,O={};"undefined"!=typeof module&&module.exports?module.exports=J:(I&&(I.i18n=I.i18n||J),a.i18n=a.i18n||J),O={load:function(a,b,c){b.useLocalStorage?O._loadLocal(a,b,function(d,e){for(var f=[],g=0,h=a.length;h>g;g++)e[a[g]]||f.push(a[g]);f.length>0?O._fetch(f,b,function(a,b){T.extend(e,b),O._storeLocal(b),c(null,e)}):c(null,e)}):O._fetch(a,b,function(a,b){c(null,b)})},_loadLocal:function(a,b,c){var d={},e=(new Date).getTime();if(window.localStorage){var f=a.length;T.each(a,function(a,g){var h=T.localStorage.getItem("res_"+g);h&&(h=JSON.parse(h),h.i18nStamp&&h.i18nStamp+b.localStorageExpirationTime>e&&(d[g]=h)),f--,0===f&&c(null,d)})}},_storeLocal:function(a){if(window.localStorage)for(var b in a)a[b].i18nStamp=(new Date).getTime(),T.localStorage.setItem("res_"+b,JSON.stringify(a[b]))},_fetch:function(a,b,c){var d=b.ns,e={};if(b.dynamicLoad){var f=function(a,b){c(null,b)};if("function"==typeof b.customLoad)b.customLoad(a,d.namespaces,b,f);else{var g=v(b.resGetPath,{lng:a.join("+"),ns:d.namespaces.join("+")});T.ajax({url:g,success:function(a){T.log("loaded: "+g),f(null,a)},error:function(a,b,c){T.log("failed loading: "+g),f("failed loading resource.json error: "+c)},dataType:"json",async:b.getAsync})}}else{var h,i=d.namespaces.length*a.length;T.each(d.namespaces,function(d,f){T.each(a,function(a,d){var g=function(a,b){a&&(h=h||[],h.push(a)),e[d]=e[d]||{},e[d][f]=b,i--,0===i&&c(h,e)};"function"==typeof b.customLoad?b.customLoad(d,f,b,g):O._fetchOne(d,f,b,g)})})}},_fetchOne:function(a,b,c,d){var e=v(c.resGetPath,{lng:a,ns:b});T.ajax({url:e,success:function(a){T.log("loaded: "+e),d(null,a)},error:function(a,b,c){if(b&&200==b||a&&a.status&&200==a.status)T.error("There is a typo in: "+e);else if(b&&404==b||a&&a.status&&404==a.status)T.log("Does not exist: "+e);else{var f=b?b:a&&a.status?a.status:null;T.log(f+" when loading "+e)}d(c,{})},dataType:"json",async:c.getAsync})},postMissing:function(a,b,c,d,e){var f={};f[c]=d;var g=[];if("fallback"===P.sendMissingTo&&P.fallbackLng[0]!==!1)for(var h=0;hh;h++)g.push({lng:e[h],url:v(P.resPostPath,{lng:e[h],ns:b})});for(var j=0,k=g.length;k>j;j++){var l=g[j];T.ajax({url:l.url,type:P.sendType,data:f,success:function(){T.log("posted missing key '"+c+"' to: "+l.url);for(var a=c.split("."),e=0,f=K[l.lng][b];a[e];)f=f[a[e]]=e===a.length-1?d:f[a[e]]||{},e++},error:function(){T.log("failed posting missing key '"+c+"' to: "+l.url)},dataType:"json",async:P.postAsync})}},reload:t};var P={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:["dev"],fallbackNS:[],detectLngQS:"setLng",detectLngFromLocalStorage:!1,ns:{namespaces:["translation"],defaultNs:"translation"},fallbackOnNull:!0,fallbackOnEmpty:!1,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",defaultVariables:!1,reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,indefiniteSuffix:"_indefinite",indefiniteNotFound:["indefinite_not_found",Math.random()].join(""),setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",cookieDomain:void 0,objectTreeKeyHandler:void 0,postProcess:void 0,parseMissingKey:void 0,missingKeyHandler:O.postMissing,shortcutFunction:"sprintf"},Q={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},R={create:function(a,b,c,d){var e;if(c){var f=new Date;f.setTime(f.getTime()+60*c*1e3),e="; expires="+f.toGMTString()}else e="";d=d?"domain="+d+";":"",document.cookie=a+"="+b+e+";"+d+"path=/"},read:function(a){for(var b=a+"=",c=document.cookie.split(";"),d=0;d-1){var c=a.split("-");b=P.lowerCaseLng?c[0].toLowerCase()+"-"+c[1].toLowerCase():c[0].toLowerCase()+"-"+c[1].toUpperCase()}else b=P.lowerCaseLng?a.toLowerCase():a;return b}var c=this.log,d=[],e=P.lngWhitelist||!1,f=function(a){!e||e.indexOf(a)>-1?d.push(a):c("rejecting non-whitelisted language: "+a)};if("string"==typeof a&&a.indexOf("-")>-1){var g=a.split("-");"unspecific"!==P.load&&f(b(a)),"current"!==P.load&&f(b(g[this.getCountyIndexOfLng(a)]))}else f(b(a));for(var h=0;h1)},2:function(a){return Number(1!=a)},3:function(){return 0},4:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},5:function(a){return Number(0===a?0:1==a?1:2==a?2:a%100>=3&&10>=a%100?3:a%100>=11?4:5)},6:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)},7:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},8:function(a){return Number(1==a?0:2==a?1:8!=a&&11!=a?2:3)},9:function(a){return Number(a>=2)},10:function(a){return Number(1==a?0:2==a?1:7>a?2:11>a?3:4)},11:function(a){return Number(1==a||11==a?0:2==a||12==a?1:a>2&&20>a?2:3)},12:function(a){return Number(a%10!=1||a%100==11)},13:function(a){return Number(0!==a)},14:function(a){return Number(1==a?0:2==a?1:3==a?2:3)},15:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&(10>a%100||a%100>=20)?1:2)},16:function(a){return Number(a%10==1&&a%100!=11?0:0!==a?1:2)},17:function(a){return Number(1==a||a%10==1?0:1)},18:function(a){return Number(1==a?1:2)},19:function(a){return Number(1==a?0:0===a||a%100>1&&11>a%100?1:a%100>10&&20>a%100?2:3)},20:function(a){return Number(1==a?0:0===a||a%100>0&&20>a%100?1:2)},21:function(a){return Number(a%100==1?1:a%100==2?2:a%100==3||a%100==4?3:0)}},W={rules:function(){var a,b={};for(a=U.length;a--;)b[U[a][0]]={name:U[a][1],numbers:U[a][2],plurals:V[U[a][3]]};return b}(),addRule:function(a,b){W.rules[a]=b},setCurrentLng:function(a){if(!W.currentRule||W.currentRule.lng!==a){var b=a.split("-");W.currentRule={lng:a,rule:W.rules[b[0]]}}},needsPlural:function(a,b){var c,d=a.split("-");return c=W.currentRule&&W.currentRule.lng===a?W.currentRule.rule:W.rules[d[T.getCountyIndexOfLng(a)]],c&&c.numbers.length<=1?!1:1!==this.get(a,b)},get:function(a,b){function c(b,c){var d;if(d=W.currentRule&&W.currentRule.lng===a?W.currentRule.rule:W.rules[b]){var e;e=d.plurals(d.noAbs?c:Math.abs(c));var f=d.numbers[e];return 2===d.numbers.length&&1===d.numbers[0]&&(2===f?f=-1:1===f&&(f=1)),f}return 1===c?"1":"-1"}var d=a.split("-");return c(d[T.getCountyIndexOfLng(a)],b)}},X={},Y=function(a,b){X[a]=b},Z=function(){function a(a){return Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}function b(a,b){for(var c=[];b>0;c[--b]=a);return c.join("")}var c=function(){return c.cache.hasOwnProperty(arguments[0])||(c.cache[arguments[0]]=c.parse(arguments[0])),c.format.call(null,c.cache[arguments[0]],arguments)};return c.format=function(c,d){var e,f,g,h,i,j,k,l=1,m=c.length,n="",o=[];for(f=0;m>f;f++)if(n=a(c[f]),"string"===n)o.push(c[f]);else if("array"===n){if(h=c[f],h[2])for(e=d[l],g=0;g=0?"+"+e:e,j=h[4]?"0"==h[4]?"0":h[4].charAt(1):" ",k=h[6]-String(e).length,i=h[6]?b(j,k):"",o.push(h[5]?e+i:i+e)}return o.join("")},c.cache={},c.parse=function(a){for(var b=a,c=[],d=[],e=0;b;){if(null!==(c=/^[^\x25]+/.exec(b)))d.push(c[0]);else if(null!==(c=/^\x25{2}/.exec(b)))d.push("%");else{if(null===(c=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(b)))throw"[sprintf] huh?";if(c[2]){e|=1;var f=[],g=c[2],h=[];if(null===(h=/^([a-z_][a-z_\d]*)/i.exec(g)))throw"[sprintf] huh?";for(f.push(h[1]);""!==(g=g.substring(h[0].length));)if(null!==(h=/^\.([a-z_][a-z_\d]*)/i.exec(g)))f.push(h[1]);else{if(null===(h=/^\[(\d+)\]/.exec(g)))throw"[sprintf] huh?";f.push(h[1])}c[2]=f}else e|=2;if(3===e)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";d.push(c)}b=b.substring(c[0].length)}return d},c}(),$=function(a,b){return b.unshift(a),Z.apply(null,b)};Y("sprintf",function(a,b,c){return c.sprintf?"[object Array]"===Object.prototype.toString.apply(c.sprintf)?$(a,c.sprintf):"object"==typeof c.sprintf?Z(a,c.sprintf):a:a}),J.init=g,J.setLng=r,J.preload=h,J.addResourceBundle=i,J.hasResourceBundle=j,J.getResourceBundle=k,J.addResource=m,J.addResources=n,J.removeResourceBundle=l,J.loadNamespace=p,J.loadNamespaces=q,J.setDefaultNamespace=o,J.t=B,J.translate=B,J.exists=A,J.detectLanguage=T.detectLanguage,J.pluralExtensions=W,J.sync=O,J.functions=T,J.lng=s,J.addPostProcessor=Y,J.applyReplacement=T.applyReplacement,J.options=P}("undefined"==typeof exports?window:exports); \ No newline at end of file diff --git a/libs/i18next/license b/libs/i18next/license new file mode 100644 index 00000000..d88a4e64 --- /dev/null +++ b/libs/i18next/license @@ -0,0 +1,19 @@ +Copyright (c) 2011 Jan Mühlemann + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/libs/i18next/package.json b/libs/i18next/package.json new file mode 100644 index 00000000..f2b64ccc --- /dev/null +++ b/libs/i18next/package.json @@ -0,0 +1,28 @@ +{ + "author": "jamuhl", + "name": "i18next-client", + "version": "1.8.2", + "private": false, + "main": "i18next.js", + "browser": "i18next.js", + "engines": { + "node": "^0.4.12" + }, + "dependencies": {}, + "devDependencies": { + "grunt": "~0.4.1", + "grunt-rigger": "~0.5.0", + "grunt-contrib": ">=0.1.0", + "grunt-shell": ">=0.1.0", + "gruntacular": ">=0.1.0", + "express": ">= 0.0.1", + "async": ">= 0.1.18", + "lodash": ">= 0.5.x", + "zipstream": ">=0.2.1", + "underscore": ">=0.2.1" + }, + "repository": "https://github.com/i18next/i18next/", + "scripts": { + "test": "testacular start" + } +} diff --git a/libs/i18next/release/i18next-1.5.10.js b/libs/i18next/release/i18next-1.5.10.js new file mode 100644 index 00000000..aa01e42c --- /dev/null +++ b/libs/i18next/release/i18next-1.5.10.js @@ -0,0 +1,2368 @@ +// i18next, v1.5.10 +// Copyright (c)2012 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function() { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + var root = this + , $ = root.jQuery + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = []; + + + // Export the i18next object for **CommonJS**. + // If we're not in CommonJS, add `i18n` to the + // global object or to jquery. + if (typeof module !== 'undefined' && module.exports) { + module.exports = i18n; + } else { + if ($) { + $.i18n = $.i18n || i18n; + } + + root.i18n = root.i18n || i18n; + } + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: 'dev', + detectLngQS: 'setLng', + ns: 'translation', + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + + postProcess: undefined + }; + + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = '?' + queryString.join('&'); + url += queryString !== '?' ? queryString : ''; + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + return JSON.parse(data); + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, {async: options.async}, function (status, data) { + if (status === 200) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + document.cookie = name+"="+value+expires+"; path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : _ajax, + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + toLanguages: function(lng) { + var languages = []; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + + if (o.load !== 'unspecific') languages.push(lng); + if (o.load !== 'current') languages.push(parts[0]); + } else { + languages.push(lng); + } + + if (languages.indexOf(o.fallbackLng) === -1 && o.fallbackLng) languages.push(o.fallbackLng); + + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + if (o.lng) { + // set cookie with lng set (as detectLanguage will set cookie on need) + if (o.useCookie) f.cookie.create(o.cookieName, o.lng, o.cookieExpirationTime); + } else { + o.lng = o.fallbackLng; + if (o.useCookie) f.cookie.remove(o.cookieName); + } + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + if (cb) cb(translate); + if (deferred) deferred.resolve(); + return deferred; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + + if (cb) cb(translate); + if (deferred) deferred.resolve(); + }); + + return deferred; + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, cb) { + return init({lng: lng}, cb); + } + + function lng() { + return currentLng; + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } + else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key) return; + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') <= key.length-1) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + parse(ele, k, options); + }); + + } else { + parse(ele, k, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + + function applyReplacement(str, replacementHash, nestedKey) { + if (str.indexOf(o.interpolationPrefix) < 0) return str; + + f.each(replacementHash, function(key, value) { + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nestedKey ? nestedKey + '.' + key : key); + } else { + str = str.replace(new RegExp([o.interpolationPrefixEscaped, nestedKey ? nestedKey + '.' + key : key, o.interpolationSuffixEscaped].join(''), 'g'), value); + } + }); + return str; + } + + function applyReuse(translated, options){ + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.indexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_sans_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + var translated_token = _translate(token_sans_symbols, opts); + translated = translated.replace(token, translated_token); + } + return translated; + } + + function hasContext(options) { + return (options.context && typeof options.context == 'string'); + } + + function needsPlural(options) { + return (options.count !== undefined && typeof options.count != 'string' && options.count !== 1); + } + + function translate(key, options){ + replacementCounter = 0; + return _translate(key, options); + } + + function _translate(key, options){ + options = options || {}; + + if (!resStore) { return notfound; } // no resStore to translate from + + var optionWithoutCount, translated + , notfound = options.defaultValue || key + , lngs = languages; + + if (options.lng) { + lngs = f.toLanguages(options.lng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + ':' + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.count; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey = ns + ':' + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(currentLng, options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + ':' + key; // singular + } + + translated = translate(pluralKey, optionWithoutCount); + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { count: options.count }); // apply replacement for count only + } // else continue translation with original/singular key + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (Object.prototype.toString.apply(value) === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned a object instead of string.'; + f.log(value); + } else { + for (var m in value) { + // apply translation on childs + value[m] = _translate(ns + ':' + key + '.' + m, options); + } + } + } + found = value; + } + } + + if (found === undefined && o.sendMissing) { + if (options.lng) { + sync.postMissing(options.lng, ns, key, notfound, lngs); + } else { + sync.postMissing(o.lng, ns, key, notfound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found !== undefined && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + if (found === undefined) { + notfound = applyReplacement(notfound, options); + notfound = applyReuse(notfound, options); + } + + return (found !== undefined) ? found : notfound; + } + + function detectLanguage() { + var detectedLng; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var parms = query.split('&'); + for (var i=0; i 0) { + var key = parms[i].substring(0,pos); + var val = parms[i].substring(pos+1); + qsParm[key] = val; + } + } + })(); + if (qsParm[o.detectLngQS]) { + detectedLng = qsParm[o.detectLngQS]; + } + } + + // get from cookie + if (!detectedLng && typeof document !== 'undefined' && o.useCookie ) { + var c = f.cookie.read(o.cookieName); + if (c) detectedLng = c; + } + + // get from navigator + if (!detectedLng && typeof navigator !== 'undefined') { + detectedLng = (navigator.language) ? navigator.language : navigator.userLanguage; + } + + return detectedLng; + } + var sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + window.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + cb(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + cb('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback') { + urls.push({lng: o.fallbackLng, url: applyReplacement(o.resPostPath, { lng: o.fallbackLng, ns: ns })}); + } else if (o.sendMissingTo === 'current') { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + resStore[item.lng][ns][key] = defaultValue; + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + } + }; + + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + var pluralExtensions = { + + rules: { + "ach": { + "name": "Acholi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "af": { + "name": "Afrikaans", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ak": { + "name": "Akan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "am": { + "name": "Amharic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "an": { + "name": "Aragonese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ar": { + "name": "Arabic", + "numbers": [ + 0, + 1, + 2, + 3, + 11, + 100 + ], + "plurals": function(n) { return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5); } + }, + "arn": { + "name": "Mapudungun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ast": { + "name": "Asturian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ay": { + "name": "Aymar\u00e1", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "az": { + "name": "Azerbaijani", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "be": { + "name": "Belarusian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "bg": { + "name": "Bulgarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bn": { + "name": "Bengali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bo": { + "name": "Tibetan", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "br": { + "name": "Breton", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "bs": { + "name": "Bosnian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ca": { + "name": "Catalan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "cgg": { + "name": "Chiga", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "cs": { + "name": "Czech", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "csb": { + "name": "Kashubian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "cy": { + "name": "Welsh", + "numbers": [ + 1, + 2, + 3, + 8 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3); } + }, + "da": { + "name": "Danish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "de": { + "name": "German", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "dz": { + "name": "Dzongkha", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "el": { + "name": "Greek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "en": { + "name": "English", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eo": { + "name": "Esperanto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es": { + "name": "Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es_ar": { + "name": "Argentinean Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "et": { + "name": "Estonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eu": { + "name": "Basque", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fa": { + "name": "Persian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "fi": { + "name": "Finnish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fil": { + "name": "Filipino", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fo": { + "name": "Faroese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fr": { + "name": "French", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fur": { + "name": "Friulian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fy": { + "name": "Frisian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ga": { + "name": "Irish", + "numbers": [ + 1, + 2, + 3, + 7, + 11 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;} + }, + "gd": { + "name": "Scottish Gaelic", + "numbers": [ + 1, + 2, + 3, + 20 + ], + "plurals": function(n) { return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3); } + }, + "gl": { + "name": "Galician", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gu": { + "name": "Gujarati", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gun": { + "name": "Gun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ha": { + "name": "Hausa", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "he": { + "name": "Hebrew", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hi": { + "name": "Hindi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hr": { + "name": "Croatian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "hu": { + "name": "Hungarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hy": { + "name": "Armenian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ia": { + "name": "Interlingua", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "id": { + "name": "Indonesian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "is": { + "name": "Icelandic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n%10!=1 || n%100==11); } + }, + "it": { + "name": "Italian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ja": { + "name": "Japanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jbo": { + "name": "Lojban", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jv": { + "name": "Javanese", + "numbers": [ + 0, + 1 + ], + "plurals": function(n) { return Number(n !== 0); } + }, + "ka": { + "name": "Georgian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kk": { + "name": "Kazakh", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "km": { + "name": "Khmer", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kn": { + "name": "Kannada", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ko": { + "name": "Korean", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ku": { + "name": "Kurdish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "kw": { + "name": "Cornish", + "numbers": [ + 1, + 2, + 3, + 4 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3); } + }, + "ky": { + "name": "Kyrgyz", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lb": { + "name": "Letzeburgesch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ln": { + "name": "Lingala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "lo": { + "name": "Lao", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lt": { + "name": "Lithuanian", + "numbers": [ + 1, + 2, + 10 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "lv": { + "name": "Latvian", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2); } + }, + "mai": { + "name": "Maithili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mfe": { + "name": "Mauritian Creole", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mg": { + "name": "Malagasy", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mi": { + "name": "Maori", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mk": { + "name": "Macedonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 || n%10==1 ? 0 : 1); } + }, + "ml": { + "name": "Malayalam", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mn": { + "name": "Mongolian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mnk": { + "name": "Mandinka", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(0 ? 0 : n==1 ? 1 : 2); } + }, + "mr": { + "name": "Marathi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ms": { + "name": "Malay", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "mt": { + "name": "Maltese", + "numbers": [ + 1, + 2, + 11, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3); } + }, + "nah": { + "name": "Nahuatl", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nap": { + "name": "Neapolitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nb": { + "name": "Norwegian Bokmal", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ne": { + "name": "Nepali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nl": { + "name": "Dutch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nn": { + "name": "Norwegian Nynorsk", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "no": { + "name": "Norwegian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nso": { + "name": "Northern Sotho", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "oc": { + "name": "Occitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "or": { + "name": "Oriya", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pa": { + "name": "Punjabi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pap": { + "name": "Papiamento", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pl": { + "name": "Polish", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "pms": { + "name": "Piemontese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ps": { + "name": "Pashto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt": { + "name": "Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt_br": { + "name": "Brazilian Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "rm": { + "name": "Romansh", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ro": { + "name": "Romanian", + "numbers": [ + 1, + 2, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2); } + }, + "ru": { + "name": "Russian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "sah": { + "name": "Yakut", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sco": { + "name": "Scots", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "se": { + "name": "Northern Sami", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "si": { + "name": "Sinhala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sk": { + "name": "Slovak", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "sl": { + "name": "Slovenian", + "numbers": [ + 5, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }, + "so": { + "name": "Somali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "son": { + "name": "Songhay", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sq": { + "name": "Albanian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sr": { + "name": "Serbian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "su": { + "name": "Sundanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sv": { + "name": "Swedish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sw": { + "name": "Swahili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ta": { + "name": "Tamil", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "te": { + "name": "Telugu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tg": { + "name": "Tajik", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "th": { + "name": "Thai", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ti": { + "name": "Tigrinya", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tk": { + "name": "Turkmen", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tr": { + "name": "Turkish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tt": { + "name": "Tatar", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ug": { + "name": "Uyghur", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "uk": { + "name": "Ukrainian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ur": { + "name": "Urdu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "uz": { + "name": "Uzbek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "vi": { + "name": "Vietnamese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "wa": { + "name": "Walloon", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "wo": { + "name": "Wolof", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "yo": { + "name": "Yoruba", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "zh": { + "name": "Chinese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + } + }, + + // for demonstration only sl and ar is added but you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i = ext.plurals(c); + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[0], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + +})(); \ No newline at end of file diff --git a/libs/i18next/release/i18next-1.5.10.zip b/libs/i18next/release/i18next-1.5.10.zip new file mode 100644 index 00000000..0df80c82 Binary files /dev/null and b/libs/i18next/release/i18next-1.5.10.zip differ diff --git a/libs/i18next/release/i18next-1.5.5.zip b/libs/i18next/release/i18next-1.5.5.zip new file mode 100644 index 00000000..7980dc03 Binary files /dev/null and b/libs/i18next/release/i18next-1.5.5.zip differ diff --git a/libs/i18next/release/i18next-1.5.6.js b/libs/i18next/release/i18next-1.5.6.js new file mode 100644 index 00000000..1a78d968 --- /dev/null +++ b/libs/i18next/release/i18next-1.5.6.js @@ -0,0 +1,2272 @@ +// i18next, v1.5.6 +// Copyright (c)2012 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function() { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + var root = this + , $ = root.jQuery + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = []; + + + // Export the i18next object for **CommonJS**. + // If we're not in CommonJS, add `i18n` to the + // global object or to jquery. + if (typeof module !== 'undefined' && module.exports) { + module.exports = i18n; + } else { + if ($) { + $.i18n = $.i18n || i18n; + } + + root.i18n = root.i18n || i18n; + } + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: 'dev', + ns: 'translation', + nsseparator: ':', + keyseparator: '.', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + + setJqueryExt: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + + postProcess: undefined + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = '?' + queryString.join('&'); + url += queryString !== '?' ? queryString : ''; + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + return JSON.parse(data); + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.sendType ? options.sendType.toLowerCase() : 'get'; + + http[methode](options.url, {async: options.async}, function (status, data) { + if (status === 200) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + document.cookie = name+"="+value+expires+"; path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : _ajax, + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + log: function(str) { + if (o.debug) console.log(str); + }, + toLanguages: function(lng) { + var languages = []; + if (lng.indexOf('-') === 2 && lng.length === 5) { + var parts = lng.split('-'); + + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + + if (o.load !== 'unspecific') languages.push(lng); + if (o.load !== 'current') languages.push(lng.substr(0, 2)); + } else { + languages.push(lng); + } + + if (languages.indexOf(o.fallbackLng) === -1 && o.fallbackLng) languages.push(o.fallbackLng); + + return languages; + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + if (!o.lng) o.lng = f.detectLanguage(); + if (o.lng) { + // set cookie with lng set (as detectLanguage will set cookie on need) + f.cookie.create('i18next', o.lng, o.cookieExpirationTime); + } else { + o.lng = o.fallbackLng; + f.cookie.remove('i18next'); + } + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + if (cb) cb(translate); + if (deferred) deferred.resolve(); + return deferred; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + + if (cb) cb(translate); + if (deferred) deferred.resolve(); + }); + + return deferred; + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function setLng(lng, cb) { + return init({lng: lng}, cb); + } + + function lng() { + return currentLng; + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = $.extend({ defaultValue: ele.html() }, options); + ele.html($.t(key, optionsToUse)); + } + else if (attr === 'text') { + optionsToUse = $.extend({ defaultValue: ele.text() }, options); + ele.text($.t(key, optionsToUse)); + } else { + optionsToUse = $.extend({ defaultValue: ele.attr(attr) }, options); + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr('data-i18n'); + if (!key) return; + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') <= key.length-1) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + parse(ele, k, options); + }); + + } else { + parse(ele, k, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[data-i18n]'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey) { + if (str.indexOf(o.interpolationPrefix) < 0) return str; + + f.each(replacementHash, function(key, value) { + if (typeof value === 'object') { + str = applyReplacement(str, value, key); + } else { + str = str.replace(new RegExp([o.interpolationPrefix, nestedKey ? nestedKey + '.' + key : key, o.interpolationSuffix].join(''), 'g'), value); + } + }); + return str; + } + + function applyReuse(translated, options){ + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.indexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_sans_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + var translated_token = _translate(token_sans_symbols, opts); + translated = translated.replace(token, translated_token); + } + return translated; + } + + function hasContext(options) { + return (options.context && typeof options.context == 'string'); + } + + function needsPlural(options) { + return (options.count !== undefined && typeof options.count != 'string' && options.count !== 1); + } + + function translate(key, options){ + replacementCounter = 0; + return _translate(key, options); + } + + function _translate(key, options){ + options = options || {}; + + var optionsSansCount, translated + , notfound = options.defaultValue || key + , lngs = languages; + + if (options.lng) { + lngs = f.toLanguages(options.lng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + if (!resStore) { return notfound; } // no resStore to translate from + + var ns = o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionsSansCount = f.extend({}, options); + delete optionsSansCount.context; + optionsSansCount.defaultValue = o.contextNotFound; + + var contextKey = ns + ':' + key + '_' + options.context; + + translated = translate(contextKey, optionsSansCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options)) { + optionsSansCount = f.extend({}, options); + delete optionsSansCount.count; + optionsSansCount.defaultValue = o.pluralNotFound; + + var pluralKey = ns + ':' + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(currentLng, options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + ':' + key; // singular + } + + translated = translate(pluralKey, optionsSansCount); + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { count: options.count }); // apply replacement for count only + } // else continue translation with original/singular key + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value) { + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (Object.prototype.toString.apply(value) === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned a object instead of string.'; + f.log(value); + } else { + for (var m in value) { + // apply translation on childs + value[m] = _translate(key + '.' + m, options); + } + } + } + found = value; + } + } + + if (!found && o.sendMissing) { + if (options.lng) { + sync.postMissing(options.lng, ns, key, notfound, lngs); + } else { + sync.postMissing(o.lng, ns, key, notfound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + if (!found) { + notfound = applyReplacement(notfound, options); + notfound = applyReuse(notfound, options); + } + + return (found) ? found : notfound; + } + function detectLanguage() { + var detectedLng; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var parms = query.split('&'); + for (var i=0; i 0) { + var key = parms[i].substring(0,pos); + var val = parms[i].substring(pos+1); + qsParm[key] = val; + } + } + })(); + if (qsParm.setLng) { + detectedLng = qsParm.setLng; + } + } + + // get from cookie + if (!detectedLng && typeof document !== 'undefined') { + var c = f.cookie.read('i18next'); + if (c) detectedLng = c; + } + + // get from navigator + if (!detectedLng && typeof navigator !== 'undefined') { + detectedLng = (navigator.language) ? navigator.language : navigator.userLanguage; + } + + return detectedLng; + } + var sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched){ + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + window.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + sync._fetchOne(lngValue, nsValue, options, function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }); + }); + }); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + cb(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + cb('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback') { + urls.push({lng: o.fallbackLng, url: applyReplacement(o.resPostPath, { lng: o.fallbackLng, ns: ns })}); + } else if (o.sendMissingTo === 'current') { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + resStore[item.lng][ns][key] = defaultValue; + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + } + }; + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + var pluralExtensions = { + + rules: { + "ach": { + "name": "Acholi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "af": { + "name": "Afrikaans", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ak": { + "name": "Akan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "am": { + "name": "Amharic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "an": { + "name": "Aragonese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ar": { + "name": "Arabic", + "numbers": [ + 0, + 1, + 2, + 3, + 11, + 100 + ], + "plurals": function(n) { return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5); } + }, + "arn": { + "name": "Mapudungun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ast": { + "name": "Asturian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ay": { + "name": "Aymar\u00e1", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "az": { + "name": "Azerbaijani", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "be": { + "name": "Belarusian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "bg": { + "name": "Bulgarian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bn": { + "name": "Bengali", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bo": { + "name": "Tibetan", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "br": { + "name": "Breton", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "bs": { + "name": "Bosnian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ca": { + "name": "Catalan", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "cgg": { + "name": "Chiga", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "cs": { + "name": "Czech", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "csb": { + "name": "Kashubian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "cy": { + "name": "Welsh", + "numbers": [ + 3, + 1, + 2, + 8 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3); } + }, + "da": { + "name": "Danish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "de": { + "name": "German", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "dz": { + "name": "Dzongkha", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "el": { + "name": "Greek", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "en": { + "name": "English", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eo": { + "name": "Esperanto", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es": { + "name": "Spanish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es_ar": { + "name": "Argentinean Spanish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "et": { + "name": "Estonian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eu": { + "name": "Basque", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fa": { + "name": "Persian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "fi": { + "name": "Finnish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fil": { + "name": "Filipino", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fo": { + "name": "Faroese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fr": { + "name": "French", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fur": { + "name": "Friulian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fy": { + "name": "Frisian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ga": { + "name": "Irish", + "numbers": [ + 3, + 1, + 2, + 7, + 11 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;} + }, + "gd": { + "name": "Scottish Gaelic", + "numbers": [ + 20, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3); } + }, + "gl": { + "name": "Galician", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gu": { + "name": "Gujarati", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gun": { + "name": "Gun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ha": { + "name": "Hausa", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "he": { + "name": "Hebrew", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hi": { + "name": "Hindi", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hr": { + "name": "Croatian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "hu": { + "name": "Hungarian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hy": { + "name": "Armenian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ia": { + "name": "Interlingua", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "id": { + "name": "Indonesian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "is": { + "name": "Icelandic", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n%10!=1 || n%100==11); } + }, + "it": { + "name": "Italian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ja": { + "name": "Japanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jbo": { + "name": "Lojban", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jv": { + "name": "Javanese", + "numbers": [ + 0, + 1 + ], + "plurals": function(n) { return Number(n !== 0); } + }, + "ka": { + "name": "Georgian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kk": { + "name": "Kazakh", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "km": { + "name": "Khmer", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kn": { + "name": "Kannada", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ko": { + "name": "Korean", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ku": { + "name": "Kurdish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "kw": { + "name": "Cornish", + "numbers": [ + 4, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3); } + }, + "ky": { + "name": "Kyrgyz", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lb": { + "name": "Letzeburgesch", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ln": { + "name": "Lingala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "lo": { + "name": "Lao", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lt": { + "name": "Lithuanian", + "numbers": [ + 10, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "lv": { + "name": "Latvian", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2); } + }, + "mai": { + "name": "Maithili", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mfe": { + "name": "Mauritian Creole", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mg": { + "name": "Malagasy", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mi": { + "name": "Maori", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mk": { + "name": "Macedonian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n==1 || n%10==1 ? 0 : 1); } + }, + "ml": { + "name": "Malayalam", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mn": { + "name": "Mongolian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mnk": { + "name": "Mandinka", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(0 ? 0 : n==1 ? 1 : 2); } + }, + "mr": { + "name": "Marathi", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ms": { + "name": "Malay", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "mt": { + "name": "Maltese", + "numbers": [ + 2, + 1, + 11, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3); } + }, + "nah": { + "name": "Nahuatl", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nap": { + "name": "Neapolitan", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nb": { + "name": "Norwegian Bokmal", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ne": { + "name": "Nepali", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nl": { + "name": "Dutch", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nn": { + "name": "Norwegian Nynorsk", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "no": { + "name": "Norwegian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nso": { + "name": "Northern Sotho", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "oc": { + "name": "Occitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "or": { + "name": "Oriya", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pa": { + "name": "Punjabi", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pap": { + "name": "Papiamento", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pl": { + "name": "Polish", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "pms": { + "name": "Piemontese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ps": { + "name": "Pashto", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt": { + "name": "Portuguese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt_br": { + "name": "Brazilian Portuguese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "rm": { + "name": "Romansh", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ro": { + "name": "Romanian", + "numbers": [ + 2, + 1, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2); } + }, + "ru": { + "name": "Russian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "sah": { + "name": "Yakut", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sco": { + "name": "Scots", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "se": { + "name": "Northern Sami", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "si": { + "name": "Sinhala", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sk": { + "name": "Slovak", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "sl": { + "name": "Slovenian", + "numbers": [ + 5, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }, + "so": { + "name": "Somali", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "son": { + "name": "Songhay", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sq": { + "name": "Albanian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sr": { + "name": "Serbian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "su": { + "name": "Sundanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sv": { + "name": "Swedish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sw": { + "name": "Swahili", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ta": { + "name": "Tamil", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "te": { + "name": "Telugu", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tg": { + "name": "Tajik", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "th": { + "name": "Thai", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ti": { + "name": "Tigrinya", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tk": { + "name": "Turkmen", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tr": { + "name": "Turkish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tt": { + "name": "Tatar", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ug": { + "name": "Uyghur", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "uk": { + "name": "Ukrainian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ur": { + "name": "Urdu", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "uz": { + "name": "Uzbek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "vi": { + "name": "Vietnamese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "wa": { + "name": "Walloon", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "wo": { + "name": "Wolof", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "yo": { + "name": "Yoruba", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "zh": { + "name": "Chinese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + } + }, + + // for demonstration only sl and ar is added but you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i = ext.plurals(c); + var number = ext.numbers[i]; + if (ext.numbers.length === 2) { + if (number === 2) { + number = 1; + } else if (number === 1) { + number = -1; + } + } //console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[0], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.t = translate; + i18n.translate = translate; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + +})(); \ No newline at end of file diff --git a/libs/i18next/release/i18next-1.5.6.zip b/libs/i18next/release/i18next-1.5.6.zip new file mode 100644 index 00000000..d72bc4f7 Binary files /dev/null and b/libs/i18next/release/i18next-1.5.6.zip differ diff --git a/libs/i18next/release/i18next-1.5.7.js b/libs/i18next/release/i18next-1.5.7.js new file mode 100644 index 00000000..6a9d6e8d --- /dev/null +++ b/libs/i18next/release/i18next-1.5.7.js @@ -0,0 +1,2274 @@ +// i18next, v1.5.7 +// Copyright (c)2012 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function() { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + var root = this + , $ = root.jQuery + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = []; + + + // Export the i18next object for **CommonJS**. + // If we're not in CommonJS, add `i18n` to the + // global object or to jquery. + if (typeof module !== 'undefined' && module.exports) { + module.exports = i18n; + } else { + if ($) { + $.i18n = $.i18n || i18n; + } + + root.i18n = root.i18n || i18n; + } + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: 'dev', + detectLngQS: 'setLng', + ns: 'translation', + nsseparator: ':', + keyseparator: '.', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + + setJqueryExt: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + + postProcess: undefined + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = '?' + queryString.join('&'); + url += queryString !== '?' ? queryString : ''; + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + return JSON.parse(data); + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.sendType ? options.sendType.toLowerCase() : 'get'; + + http[methode](options.url, {async: options.async}, function (status, data) { + if (status === 200) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + document.cookie = name+"="+value+expires+"; path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : _ajax, + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + log: function(str) { + if (o.debug) console.log(str); + }, + toLanguages: function(lng) { + var languages = []; + if (lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + + if (o.load !== 'unspecific') languages.push(lng); + if (o.load !== 'current') languages.push(parts[0]); + } else { + languages.push(lng); + } + + if (languages.indexOf(o.fallbackLng) === -1 && o.fallbackLng) languages.push(o.fallbackLng); + + return languages; + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + if (!o.lng) o.lng = f.detectLanguage(); + if (o.lng) { + // set cookie with lng set (as detectLanguage will set cookie on need) + f.cookie.create('i18next', o.lng, o.cookieExpirationTime); + } else { + o.lng = o.fallbackLng; + f.cookie.remove('i18next'); + } + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + if (cb) cb(translate); + if (deferred) deferred.resolve(); + return deferred; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + + if (cb) cb(translate); + if (deferred) deferred.resolve(); + }); + + return deferred; + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function setLng(lng, cb) { + return init({lng: lng}, cb); + } + + function lng() { + return currentLng; + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = $.extend({ defaultValue: ele.html() }, options); + ele.html($.t(key, optionsToUse)); + } + else if (attr === 'text') { + optionsToUse = $.extend({ defaultValue: ele.text() }, options); + ele.text($.t(key, optionsToUse)); + } else { + optionsToUse = $.extend({ defaultValue: ele.attr(attr) }, options); + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr('data-i18n'); + if (!key) return; + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') <= key.length-1) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + parse(ele, k, options); + }); + + } else { + parse(ele, k, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[data-i18n]'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey) { + if (str.indexOf(o.interpolationPrefix) < 0) return str; + + f.each(replacementHash, function(key, value) { + if (typeof value === 'object') { + str = applyReplacement(str, value, nestedKey ? nestedKey + '.' + key : key); + } else { + str = str.replace(new RegExp([o.interpolationPrefix, nestedKey ? nestedKey + '.' + key : key, o.interpolationSuffix].join(''), 'g'), value); + } + }); + return str; + } + + function applyReuse(translated, options){ + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.indexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_sans_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + var translated_token = _translate(token_sans_symbols, opts); + translated = translated.replace(token, translated_token); + } + return translated; + } + + function hasContext(options) { + return (options.context && typeof options.context == 'string'); + } + + function needsPlural(options) { + return (options.count !== undefined && typeof options.count != 'string' && options.count !== 1); + } + + function translate(key, options){ + replacementCounter = 0; + return _translate(key, options); + } + + function _translate(key, options){ + options = options || {}; + + var optionsSansCount, translated + , notfound = options.defaultValue || key + , lngs = languages; + + if (options.lng) { + lngs = f.toLanguages(options.lng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + if (!resStore) { return notfound; } // no resStore to translate from + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionsSansCount = f.extend({}, options); + delete optionsSansCount.context; + optionsSansCount.defaultValue = o.contextNotFound; + + var contextKey = ns + ':' + key + '_' + options.context; + + translated = translate(contextKey, optionsSansCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options)) { + optionsSansCount = f.extend({}, options); + delete optionsSansCount.count; + optionsSansCount.defaultValue = o.pluralNotFound; + + var pluralKey = ns + ':' + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(currentLng, options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + ':' + key; // singular + } + + translated = translate(pluralKey, optionsSansCount); + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { count: options.count }); // apply replacement for count only + } // else continue translation with original/singular key + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value) { + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (Object.prototype.toString.apply(value) === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned a object instead of string.'; + f.log(value); + } else { + for (var m in value) { + // apply translation on childs + value[m] = _translate(key + '.' + m, options); + } + } + } + found = value; + } + } + + if (!found && o.sendMissing) { + if (options.lng) { + sync.postMissing(options.lng, ns, key, notfound, lngs); + } else { + sync.postMissing(o.lng, ns, key, notfound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + if (!found) { + notfound = applyReplacement(notfound, options); + notfound = applyReuse(notfound, options); + } + + return (found) ? found : notfound; + } + + function detectLanguage() { + var detectedLng; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var parms = query.split('&'); + for (var i=0; i 0) { + var key = parms[i].substring(0,pos); + var val = parms[i].substring(pos+1); + qsParm[key] = val; + } + } + })(); + if (qsParm[o.detectLngQS]) { + detectedLng = qsParm[o.detectLngQS]; + } + } + + // get from cookie + if (!detectedLng && typeof document !== 'undefined') { + var c = f.cookie.read('i18next'); + if (c) detectedLng = c; + } + + // get from navigator + if (!detectedLng && typeof navigator !== 'undefined') { + detectedLng = (navigator.language) ? navigator.language : navigator.userLanguage; + } + + return detectedLng; + } + var sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched){ + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + window.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + sync._fetchOne(lngValue, nsValue, options, function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }); + }); + }); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + cb(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + cb('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback') { + urls.push({lng: o.fallbackLng, url: applyReplacement(o.resPostPath, { lng: o.fallbackLng, ns: ns })}); + } else if (o.sendMissingTo === 'current') { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + resStore[item.lng][ns][key] = defaultValue; + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + } + }; + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + var pluralExtensions = { + + rules: { + "ach": { + "name": "Acholi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "af": { + "name": "Afrikaans", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ak": { + "name": "Akan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "am": { + "name": "Amharic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "an": { + "name": "Aragonese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ar": { + "name": "Arabic", + "numbers": [ + 0, + 1, + 2, + 3, + 11, + 100 + ], + "plurals": function(n) { return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5); } + }, + "arn": { + "name": "Mapudungun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ast": { + "name": "Asturian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ay": { + "name": "Aymar\u00e1", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "az": { + "name": "Azerbaijani", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "be": { + "name": "Belarusian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "bg": { + "name": "Bulgarian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bn": { + "name": "Bengali", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bo": { + "name": "Tibetan", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "br": { + "name": "Breton", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "bs": { + "name": "Bosnian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ca": { + "name": "Catalan", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "cgg": { + "name": "Chiga", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "cs": { + "name": "Czech", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "csb": { + "name": "Kashubian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "cy": { + "name": "Welsh", + "numbers": [ + 3, + 1, + 2, + 8 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3); } + }, + "da": { + "name": "Danish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "de": { + "name": "German", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "dz": { + "name": "Dzongkha", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "el": { + "name": "Greek", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "en": { + "name": "English", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eo": { + "name": "Esperanto", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es": { + "name": "Spanish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es_ar": { + "name": "Argentinean Spanish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "et": { + "name": "Estonian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eu": { + "name": "Basque", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fa": { + "name": "Persian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "fi": { + "name": "Finnish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fil": { + "name": "Filipino", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fo": { + "name": "Faroese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fr": { + "name": "French", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fur": { + "name": "Friulian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fy": { + "name": "Frisian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ga": { + "name": "Irish", + "numbers": [ + 3, + 1, + 2, + 7, + 11 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;} + }, + "gd": { + "name": "Scottish Gaelic", + "numbers": [ + 20, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3); } + }, + "gl": { + "name": "Galician", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gu": { + "name": "Gujarati", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gun": { + "name": "Gun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ha": { + "name": "Hausa", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "he": { + "name": "Hebrew", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hi": { + "name": "Hindi", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hr": { + "name": "Croatian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "hu": { + "name": "Hungarian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hy": { + "name": "Armenian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ia": { + "name": "Interlingua", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "id": { + "name": "Indonesian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "is": { + "name": "Icelandic", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n%10!=1 || n%100==11); } + }, + "it": { + "name": "Italian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ja": { + "name": "Japanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jbo": { + "name": "Lojban", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jv": { + "name": "Javanese", + "numbers": [ + 0, + 1 + ], + "plurals": function(n) { return Number(n !== 0); } + }, + "ka": { + "name": "Georgian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kk": { + "name": "Kazakh", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "km": { + "name": "Khmer", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kn": { + "name": "Kannada", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ko": { + "name": "Korean", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ku": { + "name": "Kurdish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "kw": { + "name": "Cornish", + "numbers": [ + 4, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3); } + }, + "ky": { + "name": "Kyrgyz", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lb": { + "name": "Letzeburgesch", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ln": { + "name": "Lingala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "lo": { + "name": "Lao", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lt": { + "name": "Lithuanian", + "numbers": [ + 10, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "lv": { + "name": "Latvian", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2); } + }, + "mai": { + "name": "Maithili", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mfe": { + "name": "Mauritian Creole", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mg": { + "name": "Malagasy", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mi": { + "name": "Maori", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mk": { + "name": "Macedonian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n==1 || n%10==1 ? 0 : 1); } + }, + "ml": { + "name": "Malayalam", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mn": { + "name": "Mongolian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mnk": { + "name": "Mandinka", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(0 ? 0 : n==1 ? 1 : 2); } + }, + "mr": { + "name": "Marathi", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ms": { + "name": "Malay", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "mt": { + "name": "Maltese", + "numbers": [ + 2, + 1, + 11, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3); } + }, + "nah": { + "name": "Nahuatl", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nap": { + "name": "Neapolitan", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nb": { + "name": "Norwegian Bokmal", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ne": { + "name": "Nepali", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nl": { + "name": "Dutch", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nn": { + "name": "Norwegian Nynorsk", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "no": { + "name": "Norwegian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nso": { + "name": "Northern Sotho", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "oc": { + "name": "Occitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "or": { + "name": "Oriya", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pa": { + "name": "Punjabi", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pap": { + "name": "Papiamento", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pl": { + "name": "Polish", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "pms": { + "name": "Piemontese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ps": { + "name": "Pashto", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt": { + "name": "Portuguese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt_br": { + "name": "Brazilian Portuguese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "rm": { + "name": "Romansh", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ro": { + "name": "Romanian", + "numbers": [ + 2, + 1, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2); } + }, + "ru": { + "name": "Russian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "sah": { + "name": "Yakut", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sco": { + "name": "Scots", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "se": { + "name": "Northern Sami", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "si": { + "name": "Sinhala", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sk": { + "name": "Slovak", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "sl": { + "name": "Slovenian", + "numbers": [ + 5, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }, + "so": { + "name": "Somali", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "son": { + "name": "Songhay", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sq": { + "name": "Albanian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sr": { + "name": "Serbian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "su": { + "name": "Sundanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sv": { + "name": "Swedish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sw": { + "name": "Swahili", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ta": { + "name": "Tamil", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "te": { + "name": "Telugu", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tg": { + "name": "Tajik", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "th": { + "name": "Thai", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ti": { + "name": "Tigrinya", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tk": { + "name": "Turkmen", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tr": { + "name": "Turkish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tt": { + "name": "Tatar", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ug": { + "name": "Uyghur", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "uk": { + "name": "Ukrainian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ur": { + "name": "Urdu", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "uz": { + "name": "Uzbek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "vi": { + "name": "Vietnamese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "wa": { + "name": "Walloon", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "wo": { + "name": "Wolof", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "yo": { + "name": "Yoruba", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "zh": { + "name": "Chinese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + } + }, + + // for demonstration only sl and ar is added but you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i = ext.plurals(c); + var number = ext.numbers[i]; + if (ext.numbers.length === 2) { + if (number === 2) { + number = 1; + } else if (number === 1) { + number = -1; + } + } //console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[0], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.t = translate; + i18n.translate = translate; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + +})(); \ No newline at end of file diff --git a/libs/i18next/release/i18next-1.5.7.zip b/libs/i18next/release/i18next-1.5.7.zip new file mode 100644 index 00000000..1fef3b29 Binary files /dev/null and b/libs/i18next/release/i18next-1.5.7.zip differ diff --git a/libs/i18next/release/i18next-1.5.8.js b/libs/i18next/release/i18next-1.5.8.js new file mode 100644 index 00000000..f7c0b9de --- /dev/null +++ b/libs/i18next/release/i18next-1.5.8.js @@ -0,0 +1,2286 @@ +// i18next, v1.5.8 +// Copyright (c)2012 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function() { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + var root = this + , $ = root.jQuery + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = []; + + + // Export the i18next object for **CommonJS**. + // If we're not in CommonJS, add `i18n` to the + // global object or to jquery. + if (typeof module !== 'undefined' && module.exports) { + module.exports = i18n; + } else { + if ($) { + $.i18n = $.i18n || i18n; + } + + root.i18n = root.i18n || i18n; + } + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: 'dev', + detectLngQS: 'setLng', + ns: 'translation', + nsseparator: ':', + keyseparator: '.', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + + setJqueryExt: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + + postProcess: undefined + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = '?' + queryString.join('&'); + url += queryString !== '?' ? queryString : ''; + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + return JSON.parse(data); + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, {async: options.async}, function (status, data) { + if (status === 200) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + document.cookie = name+"="+value+expires+"; path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : _ajax, + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + log: function(str) { + if (o.debug) console.log(str); + }, + toLanguages: function(lng) { + var languages = []; + if (lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + + if (o.load !== 'unspecific') languages.push(lng); + if (o.load !== 'current') languages.push(parts[0]); + } else { + languages.push(lng); + } + + if (languages.indexOf(o.fallbackLng) === -1 && o.fallbackLng) languages.push(o.fallbackLng); + + return languages; + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + if (!o.lng) o.lng = f.detectLanguage(); + if (o.lng) { + // set cookie with lng set (as detectLanguage will set cookie on need) + if (o.useCookie) f.cookie.create('i18next', o.lng, o.cookieExpirationTime); + } else { + o.lng = o.fallbackLng; + if (o.useCookie) f.cookie.remove('i18next'); + } + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + if (cb) cb(translate); + if (deferred) deferred.resolve(); + return deferred; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + + if (cb) cb(translate); + if (deferred) deferred.resolve(); + }); + + return deferred; + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function setLng(lng, cb) { + return init({lng: lng}, cb); + } + + function lng() { + return currentLng; + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = $.extend({ defaultValue: ele.html() }, options); + ele.html($.t(key, optionsToUse)); + } + else if (attr === 'text') { + optionsToUse = $.extend({ defaultValue: ele.text() }, options); + ele.text($.t(key, optionsToUse)); + } else { + optionsToUse = $.extend({ defaultValue: ele.attr(attr) }, options); + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr('data-i18n'); + if (!key) return; + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') <= key.length-1) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + parse(ele, k, options); + }); + + } else { + parse(ele, k, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[data-i18n]'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey) { + if (str.indexOf(o.interpolationPrefix) < 0) return str; + + f.each(replacementHash, function(key, value) { + if (typeof value === 'object') { + str = applyReplacement(str, value, nestedKey ? nestedKey + '.' + key : key); + } else { + str = str.replace(new RegExp([o.interpolationPrefix, nestedKey ? nestedKey + '.' + key : key, o.interpolationSuffix].join(''), 'g'), value); + } + }); + return str; + } + + function applyReuse(translated, options){ + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.indexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_sans_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + var translated_token = _translate(token_sans_symbols, opts); + translated = translated.replace(token, translated_token); + } + return translated; + } + + function hasContext(options) { + return (options.context && typeof options.context == 'string'); + } + + function needsPlural(options) { + return (options.count !== undefined && typeof options.count != 'string' && options.count !== 1); + } + + function translate(key, options){ + replacementCounter = 0; + return _translate(key, options); + } + + function _translate(key, options){ + options = options || {}; + + var optionWithoutCount, translated + , notfound = options.defaultValue || key + , lngs = languages; + + if (options.lng) { + lngs = f.toLanguages(options.lng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + if (!resStore) { return notfound; } // no resStore to translate from + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + ':' + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.count; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey = ns + ':' + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(currentLng, options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + ':' + key; // singular + } + + translated = translate(pluralKey, optionWithoutCount); + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { count: options.count }); // apply replacement for count only + } // else continue translation with original/singular key + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (Object.prototype.toString.apply(value) === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned a object instead of string.'; + f.log(value); + } else { + for (var m in value) { + // apply translation on childs + value[m] = _translate(ns + ':' + key + '.' + m, options); + } + } + } + found = value; + } + } + + if (found === undefined && o.sendMissing) { + if (options.lng) { + sync.postMissing(options.lng, ns, key, notfound, lngs); + } else { + sync.postMissing(o.lng, ns, key, notfound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found !== undefined && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + if (found === undefined) { + notfound = applyReplacement(notfound, options); + notfound = applyReuse(notfound, options); + } + + return (found !== undefined) ? found : notfound; + } + + function detectLanguage() { + var detectedLng; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var parms = query.split('&'); + for (var i=0; i 0) { + var key = parms[i].substring(0,pos); + var val = parms[i].substring(pos+1); + qsParm[key] = val; + } + } + })(); + if (qsParm[o.detectLngQS]) { + detectedLng = qsParm[o.detectLngQS]; + } + } + + // get from cookie + if (!detectedLng && typeof document !== 'undefined' && o.useCookie ) { + var c = f.cookie.read('i18next'); + if (c) detectedLng = c; + } + + // get from navigator + if (!detectedLng && typeof navigator !== 'undefined') { + detectedLng = (navigator.language) ? navigator.language : navigator.userLanguage; + } + + return detectedLng; + } + var sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched){ + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + window.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + sync._fetchOne(lngValue, nsValue, options, function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }); + }); + }); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + cb(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + cb('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback') { + urls.push({lng: o.fallbackLng, url: applyReplacement(o.resPostPath, { lng: o.fallbackLng, ns: ns })}); + } else if (o.sendMissingTo === 'current') { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + resStore[item.lng][ns][key] = defaultValue; + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + } + }; + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + var pluralExtensions = { + + rules: { + "ach": { + "name": "Acholi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "af": { + "name": "Afrikaans", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ak": { + "name": "Akan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "am": { + "name": "Amharic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "an": { + "name": "Aragonese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ar": { + "name": "Arabic", + "numbers": [ + 0, + 1, + 2, + 3, + 11, + 100 + ], + "plurals": function(n) { return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5); } + }, + "arn": { + "name": "Mapudungun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ast": { + "name": "Asturian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ay": { + "name": "Aymar\u00e1", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "az": { + "name": "Azerbaijani", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "be": { + "name": "Belarusian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "bg": { + "name": "Bulgarian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bn": { + "name": "Bengali", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bo": { + "name": "Tibetan", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "br": { + "name": "Breton", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "bs": { + "name": "Bosnian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ca": { + "name": "Catalan", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "cgg": { + "name": "Chiga", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "cs": { + "name": "Czech", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "csb": { + "name": "Kashubian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "cy": { + "name": "Welsh", + "numbers": [ + 3, + 1, + 2, + 8 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3); } + }, + "da": { + "name": "Danish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "de": { + "name": "German", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "dz": { + "name": "Dzongkha", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "el": { + "name": "Greek", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "en": { + "name": "English", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eo": { + "name": "Esperanto", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es": { + "name": "Spanish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es_ar": { + "name": "Argentinean Spanish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "et": { + "name": "Estonian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eu": { + "name": "Basque", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fa": { + "name": "Persian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "fi": { + "name": "Finnish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fil": { + "name": "Filipino", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fo": { + "name": "Faroese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fr": { + "name": "French", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fur": { + "name": "Friulian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fy": { + "name": "Frisian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ga": { + "name": "Irish", + "numbers": [ + 3, + 1, + 2, + 7, + 11 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;} + }, + "gd": { + "name": "Scottish Gaelic", + "numbers": [ + 20, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3); } + }, + "gl": { + "name": "Galician", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gu": { + "name": "Gujarati", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gun": { + "name": "Gun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ha": { + "name": "Hausa", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "he": { + "name": "Hebrew", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hi": { + "name": "Hindi", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hr": { + "name": "Croatian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "hu": { + "name": "Hungarian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hy": { + "name": "Armenian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ia": { + "name": "Interlingua", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "id": { + "name": "Indonesian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "is": { + "name": "Icelandic", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n%10!=1 || n%100==11); } + }, + "it": { + "name": "Italian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ja": { + "name": "Japanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jbo": { + "name": "Lojban", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jv": { + "name": "Javanese", + "numbers": [ + 0, + 1 + ], + "plurals": function(n) { return Number(n !== 0); } + }, + "ka": { + "name": "Georgian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kk": { + "name": "Kazakh", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "km": { + "name": "Khmer", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kn": { + "name": "Kannada", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ko": { + "name": "Korean", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ku": { + "name": "Kurdish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "kw": { + "name": "Cornish", + "numbers": [ + 4, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3); } + }, + "ky": { + "name": "Kyrgyz", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lb": { + "name": "Letzeburgesch", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ln": { + "name": "Lingala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "lo": { + "name": "Lao", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lt": { + "name": "Lithuanian", + "numbers": [ + 10, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "lv": { + "name": "Latvian", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2); } + }, + "mai": { + "name": "Maithili", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mfe": { + "name": "Mauritian Creole", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mg": { + "name": "Malagasy", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mi": { + "name": "Maori", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mk": { + "name": "Macedonian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n==1 || n%10==1 ? 0 : 1); } + }, + "ml": { + "name": "Malayalam", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mn": { + "name": "Mongolian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mnk": { + "name": "Mandinka", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(0 ? 0 : n==1 ? 1 : 2); } + }, + "mr": { + "name": "Marathi", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ms": { + "name": "Malay", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "mt": { + "name": "Maltese", + "numbers": [ + 2, + 1, + 11, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3); } + }, + "nah": { + "name": "Nahuatl", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nap": { + "name": "Neapolitan", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nb": { + "name": "Norwegian Bokmal", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ne": { + "name": "Nepali", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nl": { + "name": "Dutch", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nn": { + "name": "Norwegian Nynorsk", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "no": { + "name": "Norwegian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nso": { + "name": "Northern Sotho", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "oc": { + "name": "Occitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "or": { + "name": "Oriya", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pa": { + "name": "Punjabi", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pap": { + "name": "Papiamento", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pl": { + "name": "Polish", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "pms": { + "name": "Piemontese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ps": { + "name": "Pashto", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt": { + "name": "Portuguese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt_br": { + "name": "Brazilian Portuguese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "rm": { + "name": "Romansh", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ro": { + "name": "Romanian", + "numbers": [ + 2, + 1, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2); } + }, + "ru": { + "name": "Russian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "sah": { + "name": "Yakut", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sco": { + "name": "Scots", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "se": { + "name": "Northern Sami", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "si": { + "name": "Sinhala", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sk": { + "name": "Slovak", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "sl": { + "name": "Slovenian", + "numbers": [ + 5, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }, + "so": { + "name": "Somali", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "son": { + "name": "Songhay", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sq": { + "name": "Albanian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sr": { + "name": "Serbian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "su": { + "name": "Sundanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sv": { + "name": "Swedish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sw": { + "name": "Swahili", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ta": { + "name": "Tamil", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "te": { + "name": "Telugu", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tg": { + "name": "Tajik", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "th": { + "name": "Thai", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ti": { + "name": "Tigrinya", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tk": { + "name": "Turkmen", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tr": { + "name": "Turkish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tt": { + "name": "Tatar", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ug": { + "name": "Uyghur", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "uk": { + "name": "Ukrainian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ur": { + "name": "Urdu", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "uz": { + "name": "Uzbek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "vi": { + "name": "Vietnamese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "wa": { + "name": "Walloon", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "wo": { + "name": "Wolof", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "yo": { + "name": "Yoruba", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "zh": { + "name": "Chinese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + } + }, + + // for demonstration only sl and ar is added but you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i = ext.plurals(c); + var number = ext.numbers[i]; + if (ext.numbers.length === 2) { + // germanic like en + if (ext.numbers[0] === 2) { + if (number === 2) { + number = 1; // singular + } else if (number === 1) { + number = -1; // regular plural + } + } + // romanic like fr + else if (ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + } + } //console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[0], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.t = translate; + i18n.translate = translate; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + +})(); \ No newline at end of file diff --git a/libs/i18next/release/i18next-1.5.8.zip b/libs/i18next/release/i18next-1.5.8.zip new file mode 100644 index 00000000..072b54f7 Binary files /dev/null and b/libs/i18next/release/i18next-1.5.8.zip differ diff --git a/libs/i18next/release/i18next-1.5.9.js b/libs/i18next/release/i18next-1.5.9.js new file mode 100644 index 00000000..db5418a2 --- /dev/null +++ b/libs/i18next/release/i18next-1.5.9.js @@ -0,0 +1,2361 @@ +// i18next, v1.5.9 +// Copyright (c)2012 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function() { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + var root = this + , $ = root.jQuery + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = []; + + + // Export the i18next object for **CommonJS**. + // If we're not in CommonJS, add `i18n` to the + // global object or to jquery. + if (typeof module !== 'undefined' && module.exports) { + module.exports = i18n; + } else { + if ($) { + $.i18n = $.i18n || i18n; + } + + root.i18n = root.i18n || i18n; + } + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: 'dev', + detectLngQS: 'setLng', + ns: 'translation', + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + + postProcess: undefined + }; + + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = '?' + queryString.join('&'); + url += queryString !== '?' ? queryString : ''; + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + return JSON.parse(data); + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, {async: options.async}, function (status, data) { + if (status === 200) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + document.cookie = name+"="+value+expires+"; path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : _ajax, + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + toLanguages: function(lng) { + var languages = []; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + + if (o.load !== 'unspecific') languages.push(lng); + if (o.load !== 'current') languages.push(parts[0]); + } else { + languages.push(lng); + } + + if (languages.indexOf(o.fallbackLng) === -1 && o.fallbackLng) languages.push(o.fallbackLng); + + return languages; + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + if (!o.lng) o.lng = f.detectLanguage(); + if (o.lng) { + // set cookie with lng set (as detectLanguage will set cookie on need) + if (o.useCookie) f.cookie.create(o.cookieName, o.lng, o.cookieExpirationTime); + } else { + o.lng = o.fallbackLng; + if (o.useCookie) f.cookie.remove(o.cookieName); + } + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + if (cb) cb(translate); + if (deferred) deferred.resolve(); + return deferred; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + + if (cb) cb(translate); + if (deferred) deferred.resolve(); + }); + + return deferred; + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, cb) { + return init({lng: lng}, cb); + } + + function lng() { + return currentLng; + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } + else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key) return; + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') <= key.length-1) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + parse(ele, k, options); + }); + + } else { + parse(ele, k, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + + function applyReplacement(str, replacementHash, nestedKey) { + if (str.indexOf(o.interpolationPrefix) < 0) return str; + + f.each(replacementHash, function(key, value) { + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nestedKey ? nestedKey + '.' + key : key); + } else { + str = str.replace(new RegExp([o.interpolationPrefix, nestedKey ? nestedKey + '.' + key : key, o.interpolationSuffix].join(''), 'g'), value); + } + }); + return str; + } + + function applyReuse(translated, options){ + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.indexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_sans_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + var translated_token = _translate(token_sans_symbols, opts); + translated = translated.replace(token, translated_token); + } + return translated; + } + + function hasContext(options) { + return (options.context && typeof options.context == 'string'); + } + + function needsPlural(options) { + return (options.count !== undefined && typeof options.count != 'string' && options.count !== 1); + } + + function translate(key, options){ + replacementCounter = 0; + return _translate(key, options); + } + + function _translate(key, options){ + options = options || {}; + + if (!resStore) { return notfound; } // no resStore to translate from + + var optionWithoutCount, translated + , notfound = options.defaultValue || key + , lngs = languages; + + if (options.lng) { + lngs = f.toLanguages(options.lng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + ':' + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.count; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey = ns + ':' + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(currentLng, options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + ':' + key; // singular + } + + translated = translate(pluralKey, optionWithoutCount); + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { count: options.count }); // apply replacement for count only + } // else continue translation with original/singular key + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (Object.prototype.toString.apply(value) === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned a object instead of string.'; + f.log(value); + } else { + for (var m in value) { + // apply translation on childs + value[m] = _translate(ns + ':' + key + '.' + m, options); + } + } + } + found = value; + } + } + + if (found === undefined && o.sendMissing) { + if (options.lng) { + sync.postMissing(options.lng, ns, key, notfound, lngs); + } else { + sync.postMissing(o.lng, ns, key, notfound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found !== undefined && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + if (found === undefined) { + notfound = applyReplacement(notfound, options); + notfound = applyReuse(notfound, options); + } + + return (found !== undefined) ? found : notfound; + } + + function detectLanguage() { + var detectedLng; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var parms = query.split('&'); + for (var i=0; i 0) { + var key = parms[i].substring(0,pos); + var val = parms[i].substring(pos+1); + qsParm[key] = val; + } + } + })(); + if (qsParm[o.detectLngQS]) { + detectedLng = qsParm[o.detectLngQS]; + } + } + + // get from cookie + if (!detectedLng && typeof document !== 'undefined' && o.useCookie ) { + var c = f.cookie.read(o.cookieName); + if (c) detectedLng = c; + } + + // get from navigator + if (!detectedLng && typeof navigator !== 'undefined') { + detectedLng = (navigator.language) ? navigator.language : navigator.userLanguage; + } + + return detectedLng; + } + var sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + window.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + sync._fetchOne(lngValue, nsValue, options, function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }); + }); + }); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + cb(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + cb('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback') { + urls.push({lng: o.fallbackLng, url: applyReplacement(o.resPostPath, { lng: o.fallbackLng, ns: ns })}); + } else if (o.sendMissingTo === 'current') { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + resStore[item.lng][ns][key] = defaultValue; + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + } + }; + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + var pluralExtensions = { + + rules: { + "ach": { + "name": "Acholi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "af": { + "name": "Afrikaans", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ak": { + "name": "Akan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "am": { + "name": "Amharic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "an": { + "name": "Aragonese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ar": { + "name": "Arabic", + "numbers": [ + 0, + 1, + 2, + 3, + 11, + 100 + ], + "plurals": function(n) { return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5); } + }, + "arn": { + "name": "Mapudungun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ast": { + "name": "Asturian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ay": { + "name": "Aymar\u00e1", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "az": { + "name": "Azerbaijani", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "be": { + "name": "Belarusian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "bg": { + "name": "Bulgarian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bn": { + "name": "Bengali", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bo": { + "name": "Tibetan", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "br": { + "name": "Breton", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "bs": { + "name": "Bosnian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ca": { + "name": "Catalan", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "cgg": { + "name": "Chiga", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "cs": { + "name": "Czech", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "csb": { + "name": "Kashubian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "cy": { + "name": "Welsh", + "numbers": [ + 3, + 1, + 2, + 8 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3); } + }, + "da": { + "name": "Danish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "de": { + "name": "German", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "dz": { + "name": "Dzongkha", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "el": { + "name": "Greek", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "en": { + "name": "English", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eo": { + "name": "Esperanto", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es": { + "name": "Spanish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es_ar": { + "name": "Argentinean Spanish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "et": { + "name": "Estonian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eu": { + "name": "Basque", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fa": { + "name": "Persian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "fi": { + "name": "Finnish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fil": { + "name": "Filipino", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fo": { + "name": "Faroese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fr": { + "name": "French", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fur": { + "name": "Friulian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fy": { + "name": "Frisian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ga": { + "name": "Irish", + "numbers": [ + 3, + 1, + 2, + 7, + 11 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;} + }, + "gd": { + "name": "Scottish Gaelic", + "numbers": [ + 20, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3); } + }, + "gl": { + "name": "Galician", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gu": { + "name": "Gujarati", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gun": { + "name": "Gun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ha": { + "name": "Hausa", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "he": { + "name": "Hebrew", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hi": { + "name": "Hindi", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hr": { + "name": "Croatian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "hu": { + "name": "Hungarian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hy": { + "name": "Armenian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ia": { + "name": "Interlingua", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "id": { + "name": "Indonesian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "is": { + "name": "Icelandic", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n%10!=1 || n%100==11); } + }, + "it": { + "name": "Italian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ja": { + "name": "Japanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jbo": { + "name": "Lojban", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jv": { + "name": "Javanese", + "numbers": [ + 0, + 1 + ], + "plurals": function(n) { return Number(n !== 0); } + }, + "ka": { + "name": "Georgian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kk": { + "name": "Kazakh", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "km": { + "name": "Khmer", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kn": { + "name": "Kannada", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ko": { + "name": "Korean", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ku": { + "name": "Kurdish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "kw": { + "name": "Cornish", + "numbers": [ + 4, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3); } + }, + "ky": { + "name": "Kyrgyz", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lb": { + "name": "Letzeburgesch", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ln": { + "name": "Lingala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "lo": { + "name": "Lao", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lt": { + "name": "Lithuanian", + "numbers": [ + 10, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "lv": { + "name": "Latvian", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2); } + }, + "mai": { + "name": "Maithili", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mfe": { + "name": "Mauritian Creole", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mg": { + "name": "Malagasy", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mi": { + "name": "Maori", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mk": { + "name": "Macedonian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n==1 || n%10==1 ? 0 : 1); } + }, + "ml": { + "name": "Malayalam", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mn": { + "name": "Mongolian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mnk": { + "name": "Mandinka", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(0 ? 0 : n==1 ? 1 : 2); } + }, + "mr": { + "name": "Marathi", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ms": { + "name": "Malay", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "mt": { + "name": "Maltese", + "numbers": [ + 2, + 1, + 11, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3); } + }, + "nah": { + "name": "Nahuatl", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nap": { + "name": "Neapolitan", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nb": { + "name": "Norwegian Bokmal", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ne": { + "name": "Nepali", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nl": { + "name": "Dutch", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nn": { + "name": "Norwegian Nynorsk", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "no": { + "name": "Norwegian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nso": { + "name": "Northern Sotho", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "oc": { + "name": "Occitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "or": { + "name": "Oriya", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pa": { + "name": "Punjabi", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pap": { + "name": "Papiamento", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pl": { + "name": "Polish", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "pms": { + "name": "Piemontese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ps": { + "name": "Pashto", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt": { + "name": "Portuguese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt_br": { + "name": "Brazilian Portuguese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "rm": { + "name": "Romansh", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ro": { + "name": "Romanian", + "numbers": [ + 2, + 1, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2); } + }, + "ru": { + "name": "Russian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "sah": { + "name": "Yakut", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sco": { + "name": "Scots", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "se": { + "name": "Northern Sami", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "si": { + "name": "Sinhala", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sk": { + "name": "Slovak", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "sl": { + "name": "Slovenian", + "numbers": [ + 5, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }, + "so": { + "name": "Somali", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "son": { + "name": "Songhay", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sq": { + "name": "Albanian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sr": { + "name": "Serbian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "su": { + "name": "Sundanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sv": { + "name": "Swedish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sw": { + "name": "Swahili", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ta": { + "name": "Tamil", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "te": { + "name": "Telugu", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tg": { + "name": "Tajik", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "th": { + "name": "Thai", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ti": { + "name": "Tigrinya", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tk": { + "name": "Turkmen", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tr": { + "name": "Turkish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tt": { + "name": "Tatar", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ug": { + "name": "Uyghur", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "uk": { + "name": "Ukrainian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ur": { + "name": "Urdu", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "uz": { + "name": "Uzbek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "vi": { + "name": "Vietnamese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "wa": { + "name": "Walloon", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "wo": { + "name": "Wolof", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "yo": { + "name": "Yoruba", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "zh": { + "name": "Chinese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + } + }, + + // for demonstration only sl and ar is added but you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i = ext.plurals(c); + var number = ext.numbers[i]; + if (ext.numbers.length === 2) { + // germanic like en + if (ext.numbers[0] === 2) { + if (number === 2) { + number = 1; // singular + } else if (number === 1) { + number = -1; // regular plural + } + } + // romanic like fr + else if (ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + } + } //console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[0], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + +})(); \ No newline at end of file diff --git a/libs/i18next/release/i18next-1.5.9.zip b/libs/i18next/release/i18next-1.5.9.zip new file mode 100644 index 00000000..11ec702e Binary files /dev/null and b/libs/i18next/release/i18next-1.5.9.zip differ diff --git a/libs/i18next/release/i18next-1.6.0.js b/libs/i18next/release/i18next-1.6.0.js new file mode 100644 index 00000000..39db96a7 --- /dev/null +++ b/libs/i18next/release/i18next-1.6.0.js @@ -0,0 +1,2436 @@ +// i18next, v1.6.0 +// Copyright (c)2013 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function() { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + var root = this + , $ = root.jQuery + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = []; + + + // Export the i18next object for **CommonJS**. + // If we're not in CommonJS, add `i18n` to the + // global object or to jquery. + if (typeof module !== 'undefined' && module.exports) { + module.exports = i18n; + } else { + if ($) { + $.i18n = $.i18n || i18n; + } + + root.i18n = root.i18n || i18n; + } + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: 'dev', + detectLngQS: 'setLng', + ns: 'translation', + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + + postProcess: undefined + }; + + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + return JSON.parse(data); + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + if (status === 200) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + document.cookie = name+"="+value+expires+"; path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : _ajax, + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + toLanguages: function(lng) { + var languages = []; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + + if (o.load !== 'unspecific') languages.push(lng); + if (o.load !== 'current') languages.push(parts[0]); + } else { + languages.push(lng); + } + + if (languages.indexOf(o.fallbackLng) === -1 && o.fallbackLng) languages.push(o.fallbackLng); + + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + if (o.lng) { + // set cookie with lng set (as detectLanguage will set cookie on need) + if (o.useCookie) f.cookie.create(o.cookieName, o.lng, o.cookieExpirationTime); + } else { + o.lng = o.fallbackLng; + if (o.useCookie) f.cookie.remove(o.cookieName); + } + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + if (cb) cb(translate); + if (deferred) deferred.resolve(); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + + if (cb) cb(translate); + if (deferred) deferred.resolve(); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + f.extend(resStore[lng][ns], resources); + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, cb) { + return init({lng: lng}, cb); + } + + function lng() { + return currentLng; + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } + else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') <= key.length-1) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + parse(target, k, options); + }); + + } else { + parse(target, k, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + + function applyReplacement(str, replacementHash, nestedKey, options) { + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped; + + f.each(replacementHash, function(key, value) { + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nestedKey ? nestedKey + o.keyseparator + key : key, options); + } else { + str = str.replace(new RegExp([prefix, nestedKey ? nestedKey + o.keyseparator + key : key, suffix].join(''), 'g'), value); + } + }); + return str; + } + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.indexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, translated_token); + } + return translated; + } + + function hasContext(options) { + return (options.context && typeof options.context == 'string'); + } + + function needsPlural(options) { + return (options.count !== undefined && typeof options.count != 'string' && options.count !== 1); + } + + function translate(key, options){ + replacementCounter = 0; + return _translate(key, options); + } + + function _translate(key, options){ + options = options || {}; + + if (!resStore) { return notfound; } // no resStore to translate from + + var optionWithoutCount, translated + , notfound = options.defaultValue || key + , lngs = languages; + + if (options.lng) { + lngs = f.toLanguages(options.lng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.count; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(currentLng, options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + + translated = translate(pluralKey, optionWithoutCount); + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { count: options.count }); // apply replacement for count only + } // else continue translation with original/singular key + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (Object.prototype.toString.apply(value) === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned a object instead of string.'; + f.log(value); + } else { + var copy = {}; // apply child translation on a copy + for (var m in value) { + // apply translation on childs + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + } + value = copy; + } + } + found = value; + } + } + + if (found === undefined && o.fallbackToDefaultNS) { + found = _translate(key, options); + } + + if (found === undefined && o.sendMissing) { + if (options.lng) { + sync.postMissing(lngs[0], ns, key, notfound, lngs); + } else { + sync.postMissing(o.lng, ns, key, notfound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found !== undefined && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + if (found === undefined) { + notfound = applyReplacement(notfound, options); + notfound = applyReuse(notfound, options); + } + + return (found !== undefined) ? found : notfound; + } + + function detectLanguage() { + var detectedLng; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var parms = query.split('&'); + for (var i=0; i 0) { + var key = parms[i].substring(0,pos); + var val = parms[i].substring(pos+1); + qsParm[key] = val; + } + } + })(); + if (qsParm[o.detectLngQS]) { + detectedLng = qsParm[o.detectLngQS]; + } + } + + // get from cookie + if (!detectedLng && typeof document !== 'undefined' && o.useCookie ) { + var c = f.cookie.read(o.cookieName); + if (c) detectedLng = c; + } + + // get from navigator + if (!detectedLng && typeof navigator !== 'undefined') { + detectedLng = (navigator.language) ? navigator.language : navigator.userLanguage; + } + + return detectedLng; + } + var sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + window.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + cb(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + cb('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback') { + urls.push({lng: o.fallbackLng, url: applyReplacement(o.resPostPath, { lng: o.fallbackLng, ns: ns })}); + } else if (o.sendMissingTo === 'current') { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + } + }; + + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + var pluralExtensions = { + + rules: { + "ach": { + "name": "Acholi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "af": { + "name": "Afrikaans", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ak": { + "name": "Akan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "am": { + "name": "Amharic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "an": { + "name": "Aragonese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ar": { + "name": "Arabic", + "numbers": [ + 0, + 1, + 2, + 3, + 11, + 100 + ], + "plurals": function(n) { return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5); } + }, + "arn": { + "name": "Mapudungun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ast": { + "name": "Asturian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ay": { + "name": "Aymar\u00e1", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "az": { + "name": "Azerbaijani", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "be": { + "name": "Belarusian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "bg": { + "name": "Bulgarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bn": { + "name": "Bengali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bo": { + "name": "Tibetan", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "br": { + "name": "Breton", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "bs": { + "name": "Bosnian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ca": { + "name": "Catalan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "cgg": { + "name": "Chiga", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "cs": { + "name": "Czech", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "csb": { + "name": "Kashubian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "cy": { + "name": "Welsh", + "numbers": [ + 1, + 2, + 3, + 8 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3); } + }, + "da": { + "name": "Danish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "de": { + "name": "German", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "dz": { + "name": "Dzongkha", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "el": { + "name": "Greek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "en": { + "name": "English", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eo": { + "name": "Esperanto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es": { + "name": "Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es_ar": { + "name": "Argentinean Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "et": { + "name": "Estonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eu": { + "name": "Basque", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fa": { + "name": "Persian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "fi": { + "name": "Finnish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fil": { + "name": "Filipino", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fo": { + "name": "Faroese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fr": { + "name": "French", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fur": { + "name": "Friulian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fy": { + "name": "Frisian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ga": { + "name": "Irish", + "numbers": [ + 1, + 2, + 3, + 7, + 11 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;} + }, + "gd": { + "name": "Scottish Gaelic", + "numbers": [ + 1, + 2, + 3, + 20 + ], + "plurals": function(n) { return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3); } + }, + "gl": { + "name": "Galician", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gu": { + "name": "Gujarati", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gun": { + "name": "Gun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ha": { + "name": "Hausa", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "he": { + "name": "Hebrew", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hi": { + "name": "Hindi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hr": { + "name": "Croatian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "hu": { + "name": "Hungarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hy": { + "name": "Armenian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ia": { + "name": "Interlingua", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "id": { + "name": "Indonesian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "is": { + "name": "Icelandic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n%10!=1 || n%100==11); } + }, + "it": { + "name": "Italian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ja": { + "name": "Japanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jbo": { + "name": "Lojban", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jv": { + "name": "Javanese", + "numbers": [ + 0, + 1 + ], + "plurals": function(n) { return Number(n !== 0); } + }, + "ka": { + "name": "Georgian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kk": { + "name": "Kazakh", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "km": { + "name": "Khmer", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kn": { + "name": "Kannada", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ko": { + "name": "Korean", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ku": { + "name": "Kurdish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "kw": { + "name": "Cornish", + "numbers": [ + 1, + 2, + 3, + 4 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3); } + }, + "ky": { + "name": "Kyrgyz", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lb": { + "name": "Letzeburgesch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ln": { + "name": "Lingala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "lo": { + "name": "Lao", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lt": { + "name": "Lithuanian", + "numbers": [ + 1, + 2, + 10 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "lv": { + "name": "Latvian", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2); } + }, + "mai": { + "name": "Maithili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mfe": { + "name": "Mauritian Creole", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mg": { + "name": "Malagasy", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mi": { + "name": "Maori", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mk": { + "name": "Macedonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 || n%10==1 ? 0 : 1); } + }, + "ml": { + "name": "Malayalam", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mn": { + "name": "Mongolian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mnk": { + "name": "Mandinka", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(0 ? 0 : n==1 ? 1 : 2); } + }, + "mr": { + "name": "Marathi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ms": { + "name": "Malay", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "mt": { + "name": "Maltese", + "numbers": [ + 1, + 2, + 11, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3); } + }, + "nah": { + "name": "Nahuatl", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nap": { + "name": "Neapolitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nb": { + "name": "Norwegian Bokmal", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ne": { + "name": "Nepali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nl": { + "name": "Dutch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nn": { + "name": "Norwegian Nynorsk", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "no": { + "name": "Norwegian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nso": { + "name": "Northern Sotho", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "oc": { + "name": "Occitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "or": { + "name": "Oriya", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pa": { + "name": "Punjabi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pap": { + "name": "Papiamento", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pl": { + "name": "Polish", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "pms": { + "name": "Piemontese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ps": { + "name": "Pashto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt": { + "name": "Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt_br": { + "name": "Brazilian Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "rm": { + "name": "Romansh", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ro": { + "name": "Romanian", + "numbers": [ + 1, + 2, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2); } + }, + "ru": { + "name": "Russian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "sah": { + "name": "Yakut", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sco": { + "name": "Scots", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "se": { + "name": "Northern Sami", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "si": { + "name": "Sinhala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sk": { + "name": "Slovak", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "sl": { + "name": "Slovenian", + "numbers": [ + 5, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }, + "so": { + "name": "Somali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "son": { + "name": "Songhay", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sq": { + "name": "Albanian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sr": { + "name": "Serbian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "su": { + "name": "Sundanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sv": { + "name": "Swedish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sw": { + "name": "Swahili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ta": { + "name": "Tamil", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "te": { + "name": "Telugu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tg": { + "name": "Tajik", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "th": { + "name": "Thai", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ti": { + "name": "Tigrinya", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tk": { + "name": "Turkmen", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tr": { + "name": "Turkish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tt": { + "name": "Tatar", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ug": { + "name": "Uyghur", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "uk": { + "name": "Ukrainian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ur": { + "name": "Urdu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "uz": { + "name": "Uzbek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "vi": { + "name": "Vietnamese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "wa": { + "name": "Walloon", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "wo": { + "name": "Wolof", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "yo": { + "name": "Yoruba", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "zh": { + "name": "Chinese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + } + }, + + // for demonstration only sl and ar is added but you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i = ext.plurals(c); + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[0], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + +})(); \ No newline at end of file diff --git a/libs/i18next/release/i18next-1.6.0.min.js b/libs/i18next/release/i18next-1.6.0.min.js new file mode 100644 index 00000000..a8caa875 --- /dev/null +++ b/libs/i18next/release/i18next-1.6.0.min.js @@ -0,0 +1,5 @@ +// i18next, v1.6.0 +// Copyright (c)2013 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function(){function a(e,t){if(!t||typeof t=="function")return e;for(var n in t)e[n]=t[n];return e}function f(e,t,n){var r,i=0,s=e.length,o=s===undefined||typeof e=="function";if(n){if(o){for(r in e)if(t.apply(e[r],n)===!1)break}else for(;i127&&r<2048?(t+=String.fromCharCode(r>>6|192),t+=String.fromCharCode(r&63|128)):(t+=String.fromCharCode(r>>12|224),t+=String.fromCharCode(r>>6&63|128),t+=String.fromCharCode(r&63|128))}return t},i=function(e){var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";e=r(e);var n="",i,s,o,u,a,f,l,c=0;do i=e.charCodeAt(c++),s=e.charCodeAt(c++),o=e.charCodeAt(c++),u=i>>2,a=(i&3)<<4|s>>4,f=(s&15)<<2|o>>6,l=o&63,isNaN(s)?f=l=64:isNaN(o)&&(l=64),n+=t.charAt(u)+t.charAt(a)+t.charAt(f)+t.charAt(l),i=s=o="",u=a=f=l="";while(c1&&(r.indexOf("?")>-1?r+="&"+l:r+="?"+l);if(i.jsonp){var c=document.getElementsByTagName("head")[0],h=document.createElement("script");h.type="text/javascript",h.src=r,c.appendChild(h);return}}t(function(t,n){if(t)return u(t);n.open(e,r,i.async);for(var s in a)a.hasOwnProperty(s)&&n.setRequestHeader(s,a[s]);n.onreadystatechange=function(){if(n.readyState===4){var e=n.responseText||"";if(!u)return;u(n.status,{text:function(){return e},json:function(){return JSON.parse(e)}})}},n.send(f)})},u={authBasic:function(e,t){o.headers.Authorization="Basic "+i(e+":"+t)},connect:function(e,t,n){return o("CONNECT",e,t,n)},del:function(e,t,n){return o("DELETE",e,t,n)},get:function(e,t,n){return o("GET",e,t,n)},head:function(e,t,n){return o("HEAD",e,t,n)},headers:function(e){o.headers=e||{}},isAllowed:function(e,t,n){this.options(e,function(e,r){n(r.text().indexOf(t)!==-1)})},options:function(e,t,n){return o("OPTIONS",e,t,n)},patch:function(e,t,n){return o("PATCH",e,t,n)},post:function(e,t,n){return o("POST",e,t,n)},put:function(e,t,n){return o("PUT",e,t,n)},trace:function(e,t,n){return o("TRACE",e,t,n)}},a=e.type?e.type.toLowerCase():"get";u[a](e.url,e,function(t,n){t===200?e.success(n.json(),t,null):e.error(n.text(),t,null)})}function d(e,s){typeof e=="function"&&(s=e,e={}),e=e||{},p.extend(u,e),typeof u.ns=="string"&&(u.ns={namespaces:[u.ns],defaultNs:u.ns}),u.interpolationPrefixEscaped=p.regexEscape(u.interpolationPrefix),u.interpolationSuffixEscaped=p.regexEscape(u.interpolationSuffix),u.lng||(u.lng=p.detectLanguage()),u.lng?u.useCookie&&p.cookie.create(u.cookieName,u.lng,u.cookieExpirationTime):(u.lng=u.fallbackLng,u.useCookie&&p.cookie.remove(u.cookieName)),o=p.toLanguages(u.lng),i=o[0],p.log("currentLng set to: "+i),_.setCurrentLng(i),t&&u.setJqueryExt&&S();var a;t&&t.Deferred&&(a=t.Deferred());if(u.resStore){r=u.resStore,s&&s(L),a&&a.resolve();if(a)return a.promise();return}var f=p.toLanguages(u.lng);typeof u.preload=="string"&&(u.preload=[u.preload]);for(var l=0,c=u.preload.length;lu.maxRecursion)break;var a=e.indexOf(u.reusePrefix),f=e.indexOf(u.reuseSuffix,a)+u.reuseSuffix.length,l=e.substring(a,f),c=l.replace(u.reusePrefix,"").replace(u.reuseSuffix,"");if(c.indexOf(n)!=-1){var h=c.indexOf(n);if(c.indexOf(r,h)!=-1&&c.indexOf(i,h)!=-1){var d=c.indexOf(r,h),v=c.indexOf(i,d)+i.length;try{o=p.extend(o,JSON.parse(c.substring(d,v))),c=c.substring(0,h)}catch(m){}}}var g=A(c,o);e=e.replace(l,g)}return e}function N(e){return e.context&&typeof e.context=="string"}function C(e){return e.count!==undefined&&typeof e.count!="string"&&e.count!==1}function L(e,t){return s=0,A(e,t)}function A(e,t){t=t||{};if(!r)return f;var s,a,f=t.defaultValue||e,l=o;if(t.lng){l=p.toLanguages(t.lng);if(!r[l[0]]){var c=u.getAsync;u.getAsync=!1,n.sync.load(l,u,function(e,t){p.extend(r,t),u.getAsync=c})}}var h=t.ns||u.ns.defaultNs;if(e.indexOf(u.nsseparator)>-1){var d=e.split(u.nsseparator);h=d[0],e=d[1]}if(N(t)){s=p.extend({},t),delete s.context,s.defaultValue=u.contextNotFound;var v=h+u.nsseparator+e+"_"+t.context;a=L(v,s);if(a!=u.contextNotFound)return x(a,{context:t.context})}if(C(t)){s=p.extend({},t),delete s.count,s.defaultValue=u.pluralNotFound;var m=h+u.nsseparator+e+u.pluralSuffix,g=_.get(i,t.count);g>=0?m=m+"_"+g:g===1&&(m=h+u.nsseparator+e),a=L(m,s);if(a!=u.pluralNotFound)return x(a,{count:t.count})}var y,b=e.split(u.keyseparator);for(var w=0,E=l.length;w0){var s=n[r].substring(0,i),o=n[r].substring(i+1);t[s]=o}}}(),t[u.detectLngQS]&&(e=t[u.detectLngQS]));if(!e&&typeof document!="undefined"&&u.useCookie){var n=p.cookie.read(u.cookieName);n&&(e=n)}return!e&&typeof navigator!="undefined"&&(e=navigator.language?navigator.language:navigator.userLanguage),e}Array.prototype.indexOf||(Array.prototype.indexOf=function(e){"use strict";if(this==null)throw new TypeError;var t=Object(this),n=t.length>>>0;if(n===0)return-1;var r=0;arguments.length>0&&(r=Number(arguments[1]),r!=r?r=0:r!=0&&r!=Infinity&&r!=-Infinity&&(r=(r>0||-1)*Math.floor(Math.abs(r))));if(r>=n)return-1;var i=r>=0?r:Math.max(n-Math.abs(r),0);for(;i-1){var n=e.split("-");e=u.lowerCaseLng?n[0].toLowerCase()+"-"+n[1].toLowerCase():n[0].toLowerCase()+"-"+n[1].toUpperCase(),u.load!=="unspecific"&&t.push(e),u.load!=="current"&&t.push(n[0])}else t.push(e);return t.indexOf(u.fallbackLng)===-1&&u.fallbackLng&&t.push(u.fallbackLng),t},regexEscape:function(e){return e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}},M={load:function(e,t,n){t.useLocalStorage?M._loadLocal(e,t,function(r,i){var s=[];for(var o=0,u=e.length;o0?M._fetch(s,t,function(e,t){p.extend(i,t),M._storeLocal(t),n(null,i)}):n(null,i)}):M._fetch(e,t,function(e,t){n(null,t)})},_loadLocal:function(e,t,n){var r={},i=(new Date).getTime();if(window.localStorage){var s=e.length;p.each(e,function(e,o){var u=window.localStorage.getItem("res_"+o);u&&(u=JSON.parse(u),u.i18nStamp&&u.i18nStamp+t.localStorageExpirationTime>i&&(r[o]=u)),s--,s===0&&n(null,r)})}},_storeLocal:function(e){if(window.localStorage)for(var t in e)e[t].i18nStamp=(new Date).getTime(),window.localStorage.setItem("res_"+t,JSON.stringify(e[t]));return},_fetch:function(e,t,n){var r=t.ns,i={};if(!t.dynamicLoad){var s=r.namespaces.length*e.length,o;p.each(r.namespaces,function(r,u){p.each(e,function(e,r){var a=function(e,t){e&&(o=o||[],o.push(e)),i[r]=i[r]||{},i[r][u]=t,s--,s===0&&n(o,i)};typeof t.customLoad=="function"?t.customLoad(r,u,t,a):M._fetchOne(r,u,t,a)})})}else{var u=x(t.resGetPath,{lng:e.join("+"),ns:r.namespaces.join("+")});p.ajax({url:u,success:function(e,t,r){p.log("loaded: "+u),n(null,e)},error:function(e,t,r){p.log("failed loading: "+u),n("failed loading resource.json error: "+r)},dataType:"json",async:t.getAsync})}},_fetchOne:function(e,t,n,r){var i=x(n.resGetPath,{lng:e,ns:t});p.ajax({url:i,success:function(e,t,n){p.log("loaded: "+i),r(null,e)},error:function(e,t,n){p.log("failed loading: "+i),r(n,{})},dataType:"json",async:n.getAsync})},postMissing:function(e,t,n,i,s){var o={};o[n]=i;var a=[];if(u.sendMissingTo==="fallback")a.push({lng:u.fallbackLng,url:x(u.resPostPath,{lng:u.fallbackLng,ns:t})});else if(u.sendMissingTo==="current")a.push({lng:e,url:x(u.resPostPath,{lng:e,ns:t})});else if(u.sendMissingTo==="all")for(var f=0,l=s.length;f1)}},af:{name:"Afrikaans",numbers:[1,2],plurals:function(e){return Number(e!=1)}},ak:{name:"Akan",numbers:[1,2],plurals:function(e){return Number(e>1)}},am:{name:"Amharic",numbers:[1,2],plurals:function(e){return Number(e>1)}},an:{name:"Aragonese",numbers:[1,2],plurals:function(e){return Number(e!=1)}},ar:{name:"Arabic",numbers:[0,1,2,3,11,100],plurals:function(e){return Number(e===0?0:e==1?1:e==2?2:e%100>=3&&e%100<=10?3:e%100>=11?4:5)}},arn:{name:"Mapudungun",numbers:[1,2],plurals:function(e){return Number(e>1)}},ast:{name:"Asturian",numbers:[1,2],plurals:function(e){return Number(e!=1)}},ay:{name:"Aymará",numbers:[1],plurals:function(e){return 0}},az:{name:"Azerbaijani",numbers:[1,2],plurals:function(e){return Number(e!=1)}},be:{name:"Belarusian",numbers:[1,2,5],plurals:function(e){return Number(e%10==1&&e%100!=11?0:e%10>=2&&e%10<=4&&(e%100<10||e%100>=20)?1:2)}},bg:{name:"Bulgarian",numbers:[1,2],plurals:function(e){return Number(e!=1)}},bn:{name:"Bengali",numbers:[1,2],plurals:function(e){return Number(e!=1)}},bo:{name:"Tibetan",numbers:[1],plurals:function(e){return 0}},br:{name:"Breton",numbers:[1,2],plurals:function(e){return Number(e>1)}},bs:{name:"Bosnian",numbers:[1,2,5],plurals:function(e){return Number(e%10==1&&e%100!=11?0:e%10>=2&&e%10<=4&&(e%100<10||e%100>=20)?1:2)}},ca:{name:"Catalan",numbers:[1,2],plurals:function(e){return Number(e!=1)}},cgg:{name:"Chiga",numbers:[1],plurals:function(e){return 0}},cs:{name:"Czech",numbers:[1,2,5],plurals:function(e){return Number(e==1?0:e>=2&&e<=4?1:2)}},csb:{name:"Kashubian",numbers:[1,2,5],plurals:function(e){return Number(e==1?0:e%10>=2&&e%10<=4&&(e%100<10||e%100>=20)?1:2)}},cy:{name:"Welsh",numbers:[1,2,3,8],plurals:function(e){return Number(e==1?0:e==2?1:e!=8&&e!=11?2:3)}},da:{name:"Danish",numbers:[1,2],plurals:function(e){return Number(e!=1)}},de:{name:"German",numbers:[1,2],plurals:function(e){return Number(e!=1)}},dz:{name:"Dzongkha",numbers:[1],plurals:function(e){return 0}},el:{name:"Greek",numbers:[1,2],plurals:function(e){return Number(e!=1)}},en:{name:"English",numbers:[1,2],plurals:function(e){return Number(e!=1)}},eo:{name:"Esperanto",numbers:[1,2],plurals:function(e){return Number(e!=1)}},es:{name:"Spanish",numbers:[1,2],plurals:function(e){return Number(e!=1)}},es_ar:{name:"Argentinean Spanish",numbers:[1,2],plurals:function(e){return Number(e!=1)}},et:{name:"Estonian",numbers:[1,2],plurals:function(e){return Number(e!=1)}},eu:{name:"Basque",numbers:[1,2],plurals:function(e){return Number(e!=1)}},fa:{name:"Persian",numbers:[1],plurals:function(e){return 0}},fi:{name:"Finnish",numbers:[1,2],plurals:function(e){return Number(e!=1)}},fil:{name:"Filipino",numbers:[1,2],plurals:function(e){return Number(e>1)}},fo:{name:"Faroese",numbers:[1,2],plurals:function(e){return Number(e!=1)}},fr:{name:"French",numbers:[1,2],plurals:function(e){return Number(e>1)}},fur:{name:"Friulian",numbers:[1,2],plurals:function(e){return Number(e!=1)}},fy:{name:"Frisian",numbers:[1,2],plurals:function(e){return Number(e!=1)}},ga:{name:"Irish",numbers:[1,2,3,7,11],plurals:function(e){return Number(e==1?0:e==2?1:e<7?2:e<11?3:4)}},gd:{name:"Scottish Gaelic",numbers:[1,2,3,20],plurals:function(e){return Number(e==1||e==11?0:e==2||e==12?1:e>2&&e<20?2:3)}},gl:{name:"Galician",numbers:[1,2],plurals:function(e){return Number(e!=1)}},gu:{name:"Gujarati",numbers:[1,2],plurals:function(e){return Number(e!=1)}},gun:{name:"Gun",numbers:[1,2],plurals:function(e){return Number(e>1)}},ha:{name:"Hausa",numbers:[1,2],plurals:function(e){return Number(e!=1)}},he:{name:"Hebrew",numbers:[1,2],plurals:function(e){return Number(e!=1)}},hi:{name:"Hindi",numbers:[1,2],plurals:function(e){return Number(e!=1)}},hr:{name:"Croatian",numbers:[1,2,5],plurals:function(e){return Number(e%10==1&&e%100!=11?0:e%10>=2&&e%10<=4&&(e%100<10||e%100>=20)?1:2)}},hu:{name:"Hungarian",numbers:[1,2],plurals:function(e){return Number(e!=1)}},hy:{name:"Armenian",numbers:[1,2],plurals:function(e){return Number(e!=1)}},ia:{name:"Interlingua",numbers:[1,2],plurals:function(e){return Number(e!=1)}},id:{name:"Indonesian",numbers:[1],plurals:function(e){return 0}},is:{name:"Icelandic",numbers:[1,2],plurals:function(e){return Number(e%10!=1||e%100==11)}},it:{name:"Italian",numbers:[1,2],plurals:function(e){return Number(e!=1)}},ja:{name:"Japanese",numbers:[1],plurals:function(e){return 0}},jbo:{name:"Lojban",numbers:[1],plurals:function(e){return 0}},jv:{name:"Javanese",numbers:[0,1],plurals:function(e){return Number(e!==0)}},ka:{name:"Georgian",numbers:[1],plurals:function(e){return 0}},kk:{name:"Kazakh",numbers:[1],plurals:function(e){return 0}},km:{name:"Khmer",numbers:[1],plurals:function(e){return 0}},kn:{name:"Kannada",numbers:[1,2],plurals:function(e){return Number(e!=1)}},ko:{name:"Korean",numbers:[1],plurals:function(e){return 0}},ku:{name:"Kurdish",numbers:[1,2],plurals:function(e){return Number(e!=1)}},kw:{name:"Cornish",numbers:[1,2,3,4],plurals:function(e){return Number(e==1?0:e==2?1:e==3?2:3)}},ky:{name:"Kyrgyz",numbers:[1],plurals:function(e){return 0}},lb:{name:"Letzeburgesch",numbers:[1,2],plurals:function(e){return Number(e!=1)}},ln:{name:"Lingala",numbers:[1,2],plurals:function(e){return Number(e>1)}},lo:{name:"Lao",numbers:[1],plurals:function(e){return 0}},lt:{name:"Lithuanian",numbers:[1,2,10],plurals:function(e){return Number(e%10==1&&e%100!=11?0:e%10>=2&&(e%100<10||e%100>=20)?1:2)}},lv:{name:"Latvian",numbers:[0,1,2],plurals:function(e){return Number(e%10==1&&e%100!=11?0:e!==0?1:2)}},mai:{name:"Maithili",numbers:[1,2],plurals:function(e){return Number(e!=1)}},mfe:{name:"Mauritian Creole",numbers:[1,2],plurals:function(e){return Number(e>1)}},mg:{name:"Malagasy",numbers:[1,2],plurals:function(e){return Number(e>1)}},mi:{name:"Maori",numbers:[1,2],plurals:function(e){return Number(e>1)}},mk:{name:"Macedonian",numbers:[1,2],plurals:function(e){return Number(e==1||e%10==1?0:1)}},ml:{name:"Malayalam",numbers:[1,2],plurals:function(e){return Number(e!=1)}},mn:{name:"Mongolian",numbers:[1,2],plurals:function(e){return Number(e!=1)}},mnk:{name:"Mandinka",numbers:[0,1,2],plurals:function(e){return Number(e==1?1:2)}},mr:{name:"Marathi",numbers:[1,2],plurals:function(e){return Number(e!=1)}},ms:{name:"Malay",numbers:[1],plurals:function(e){return 0}},mt:{name:"Maltese",numbers:[1,2,11,20],plurals:function(e){return Number(e==1?0:e===0||e%100>1&&e%100<11?1:e%100>10&&e%100<20?2:3)}},nah:{name:"Nahuatl",numbers:[1,2],plurals:function(e){return Number(e!=1)}},nap:{name:"Neapolitan",numbers:[1,2],plurals:function(e){return Number(e!=1)}},nb:{name:"Norwegian Bokmal",numbers:[1,2],plurals:function(e){return Number(e!=1)}},ne:{name:"Nepali",numbers:[1,2],plurals:function(e){return Number(e!=1)}},nl:{name:"Dutch",numbers:[1,2],plurals:function(e){return Number(e!=1)}},nn:{name:"Norwegian Nynorsk",numbers:[1,2],plurals:function(e){return Number(e!=1)}},no:{name:"Norwegian",numbers:[1,2],plurals:function(e){return Number(e!=1)}},nso:{name:"Northern Sotho",numbers:[1,2],plurals:function(e){return Number(e!=1)}},oc:{name:"Occitan",numbers:[1,2],plurals:function(e){return Number(e>1)}},or:{name:"Oriya",numbers:[2,1],plurals:function(e){return Number(e!=1)}},pa:{name:"Punjabi",numbers:[1,2],plurals:function(e){return Number(e!=1)}},pap:{name:"Papiamento",numbers:[1,2],plurals:function(e){return Number(e!=1)}},pl:{name:"Polish",numbers:[1,2,5],plurals:function(e){return Number(e==1?0:e%10>=2&&e%10<=4&&(e%100<10||e%100>=20)?1:2)}},pms:{name:"Piemontese",numbers:[1,2],plurals:function(e){return Number(e!=1)}},ps:{name:"Pashto",numbers:[1,2],plurals:function(e){return Number(e!=1)}},pt:{name:"Portuguese",numbers:[1,2],plurals:function(e){return Number(e!=1)}},pt_br:{name:"Brazilian Portuguese",numbers:[1,2],plurals:function(e){return Number(e!=1)}},rm:{name:"Romansh",numbers:[1,2],plurals:function(e){return Number(e!=1)}},ro:{name:"Romanian",numbers:[1,2,20],plurals:function(e){return Number(e==1?0:e===0||e%100>0&&e%100<20?1:2)}},ru:{name:"Russian",numbers:[1,2,5],plurals:function(e){return Number(e%10==1&&e%100!=11?0:e%10>=2&&e%10<=4&&(e%100<10||e%100>=20)?1:2)}},sah:{name:"Yakut",numbers:[1],plurals:function(e){return 0}},sco:{name:"Scots",numbers:[1,2],plurals:function(e){return Number(e!=1)}},se:{name:"Northern Sami",numbers:[1,2],plurals:function(e){return Number(e!=1)}},si:{name:"Sinhala",numbers:[1,2],plurals:function(e){return Number(e!=1)}},sk:{name:"Slovak",numbers:[1,2,5],plurals:function(e){return Number(e==1?0:e>=2&&e<=4?1:2)}},sl:{name:"Slovenian",numbers:[5,1,2,3],plurals:function(e){return Number(e%100==1?1:e%100==2?2:e%100==3||e%100==4?3:0)}},so:{name:"Somali",numbers:[1,2],plurals:function(e){return Number(e!=1)}},son:{name:"Songhay",numbers:[1,2],plurals:function(e){return Number(e!=1)}},sq:{name:"Albanian",numbers:[1,2],plurals:function(e){return Number(e!=1)}},sr:{name:"Serbian",numbers:[1,2,5],plurals:function(e){return Number(e%10==1&&e%100!=11?0:e%10>=2&&e%10<=4&&(e%100<10||e%100>=20)?1:2)}},su:{name:"Sundanese",numbers:[1],plurals:function(e){return 0}},sv:{name:"Swedish",numbers:[1,2],plurals:function(e){return Number(e!=1)}},sw:{name:"Swahili",numbers:[1,2],plurals:function(e){return Number(e!=1)}},ta:{name:"Tamil",numbers:[1,2],plurals:function(e){return Number(e!=1)}},te:{name:"Telugu",numbers:[1,2],plurals:function(e){return Number(e!=1)}},tg:{name:"Tajik",numbers:[1,2],plurals:function(e){return Number(e>1)}},th:{name:"Thai",numbers:[1],plurals:function(e){return 0}},ti:{name:"Tigrinya",numbers:[1,2],plurals:function(e){return Number(e>1)}},tk:{name:"Turkmen",numbers:[1,2],plurals:function(e){return Number(e!=1)}},tr:{name:"Turkish",numbers:[1,2],plurals:function(e){return Number(e>1)}},tt:{name:"Tatar",numbers:[1],plurals:function(e){return 0}},ug:{name:"Uyghur",numbers:[1],plurals:function(e){return 0}},uk:{name:"Ukrainian",numbers:[1,2,5],plurals:function(e){return Number(e%10==1&&e%100!=11?0:e%10>=2&&e%10<=4&&(e%100<10||e%100>=20)?1:2)}},ur:{name:"Urdu",numbers:[1,2],plurals:function(e){return Number(e!=1)}},uz:{name:"Uzbek",numbers:[1,2],plurals:function(e){return Number(e>1)}},vi:{name:"Vietnamese",numbers:[1],plurals:function(e){return 0}},wa:{name:"Walloon",numbers:[1,2],plurals:function(e){return Number(e>1)}},wo:{name:"Wolof",numbers:[1],plurals:function(e){return 0}},yo:{name:"Yoruba",numbers:[1,2],plurals:function(e){return Number(e!=1)}},zh:{name:"Chinese",numbers:[1],plurals:function(e){return 0}}},addRule:function(e,t){_.rules[e]=t},setCurrentLng:function(e){if(!_.currentRule||_.currentRule.lng!==e){var t=e.split("-");_.currentRule={lng:e,rule:_.rules[t[0]]}}},get:function(e,t){function r(t,n){var r;_.currentRule&&_.currentRule.lng===e?r=_.currentRule.rule:r=_.rules[t];if(r){var i=r.plurals(n),s=r.numbers[i];return r.numbers.length===2&&r.numbers[0]===1&&(s===2?s=-1:s===1&&(s=1)),s}return n===1?"1":"-1"}var n=e.split("-");return r(n[0],t)}},D={},P=function(e,t){D[e]=t},H=function(){function e(e){return Object.prototype.toString.call(e).slice(8,-1).toLowerCase()}function t(e,t){for(var n=[];t>0;n[--t]=e);return n.join("")}var n=function(){return n.cache.hasOwnProperty(arguments[0])||(n.cache[arguments[0]]=n.parse(arguments[0])),n.format.call(null,n.cache[arguments[0]],arguments)};return n.format=function(n,r){var i=1,s=n.length,o="",u,a=[],f,l,c,h,p,d;for(f=0;f=0?"+"+u:u,p=c[4]?c[4]=="0"?"0":c[4].charAt(1):" ",d=c[6]-String(u).length,h=c[6]?t(p,d):"",a.push(c[5]?u+h:h+u)}}return a.join("")},n.cache={},n.parse=function(e){var t=e,n=[],r=[],i=0;while(t){if((n=/^[^\x25]+/.exec(t))!==null)r.push(n[0]);else if((n=/^\x25{2}/.exec(t))!==null)r.push("%");else{if((n=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(t))===null)throw"[sprintf] huh?";if(n[2]){i|=1;var s=[],o=n[2],u=[];if((u=/^([a-z_][a-z_\d]*)/i.exec(o))===null)throw"[sprintf] huh?";s.push(u[1]);while((o=o.substring(u[0].length))!=="")if((u=/^\.([a-z_][a-z_\d]*)/i.exec(o))!==null)s.push(u[1]);else{if((u=/^\[(\d+)\]/.exec(o))===null)throw"[sprintf] huh?";s.push(u[1])}n[2]=s}else i|=2;if(i===3)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";r.push(n)}t=t.substring(n[0].length)}return r},n}(),B=function(e,t){return t.unshift(e),H.apply(null,t)};P("sprintf",function(e,t,n){return n.sprintf?Object.prototype.toString.apply(n.sprintf)==="[object Array]"?B(e,n.sprintf):typeof n.sprintf=="object"?H(e,n.sprintf):e:e}),n.init=d,n.setLng=w,n.preload=v,n.addResourceBundle=m,n.loadNamespace=y,n.loadNamespaces=b,n.setDefaultNamespace=g,n.t=L,n.translate=L,n.detectLanguage=p.detectLanguage,n.pluralExtensions=_,n.sync=M,n.functions=p,n.lng=E,n.addPostProcessor=P,n.options=u})(); \ No newline at end of file diff --git a/libs/i18next/release/i18next-1.6.0.zip b/libs/i18next/release/i18next-1.6.0.zip new file mode 100644 index 00000000..46f04051 Binary files /dev/null and b/libs/i18next/release/i18next-1.6.0.zip differ diff --git a/libs/i18next/release/i18next-1.6.1.js b/libs/i18next/release/i18next-1.6.1.js new file mode 100644 index 00000000..1cccec4a --- /dev/null +++ b/libs/i18next/release/i18next-1.6.1.js @@ -0,0 +1,2593 @@ +// i18next, v1.6.1 +// Copyright (c)2013 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function() { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + var root = this + , $ = root.jQuery || root.Zepto + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = []; + + + // Export the i18next object for **CommonJS**. + // If we're not in CommonJS, add `i18n` to the + // global object or to jquery. + if (typeof module !== 'undefined' && module.exports) { + module.exports = i18n; + } else { + if ($) { + $.i18n = $.i18n || i18n; + } + + root.i18n = root.i18n || i18n; + } + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: 'dev', + fallbackNS: [], + detectLngQS: 'setLng', + ns: 'translation', + fallbackOnNull: true, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + + postProcess: undefined + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + return JSON.parse(data); + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + if (status === 200) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + document.cookie = name+"="+value+expires+"; path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : _ajax, + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + toLanguages: function(lng) { + var languages = []; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + + if (o.load !== 'unspecific') languages.push(lng); + if (o.load !== 'current') languages.push(parts[0]); + } else { + languages.push(lng); + } + + if (languages.indexOf(o.fallbackLng) === -1 && o.fallbackLng) languages.push(o.fallbackLng); + + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + if (o.lng) { + // set cookie with lng set (as detectLanguage will set cookie on need) + if (o.useCookie) f.cookie.create(o.cookieName, o.lng, o.cookieExpirationTime); + } else { + o.lng = o.fallbackLng; + if (o.useCookie) f.cookie.remove(o.cookieName); + } + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + if (cb) cb(translate); + if (deferred) deferred.resolve(); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + + if (cb) cb(translate); + if (deferred) deferred.resolve(); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + f.extend(resStore[lng][ns], resources); + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, cb) { + return init({lng: lng}, cb); + } + + function lng() { + return currentLng; + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } + else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + f.each(replacementHash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), value); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.escape(value)); + }else{ + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), value); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, translated_token); + } + return translated; + } + + function hasContext(options) { + return (options.context && typeof options.context == 'string'); + } + + function needsPlural(options) { + return (options.count !== undefined && typeof options.count != 'string' && options.count !== 1); + } + + function exists(key, options) { + options = options || {}; + + var notFound = options.defaultValue || key + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(key, options) { + + if (typeof options == 'string') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else { + options = options || {}; + } + + var notFound = options.defaultValue || key + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng) : languages + , ns = options.ns || o.ns.defaultNs; + + if (found === undefined && o.sendMissing) { + if (options.lng) { + sync.postMissing(lngs[0], ns, key, notfound, lngs); + } else { + sync.postMissing(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found !== undefined && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessor && postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options){ + options = options || {}; + + if (!resStore) { return notfound; } // no resStore to translate from + + var optionWithoutCount, translated + , notFound = options.defaultValue || key + , lngs = languages; + + if (options.lng) { + lngs = f.toLanguages(options.lng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.count; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(currentLng, options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + + translated = translate(pluralKey, optionWithoutCount); + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } // else continue translation with original/singular key + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (Object.prototype.toString.apply(value) === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned a object instead of string.'; + f.log(value); + } else { + var copy = {}; // apply child translation on a copy + for (var m in value) { + // apply translation on childs + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + } + value = copy; + } + } + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _translate(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _translate(key, options); // fallback to default NS + } + } + + return found; + } + function detectLanguage() { + var detectedLng; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var parms = query.split('&'); + for (var i=0; i 0) { + var key = parms[i].substring(0,pos); + var val = parms[i].substring(pos+1); + qsParm[key] = val; + } + } + })(); + if (qsParm[o.detectLngQS]) { + detectedLng = qsParm[o.detectLngQS]; + } + } + + // get from cookie + if (!detectedLng && typeof document !== 'undefined' && o.useCookie ) { + var c = f.cookie.read(o.cookieName); + if (c) detectedLng = c; + } + + // get from navigator + if (!detectedLng && typeof navigator !== 'undefined') { + detectedLng = (navigator.language) ? navigator.language : navigator.userLanguage; + } + + return detectedLng; + } + var sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + window.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback') { + urls.push({lng: o.fallbackLng, url: applyReplacement(o.resPostPath, { lng: o.fallbackLng, ns: ns })}); + } else if (o.sendMissingTo === 'current') { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + } + }; + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + var pluralExtensions = { + + rules: { + "ach": { + "name": "Acholi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "af": { + "name": "Afrikaans", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ak": { + "name": "Akan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "am": { + "name": "Amharic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "an": { + "name": "Aragonese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ar": { + "name": "Arabic", + "numbers": [ + 0, + 1, + 2, + 3, + 11, + 100 + ], + "plurals": function(n) { return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5); } + }, + "arn": { + "name": "Mapudungun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ast": { + "name": "Asturian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ay": { + "name": "Aymar\u00e1", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "az": { + "name": "Azerbaijani", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "be": { + "name": "Belarusian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "bg": { + "name": "Bulgarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bn": { + "name": "Bengali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bo": { + "name": "Tibetan", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "br": { + "name": "Breton", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "bs": { + "name": "Bosnian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ca": { + "name": "Catalan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "cgg": { + "name": "Chiga", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "cs": { + "name": "Czech", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "csb": { + "name": "Kashubian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "cy": { + "name": "Welsh", + "numbers": [ + 1, + 2, + 3, + 8 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3); } + }, + "da": { + "name": "Danish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "de": { + "name": "German", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "dz": { + "name": "Dzongkha", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "el": { + "name": "Greek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "en": { + "name": "English", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eo": { + "name": "Esperanto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es": { + "name": "Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es_ar": { + "name": "Argentinean Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "et": { + "name": "Estonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eu": { + "name": "Basque", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fa": { + "name": "Persian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "fi": { + "name": "Finnish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fil": { + "name": "Filipino", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fo": { + "name": "Faroese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fr": { + "name": "French", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fur": { + "name": "Friulian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fy": { + "name": "Frisian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ga": { + "name": "Irish", + "numbers": [ + 1, + 2, + 3, + 7, + 11 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;} + }, + "gd": { + "name": "Scottish Gaelic", + "numbers": [ + 1, + 2, + 3, + 20 + ], + "plurals": function(n) { return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3); } + }, + "gl": { + "name": "Galician", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gu": { + "name": "Gujarati", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gun": { + "name": "Gun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ha": { + "name": "Hausa", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "he": { + "name": "Hebrew", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hi": { + "name": "Hindi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hr": { + "name": "Croatian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "hu": { + "name": "Hungarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hy": { + "name": "Armenian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ia": { + "name": "Interlingua", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "id": { + "name": "Indonesian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "is": { + "name": "Icelandic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n%10!=1 || n%100==11); } + }, + "it": { + "name": "Italian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ja": { + "name": "Japanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jbo": { + "name": "Lojban", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jv": { + "name": "Javanese", + "numbers": [ + 0, + 1 + ], + "plurals": function(n) { return Number(n !== 0); } + }, + "ka": { + "name": "Georgian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kk": { + "name": "Kazakh", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "km": { + "name": "Khmer", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kn": { + "name": "Kannada", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ko": { + "name": "Korean", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ku": { + "name": "Kurdish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "kw": { + "name": "Cornish", + "numbers": [ + 1, + 2, + 3, + 4 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3); } + }, + "ky": { + "name": "Kyrgyz", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lb": { + "name": "Letzeburgesch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ln": { + "name": "Lingala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "lo": { + "name": "Lao", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lt": { + "name": "Lithuanian", + "numbers": [ + 1, + 2, + 10 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "lv": { + "name": "Latvian", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2); } + }, + "mai": { + "name": "Maithili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mfe": { + "name": "Mauritian Creole", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mg": { + "name": "Malagasy", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mi": { + "name": "Maori", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mk": { + "name": "Macedonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 || n%10==1 ? 0 : 1); } + }, + "ml": { + "name": "Malayalam", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mn": { + "name": "Mongolian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mnk": { + "name": "Mandinka", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(0 ? 0 : n==1 ? 1 : 2); } + }, + "mr": { + "name": "Marathi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ms": { + "name": "Malay", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "mt": { + "name": "Maltese", + "numbers": [ + 1, + 2, + 11, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3); } + }, + "nah": { + "name": "Nahuatl", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nap": { + "name": "Neapolitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nb": { + "name": "Norwegian Bokmal", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ne": { + "name": "Nepali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nl": { + "name": "Dutch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nn": { + "name": "Norwegian Nynorsk", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "no": { + "name": "Norwegian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nso": { + "name": "Northern Sotho", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "oc": { + "name": "Occitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "or": { + "name": "Oriya", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pa": { + "name": "Punjabi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pap": { + "name": "Papiamento", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pl": { + "name": "Polish", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "pms": { + "name": "Piemontese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ps": { + "name": "Pashto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt": { + "name": "Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt_br": { + "name": "Brazilian Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "rm": { + "name": "Romansh", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ro": { + "name": "Romanian", + "numbers": [ + 1, + 2, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2); } + }, + "ru": { + "name": "Russian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "sah": { + "name": "Yakut", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sco": { + "name": "Scots", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "se": { + "name": "Northern Sami", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "si": { + "name": "Sinhala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sk": { + "name": "Slovak", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "sl": { + "name": "Slovenian", + "numbers": [ + 5, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }, + "so": { + "name": "Somali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "son": { + "name": "Songhay", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sq": { + "name": "Albanian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sr": { + "name": "Serbian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "su": { + "name": "Sundanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sv": { + "name": "Swedish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sw": { + "name": "Swahili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ta": { + "name": "Tamil", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "te": { + "name": "Telugu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tg": { + "name": "Tajik", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "th": { + "name": "Thai", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ti": { + "name": "Tigrinya", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tk": { + "name": "Turkmen", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tr": { + "name": "Turkish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tt": { + "name": "Tatar", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ug": { + "name": "Uyghur", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "uk": { + "name": "Ukrainian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ur": { + "name": "Urdu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "uz": { + "name": "Uzbek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "vi": { + "name": "Vietnamese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "wa": { + "name": "Walloon", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "wo": { + "name": "Wolof", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "yo": { + "name": "Yoruba", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "zh": { + "name": "Chinese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + } + }, + + // for demonstration only sl and ar is added but you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i = ext.plurals(c); + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[0], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + +})(); \ No newline at end of file diff --git a/libs/i18next/release/i18next-1.6.1.min.js b/libs/i18next/release/i18next-1.6.1.min.js new file mode 100644 index 00000000..38553b87 --- /dev/null +++ b/libs/i18next/release/i18next-1.6.1.min.js @@ -0,0 +1,5 @@ +// i18next, v1.6.1 +// Copyright (c)2013 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function(){function n(n,e){if(!e||"function"==typeof e)return n;for(var r in e)n[r]=e[r];return n}function e(n,e,r){var t,u=0,a=n.length,o=void 0===a||"function"==typeof n;if(r)if(o){for(t in n)if(e.apply(n[t],r)===!1)break}else for(;a>u&&e.apply(n[u++],r)!==!1;);else if(o){for(t in n)if(e.call(n[t],t,n[t])===!1)break}else for(;a>u&&e.call(n[u],u,n[u++])!==!1;);return n}function r(n){return"string"==typeof n?n.replace(/[&<>"'\/]/g,function(n){return C[n]}):n}function t(n){var e=function(n){if(window.XMLHttpRequest)return n(null,new XMLHttpRequest);if(window.ActiveXObject)try{return n(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(e){return n(null,new ActiveXObject("Microsoft.XMLHTTP"))}return n(Error())},r=function(n){if("string"==typeof n)return n;var e=[];for(var r in n)n.hasOwnProperty(r)&&e.push(encodeURIComponent(r)+"="+encodeURIComponent(n[r]));return e.join("&")},t=function(n){n=n.replace(/\r\n/g,"\n");for(var e="",r=0;n.length>r;r++){var t=n.charCodeAt(r);128>t?e+=String.fromCharCode(t):t>127&&2048>t?(e+=String.fromCharCode(192|t>>6),e+=String.fromCharCode(128|63&t)):(e+=String.fromCharCode(224|t>>12),e+=String.fromCharCode(128|63&t>>6),e+=String.fromCharCode(128|63&t))}return e},u=function(n){var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";n=t(n);var r,u,a,o,s,i,l,c="",f=0;do r=n.charCodeAt(f++),u=n.charCodeAt(f++),a=n.charCodeAt(f++),o=r>>2,s=(3&r)<<4|u>>4,i=(15&u)<<2|a>>6,l=63&a,isNaN(u)?i=l=64:isNaN(a)&&(l=64),c+=e.charAt(o)+e.charAt(s)+e.charAt(i)+e.charAt(l),r=u=a="",o=s=i=l="";while(n.length>f);return c},a=function(){for(var n=arguments[0],e=1;arguments.length>e;e++){var r=arguments[e];for(var t in r)r.hasOwnProperty(t)&&(n[t]=r[t])}return n},o=function(n,t,u,s){"function"==typeof u&&(s=u,u={}),u.cache=u.cache||!1,u.data=u.data||{},u.headers=u.headers||{},u.jsonp=u.jsonp||!1,u.async=void 0===u.async?!0:u.async;var i,l=a({accept:"*/*","content-type":"application/x-www-form-urlencoded;charset=UTF-8"},o.headers,u.headers);if(i="application/json"===l["content-type"]?JSON.stringify(u.data):r(u.data),"GET"===n){var c=[];if(i&&(c.push(i),i=null),u.cache||c.push("_="+(new Date).getTime()),u.jsonp&&(c.push("callback="+u.jsonp),c.push("jsonp="+u.jsonp)),c=c.join("&"),c.length>1&&(t+=t.indexOf("?")>-1?"&"+c:"?"+c),u.jsonp){var f=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=t,f.appendChild(m),void 0}}e(function(e,r){if(e)return s(e);r.open(n,t,u.async);for(var a in l)l.hasOwnProperty(a)&&r.setRequestHeader(a,l[a]);r.onreadystatechange=function(){if(4===r.readyState){var n=r.responseText||"";if(!s)return;s(r.status,{text:function(){return n},json:function(){return JSON.parse(n)}})}},r.send(i)})},s={authBasic:function(n,e){o.headers.Authorization="Basic "+u(n+":"+e)},connect:function(n,e,r){return o("CONNECT",n,e,r)},del:function(n,e,r){return o("DELETE",n,e,r)},get:function(n,e,r){return o("GET",n,e,r)},head:function(n,e,r){return o("HEAD",n,e,r)},headers:function(n){o.headers=n||{}},isAllowed:function(n,e,r){this.options(n,function(n,t){r(-1!==t.text().indexOf(e))})},options:function(n,e,r){return o("OPTIONS",n,e,r)},patch:function(n,e,r){return o("PATCH",n,e,r)},post:function(n,e,r){return o("POST",n,e,r)},put:function(n,e,r){return o("PUT",n,e,r)},trace:function(n,e,r){return o("TRACE",n,e,r)}},i=n.type?n.type.toLowerCase():"get";s[i](n.url,n,function(e,r){200===e?n.success(r.json(),e,null):n.error(r.text(),e,null)})}function u(n,e){"function"==typeof n&&(e=n,n={}),n=n||{},E.extend(A,n),"string"==typeof A.ns&&(A.ns={namespaces:[A.ns],defaultNs:A.ns}),"string"==typeof A.fallbackNS&&(A.fallbackNS=[A.fallbackNS]),A.interpolationPrefixEscaped=E.regexEscape(A.interpolationPrefix),A.interpolationSuffixEscaped=E.regexEscape(A.interpolationSuffix),A.lng||(A.lng=E.detectLanguage()),A.lng?A.useCookie&&E.cookie.create(A.cookieName,A.lng,A.cookieExpirationTime):(A.lng=A.fallbackLng,A.useCookie&&E.cookie.remove(A.cookieName)),P=E.toLanguages(A.lng),S=P[0],E.log("currentLng set to: "+S),R.setCurrentLng(S),L&&A.setJqueryExt&&m();var r;if(L&&L.Deferred&&(r=L.Deferred()),!A.resStore){var t=E.toLanguages(A.lng);"string"==typeof A.preload&&(A.preload=[A.preload]);for(var u=0,a=A.preload.length;a>u;u++)for(var o=E.toLanguages(A.preload[u]),s=0,i=o.length;i>s;s++)0>t.indexOf(o[s])&&t.push(o[s]);return w.sync.load(t,A,function(n,t){j=t,e&&e(N),r&&r.resolve()}),r?r.promise():void 0}return j=A.resStore,e&&e(N),r&&r.resolve(),r?r.promise():void 0}function a(n,e){"string"==typeof n&&(n=[n]);for(var r=0,t=n.length;t>r;r++)0>A.preload.indexOf(n[r])&&A.preload.push(n[r]);return u(e)}function o(n,e,r){"string"!=typeof e?(r=e,e=A.ns.defaultNs):0>A.ns.namespaces.indexOf(e)&&A.ns.namespaces.push(e),j[n]=j[n]||{},j[n][e]=j[n][e]||{},E.extend(j[n][e],r)}function s(n){A.ns.defaultNs=n}function i(n,e){l([n],e)}function l(n,e){var r={dynamicLoad:A.dynamicLoad,resGetPath:A.resGetPath,getAsync:A.getAsync,customLoad:A.customLoad,ns:{namespaces:n,defaultNs:""}},t=E.toLanguages(A.lng);"string"==typeof A.preload&&(A.preload=[A.preload]);for(var u=0,a=A.preload.length;a>u;u++)for(var o=E.toLanguages(A.preload[u]),s=0,i=o.length;i>s;s++)0>t.indexOf(o[s])&&t.push(o[s]);for(var l=[],c=0,f=t.length;f>c;c++){var m=!1,p=j[t[c]];if(p)for(var b=0,g=n.length;g>b;b++)p[n[b]]||(m=!0);else m=!0;m&&l.push(t[c])}l.length?w.sync._fetch(l,r,function(r,t){var u=n.length*l.length;E.each(n,function(n,r){0>A.ns.namespaces.indexOf(r)&&A.ns.namespaces.push(r),E.each(l,function(n,a){j[a]=j[a]||{},j[a][r]=t[a][r],u--,0===u&&e&&(A.useLocalStorage&&w.sync._storeLocal(j),e())})})}):e&&e()}function c(n,e){return u({lng:n},e)}function f(){return S}function m(){function n(n,e,r){if(0!==e.length){var t="text";if(0===e.indexOf("[")){var u=e.split("]");e=u[1],t=u[0].substr(1,u[0].length-1)}e.indexOf(";")===e.length-1&&(e=e.substr(0,e.length-2));var a;"html"===t?(a=A.defaultValueFromContent?L.extend({defaultValue:n.html()},r):r,n.html(L.t(e,a))):"text"===t?(a=A.defaultValueFromContent?L.extend({defaultValue:n.text()},r):r,n.text(L.t(e,a))):(a=A.defaultValueFromContent?L.extend({defaultValue:n.attr(t)},r):r,n.attr(t,L.t(e,a)))}}function e(e,r){var t=e.attr(A.selectorAttr);if(t){var u=e,a=e.data("i18n-target");if(a&&(u=e.find(a)||e),r||A.useDataAttrOptions!==!0||(r=e.data("i18n-options")),r=r||{},t.indexOf(";")>=0){var o=t.split(";");L.each(o,function(e,t){""!==t&&n(u,t,r)})}else n(u,t,r);A.useDataAttrOptions===!0&&e.data("i18n-options",r)}}L.t=L.t||N,L.fn.i18n=function(n){return this.each(function(){e(L(this),n);var r=L(this).find("["+A.selectorAttr+"]");r.each(function(){e(L(this),n)})})}}function p(n,e,r,t){if(!n)return n;if(t=t||e,0>n.indexOf(t.interpolationPrefix||A.interpolationPrefix))return n;var u=t.interpolationPrefix?E.regexEscape(t.interpolationPrefix):A.interpolationPrefixEscaped,a=t.interpolationSuffix?E.regexEscape(t.interpolationSuffix):A.interpolationSuffixEscaped,o="HTML"+a;return E.each(e,function(e,s){var i=r?r+A.keyseparator+e:e;"object"==typeof s&&null!==s?n=p(n,s,i,t):t.escapeInterpolation||A.escapeInterpolation?(n=n.replace(RegExp([u,i,o].join(""),"g"),s),n=n.replace(RegExp([u,i,a].join(""),"g"),E.escape(s))):n=n.replace(RegExp([u,i,a].join(""),"g"),s)}),n}function b(n,e){var r=",",t="{",u="}",a=E.extend({},e);for(delete a.postProcess;-1!=n.indexOf(A.reusePrefix)&&(T++,!(T>A.maxRecursion));){var o=n.lastIndexOf(A.reusePrefix),s=n.indexOf(A.reuseSuffix,o)+A.reuseSuffix.length,i=n.substring(o,s),l=i.replace(A.reusePrefix,"").replace(A.reuseSuffix,"");if(-1!=l.indexOf(r)){var c=l.indexOf(r);if(-1!=l.indexOf(t,c)&&-1!=l.indexOf(u,c)){var f=l.indexOf(t,c),m=l.indexOf(u,f)+u.length;try{a=E.extend(a,JSON.parse(l.substring(f,m))),l=l.substring(0,c)}catch(p){}}}var b=x(l,a);n=n.replace(i,b)}return n}function g(n){return n.context&&"string"==typeof n.context}function d(n){return void 0!==n.count&&"string"!=typeof n.count&&1!==n.count}function h(n,e){e=e||{};var r=e.defaultValue||n,t=y(n,e);return void 0!==t||t===r}function N(){return T=0,x.apply(null,arguments)}function v(){for(var n=[],e=1;arguments.length>e;e++)n.push(arguments[e]);return{postProcess:"sprintf",sprintf:n}}function x(n,e){e="string"==typeof e?v.apply(null,arguments):e||{};var r=e.defaultValue||n,t=y(n,e),u=e.lng?E.toLanguages(e.lng):P,a=e.ns||A.ns.defaultNs;void 0===t&&A.sendMissing&&(e.lng?F.postMissing(u[0],a,n,notfound,u):F.postMissing(A.lng,a,n,r,u));var o=e.postProcess||A.postProcess;return void 0!==t&&o&&z[o]&&(t=z[o](t,n,e)),void 0===t&&(r=p(r,e),r=b(r,e),o&&z[o]&&(t=z[o](t,n,e))),void 0!==t?t:r}function y(n,e){if(e=e||{},!j)return notfound;var r,t,u=e.defaultValue||n,a=P;if(e.lng&&(a=E.toLanguages(e.lng),!j[a[0]])){var o=A.getAsync;A.getAsync=!1,w.sync.load(a,A,function(n,e){E.extend(j,e),A.getAsync=o})}var s=e.ns||A.ns.defaultNs;if(n.indexOf(A.nsseparator)>-1){var i=n.split(A.nsseparator);s=i[0],n=i[1]}if(g(e)){r=E.extend({},e),delete r.context,r.defaultValue=A.contextNotFound;var l=s+A.nsseparator+n+"_"+e.context;if(t=N(l,r),t!=A.contextNotFound)return p(t,{context:e.context})}if(d(e)){r=E.extend({},e),delete r.count,r.defaultValue=A.pluralNotFound;var c=s+A.nsseparator+n+A.pluralSuffix,f=R.get(S,e.count);if(f>=0?c=c+"_"+f:1===f&&(c=s+A.nsseparator+n),t=N(c,r),t!=A.pluralNotFound)return p(t,{count:e.count,interpolationPrefix:e.interpolationPrefix,interpolationSuffix:e.interpolationSuffix})}for(var m,h=n.split(A.keyseparator),v=0,y=a.length;y>v&&void 0===m;v++){for(var k=a[v],O=0,L=j[k]&&j[k][s];h[O];)L=L&&L[h[O]],O++;if(void 0!==L){if("string"==typeof L)L=p(L,e),L=b(L,e);else if("[object Array]"!==Object.prototype.toString.apply(L)||A.returnObjectTrees||e.returnObjectTrees){if(null===L&&A.fallbackOnNull===!0)L=void 0;else if(null!==L)if(A.returnObjectTrees||e.returnObjectTrees){var T={};for(var C in L)T[C]=x(s+A.nsseparator+n+A.keyseparator+C,e);L=T}else L="key '"+s+":"+n+" ("+k+")' "+"returned a object instead of string.",E.log(L)}else L=L.join("\n"),L=p(L,e),L=b(L,e);m=L}}if(void 0===m&&!e.isFallbackLookup&&(A.fallbackToDefaultNS===!0||A.fallbackNS&&A.fallbackNS.length))if(e.isFallbackLookup=!0,A.fallbackNS.length){for(var _=0,M=A.fallbackNS.length;M>_;_++)if(m=x(A.fallbackNS[_]+A.nsseparator+n,e)){var F=m.indexOf(A.nsseparator)>-1?m.split(A.nsseparator)[1]:m,z=u.indexOf(A.nsseparator)>-1?u.split(A.nsseparator)[1]:u;if(F!==z)break}}else m=x(n,e);return m}function k(){var n,e=[];if("undefined"!=typeof window&&(function(){for(var n=window.location.search.substring(1),r=n.split("&"),t=0;r.length>t;t++){var u=r[t].indexOf("=");if(u>0){var a=r[t].substring(0,u),o=r[t].substring(u+1);e[a]=o}}}(),e[A.detectLngQS]&&(n=e[A.detectLngQS])),!n&&"undefined"!=typeof document&&A.useCookie){var r=E.cookie.read(A.cookieName);r&&(n=r)}return n||"undefined"==typeof navigator||(n=navigator.language?navigator.language:navigator.userLanguage),n}Array.prototype.indexOf||(Array.prototype.indexOf=function(n){"use strict";if(null==this)throw new TypeError;var e=Object(this),r=e.length>>>0;if(0===r)return-1;var t=0;if(arguments.length>0&&(t=Number(arguments[1]),t!=t?t=0:0!=t&&1/0!=t&&t!=-1/0&&(t=(t>0||-1)*Math.floor(Math.abs(t)))),t>=r)return-1;for(var u=t>=0?t:Math.max(r-Math.abs(t),0);r>u;u++)if(u in e&&e[u]===n)return u;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(n){"use strict";if(null==this)throw new TypeError;var e=Object(this),r=e.length>>>0;if(0===r)return-1;var t=r;arguments.length>1&&(t=Number(arguments[1]),t!=t?t=0:0!=t&&t!=1/0&&t!=-(1/0)&&(t=(t>0||-1)*Math.floor(Math.abs(t))));for(var u=t>=0?Math.min(t,r-1):r-Math.abs(t);u>=0;u--)if(u in e&&e[u]===n)return u;return-1});var S,O=this,L=O.jQuery||O.Zepto,w={},j={},T=0,P=[];"undefined"!=typeof module&&module.exports?module.exports=w:(L&&(L.i18n=L.i18n||w),O.i18n=O.i18n||w);var A={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:"dev",fallbackNS:[],detectLngQS:"setLng",ns:"translation",fallbackOnNull:!0,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",postProcess:void 0},C={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},_={create:function(n,e,r){var t;if(r){var u=new Date;u.setTime(u.getTime()+1e3*60*r),t="; expires="+u.toGMTString()}else t="";document.cookie=n+"="+e+t+"; path=/"},read:function(n){for(var e=n+"=",r=document.cookie.split(";"),t=0;r.length>t;t++){for(var u=r[t];" "==u.charAt(0);)u=u.substring(1,u.length);if(0===u.indexOf(e))return u.substring(e.length,u.length)}return null},remove:function(n){this.create(n,"",-1)}},M={create:function(){},read:function(){return null},remove:function(){}},E={extend:L?L.extend:n,each:L?L.each:e,ajax:L?L.ajax:t,cookie:"undefined"!=typeof document?_:M,detectLanguage:k,escape:r,log:function(n){A.debug&&"undefined"!=typeof console&&console.log(n)},toLanguages:function(n){var e=[];if("string"==typeof n&&n.indexOf("-")>-1){var r=n.split("-");n=A.lowerCaseLng?r[0].toLowerCase()+"-"+r[1].toLowerCase():r[0].toLowerCase()+"-"+r[1].toUpperCase(),"unspecific"!==A.load&&e.push(n),"current"!==A.load&&e.push(r[0])}else e.push(n);return-1===e.indexOf(A.fallbackLng)&&A.fallbackLng&&e.push(A.fallbackLng),e},regexEscape:function(n){return n.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}};E.applyReplacement=p;var F={load:function(n,e,r){e.useLocalStorage?F._loadLocal(n,e,function(t,u){for(var a=[],o=0,s=n.length;s>o;o++)u[n[o]]||a.push(n[o]);a.length>0?F._fetch(a,e,function(n,e){E.extend(u,e),F._storeLocal(e),r(null,u)}):r(null,u)}):F._fetch(n,e,function(n,e){r(null,e)})},_loadLocal:function(n,e,r){var t={},u=(new Date).getTime();if(window.localStorage){var a=n.length;E.each(n,function(n,o){var s=window.localStorage.getItem("res_"+o);s&&(s=JSON.parse(s),s.i18nStamp&&s.i18nStamp+e.localStorageExpirationTime>u&&(t[o]=s)),a--,0===a&&r(null,t)})}},_storeLocal:function(n){if(window.localStorage)for(var e in n)n[e].i18nStamp=(new Date).getTime(),window.localStorage.setItem("res_"+e,JSON.stringify(n[e]))},_fetch:function(n,e,r){var t=e.ns,u={};if(e.dynamicLoad){var a=function(n,e){r(null,e)};if("function"==typeof e.customLoad)e.customLoad(n,t.namespaces,e,a);else{var o=p(e.resGetPath,{lng:n.join("+"),ns:t.namespaces.join("+")});E.ajax({url:o,success:function(n){E.log("loaded: "+o),a(null,n)},error:function(n,e,r){E.log("failed loading: "+o),a("failed loading resource.json error: "+r)},dataType:"json",async:e.getAsync})}}else{var s,i=t.namespaces.length*n.length;E.each(t.namespaces,function(t,a){E.each(n,function(n,t){var o=function(n,e){n&&(s=s||[],s.push(n)),u[t]=u[t]||{},u[t][a]=e,i--,0===i&&r(s,u)};"function"==typeof e.customLoad?e.customLoad(t,a,e,o):F._fetchOne(t,a,e,o)})})}},_fetchOne:function(n,e,r,t){var u=p(r.resGetPath,{lng:n,ns:e});E.ajax({url:u,success:function(n){E.log("loaded: "+u),t(null,n)},error:function(n,e,r){E.log("failed loading: "+u),t(r,{})},dataType:"json",async:r.getAsync})},postMissing:function(n,e,r,t,u){var a={};a[r]=t;var o=[];if("fallback"===A.sendMissingTo)o.push({lng:A.fallbackLng,url:p(A.resPostPath,{lng:A.fallbackLng,ns:e})});else if("current"===A.sendMissingTo)o.push({lng:n,url:p(A.resPostPath,{lng:n,ns:e})});else if("all"===A.sendMissingTo)for(var s=0,i=u.length;i>s;s++)o.push({lng:u[s],url:p(A.resPostPath,{lng:u[s],ns:e})});for(var l=0,c=o.length;c>l;l++){var f=o[l];E.ajax({url:f.url,type:A.sendType,data:a,success:function(){E.log("posted missing key '"+r+"' to: "+f.url);for(var n=r.split("."),u=0,a=j[f.lng][e];n[u];)a=a[n[u]]=u===n.length-1?t:a[n[u]]||{},u++},error:function(){E.log("failed posting missing key '"+r+"' to: "+f.url)},dataType:"json",async:A.postAsync})}}},R={rules:{ach:{name:"Acholi",numbers:[1,2],plurals:function(n){return Number(n>1)}},af:{name:"Afrikaans",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ak:{name:"Akan",numbers:[1,2],plurals:function(n){return Number(n>1)}},am:{name:"Amharic",numbers:[1,2],plurals:function(n){return Number(n>1)}},an:{name:"Aragonese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ar:{name:"Arabic",numbers:[0,1,2,3,11,100],plurals:function(n){return Number(0===n?0:1==n?1:2==n?2:n%100>=3&&10>=n%100?3:n%100>=11?4:5)}},arn:{name:"Mapudungun",numbers:[1,2],plurals:function(n){return Number(n>1)}},ast:{name:"Asturian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ay:{name:"Aymará",numbers:[1],plurals:function(){return 0}},az:{name:"Azerbaijani",numbers:[1,2],plurals:function(n){return Number(1!=n)}},be:{name:"Belarusian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},bg:{name:"Bulgarian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},bn:{name:"Bengali",numbers:[1,2],plurals:function(n){return Number(1!=n)}},bo:{name:"Tibetan",numbers:[1],plurals:function(){return 0}},br:{name:"Breton",numbers:[1,2],plurals:function(n){return Number(n>1)}},bs:{name:"Bosnian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},ca:{name:"Catalan",numbers:[1,2],plurals:function(n){return Number(1!=n)}},cgg:{name:"Chiga",numbers:[1],plurals:function(){return 0}},cs:{name:"Czech",numbers:[1,2,5],plurals:function(n){return Number(1==n?0:n>=2&&4>=n?1:2)}},csb:{name:"Kashubian",numbers:[1,2,5],plurals:function(n){return Number(1==n?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},cy:{name:"Welsh",numbers:[1,2,3,8],plurals:function(n){return Number(1==n?0:2==n?1:8!=n&&11!=n?2:3)}},da:{name:"Danish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},de:{name:"German",numbers:[1,2],plurals:function(n){return Number(1!=n)}},dz:{name:"Dzongkha",numbers:[1],plurals:function(){return 0}},el:{name:"Greek",numbers:[1,2],plurals:function(n){return Number(1!=n)}},en:{name:"English",numbers:[1,2],plurals:function(n){return Number(1!=n)}},eo:{name:"Esperanto",numbers:[1,2],plurals:function(n){return Number(1!=n)}},es:{name:"Spanish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},es_ar:{name:"Argentinean Spanish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},et:{name:"Estonian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},eu:{name:"Basque",numbers:[1,2],plurals:function(n){return Number(1!=n)}},fa:{name:"Persian",numbers:[1],plurals:function(){return 0}},fi:{name:"Finnish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},fil:{name:"Filipino",numbers:[1,2],plurals:function(n){return Number(n>1)}},fo:{name:"Faroese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},fr:{name:"French",numbers:[1,2],plurals:function(n){return Number(n>1)}},fur:{name:"Friulian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},fy:{name:"Frisian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ga:{name:"Irish",numbers:[1,2,3,7,11],plurals:function(n){return Number(1==n?0:2==n?1:7>n?2:11>n?3:4)}},gd:{name:"Scottish Gaelic",numbers:[1,2,3,20],plurals:function(n){return Number(1==n||11==n?0:2==n||12==n?1:n>2&&20>n?2:3)}},gl:{name:"Galician",numbers:[1,2],plurals:function(n){return Number(1!=n)}},gu:{name:"Gujarati",numbers:[1,2],plurals:function(n){return Number(1!=n)}},gun:{name:"Gun",numbers:[1,2],plurals:function(n){return Number(n>1)}},ha:{name:"Hausa",numbers:[1,2],plurals:function(n){return Number(1!=n)}},he:{name:"Hebrew",numbers:[1,2],plurals:function(n){return Number(1!=n)}},hi:{name:"Hindi",numbers:[1,2],plurals:function(n){return Number(1!=n)}},hr:{name:"Croatian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},hu:{name:"Hungarian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},hy:{name:"Armenian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ia:{name:"Interlingua",numbers:[1,2],plurals:function(n){return Number(1!=n)}},id:{name:"Indonesian",numbers:[1],plurals:function(){return 0}},is:{name:"Icelandic",numbers:[1,2],plurals:function(n){return Number(1!=n%10||11==n%100)}},it:{name:"Italian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ja:{name:"Japanese",numbers:[1],plurals:function(){return 0}},jbo:{name:"Lojban",numbers:[1],plurals:function(){return 0}},jv:{name:"Javanese",numbers:[0,1],plurals:function(n){return Number(0!==n)}},ka:{name:"Georgian",numbers:[1],plurals:function(){return 0}},kk:{name:"Kazakh",numbers:[1],plurals:function(){return 0}},km:{name:"Khmer",numbers:[1],plurals:function(){return 0}},kn:{name:"Kannada",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ko:{name:"Korean",numbers:[1],plurals:function(){return 0}},ku:{name:"Kurdish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},kw:{name:"Cornish",numbers:[1,2,3,4],plurals:function(n){return Number(1==n?0:2==n?1:3==n?2:3)}},ky:{name:"Kyrgyz",numbers:[1],plurals:function(){return 0}},lb:{name:"Letzeburgesch",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ln:{name:"Lingala",numbers:[1,2],plurals:function(n){return Number(n>1)}},lo:{name:"Lao",numbers:[1],plurals:function(){return 0}},lt:{name:"Lithuanian",numbers:[1,2,10],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&(10>n%100||n%100>=20)?1:2)}},lv:{name:"Latvian",numbers:[0,1,2],plurals:function(n){return Number(1==n%10&&11!=n%100?0:0!==n?1:2)}},mai:{name:"Maithili",numbers:[1,2],plurals:function(n){return Number(1!=n)}},mfe:{name:"Mauritian Creole",numbers:[1,2],plurals:function(n){return Number(n>1)}},mg:{name:"Malagasy",numbers:[1,2],plurals:function(n){return Number(n>1)}},mi:{name:"Maori",numbers:[1,2],plurals:function(n){return Number(n>1)}},mk:{name:"Macedonian",numbers:[1,2],plurals:function(n){return Number(1==n||1==n%10?0:1)}},ml:{name:"Malayalam",numbers:[1,2],plurals:function(n){return Number(1!=n)}},mn:{name:"Mongolian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},mnk:{name:"Mandinka",numbers:[0,1,2],plurals:function(n){return Number(1==n?1:2)}},mr:{name:"Marathi",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ms:{name:"Malay",numbers:[1],plurals:function(){return 0}},mt:{name:"Maltese",numbers:[1,2,11,20],plurals:function(n){return Number(1==n?0:0===n||n%100>1&&11>n%100?1:n%100>10&&20>n%100?2:3)}},nah:{name:"Nahuatl",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nap:{name:"Neapolitan",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nb:{name:"Norwegian Bokmal",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ne:{name:"Nepali",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nl:{name:"Dutch",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nn:{name:"Norwegian Nynorsk",numbers:[1,2],plurals:function(n){return Number(1!=n)}},no:{name:"Norwegian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nso:{name:"Northern Sotho",numbers:[1,2],plurals:function(n){return Number(1!=n)}},oc:{name:"Occitan",numbers:[1,2],plurals:function(n){return Number(n>1)}},or:{name:"Oriya",numbers:[2,1],plurals:function(n){return Number(1!=n)}},pa:{name:"Punjabi",numbers:[1,2],plurals:function(n){return Number(1!=n)}},pap:{name:"Papiamento",numbers:[1,2],plurals:function(n){return Number(1!=n)}},pl:{name:"Polish",numbers:[1,2,5],plurals:function(n){return Number(1==n?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},pms:{name:"Piemontese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ps:{name:"Pashto",numbers:[1,2],plurals:function(n){return Number(1!=n)}},pt:{name:"Portuguese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},pt_br:{name:"Brazilian Portuguese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},rm:{name:"Romansh",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ro:{name:"Romanian",numbers:[1,2,20],plurals:function(n){return Number(1==n?0:0===n||n%100>0&&20>n%100?1:2)}},ru:{name:"Russian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},sah:{name:"Yakut",numbers:[1],plurals:function(){return 0}},sco:{name:"Scots",numbers:[1,2],plurals:function(n){return Number(1!=n)}},se:{name:"Northern Sami",numbers:[1,2],plurals:function(n){return Number(1!=n)}},si:{name:"Sinhala",numbers:[1,2],plurals:function(n){return Number(1!=n)}},sk:{name:"Slovak",numbers:[1,2,5],plurals:function(n){return Number(1==n?0:n>=2&&4>=n?1:2)}},sl:{name:"Slovenian",numbers:[5,1,2,3],plurals:function(n){return Number(1==n%100?1:2==n%100?2:3==n%100||4==n%100?3:0)}},so:{name:"Somali",numbers:[1,2],plurals:function(n){return Number(1!=n)}},son:{name:"Songhay",numbers:[1,2],plurals:function(n){return Number(1!=n)}},sq:{name:"Albanian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},sr:{name:"Serbian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},su:{name:"Sundanese",numbers:[1],plurals:function(){return 0}},sv:{name:"Swedish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},sw:{name:"Swahili",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ta:{name:"Tamil",numbers:[1,2],plurals:function(n){return Number(1!=n)}},te:{name:"Telugu",numbers:[1,2],plurals:function(n){return Number(1!=n)}},tg:{name:"Tajik",numbers:[1,2],plurals:function(n){return Number(n>1)}},th:{name:"Thai",numbers:[1],plurals:function(){return 0}},ti:{name:"Tigrinya",numbers:[1,2],plurals:function(n){return Number(n>1)}},tk:{name:"Turkmen",numbers:[1,2],plurals:function(n){return Number(1!=n)}},tr:{name:"Turkish",numbers:[1,2],plurals:function(n){return Number(n>1)}},tt:{name:"Tatar",numbers:[1],plurals:function(){return 0}},ug:{name:"Uyghur",numbers:[1],plurals:function(){return 0}},uk:{name:"Ukrainian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},ur:{name:"Urdu",numbers:[1,2],plurals:function(n){return Number(1!=n)}},uz:{name:"Uzbek",numbers:[1,2],plurals:function(n){return Number(n>1)}},vi:{name:"Vietnamese",numbers:[1],plurals:function(){return 0}},wa:{name:"Walloon",numbers:[1,2],plurals:function(n){return Number(n>1)}},wo:{name:"Wolof",numbers:[1],plurals:function(){return 0}},yo:{name:"Yoruba",numbers:[1,2],plurals:function(n){return Number(1!=n)}},zh:{name:"Chinese",numbers:[1],plurals:function(){return 0}}},addRule:function(n,e){R.rules[n]=e},setCurrentLng:function(n){if(!R.currentRule||R.currentRule.lng!==n){var e=n.split("-");R.currentRule={lng:n,rule:R.rules[e[0]]}}},get:function(n,e){function r(e,r){var t;if(t=R.currentRule&&R.currentRule.lng===n?R.currentRule.rule:R.rules[e]){var u=t.plurals(r),a=t.numbers[u];return 2===t.numbers.length&&1===t.numbers[0]&&(2===a?a=-1:1===a&&(a=1)),a}return 1===r?"1":"-1"}var t=n.split("-");return r(t[0],e)}},z={},D=function(n,e){z[n]=e},I=function(){function n(n){return Object.prototype.toString.call(n).slice(8,-1).toLowerCase()}function e(n,e){for(var r=[];e>0;r[--e]=n);return r.join("")}var r=function(){return r.cache.hasOwnProperty(arguments[0])||(r.cache[arguments[0]]=r.parse(arguments[0])),r.format.call(null,r.cache[arguments[0]],arguments)};return r.format=function(r,t){var u,a,o,s,i,l,c,f=1,m=r.length,p="",b=[];for(a=0;m>a;a++)if(p=n(r[a]),"string"===p)b.push(r[a]);else if("array"===p){if(s=r[a],s[2])for(u=t[f],o=0;s[2].length>o;o++){if(!u.hasOwnProperty(s[2][o]))throw I('[sprintf] property "%s" does not exist',s[2][o]);u=u[s[2][o]]}else u=s[1]?t[s[1]]:t[f++];if(/[^s]/.test(s[8])&&"number"!=n(u))throw I("[sprintf] expecting number but found %s",n(u));switch(s[8]){case"b":u=u.toString(2);break;case"c":u=String.fromCharCode(u);break;case"d":u=parseInt(u,10);break;case"e":u=s[7]?u.toExponential(s[7]):u.toExponential();break;case"f":u=s[7]?parseFloat(u).toFixed(s[7]):parseFloat(u);break;case"o":u=u.toString(8);break;case"s":u=(u+="")&&s[7]?u.substring(0,s[7]):u;break;case"u":u=Math.abs(u);break;case"x":u=u.toString(16);break;case"X":u=u.toString(16).toUpperCase()}u=/[def]/.test(s[8])&&s[3]&&u>=0?"+"+u:u,l=s[4]?"0"==s[4]?"0":s[4].charAt(1):" ",c=s[6]-(u+"").length,i=s[6]?e(l,c):"",b.push(s[5]?u+i:i+u)}return b.join("")},r.cache={},r.parse=function(n){for(var e=n,r=[],t=[],u=0;e;){if(null!==(r=/^[^\x25]+/.exec(e)))t.push(r[0]);else if(null!==(r=/^\x25{2}/.exec(e)))t.push("%");else{if(null===(r=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(e)))throw"[sprintf] huh?";if(r[2]){u|=1;var a=[],o=r[2],s=[];if(null===(s=/^([a-z_][a-z_\d]*)/i.exec(o)))throw"[sprintf] huh?";for(a.push(s[1]);""!==(o=o.substring(s[0].length));)if(null!==(s=/^\.([a-z_][a-z_\d]*)/i.exec(o)))a.push(s[1]);else{if(null===(s=/^\[(\d+)\]/.exec(o)))throw"[sprintf] huh?";a.push(s[1])}r[2]=a}else u|=2;if(3===u)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";t.push(r)}e=e.substring(r[0].length)}return t},r}(),G=function(n,e){return e.unshift(n),I.apply(null,e)};D("sprintf",function(n,e,r){return r.sprintf?"[object Array]"===Object.prototype.toString.apply(r.sprintf)?G(n,r.sprintf):"object"==typeof r.sprintf?I(n,r.sprintf):n:n}),w.init=u,w.setLng=c,w.preload=a,w.addResourceBundle=o,w.loadNamespace=i,w.loadNamespaces=l,w.setDefaultNamespace=s,w.t=N,w.translate=N,w.exists=h,w.detectLanguage=E.detectLanguage,w.pluralExtensions=R,w.sync=F,w.functions=E,w.lng=f,w.addPostProcessor=D,w.options=A})(); \ No newline at end of file diff --git a/libs/i18next/release/i18next-1.6.1.zip b/libs/i18next/release/i18next-1.6.1.zip new file mode 100644 index 00000000..0f134ba9 Binary files /dev/null and b/libs/i18next/release/i18next-1.6.1.zip differ diff --git a/libs/i18next/release/i18next-1.6.2.js b/libs/i18next/release/i18next-1.6.2.js new file mode 100644 index 00000000..5fc31c4c --- /dev/null +++ b/libs/i18next/release/i18next-1.6.2.js @@ -0,0 +1,2600 @@ +// i18next, v1.6.2 +// Copyright (c)2013 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function() { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + var root = this + , $ = root.jQuery || root.Zepto + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = []; + + + // Export the i18next object for **CommonJS**. + // If we're not in CommonJS, add `i18n` to the + // global object or to jquery. + if (typeof module !== 'undefined' && module.exports) { + module.exports = i18n; + } else { + if ($) { + $.i18n = $.i18n || i18n; + } + + root.i18n = root.i18n || i18n; + } + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: 'dev', + fallbackNS: [], + detectLngQS: 'setLng', + ns: 'translation', + fallbackOnNull: true, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + + postProcess: undefined + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + return JSON.parse(data); + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + if (status === 200) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + document.cookie = name+"="+value+expires+"; path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : _ajax, + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + toLanguages: function(lng) { + var languages = []; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + + if (o.load !== 'unspecific') languages.push(lng); + if (o.load !== 'current') languages.push(parts[0]); + } else { + languages.push(lng); + } + + if (languages.indexOf(o.fallbackLng) === -1 && o.fallbackLng) languages.push(o.fallbackLng); + + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + if (o.lng) { + // set cookie with lng set (as detectLanguage will set cookie on need) + if (o.useCookie) f.cookie.create(o.cookieName, o.lng, o.cookieExpirationTime); + } else { + o.lng = o.fallbackLng; + if (o.useCookie) f.cookie.remove(o.cookieName); + } + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + if (cb) cb(translate); + if (deferred) deferred.resolve(); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + + if (cb) cb(translate); + if (deferred) deferred.resolve(); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + f.extend(resStore[lng][ns], resources); + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, cb) { + return init({lng: lng}, cb); + } + + function lng() { + return currentLng; + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } + else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + f.each(replacementHash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), value); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.escape(value)); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), value); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, translated_token); + } + return translated; + } + + function hasContext(options) { + return (options.context && typeof options.context == 'string'); + } + + function needsPlural(options) { + return (options.count !== undefined && typeof options.count != 'string' && options.count !== 1); + } + + function exists(key, options) { + options = options || {}; + + var notFound = options.defaultValue || key + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(key, options) { + + if (typeof options == 'string') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else { + options = options || {}; + } + + var notFound = options.defaultValue || key + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng) : languages + , ns = options.ns || o.ns.defaultNs; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing) { + if (options.lng) { + sync.postMissing(lngs[0], ns, key, notFound, lngs); + } else { + sync.postMissing(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found !== undefined && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessor && postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options){ + options = options || {}; + + var optionWithoutCount, translated + , notFound = options.defaultValue || key + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + if (options.lng) { + lngs = f.toLanguages(options.lng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.count; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(currentLng, options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + + translated = translate(pluralKey, optionWithoutCount); + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } // else continue translation with original/singular key + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (Object.prototype.toString.apply(value) === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned a object instead of string.'; + f.log(value); + } else { + var copy = {}; // apply child translation on a copy + for (var m in value) { + // apply translation on childs + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + } + value = copy; + } + } + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + } + + return found; + } + function detectLanguage() { + var detectedLng; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var parms = query.split('&'); + for (var i=0; i 0) { + var key = parms[i].substring(0,pos); + var val = parms[i].substring(pos+1); + qsParm[key] = val; + } + } + })(); + if (qsParm[o.detectLngQS]) { + detectedLng = qsParm[o.detectLngQS]; + } + } + + // get from cookie + if (!detectedLng && typeof document !== 'undefined' && o.useCookie ) { + var c = f.cookie.read(o.cookieName); + if (c) detectedLng = c; + } + + // get from navigator + if (!detectedLng && typeof navigator !== 'undefined') { + detectedLng = (navigator.language) ? navigator.language : navigator.userLanguage; + } + + return detectedLng; + } + var sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + window.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback') { + urls.push({lng: o.fallbackLng, url: applyReplacement(o.resPostPath, { lng: o.fallbackLng, ns: ns })}); + } else if (o.sendMissingTo === 'current') { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + } + }; + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + var pluralExtensions = { + + rules: { + "ach": { + "name": "Acholi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "af": { + "name": "Afrikaans", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ak": { + "name": "Akan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "am": { + "name": "Amharic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "an": { + "name": "Aragonese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ar": { + "name": "Arabic", + "numbers": [ + 0, + 1, + 2, + 3, + 11, + 100 + ], + "plurals": function(n) { return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5); } + }, + "arn": { + "name": "Mapudungun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ast": { + "name": "Asturian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ay": { + "name": "Aymar\u00e1", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "az": { + "name": "Azerbaijani", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "be": { + "name": "Belarusian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "bg": { + "name": "Bulgarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bn": { + "name": "Bengali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bo": { + "name": "Tibetan", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "br": { + "name": "Breton", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "bs": { + "name": "Bosnian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ca": { + "name": "Catalan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "cgg": { + "name": "Chiga", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "cs": { + "name": "Czech", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "csb": { + "name": "Kashubian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "cy": { + "name": "Welsh", + "numbers": [ + 1, + 2, + 3, + 8 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3); } + }, + "da": { + "name": "Danish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "de": { + "name": "German", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "dz": { + "name": "Dzongkha", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "el": { + "name": "Greek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "en": { + "name": "English", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eo": { + "name": "Esperanto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es": { + "name": "Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es_ar": { + "name": "Argentinean Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "et": { + "name": "Estonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eu": { + "name": "Basque", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fa": { + "name": "Persian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "fi": { + "name": "Finnish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fil": { + "name": "Filipino", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fo": { + "name": "Faroese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fr": { + "name": "French", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fur": { + "name": "Friulian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fy": { + "name": "Frisian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ga": { + "name": "Irish", + "numbers": [ + 1, + 2, + 3, + 7, + 11 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;} + }, + "gd": { + "name": "Scottish Gaelic", + "numbers": [ + 1, + 2, + 3, + 20 + ], + "plurals": function(n) { return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3); } + }, + "gl": { + "name": "Galician", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gu": { + "name": "Gujarati", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gun": { + "name": "Gun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ha": { + "name": "Hausa", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "he": { + "name": "Hebrew", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hi": { + "name": "Hindi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hr": { + "name": "Croatian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "hu": { + "name": "Hungarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hy": { + "name": "Armenian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ia": { + "name": "Interlingua", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "id": { + "name": "Indonesian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "is": { + "name": "Icelandic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n%10!=1 || n%100==11); } + }, + "it": { + "name": "Italian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ja": { + "name": "Japanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jbo": { + "name": "Lojban", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jv": { + "name": "Javanese", + "numbers": [ + 0, + 1 + ], + "plurals": function(n) { return Number(n !== 0); } + }, + "ka": { + "name": "Georgian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kk": { + "name": "Kazakh", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "km": { + "name": "Khmer", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kn": { + "name": "Kannada", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ko": { + "name": "Korean", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ku": { + "name": "Kurdish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "kw": { + "name": "Cornish", + "numbers": [ + 1, + 2, + 3, + 4 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3); } + }, + "ky": { + "name": "Kyrgyz", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lb": { + "name": "Letzeburgesch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ln": { + "name": "Lingala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "lo": { + "name": "Lao", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lt": { + "name": "Lithuanian", + "numbers": [ + 1, + 2, + 10 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "lv": { + "name": "Latvian", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2); } + }, + "mai": { + "name": "Maithili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mfe": { + "name": "Mauritian Creole", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mg": { + "name": "Malagasy", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mi": { + "name": "Maori", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mk": { + "name": "Macedonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 || n%10==1 ? 0 : 1); } + }, + "ml": { + "name": "Malayalam", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mn": { + "name": "Mongolian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mnk": { + "name": "Mandinka", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(0 ? 0 : n==1 ? 1 : 2); } + }, + "mr": { + "name": "Marathi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ms": { + "name": "Malay", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "mt": { + "name": "Maltese", + "numbers": [ + 1, + 2, + 11, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3); } + }, + "nah": { + "name": "Nahuatl", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nap": { + "name": "Neapolitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nb": { + "name": "Norwegian Bokmal", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ne": { + "name": "Nepali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nl": { + "name": "Dutch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nn": { + "name": "Norwegian Nynorsk", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "no": { + "name": "Norwegian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nso": { + "name": "Northern Sotho", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "oc": { + "name": "Occitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "or": { + "name": "Oriya", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pa": { + "name": "Punjabi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pap": { + "name": "Papiamento", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pl": { + "name": "Polish", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "pms": { + "name": "Piemontese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ps": { + "name": "Pashto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt": { + "name": "Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt_br": { + "name": "Brazilian Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "rm": { + "name": "Romansh", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ro": { + "name": "Romanian", + "numbers": [ + 1, + 2, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2); } + }, + "ru": { + "name": "Russian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "sah": { + "name": "Yakut", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sco": { + "name": "Scots", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "se": { + "name": "Northern Sami", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "si": { + "name": "Sinhala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sk": { + "name": "Slovak", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "sl": { + "name": "Slovenian", + "numbers": [ + 5, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }, + "so": { + "name": "Somali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "son": { + "name": "Songhay", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sq": { + "name": "Albanian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sr": { + "name": "Serbian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "su": { + "name": "Sundanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sv": { + "name": "Swedish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sw": { + "name": "Swahili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ta": { + "name": "Tamil", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "te": { + "name": "Telugu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tg": { + "name": "Tajik", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "th": { + "name": "Thai", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ti": { + "name": "Tigrinya", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tk": { + "name": "Turkmen", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tr": { + "name": "Turkish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tt": { + "name": "Tatar", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ug": { + "name": "Uyghur", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "uk": { + "name": "Ukrainian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ur": { + "name": "Urdu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "uz": { + "name": "Uzbek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "vi": { + "name": "Vietnamese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "wa": { + "name": "Walloon", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "wo": { + "name": "Wolof", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "yo": { + "name": "Yoruba", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "zh": { + "name": "Chinese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + } + }, + + // for demonstration only sl and ar is added but you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i = ext.plurals(c); + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[0], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + +})(); \ No newline at end of file diff --git a/libs/i18next/release/i18next-1.6.2.min.js b/libs/i18next/release/i18next-1.6.2.min.js new file mode 100644 index 00000000..2334a45a --- /dev/null +++ b/libs/i18next/release/i18next-1.6.2.min.js @@ -0,0 +1,5 @@ +// i18next, v1.6.2 +// Copyright (c)2013 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function(){function n(n,e){if(!e||"function"==typeof e)return n;for(var r in e)n[r]=e[r];return n}function e(n,e,r){var t,u=0,a=n.length,s=void 0===a||"function"==typeof n;if(r)if(s){for(t in n)if(e.apply(n[t],r)===!1)break}else for(;a>u&&e.apply(n[u++],r)!==!1;);else if(s){for(t in n)if(e.call(n[t],t,n[t])===!1)break}else for(;a>u&&e.call(n[u],u,n[u++])!==!1;);return n}function r(n){return"string"==typeof n?n.replace(/[&<>"'\/]/g,function(n){return C[n]}):n}function t(n){var e=function(n){if(window.XMLHttpRequest)return n(null,new XMLHttpRequest);if(window.ActiveXObject)try{return n(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(e){return n(null,new ActiveXObject("Microsoft.XMLHTTP"))}return n(Error())},r=function(n){if("string"==typeof n)return n;var e=[];for(var r in n)n.hasOwnProperty(r)&&e.push(encodeURIComponent(r)+"="+encodeURIComponent(n[r]));return e.join("&")},t=function(n){n=n.replace(/\r\n/g,"\n");for(var e="",r=0;n.length>r;r++){var t=n.charCodeAt(r);128>t?e+=String.fromCharCode(t):t>127&&2048>t?(e+=String.fromCharCode(192|t>>6),e+=String.fromCharCode(128|63&t)):(e+=String.fromCharCode(224|t>>12),e+=String.fromCharCode(128|63&t>>6),e+=String.fromCharCode(128|63&t))}return e},u=function(n){var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";n=t(n);var r,u,a,s,o,i,l,c="",f=0;do r=n.charCodeAt(f++),u=n.charCodeAt(f++),a=n.charCodeAt(f++),s=r>>2,o=(3&r)<<4|u>>4,i=(15&u)<<2|a>>6,l=63&a,isNaN(u)?i=l=64:isNaN(a)&&(l=64),c+=e.charAt(s)+e.charAt(o)+e.charAt(i)+e.charAt(l),r=u=a="",s=o=i=l="";while(n.length>f);return c},a=function(){for(var n=arguments[0],e=1;arguments.length>e;e++){var r=arguments[e];for(var t in r)r.hasOwnProperty(t)&&(n[t]=r[t])}return n},s=function(n,t,u,o){"function"==typeof u&&(o=u,u={}),u.cache=u.cache||!1,u.data=u.data||{},u.headers=u.headers||{},u.jsonp=u.jsonp||!1,u.async=void 0===u.async?!0:u.async;var i,l=a({accept:"*/*","content-type":"application/x-www-form-urlencoded;charset=UTF-8"},s.headers,u.headers);if(i="application/json"===l["content-type"]?JSON.stringify(u.data):r(u.data),"GET"===n){var c=[];if(i&&(c.push(i),i=null),u.cache||c.push("_="+(new Date).getTime()),u.jsonp&&(c.push("callback="+u.jsonp),c.push("jsonp="+u.jsonp)),c=c.join("&"),c.length>1&&(t+=t.indexOf("?")>-1?"&"+c:"?"+c),u.jsonp){var f=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=t,f.appendChild(m),void 0}}e(function(e,r){if(e)return o(e);r.open(n,t,u.async);for(var a in l)l.hasOwnProperty(a)&&r.setRequestHeader(a,l[a]);r.onreadystatechange=function(){if(4===r.readyState){var n=r.responseText||"";if(!o)return;o(r.status,{text:function(){return n},json:function(){return JSON.parse(n)}})}},r.send(i)})},o={authBasic:function(n,e){s.headers.Authorization="Basic "+u(n+":"+e)},connect:function(n,e,r){return s("CONNECT",n,e,r)},del:function(n,e,r){return s("DELETE",n,e,r)},get:function(n,e,r){return s("GET",n,e,r)},head:function(n,e,r){return s("HEAD",n,e,r)},headers:function(n){s.headers=n||{}},isAllowed:function(n,e,r){this.options(n,function(n,t){r(-1!==t.text().indexOf(e))})},options:function(n,e,r){return s("OPTIONS",n,e,r)},patch:function(n,e,r){return s("PATCH",n,e,r)},post:function(n,e,r){return s("POST",n,e,r)},put:function(n,e,r){return s("PUT",n,e,r)},trace:function(n,e,r){return s("TRACE",n,e,r)}},i=n.type?n.type.toLowerCase():"get";o[i](n.url,n,function(e,r){200===e?n.success(r.json(),e,null):n.error(r.text(),e,null)})}function u(n,e){"function"==typeof n&&(e=n,n={}),n=n||{},E.extend(A,n),"string"==typeof A.ns&&(A.ns={namespaces:[A.ns],defaultNs:A.ns}),"string"==typeof A.fallbackNS&&(A.fallbackNS=[A.fallbackNS]),A.interpolationPrefixEscaped=E.regexEscape(A.interpolationPrefix),A.interpolationSuffixEscaped=E.regexEscape(A.interpolationSuffix),A.lng||(A.lng=E.detectLanguage()),A.lng?A.useCookie&&E.cookie.create(A.cookieName,A.lng,A.cookieExpirationTime):(A.lng=A.fallbackLng,A.useCookie&&E.cookie.remove(A.cookieName)),P=E.toLanguages(A.lng),S=P[0],E.log("currentLng set to: "+S),R.setCurrentLng(S),L&&A.setJqueryExt&&m();var r;if(L&&L.Deferred&&(r=L.Deferred()),!A.resStore){var t=E.toLanguages(A.lng);"string"==typeof A.preload&&(A.preload=[A.preload]);for(var u=0,a=A.preload.length;a>u;u++)for(var s=E.toLanguages(A.preload[u]),o=0,i=s.length;i>o;o++)0>t.indexOf(s[o])&&t.push(s[o]);return w.sync.load(t,A,function(n,t){j=t,e&&e(N),r&&r.resolve()}),r?r.promise():void 0}return j=A.resStore,e&&e(N),r&&r.resolve(),r?r.promise():void 0}function a(n,e){"string"==typeof n&&(n=[n]);for(var r=0,t=n.length;t>r;r++)0>A.preload.indexOf(n[r])&&A.preload.push(n[r]);return u(e)}function s(n,e,r){"string"!=typeof e?(r=e,e=A.ns.defaultNs):0>A.ns.namespaces.indexOf(e)&&A.ns.namespaces.push(e),j[n]=j[n]||{},j[n][e]=j[n][e]||{},E.extend(j[n][e],r)}function o(n){A.ns.defaultNs=n}function i(n,e){l([n],e)}function l(n,e){var r={dynamicLoad:A.dynamicLoad,resGetPath:A.resGetPath,getAsync:A.getAsync,customLoad:A.customLoad,ns:{namespaces:n,defaultNs:""}},t=E.toLanguages(A.lng);"string"==typeof A.preload&&(A.preload=[A.preload]);for(var u=0,a=A.preload.length;a>u;u++)for(var s=E.toLanguages(A.preload[u]),o=0,i=s.length;i>o;o++)0>t.indexOf(s[o])&&t.push(s[o]);for(var l=[],c=0,f=t.length;f>c;c++){var m=!1,p=j[t[c]];if(p)for(var b=0,g=n.length;g>b;b++)p[n[b]]||(m=!0);else m=!0;m&&l.push(t[c])}l.length?w.sync._fetch(l,r,function(r,t){var u=n.length*l.length;E.each(n,function(n,r){0>A.ns.namespaces.indexOf(r)&&A.ns.namespaces.push(r),E.each(l,function(n,a){j[a]=j[a]||{},j[a][r]=t[a][r],u--,0===u&&e&&(A.useLocalStorage&&w.sync._storeLocal(j),e())})})}):e&&e()}function c(n,e){return u({lng:n},e)}function f(){return S}function m(){function n(n,e,r){if(0!==e.length){var t="text";if(0===e.indexOf("[")){var u=e.split("]");e=u[1],t=u[0].substr(1,u[0].length-1)}e.indexOf(";")===e.length-1&&(e=e.substr(0,e.length-2));var a;"html"===t?(a=A.defaultValueFromContent?L.extend({defaultValue:n.html()},r):r,n.html(L.t(e,a))):"text"===t?(a=A.defaultValueFromContent?L.extend({defaultValue:n.text()},r):r,n.text(L.t(e,a))):(a=A.defaultValueFromContent?L.extend({defaultValue:n.attr(t)},r):r,n.attr(t,L.t(e,a)))}}function e(e,r){var t=e.attr(A.selectorAttr);if(t){var u=e,a=e.data("i18n-target");if(a&&(u=e.find(a)||e),r||A.useDataAttrOptions!==!0||(r=e.data("i18n-options")),r=r||{},t.indexOf(";")>=0){var s=t.split(";");L.each(s,function(e,t){""!==t&&n(u,t,r)})}else n(u,t,r);A.useDataAttrOptions===!0&&e.data("i18n-options",r)}}L.t=L.t||N,L.fn.i18n=function(n){return this.each(function(){e(L(this),n);var r=L(this).find("["+A.selectorAttr+"]");r.each(function(){e(L(this),n)})})}}function p(n,e,r,t){if(!n)return n;if(t=t||e,0>n.indexOf(t.interpolationPrefix||A.interpolationPrefix))return n;var u=t.interpolationPrefix?E.regexEscape(t.interpolationPrefix):A.interpolationPrefixEscaped,a=t.interpolationSuffix?E.regexEscape(t.interpolationSuffix):A.interpolationSuffixEscaped,s="HTML"+a;return E.each(e,function(e,o){var i=r?r+A.keyseparator+e:e;"object"==typeof o&&null!==o?n=p(n,o,i,t):t.escapeInterpolation||A.escapeInterpolation?(n=n.replace(RegExp([u,i,s].join(""),"g"),o),n=n.replace(RegExp([u,i,a].join(""),"g"),E.escape(o))):n=n.replace(RegExp([u,i,a].join(""),"g"),o)}),n}function b(n,e){var r=",",t="{",u="}",a=E.extend({},e);for(delete a.postProcess;-1!=n.indexOf(A.reusePrefix)&&(T++,!(T>A.maxRecursion));){var s=n.lastIndexOf(A.reusePrefix),o=n.indexOf(A.reuseSuffix,s)+A.reuseSuffix.length,i=n.substring(s,o),l=i.replace(A.reusePrefix,"").replace(A.reuseSuffix,"");if(-1!=l.indexOf(r)){var c=l.indexOf(r);if(-1!=l.indexOf(t,c)&&-1!=l.indexOf(u,c)){var f=l.indexOf(t,c),m=l.indexOf(u,f)+u.length;try{a=E.extend(a,JSON.parse(l.substring(f,m))),l=l.substring(0,c)}catch(p){}}}var b=x(l,a);n=n.replace(i,b)}return n}function g(n){return n.context&&"string"==typeof n.context}function d(n){return void 0!==n.count&&"string"!=typeof n.count&&1!==n.count}function h(n,e){e=e||{};var r=e.defaultValue||n,t=y(n,e);return void 0!==t||t===r}function N(){return T=0,x.apply(null,arguments)}function v(){for(var n=[],e=1;arguments.length>e;e++)n.push(arguments[e]);return{postProcess:"sprintf",sprintf:n}}function x(n,e){e="string"==typeof e?v.apply(null,arguments):e||{};var r=e.defaultValue||n,t=y(n,e),u=e.lng?E.toLanguages(e.lng):P,a=e.ns||A.ns.defaultNs;if(n.indexOf(A.nsseparator)>-1){var s=n.split(A.nsseparator);a=s[0],n=s[1]}void 0===t&&A.sendMissing&&(e.lng?F.postMissing(u[0],a,n,r,u):F.postMissing(A.lng,a,n,r,u));var o=e.postProcess||A.postProcess;return void 0!==t&&o&&z[o]&&(t=z[o](t,n,e)),void 0===t&&(r=p(r,e),r=b(r,e),o&&z[o]&&(t=z[o](t,n,e))),void 0!==t?t:r}function y(n,e){e=e||{};var r,t,u=e.defaultValue||n,a=P;if(!j)return u;if(e.lng&&(a=E.toLanguages(e.lng),!j[a[0]])){var s=A.getAsync;A.getAsync=!1,w.sync.load(a,A,function(n,e){E.extend(j,e),A.getAsync=s})}var o=e.ns||A.ns.defaultNs;if(n.indexOf(A.nsseparator)>-1){var i=n.split(A.nsseparator);o=i[0],n=i[1]}if(g(e)){r=E.extend({},e),delete r.context,r.defaultValue=A.contextNotFound;var l=o+A.nsseparator+n+"_"+e.context;if(t=N(l,r),t!=A.contextNotFound)return p(t,{context:e.context})}if(d(e)){r=E.extend({},e),delete r.count,r.defaultValue=A.pluralNotFound;var c=o+A.nsseparator+n+A.pluralSuffix,f=R.get(S,e.count);if(f>=0?c=c+"_"+f:1===f&&(c=o+A.nsseparator+n),t=N(c,r),t!=A.pluralNotFound)return p(t,{count:e.count,interpolationPrefix:e.interpolationPrefix,interpolationSuffix:e.interpolationSuffix})}for(var m,h=n.split(A.keyseparator),v=0,k=a.length;k>v&&void 0===m;v++){for(var O=a[v],L=0,T=j[O]&&j[O][o];h[L];)T=T&&T[h[L]],L++;if(void 0!==T){if("string"==typeof T)T=p(T,e),T=b(T,e);else if("[object Array]"!==Object.prototype.toString.apply(T)||A.returnObjectTrees||e.returnObjectTrees){if(null===T&&A.fallbackOnNull===!0)T=void 0;else if(null!==T)if(A.returnObjectTrees||e.returnObjectTrees){var C={};for(var _ in T)C[_]=x(o+A.nsseparator+n+A.keyseparator+_,e);T=C}else T="key '"+o+":"+n+" ("+O+")' "+"returned a object instead of string.",E.log(T)}else T=T.join("\n"),T=p(T,e),T=b(T,e);m=T}}if(void 0===m&&!e.isFallbackLookup&&(A.fallbackToDefaultNS===!0||A.fallbackNS&&A.fallbackNS.length))if(e.isFallbackLookup=!0,A.fallbackNS.length){for(var M=0,F=A.fallbackNS.length;F>M;M++)if(m=y(A.fallbackNS[M]+A.nsseparator+n,e)){var z=m.indexOf(A.nsseparator)>-1?m.split(A.nsseparator)[1]:m,D=u.indexOf(A.nsseparator)>-1?u.split(A.nsseparator)[1]:u;if(z!==D)break}}else m=y(n,e);return m}function k(){var n,e=[];if("undefined"!=typeof window&&(function(){for(var n=window.location.search.substring(1),r=n.split("&"),t=0;r.length>t;t++){var u=r[t].indexOf("=");if(u>0){var a=r[t].substring(0,u),s=r[t].substring(u+1);e[a]=s}}}(),e[A.detectLngQS]&&(n=e[A.detectLngQS])),!n&&"undefined"!=typeof document&&A.useCookie){var r=E.cookie.read(A.cookieName);r&&(n=r)}return n||"undefined"==typeof navigator||(n=navigator.language?navigator.language:navigator.userLanguage),n}Array.prototype.indexOf||(Array.prototype.indexOf=function(n){"use strict";if(null==this)throw new TypeError;var e=Object(this),r=e.length>>>0;if(0===r)return-1;var t=0;if(arguments.length>0&&(t=Number(arguments[1]),t!=t?t=0:0!=t&&1/0!=t&&t!=-1/0&&(t=(t>0||-1)*Math.floor(Math.abs(t)))),t>=r)return-1;for(var u=t>=0?t:Math.max(r-Math.abs(t),0);r>u;u++)if(u in e&&e[u]===n)return u;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(n){"use strict";if(null==this)throw new TypeError;var e=Object(this),r=e.length>>>0;if(0===r)return-1;var t=r;arguments.length>1&&(t=Number(arguments[1]),t!=t?t=0:0!=t&&t!=1/0&&t!=-(1/0)&&(t=(t>0||-1)*Math.floor(Math.abs(t))));for(var u=t>=0?Math.min(t,r-1):r-Math.abs(t);u>=0;u--)if(u in e&&e[u]===n)return u;return-1});var S,O=this,L=O.jQuery||O.Zepto,w={},j={},T=0,P=[];"undefined"!=typeof module&&module.exports?module.exports=w:(L&&(L.i18n=L.i18n||w),O.i18n=O.i18n||w);var A={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:"dev",fallbackNS:[],detectLngQS:"setLng",ns:"translation",fallbackOnNull:!0,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",postProcess:void 0},C={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},_={create:function(n,e,r){var t;if(r){var u=new Date;u.setTime(u.getTime()+1e3*60*r),t="; expires="+u.toGMTString()}else t="";document.cookie=n+"="+e+t+"; path=/"},read:function(n){for(var e=n+"=",r=document.cookie.split(";"),t=0;r.length>t;t++){for(var u=r[t];" "==u.charAt(0);)u=u.substring(1,u.length);if(0===u.indexOf(e))return u.substring(e.length,u.length)}return null},remove:function(n){this.create(n,"",-1)}},M={create:function(){},read:function(){return null},remove:function(){}},E={extend:L?L.extend:n,each:L?L.each:e,ajax:L?L.ajax:t,cookie:"undefined"!=typeof document?_:M,detectLanguage:k,escape:r,log:function(n){A.debug&&"undefined"!=typeof console&&console.log(n)},toLanguages:function(n){var e=[];if("string"==typeof n&&n.indexOf("-")>-1){var r=n.split("-");n=A.lowerCaseLng?r[0].toLowerCase()+"-"+r[1].toLowerCase():r[0].toLowerCase()+"-"+r[1].toUpperCase(),"unspecific"!==A.load&&e.push(n),"current"!==A.load&&e.push(r[0])}else e.push(n);return-1===e.indexOf(A.fallbackLng)&&A.fallbackLng&&e.push(A.fallbackLng),e},regexEscape:function(n){return n.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}};E.applyReplacement=p;var F={load:function(n,e,r){e.useLocalStorage?F._loadLocal(n,e,function(t,u){for(var a=[],s=0,o=n.length;o>s;s++)u[n[s]]||a.push(n[s]);a.length>0?F._fetch(a,e,function(n,e){E.extend(u,e),F._storeLocal(e),r(null,u)}):r(null,u)}):F._fetch(n,e,function(n,e){r(null,e)})},_loadLocal:function(n,e,r){var t={},u=(new Date).getTime();if(window.localStorage){var a=n.length;E.each(n,function(n,s){var o=window.localStorage.getItem("res_"+s);o&&(o=JSON.parse(o),o.i18nStamp&&o.i18nStamp+e.localStorageExpirationTime>u&&(t[s]=o)),a--,0===a&&r(null,t)})}},_storeLocal:function(n){if(window.localStorage)for(var e in n)n[e].i18nStamp=(new Date).getTime(),window.localStorage.setItem("res_"+e,JSON.stringify(n[e]))},_fetch:function(n,e,r){var t=e.ns,u={};if(e.dynamicLoad){var a=function(n,e){r(null,e)};if("function"==typeof e.customLoad)e.customLoad(n,t.namespaces,e,a);else{var s=p(e.resGetPath,{lng:n.join("+"),ns:t.namespaces.join("+")});E.ajax({url:s,success:function(n){E.log("loaded: "+s),a(null,n)},error:function(n,e,r){E.log("failed loading: "+s),a("failed loading resource.json error: "+r)},dataType:"json",async:e.getAsync})}}else{var o,i=t.namespaces.length*n.length;E.each(t.namespaces,function(t,a){E.each(n,function(n,t){var s=function(n,e){n&&(o=o||[],o.push(n)),u[t]=u[t]||{},u[t][a]=e,i--,0===i&&r(o,u)};"function"==typeof e.customLoad?e.customLoad(t,a,e,s):F._fetchOne(t,a,e,s)})})}},_fetchOne:function(n,e,r,t){var u=p(r.resGetPath,{lng:n,ns:e});E.ajax({url:u,success:function(n){E.log("loaded: "+u),t(null,n)},error:function(n,e,r){E.log("failed loading: "+u),t(r,{})},dataType:"json",async:r.getAsync})},postMissing:function(n,e,r,t,u){var a={};a[r]=t;var s=[];if("fallback"===A.sendMissingTo)s.push({lng:A.fallbackLng,url:p(A.resPostPath,{lng:A.fallbackLng,ns:e})});else if("current"===A.sendMissingTo)s.push({lng:n,url:p(A.resPostPath,{lng:n,ns:e})});else if("all"===A.sendMissingTo)for(var o=0,i=u.length;i>o;o++)s.push({lng:u[o],url:p(A.resPostPath,{lng:u[o],ns:e})});for(var l=0,c=s.length;c>l;l++){var f=s[l];E.ajax({url:f.url,type:A.sendType,data:a,success:function(){E.log("posted missing key '"+r+"' to: "+f.url);for(var n=r.split("."),u=0,a=j[f.lng][e];n[u];)a=a[n[u]]=u===n.length-1?t:a[n[u]]||{},u++},error:function(){E.log("failed posting missing key '"+r+"' to: "+f.url)},dataType:"json",async:A.postAsync})}}},R={rules:{ach:{name:"Acholi",numbers:[1,2],plurals:function(n){return Number(n>1)}},af:{name:"Afrikaans",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ak:{name:"Akan",numbers:[1,2],plurals:function(n){return Number(n>1)}},am:{name:"Amharic",numbers:[1,2],plurals:function(n){return Number(n>1)}},an:{name:"Aragonese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ar:{name:"Arabic",numbers:[0,1,2,3,11,100],plurals:function(n){return Number(0===n?0:1==n?1:2==n?2:n%100>=3&&10>=n%100?3:n%100>=11?4:5)}},arn:{name:"Mapudungun",numbers:[1,2],plurals:function(n){return Number(n>1)}},ast:{name:"Asturian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ay:{name:"Aymará",numbers:[1],plurals:function(){return 0}},az:{name:"Azerbaijani",numbers:[1,2],plurals:function(n){return Number(1!=n)}},be:{name:"Belarusian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},bg:{name:"Bulgarian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},bn:{name:"Bengali",numbers:[1,2],plurals:function(n){return Number(1!=n)}},bo:{name:"Tibetan",numbers:[1],plurals:function(){return 0}},br:{name:"Breton",numbers:[1,2],plurals:function(n){return Number(n>1)}},bs:{name:"Bosnian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},ca:{name:"Catalan",numbers:[1,2],plurals:function(n){return Number(1!=n)}},cgg:{name:"Chiga",numbers:[1],plurals:function(){return 0}},cs:{name:"Czech",numbers:[1,2,5],plurals:function(n){return Number(1==n?0:n>=2&&4>=n?1:2)}},csb:{name:"Kashubian",numbers:[1,2,5],plurals:function(n){return Number(1==n?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},cy:{name:"Welsh",numbers:[1,2,3,8],plurals:function(n){return Number(1==n?0:2==n?1:8!=n&&11!=n?2:3)}},da:{name:"Danish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},de:{name:"German",numbers:[1,2],plurals:function(n){return Number(1!=n)}},dz:{name:"Dzongkha",numbers:[1],plurals:function(){return 0}},el:{name:"Greek",numbers:[1,2],plurals:function(n){return Number(1!=n)}},en:{name:"English",numbers:[1,2],plurals:function(n){return Number(1!=n)}},eo:{name:"Esperanto",numbers:[1,2],plurals:function(n){return Number(1!=n)}},es:{name:"Spanish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},es_ar:{name:"Argentinean Spanish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},et:{name:"Estonian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},eu:{name:"Basque",numbers:[1,2],plurals:function(n){return Number(1!=n)}},fa:{name:"Persian",numbers:[1],plurals:function(){return 0}},fi:{name:"Finnish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},fil:{name:"Filipino",numbers:[1,2],plurals:function(n){return Number(n>1)}},fo:{name:"Faroese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},fr:{name:"French",numbers:[1,2],plurals:function(n){return Number(n>1)}},fur:{name:"Friulian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},fy:{name:"Frisian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ga:{name:"Irish",numbers:[1,2,3,7,11],plurals:function(n){return Number(1==n?0:2==n?1:7>n?2:11>n?3:4)}},gd:{name:"Scottish Gaelic",numbers:[1,2,3,20],plurals:function(n){return Number(1==n||11==n?0:2==n||12==n?1:n>2&&20>n?2:3)}},gl:{name:"Galician",numbers:[1,2],plurals:function(n){return Number(1!=n)}},gu:{name:"Gujarati",numbers:[1,2],plurals:function(n){return Number(1!=n)}},gun:{name:"Gun",numbers:[1,2],plurals:function(n){return Number(n>1)}},ha:{name:"Hausa",numbers:[1,2],plurals:function(n){return Number(1!=n)}},he:{name:"Hebrew",numbers:[1,2],plurals:function(n){return Number(1!=n)}},hi:{name:"Hindi",numbers:[1,2],plurals:function(n){return Number(1!=n)}},hr:{name:"Croatian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},hu:{name:"Hungarian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},hy:{name:"Armenian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ia:{name:"Interlingua",numbers:[1,2],plurals:function(n){return Number(1!=n)}},id:{name:"Indonesian",numbers:[1],plurals:function(){return 0}},is:{name:"Icelandic",numbers:[1,2],plurals:function(n){return Number(1!=n%10||11==n%100)}},it:{name:"Italian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ja:{name:"Japanese",numbers:[1],plurals:function(){return 0}},jbo:{name:"Lojban",numbers:[1],plurals:function(){return 0}},jv:{name:"Javanese",numbers:[0,1],plurals:function(n){return Number(0!==n)}},ka:{name:"Georgian",numbers:[1],plurals:function(){return 0}},kk:{name:"Kazakh",numbers:[1],plurals:function(){return 0}},km:{name:"Khmer",numbers:[1],plurals:function(){return 0}},kn:{name:"Kannada",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ko:{name:"Korean",numbers:[1],plurals:function(){return 0}},ku:{name:"Kurdish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},kw:{name:"Cornish",numbers:[1,2,3,4],plurals:function(n){return Number(1==n?0:2==n?1:3==n?2:3)}},ky:{name:"Kyrgyz",numbers:[1],plurals:function(){return 0}},lb:{name:"Letzeburgesch",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ln:{name:"Lingala",numbers:[1,2],plurals:function(n){return Number(n>1)}},lo:{name:"Lao",numbers:[1],plurals:function(){return 0}},lt:{name:"Lithuanian",numbers:[1,2,10],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&(10>n%100||n%100>=20)?1:2)}},lv:{name:"Latvian",numbers:[0,1,2],plurals:function(n){return Number(1==n%10&&11!=n%100?0:0!==n?1:2)}},mai:{name:"Maithili",numbers:[1,2],plurals:function(n){return Number(1!=n)}},mfe:{name:"Mauritian Creole",numbers:[1,2],plurals:function(n){return Number(n>1)}},mg:{name:"Malagasy",numbers:[1,2],plurals:function(n){return Number(n>1)}},mi:{name:"Maori",numbers:[1,2],plurals:function(n){return Number(n>1)}},mk:{name:"Macedonian",numbers:[1,2],plurals:function(n){return Number(1==n||1==n%10?0:1)}},ml:{name:"Malayalam",numbers:[1,2],plurals:function(n){return Number(1!=n)}},mn:{name:"Mongolian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},mnk:{name:"Mandinka",numbers:[0,1,2],plurals:function(n){return Number(1==n?1:2)}},mr:{name:"Marathi",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ms:{name:"Malay",numbers:[1],plurals:function(){return 0}},mt:{name:"Maltese",numbers:[1,2,11,20],plurals:function(n){return Number(1==n?0:0===n||n%100>1&&11>n%100?1:n%100>10&&20>n%100?2:3)}},nah:{name:"Nahuatl",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nap:{name:"Neapolitan",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nb:{name:"Norwegian Bokmal",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ne:{name:"Nepali",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nl:{name:"Dutch",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nn:{name:"Norwegian Nynorsk",numbers:[1,2],plurals:function(n){return Number(1!=n)}},no:{name:"Norwegian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nso:{name:"Northern Sotho",numbers:[1,2],plurals:function(n){return Number(1!=n)}},oc:{name:"Occitan",numbers:[1,2],plurals:function(n){return Number(n>1)}},or:{name:"Oriya",numbers:[2,1],plurals:function(n){return Number(1!=n)}},pa:{name:"Punjabi",numbers:[1,2],plurals:function(n){return Number(1!=n)}},pap:{name:"Papiamento",numbers:[1,2],plurals:function(n){return Number(1!=n)}},pl:{name:"Polish",numbers:[1,2,5],plurals:function(n){return Number(1==n?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},pms:{name:"Piemontese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ps:{name:"Pashto",numbers:[1,2],plurals:function(n){return Number(1!=n)}},pt:{name:"Portuguese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},pt_br:{name:"Brazilian Portuguese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},rm:{name:"Romansh",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ro:{name:"Romanian",numbers:[1,2,20],plurals:function(n){return Number(1==n?0:0===n||n%100>0&&20>n%100?1:2)}},ru:{name:"Russian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},sah:{name:"Yakut",numbers:[1],plurals:function(){return 0}},sco:{name:"Scots",numbers:[1,2],plurals:function(n){return Number(1!=n)}},se:{name:"Northern Sami",numbers:[1,2],plurals:function(n){return Number(1!=n)}},si:{name:"Sinhala",numbers:[1,2],plurals:function(n){return Number(1!=n)}},sk:{name:"Slovak",numbers:[1,2,5],plurals:function(n){return Number(1==n?0:n>=2&&4>=n?1:2)}},sl:{name:"Slovenian",numbers:[5,1,2,3],plurals:function(n){return Number(1==n%100?1:2==n%100?2:3==n%100||4==n%100?3:0)}},so:{name:"Somali",numbers:[1,2],plurals:function(n){return Number(1!=n)}},son:{name:"Songhay",numbers:[1,2],plurals:function(n){return Number(1!=n)}},sq:{name:"Albanian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},sr:{name:"Serbian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},su:{name:"Sundanese",numbers:[1],plurals:function(){return 0}},sv:{name:"Swedish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},sw:{name:"Swahili",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ta:{name:"Tamil",numbers:[1,2],plurals:function(n){return Number(1!=n)}},te:{name:"Telugu",numbers:[1,2],plurals:function(n){return Number(1!=n)}},tg:{name:"Tajik",numbers:[1,2],plurals:function(n){return Number(n>1)}},th:{name:"Thai",numbers:[1],plurals:function(){return 0}},ti:{name:"Tigrinya",numbers:[1,2],plurals:function(n){return Number(n>1)}},tk:{name:"Turkmen",numbers:[1,2],plurals:function(n){return Number(1!=n)}},tr:{name:"Turkish",numbers:[1,2],plurals:function(n){return Number(n>1)}},tt:{name:"Tatar",numbers:[1],plurals:function(){return 0}},ug:{name:"Uyghur",numbers:[1],plurals:function(){return 0}},uk:{name:"Ukrainian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},ur:{name:"Urdu",numbers:[1,2],plurals:function(n){return Number(1!=n)}},uz:{name:"Uzbek",numbers:[1,2],plurals:function(n){return Number(n>1)}},vi:{name:"Vietnamese",numbers:[1],plurals:function(){return 0}},wa:{name:"Walloon",numbers:[1,2],plurals:function(n){return Number(n>1)}},wo:{name:"Wolof",numbers:[1],plurals:function(){return 0}},yo:{name:"Yoruba",numbers:[1,2],plurals:function(n){return Number(1!=n)}},zh:{name:"Chinese",numbers:[1],plurals:function(){return 0}}},addRule:function(n,e){R.rules[n]=e},setCurrentLng:function(n){if(!R.currentRule||R.currentRule.lng!==n){var e=n.split("-");R.currentRule={lng:n,rule:R.rules[e[0]]}}},get:function(n,e){function r(e,r){var t;if(t=R.currentRule&&R.currentRule.lng===n?R.currentRule.rule:R.rules[e]){var u=t.plurals(r),a=t.numbers[u];return 2===t.numbers.length&&1===t.numbers[0]&&(2===a?a=-1:1===a&&(a=1)),a}return 1===r?"1":"-1"}var t=n.split("-");return r(t[0],e)}},z={},D=function(n,e){z[n]=e},I=function(){function n(n){return Object.prototype.toString.call(n).slice(8,-1).toLowerCase()}function e(n,e){for(var r=[];e>0;r[--e]=n);return r.join("")}var r=function(){return r.cache.hasOwnProperty(arguments[0])||(r.cache[arguments[0]]=r.parse(arguments[0])),r.format.call(null,r.cache[arguments[0]],arguments)};return r.format=function(r,t){var u,a,s,o,i,l,c,f=1,m=r.length,p="",b=[];for(a=0;m>a;a++)if(p=n(r[a]),"string"===p)b.push(r[a]);else if("array"===p){if(o=r[a],o[2])for(u=t[f],s=0;o[2].length>s;s++){if(!u.hasOwnProperty(o[2][s]))throw I('[sprintf] property "%s" does not exist',o[2][s]);u=u[o[2][s]]}else u=o[1]?t[o[1]]:t[f++];if(/[^s]/.test(o[8])&&"number"!=n(u))throw I("[sprintf] expecting number but found %s",n(u));switch(o[8]){case"b":u=u.toString(2);break;case"c":u=String.fromCharCode(u);break;case"d":u=parseInt(u,10);break;case"e":u=o[7]?u.toExponential(o[7]):u.toExponential();break;case"f":u=o[7]?parseFloat(u).toFixed(o[7]):parseFloat(u);break;case"o":u=u.toString(8);break;case"s":u=(u+="")&&o[7]?u.substring(0,o[7]):u;break;case"u":u=Math.abs(u);break;case"x":u=u.toString(16);break;case"X":u=u.toString(16).toUpperCase()}u=/[def]/.test(o[8])&&o[3]&&u>=0?"+"+u:u,l=o[4]?"0"==o[4]?"0":o[4].charAt(1):" ",c=o[6]-(u+"").length,i=o[6]?e(l,c):"",b.push(o[5]?u+i:i+u)}return b.join("")},r.cache={},r.parse=function(n){for(var e=n,r=[],t=[],u=0;e;){if(null!==(r=/^[^\x25]+/.exec(e)))t.push(r[0]);else if(null!==(r=/^\x25{2}/.exec(e)))t.push("%");else{if(null===(r=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(e)))throw"[sprintf] huh?";if(r[2]){u|=1;var a=[],s=r[2],o=[];if(null===(o=/^([a-z_][a-z_\d]*)/i.exec(s)))throw"[sprintf] huh?";for(a.push(o[1]);""!==(s=s.substring(o[0].length));)if(null!==(o=/^\.([a-z_][a-z_\d]*)/i.exec(s)))a.push(o[1]);else{if(null===(o=/^\[(\d+)\]/.exec(s)))throw"[sprintf] huh?";a.push(o[1])}r[2]=a}else u|=2;if(3===u)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";t.push(r)}e=e.substring(r[0].length)}return t},r}(),G=function(n,e){return e.unshift(n),I.apply(null,e)};D("sprintf",function(n,e,r){return r.sprintf?"[object Array]"===Object.prototype.toString.apply(r.sprintf)?G(n,r.sprintf):"object"==typeof r.sprintf?I(n,r.sprintf):n:n}),w.init=u,w.setLng=c,w.preload=a,w.addResourceBundle=s,w.loadNamespace=i,w.loadNamespaces=l,w.setDefaultNamespace=o,w.t=N,w.translate=N,w.exists=h,w.detectLanguage=E.detectLanguage,w.pluralExtensions=R,w.sync=F,w.functions=E,w.lng=f,w.addPostProcessor=D,w.options=A})(); \ No newline at end of file diff --git a/libs/i18next/release/i18next-1.6.2.zip b/libs/i18next/release/i18next-1.6.2.zip new file mode 100644 index 00000000..26f177fb Binary files /dev/null and b/libs/i18next/release/i18next-1.6.2.zip differ diff --git a/libs/i18next/release/i18next-1.6.3.js b/libs/i18next/release/i18next-1.6.3.js new file mode 100644 index 00000000..c80e8699 --- /dev/null +++ b/libs/i18next/release/i18next-1.6.3.js @@ -0,0 +1,2613 @@ +// i18next, v1.6.3 +// Copyright (c)2013 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function() { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + var root = this + , $ = root.jQuery || root.Zepto + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = []; + + + // Export the i18next object for **CommonJS**. + // If we're not in CommonJS, add `i18n` to the + // global object or to jquery. + if (typeof module !== 'undefined' && module.exports) { + module.exports = i18n; + } else { + if ($) { + $.i18n = $.i18n || i18n; + } + + root.i18n = root.i18n || i18n; + } + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: 'dev', + fallbackNS: [], + detectLngQS: 'setLng', + ns: 'translation', + fallbackOnNull: true, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + + postProcess: undefined, + parseMissingKey: undefined + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + return JSON.parse(data); + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + if (status === 200) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + document.cookie = name+"="+value+expires+"; path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : _ajax, + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + toLanguages: function(lng) { + var languages = []; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + + if (o.load !== 'unspecific') languages.push(lng); + if (o.load !== 'current') languages.push(parts[0]); + } else { + languages.push(lng); + } + + if (languages.indexOf(o.fallbackLng) === -1 && o.fallbackLng) languages.push(o.fallbackLng); + + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + if (o.lng) { + // set cookie with lng set (as detectLanguage will set cookie on need) + if (o.useCookie) f.cookie.create(o.cookieName, o.lng, o.cookieExpirationTime); + } else { + o.lng = o.fallbackLng; + if (o.useCookie) f.cookie.remove(o.cookieName); + } + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + if (cb) cb(translate); + if (deferred) deferred.resolve(); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + + if (cb) cb(translate); + if (deferred) deferred.resolve(); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + f.extend(resStore[lng][ns], resources); + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, cb) { + return init({lng: lng}, cb); + } + + function lng() { + return currentLng; + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } + else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + f.each(replacementHash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), value); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.escape(value)); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), value); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, translated_token); + } + return translated; + } + + function hasContext(options) { + return (options.context && typeof options.context == 'string'); + } + + function needsPlural(options) { + return (options.count !== undefined && typeof options.count != 'string' && options.count !== 1); + } + + function exists(key, options) { + options = options || {}; + + var notFound = options.defaultValue || key + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(key, options) { + + if (typeof options == 'string') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else { + options = options || {}; + } + + var notFound = options.defaultValue || key + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng) : languages + , ns = options.ns || o.ns.defaultNs + , parts; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing) { + if (options.lng) { + sync.postMissing(lngs[0], ns, key, notFound, lngs); + } else { + sync.postMissing(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found !== undefined && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + // process notFound if function exists + var splitNotFound = notFound; + if (notFound.indexOf(o.nsseparator) > -1) { + parts = notFound.split(o.nsseparator); + splitNotFound = parts[1]; + } + if (splitNotFound === key && o.parseMissingKey) { + notFound = o.parseMissingKey(notFound); + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessor && postProcessors[postProcessor]) { + var val = options.defaultValue || key; + found = postProcessors[postProcessor](val, key, options); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options){ + options = options || {}; + + var optionWithoutCount, translated + , notFound = options.defaultValue || key + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + if (options.lng) { + lngs = f.toLanguages(options.lng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.count; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(lngs[0], options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + + translated = translate(pluralKey, optionWithoutCount); + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } // else continue translation with original/singular key + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (Object.prototype.toString.apply(value) === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned a object instead of string.'; + f.log(value); + } else { + var copy = {}; // apply child translation on a copy + for (var m in value) { + // apply translation on childs + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + } + value = copy; + } + } + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length > 0))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + } + + return found; + } + function detectLanguage() { + var detectedLng; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var parms = query.split('&'); + for (var i=0; i 0) { + var key = parms[i].substring(0,pos); + var val = parms[i].substring(pos+1); + qsParm[key] = val; + } + } + })(); + if (qsParm[o.detectLngQS]) { + detectedLng = qsParm[o.detectLngQS]; + } + } + + // get from cookie + if (!detectedLng && typeof document !== 'undefined' && o.useCookie ) { + var c = f.cookie.read(o.cookieName); + if (c) detectedLng = c; + } + + // get from navigator + if (!detectedLng && typeof navigator !== 'undefined') { + detectedLng = (navigator.language) ? navigator.language : navigator.userLanguage; + } + + return detectedLng; + } + var sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + window.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback' && o.fallbackLng !== false) { + urls.push({lng: o.fallbackLng, url: applyReplacement(o.resPostPath, { lng: o.fallbackLng, ns: ns })}); + } else if (o.sendMissingTo === 'current' || (o.sendMissingTo === 'fallback' && o.fallbackLng === false) ) { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + } + }; + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + var pluralExtensions = { + + rules: { + "ach": { + "name": "Acholi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "af": { + "name": "Afrikaans", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ak": { + "name": "Akan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "am": { + "name": "Amharic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "an": { + "name": "Aragonese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ar": { + "name": "Arabic", + "numbers": [ + 0, + 1, + 2, + 3, + 11, + 100 + ], + "plurals": function(n) { return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5); } + }, + "arn": { + "name": "Mapudungun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ast": { + "name": "Asturian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ay": { + "name": "Aymar\u00e1", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "az": { + "name": "Azerbaijani", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "be": { + "name": "Belarusian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "bg": { + "name": "Bulgarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bn": { + "name": "Bengali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bo": { + "name": "Tibetan", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "br": { + "name": "Breton", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "bs": { + "name": "Bosnian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ca": { + "name": "Catalan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "cgg": { + "name": "Chiga", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "cs": { + "name": "Czech", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "csb": { + "name": "Kashubian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "cy": { + "name": "Welsh", + "numbers": [ + 1, + 2, + 3, + 8 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3); } + }, + "da": { + "name": "Danish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "de": { + "name": "German", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "dz": { + "name": "Dzongkha", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "el": { + "name": "Greek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "en": { + "name": "English", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eo": { + "name": "Esperanto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es": { + "name": "Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es_ar": { + "name": "Argentinean Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "et": { + "name": "Estonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eu": { + "name": "Basque", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fa": { + "name": "Persian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "fi": { + "name": "Finnish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fil": { + "name": "Filipino", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fo": { + "name": "Faroese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fr": { + "name": "French", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fur": { + "name": "Friulian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fy": { + "name": "Frisian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ga": { + "name": "Irish", + "numbers": [ + 1, + 2, + 3, + 7, + 11 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;} + }, + "gd": { + "name": "Scottish Gaelic", + "numbers": [ + 1, + 2, + 3, + 20 + ], + "plurals": function(n) { return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3); } + }, + "gl": { + "name": "Galician", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gu": { + "name": "Gujarati", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gun": { + "name": "Gun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ha": { + "name": "Hausa", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "he": { + "name": "Hebrew", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hi": { + "name": "Hindi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hr": { + "name": "Croatian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "hu": { + "name": "Hungarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hy": { + "name": "Armenian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ia": { + "name": "Interlingua", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "id": { + "name": "Indonesian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "is": { + "name": "Icelandic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n%10!=1 || n%100==11); } + }, + "it": { + "name": "Italian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ja": { + "name": "Japanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jbo": { + "name": "Lojban", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jv": { + "name": "Javanese", + "numbers": [ + 0, + 1 + ], + "plurals": function(n) { return Number(n !== 0); } + }, + "ka": { + "name": "Georgian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kk": { + "name": "Kazakh", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "km": { + "name": "Khmer", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kn": { + "name": "Kannada", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ko": { + "name": "Korean", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ku": { + "name": "Kurdish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "kw": { + "name": "Cornish", + "numbers": [ + 1, + 2, + 3, + 4 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3); } + }, + "ky": { + "name": "Kyrgyz", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lb": { + "name": "Letzeburgesch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ln": { + "name": "Lingala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "lo": { + "name": "Lao", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lt": { + "name": "Lithuanian", + "numbers": [ + 1, + 2, + 10 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "lv": { + "name": "Latvian", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2); } + }, + "mai": { + "name": "Maithili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mfe": { + "name": "Mauritian Creole", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mg": { + "name": "Malagasy", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mi": { + "name": "Maori", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mk": { + "name": "Macedonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 || n%10==1 ? 0 : 1); } + }, + "ml": { + "name": "Malayalam", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mn": { + "name": "Mongolian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mnk": { + "name": "Mandinka", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(0 ? 0 : n==1 ? 1 : 2); } + }, + "mr": { + "name": "Marathi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ms": { + "name": "Malay", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "mt": { + "name": "Maltese", + "numbers": [ + 1, + 2, + 11, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3); } + }, + "nah": { + "name": "Nahuatl", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nap": { + "name": "Neapolitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nb": { + "name": "Norwegian Bokmal", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ne": { + "name": "Nepali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nl": { + "name": "Dutch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nn": { + "name": "Norwegian Nynorsk", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "no": { + "name": "Norwegian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nso": { + "name": "Northern Sotho", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "oc": { + "name": "Occitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "or": { + "name": "Oriya", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pa": { + "name": "Punjabi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pap": { + "name": "Papiamento", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pl": { + "name": "Polish", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "pms": { + "name": "Piemontese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ps": { + "name": "Pashto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt": { + "name": "Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt_br": { + "name": "Brazilian Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "rm": { + "name": "Romansh", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ro": { + "name": "Romanian", + "numbers": [ + 1, + 2, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2); } + }, + "ru": { + "name": "Russian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "sah": { + "name": "Yakut", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sco": { + "name": "Scots", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "se": { + "name": "Northern Sami", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "si": { + "name": "Sinhala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sk": { + "name": "Slovak", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "sl": { + "name": "Slovenian", + "numbers": [ + 5, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }, + "so": { + "name": "Somali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "son": { + "name": "Songhay", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sq": { + "name": "Albanian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sr": { + "name": "Serbian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "su": { + "name": "Sundanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sv": { + "name": "Swedish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sw": { + "name": "Swahili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ta": { + "name": "Tamil", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "te": { + "name": "Telugu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tg": { + "name": "Tajik", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "th": { + "name": "Thai", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ti": { + "name": "Tigrinya", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tk": { + "name": "Turkmen", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tr": { + "name": "Turkish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tt": { + "name": "Tatar", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ug": { + "name": "Uyghur", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "uk": { + "name": "Ukrainian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ur": { + "name": "Urdu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "uz": { + "name": "Uzbek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "vi": { + "name": "Vietnamese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "wa": { + "name": "Walloon", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "wo": { + "name": "Wolof", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "yo": { + "name": "Yoruba", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "zh": { + "name": "Chinese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + } + }, + + // for demonstration only sl and ar is added but you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i = ext.plurals(c); + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[0], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + +})(); \ No newline at end of file diff --git a/libs/i18next/release/i18next-1.6.3.min.js b/libs/i18next/release/i18next-1.6.3.min.js new file mode 100644 index 00000000..de2143e5 --- /dev/null +++ b/libs/i18next/release/i18next-1.6.3.min.js @@ -0,0 +1,5 @@ +// i18next, v1.6.3 +// Copyright (c)2013 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function(){function n(n,e){if(!e||"function"==typeof e)return n;for(var r in e)n[r]=e[r];return n}function e(n,e,r){var t,u=0,a=n.length,s=void 0===a||"function"==typeof n;if(r)if(s){for(t in n)if(e.apply(n[t],r)===!1)break}else for(;a>u&&e.apply(n[u++],r)!==!1;);else if(s){for(t in n)if(e.call(n[t],t,n[t])===!1)break}else for(;a>u&&e.call(n[u],u,n[u++])!==!1;);return n}function r(n){return"string"==typeof n?n.replace(/[&<>"'\/]/g,function(n){return C[n]}):n}function t(n){var e=function(n){if(window.XMLHttpRequest)return n(null,new XMLHttpRequest);if(window.ActiveXObject)try{return n(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(e){return n(null,new ActiveXObject("Microsoft.XMLHTTP"))}return n(Error())},r=function(n){if("string"==typeof n)return n;var e=[];for(var r in n)n.hasOwnProperty(r)&&e.push(encodeURIComponent(r)+"="+encodeURIComponent(n[r]));return e.join("&")},t=function(n){n=n.replace(/\r\n/g,"\n");for(var e="",r=0;n.length>r;r++){var t=n.charCodeAt(r);128>t?e+=String.fromCharCode(t):t>127&&2048>t?(e+=String.fromCharCode(192|t>>6),e+=String.fromCharCode(128|63&t)):(e+=String.fromCharCode(224|t>>12),e+=String.fromCharCode(128|63&t>>6),e+=String.fromCharCode(128|63&t))}return e},u=function(n){var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";n=t(n);var r,u,a,s,o,i,l,c="",f=0;do r=n.charCodeAt(f++),u=n.charCodeAt(f++),a=n.charCodeAt(f++),s=r>>2,o=(3&r)<<4|u>>4,i=(15&u)<<2|a>>6,l=63&a,isNaN(u)?i=l=64:isNaN(a)&&(l=64),c+=e.charAt(s)+e.charAt(o)+e.charAt(i)+e.charAt(l),r=u=a="",s=o=i=l="";while(n.length>f);return c},a=function(){for(var n=arguments[0],e=1;arguments.length>e;e++){var r=arguments[e];for(var t in r)r.hasOwnProperty(t)&&(n[t]=r[t])}return n},s=function(n,t,u,o){"function"==typeof u&&(o=u,u={}),u.cache=u.cache||!1,u.data=u.data||{},u.headers=u.headers||{},u.jsonp=u.jsonp||!1,u.async=void 0===u.async?!0:u.async;var i,l=a({accept:"*/*","content-type":"application/x-www-form-urlencoded;charset=UTF-8"},s.headers,u.headers);if(i="application/json"===l["content-type"]?JSON.stringify(u.data):r(u.data),"GET"===n){var c=[];if(i&&(c.push(i),i=null),u.cache||c.push("_="+(new Date).getTime()),u.jsonp&&(c.push("callback="+u.jsonp),c.push("jsonp="+u.jsonp)),c=c.join("&"),c.length>1&&(t+=t.indexOf("?")>-1?"&"+c:"?"+c),u.jsonp){var f=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=t,f.appendChild(m),void 0}}e(function(e,r){if(e)return o(e);r.open(n,t,u.async);for(var a in l)l.hasOwnProperty(a)&&r.setRequestHeader(a,l[a]);r.onreadystatechange=function(){if(4===r.readyState){var n=r.responseText||"";if(!o)return;o(r.status,{text:function(){return n},json:function(){return JSON.parse(n)}})}},r.send(i)})},o={authBasic:function(n,e){s.headers.Authorization="Basic "+u(n+":"+e)},connect:function(n,e,r){return s("CONNECT",n,e,r)},del:function(n,e,r){return s("DELETE",n,e,r)},get:function(n,e,r){return s("GET",n,e,r)},head:function(n,e,r){return s("HEAD",n,e,r)},headers:function(n){s.headers=n||{}},isAllowed:function(n,e,r){this.options(n,function(n,t){r(-1!==t.text().indexOf(e))})},options:function(n,e,r){return s("OPTIONS",n,e,r)},patch:function(n,e,r){return s("PATCH",n,e,r)},post:function(n,e,r){return s("POST",n,e,r)},put:function(n,e,r){return s("PUT",n,e,r)},trace:function(n,e,r){return s("TRACE",n,e,r)}},i=n.type?n.type.toLowerCase():"get";o[i](n.url,n,function(e,r){200===e?n.success(r.json(),e,null):n.error(r.text(),e,null)})}function u(n,e){"function"==typeof n&&(e=n,n={}),n=n||{},E.extend(A,n),"string"==typeof A.ns&&(A.ns={namespaces:[A.ns],defaultNs:A.ns}),"string"==typeof A.fallbackNS&&(A.fallbackNS=[A.fallbackNS]),A.interpolationPrefixEscaped=E.regexEscape(A.interpolationPrefix),A.interpolationSuffixEscaped=E.regexEscape(A.interpolationSuffix),A.lng||(A.lng=E.detectLanguage()),A.lng?A.useCookie&&E.cookie.create(A.cookieName,A.lng,A.cookieExpirationTime):(A.lng=A.fallbackLng,A.useCookie&&E.cookie.remove(A.cookieName)),P=E.toLanguages(A.lng),S=P[0],E.log("currentLng set to: "+S),R.setCurrentLng(S),L&&A.setJqueryExt&&m();var r;if(L&&L.Deferred&&(r=L.Deferred()),!A.resStore){var t=E.toLanguages(A.lng);"string"==typeof A.preload&&(A.preload=[A.preload]);for(var u=0,a=A.preload.length;a>u;u++)for(var s=E.toLanguages(A.preload[u]),o=0,i=s.length;i>o;o++)0>t.indexOf(s[o])&&t.push(s[o]);return w.sync.load(t,A,function(n,t){j=t,e&&e(N),r&&r.resolve()}),r?r.promise():void 0}return j=A.resStore,e&&e(N),r&&r.resolve(),r?r.promise():void 0}function a(n,e){"string"==typeof n&&(n=[n]);for(var r=0,t=n.length;t>r;r++)0>A.preload.indexOf(n[r])&&A.preload.push(n[r]);return u(e)}function s(n,e,r){"string"!=typeof e?(r=e,e=A.ns.defaultNs):0>A.ns.namespaces.indexOf(e)&&A.ns.namespaces.push(e),j[n]=j[n]||{},j[n][e]=j[n][e]||{},E.extend(j[n][e],r)}function o(n){A.ns.defaultNs=n}function i(n,e){l([n],e)}function l(n,e){var r={dynamicLoad:A.dynamicLoad,resGetPath:A.resGetPath,getAsync:A.getAsync,customLoad:A.customLoad,ns:{namespaces:n,defaultNs:""}},t=E.toLanguages(A.lng);"string"==typeof A.preload&&(A.preload=[A.preload]);for(var u=0,a=A.preload.length;a>u;u++)for(var s=E.toLanguages(A.preload[u]),o=0,i=s.length;i>o;o++)0>t.indexOf(s[o])&&t.push(s[o]);for(var l=[],c=0,f=t.length;f>c;c++){var m=!1,p=j[t[c]];if(p)for(var b=0,g=n.length;g>b;b++)p[n[b]]||(m=!0);else m=!0;m&&l.push(t[c])}l.length?w.sync._fetch(l,r,function(r,t){var u=n.length*l.length;E.each(n,function(n,r){0>A.ns.namespaces.indexOf(r)&&A.ns.namespaces.push(r),E.each(l,function(n,a){j[a]=j[a]||{},j[a][r]=t[a][r],u--,0===u&&e&&(A.useLocalStorage&&w.sync._storeLocal(j),e())})})}):e&&e()}function c(n,e){return u({lng:n},e)}function f(){return S}function m(){function n(n,e,r){if(0!==e.length){var t="text";if(0===e.indexOf("[")){var u=e.split("]");e=u[1],t=u[0].substr(1,u[0].length-1)}e.indexOf(";")===e.length-1&&(e=e.substr(0,e.length-2));var a;"html"===t?(a=A.defaultValueFromContent?L.extend({defaultValue:n.html()},r):r,n.html(L.t(e,a))):"text"===t?(a=A.defaultValueFromContent?L.extend({defaultValue:n.text()},r):r,n.text(L.t(e,a))):(a=A.defaultValueFromContent?L.extend({defaultValue:n.attr(t)},r):r,n.attr(t,L.t(e,a)))}}function e(e,r){var t=e.attr(A.selectorAttr);if(t){var u=e,a=e.data("i18n-target");if(a&&(u=e.find(a)||e),r||A.useDataAttrOptions!==!0||(r=e.data("i18n-options")),r=r||{},t.indexOf(";")>=0){var s=t.split(";");L.each(s,function(e,t){""!==t&&n(u,t,r)})}else n(u,t,r);A.useDataAttrOptions===!0&&e.data("i18n-options",r)}}L.t=L.t||N,L.fn.i18n=function(n){return this.each(function(){e(L(this),n);var r=L(this).find("["+A.selectorAttr+"]");r.each(function(){e(L(this),n)})})}}function p(n,e,r,t){if(!n)return n;if(t=t||e,0>n.indexOf(t.interpolationPrefix||A.interpolationPrefix))return n;var u=t.interpolationPrefix?E.regexEscape(t.interpolationPrefix):A.interpolationPrefixEscaped,a=t.interpolationSuffix?E.regexEscape(t.interpolationSuffix):A.interpolationSuffixEscaped,s="HTML"+a;return E.each(e,function(e,o){var i=r?r+A.keyseparator+e:e;"object"==typeof o&&null!==o?n=p(n,o,i,t):t.escapeInterpolation||A.escapeInterpolation?(n=n.replace(RegExp([u,i,s].join(""),"g"),o),n=n.replace(RegExp([u,i,a].join(""),"g"),E.escape(o))):n=n.replace(RegExp([u,i,a].join(""),"g"),o)}),n}function b(n,e){var r=",",t="{",u="}",a=E.extend({},e);for(delete a.postProcess;-1!=n.indexOf(A.reusePrefix)&&(T++,!(T>A.maxRecursion));){var s=n.lastIndexOf(A.reusePrefix),o=n.indexOf(A.reuseSuffix,s)+A.reuseSuffix.length,i=n.substring(s,o),l=i.replace(A.reusePrefix,"").replace(A.reuseSuffix,"");if(-1!=l.indexOf(r)){var c=l.indexOf(r);if(-1!=l.indexOf(t,c)&&-1!=l.indexOf(u,c)){var f=l.indexOf(t,c),m=l.indexOf(u,f)+u.length;try{a=E.extend(a,JSON.parse(l.substring(f,m))),l=l.substring(0,c)}catch(p){}}}var b=x(l,a);n=n.replace(i,b)}return n}function g(n){return n.context&&"string"==typeof n.context}function d(n){return void 0!==n.count&&"string"!=typeof n.count&&1!==n.count}function h(n,e){e=e||{};var r=e.defaultValue||n,t=y(n,e);return void 0!==t||t===r}function N(){return T=0,x.apply(null,arguments)}function v(){for(var n=[],e=1;arguments.length>e;e++)n.push(arguments[e]);return{postProcess:"sprintf",sprintf:n}}function x(n,e){e="string"==typeof e?v.apply(null,arguments):e||{};var r,t=e.defaultValue||n,u=y(n,e),a=e.lng?E.toLanguages(e.lng):P,s=e.ns||A.ns.defaultNs;n.indexOf(A.nsseparator)>-1&&(r=n.split(A.nsseparator),s=r[0],n=r[1]),void 0===u&&A.sendMissing&&(e.lng?F.postMissing(a[0],s,n,t,a):F.postMissing(A.lng,s,n,t,a));var o=e.postProcess||A.postProcess;void 0!==u&&o&&z[o]&&(u=z[o](u,n,e));var i=t;if(t.indexOf(A.nsseparator)>-1&&(r=t.split(A.nsseparator),i=r[1]),i===n&&A.parseMissingKey&&(t=A.parseMissingKey(t)),void 0===u&&(t=p(t,e),t=b(t,e),o&&z[o])){var l=e.defaultValue||n;u=z[o](l,n,e)}return void 0!==u?u:t}function y(n,e){e=e||{};var r,t,u=e.defaultValue||n,a=P;if(!j)return u;if(e.lng&&(a=E.toLanguages(e.lng),!j[a[0]])){var s=A.getAsync;A.getAsync=!1,w.sync.load(a,A,function(n,e){E.extend(j,e),A.getAsync=s})}var o=e.ns||A.ns.defaultNs;if(n.indexOf(A.nsseparator)>-1){var i=n.split(A.nsseparator);o=i[0],n=i[1]}if(g(e)){r=E.extend({},e),delete r.context,r.defaultValue=A.contextNotFound;var l=o+A.nsseparator+n+"_"+e.context;if(t=N(l,r),t!=A.contextNotFound)return p(t,{context:e.context})}if(d(e)){r=E.extend({},e),delete r.count,r.defaultValue=A.pluralNotFound;var c=o+A.nsseparator+n+A.pluralSuffix,f=R.get(a[0],e.count);if(f>=0?c=c+"_"+f:1===f&&(c=o+A.nsseparator+n),t=N(c,r),t!=A.pluralNotFound)return p(t,{count:e.count,interpolationPrefix:e.interpolationPrefix,interpolationSuffix:e.interpolationSuffix})}for(var m,h=n.split(A.keyseparator),v=0,k=a.length;k>v&&void 0===m;v++){for(var S=a[v],O=0,L=j[S]&&j[S][o];h[O];)L=L&&L[h[O]],O++;if(void 0!==L){if("string"==typeof L)L=p(L,e),L=b(L,e);else if("[object Array]"!==Object.prototype.toString.apply(L)||A.returnObjectTrees||e.returnObjectTrees){if(null===L&&A.fallbackOnNull===!0)L=void 0;else if(null!==L)if(A.returnObjectTrees||e.returnObjectTrees){var T={};for(var C in L)T[C]=x(o+A.nsseparator+n+A.keyseparator+C,e);L=T}else L="key '"+o+":"+n+" ("+S+")' "+"returned a object instead of string.",E.log(L)}else L=L.join("\n"),L=p(L,e),L=b(L,e);m=L}}if(void 0===m&&!e.isFallbackLookup&&(A.fallbackToDefaultNS===!0||A.fallbackNS&&A.fallbackNS.length>0))if(e.isFallbackLookup=!0,A.fallbackNS.length){for(var _=0,M=A.fallbackNS.length;M>_;_++)if(m=y(A.fallbackNS[_]+A.nsseparator+n,e)){var F=m.indexOf(A.nsseparator)>-1?m.split(A.nsseparator)[1]:m,z=u.indexOf(A.nsseparator)>-1?u.split(A.nsseparator)[1]:u;if(F!==z)break}}else m=y(n,e);return m}function k(){var n,e=[];if("undefined"!=typeof window&&(function(){for(var n=window.location.search.substring(1),r=n.split("&"),t=0;r.length>t;t++){var u=r[t].indexOf("=");if(u>0){var a=r[t].substring(0,u),s=r[t].substring(u+1);e[a]=s}}}(),e[A.detectLngQS]&&(n=e[A.detectLngQS])),!n&&"undefined"!=typeof document&&A.useCookie){var r=E.cookie.read(A.cookieName);r&&(n=r)}return n||"undefined"==typeof navigator||(n=navigator.language?navigator.language:navigator.userLanguage),n}Array.prototype.indexOf||(Array.prototype.indexOf=function(n){"use strict";if(null==this)throw new TypeError;var e=Object(this),r=e.length>>>0;if(0===r)return-1;var t=0;if(arguments.length>0&&(t=Number(arguments[1]),t!=t?t=0:0!=t&&1/0!=t&&t!=-1/0&&(t=(t>0||-1)*Math.floor(Math.abs(t)))),t>=r)return-1;for(var u=t>=0?t:Math.max(r-Math.abs(t),0);r>u;u++)if(u in e&&e[u]===n)return u;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(n){"use strict";if(null==this)throw new TypeError;var e=Object(this),r=e.length>>>0;if(0===r)return-1;var t=r;arguments.length>1&&(t=Number(arguments[1]),t!=t?t=0:0!=t&&t!=1/0&&t!=-(1/0)&&(t=(t>0||-1)*Math.floor(Math.abs(t))));for(var u=t>=0?Math.min(t,r-1):r-Math.abs(t);u>=0;u--)if(u in e&&e[u]===n)return u;return-1});var S,O=this,L=O.jQuery||O.Zepto,w={},j={},T=0,P=[];"undefined"!=typeof module&&module.exports?module.exports=w:(L&&(L.i18n=L.i18n||w),O.i18n=O.i18n||w);var A={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:"dev",fallbackNS:[],detectLngQS:"setLng",ns:"translation",fallbackOnNull:!0,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",postProcess:void 0,parseMissingKey:void 0},C={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},_={create:function(n,e,r){var t;if(r){var u=new Date;u.setTime(u.getTime()+1e3*60*r),t="; expires="+u.toGMTString()}else t="";document.cookie=n+"="+e+t+"; path=/"},read:function(n){for(var e=n+"=",r=document.cookie.split(";"),t=0;r.length>t;t++){for(var u=r[t];" "==u.charAt(0);)u=u.substring(1,u.length);if(0===u.indexOf(e))return u.substring(e.length,u.length)}return null},remove:function(n){this.create(n,"",-1)}},M={create:function(){},read:function(){return null},remove:function(){}},E={extend:L?L.extend:n,each:L?L.each:e,ajax:L?L.ajax:t,cookie:"undefined"!=typeof document?_:M,detectLanguage:k,escape:r,log:function(n){A.debug&&"undefined"!=typeof console&&console.log(n)},toLanguages:function(n){var e=[];if("string"==typeof n&&n.indexOf("-")>-1){var r=n.split("-");n=A.lowerCaseLng?r[0].toLowerCase()+"-"+r[1].toLowerCase():r[0].toLowerCase()+"-"+r[1].toUpperCase(),"unspecific"!==A.load&&e.push(n),"current"!==A.load&&e.push(r[0])}else e.push(n);return-1===e.indexOf(A.fallbackLng)&&A.fallbackLng&&e.push(A.fallbackLng),e},regexEscape:function(n){return n.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}};E.applyReplacement=p;var F={load:function(n,e,r){e.useLocalStorage?F._loadLocal(n,e,function(t,u){for(var a=[],s=0,o=n.length;o>s;s++)u[n[s]]||a.push(n[s]);a.length>0?F._fetch(a,e,function(n,e){E.extend(u,e),F._storeLocal(e),r(null,u)}):r(null,u)}):F._fetch(n,e,function(n,e){r(null,e)})},_loadLocal:function(n,e,r){var t={},u=(new Date).getTime();if(window.localStorage){var a=n.length;E.each(n,function(n,s){var o=window.localStorage.getItem("res_"+s);o&&(o=JSON.parse(o),o.i18nStamp&&o.i18nStamp+e.localStorageExpirationTime>u&&(t[s]=o)),a--,0===a&&r(null,t)})}},_storeLocal:function(n){if(window.localStorage)for(var e in n)n[e].i18nStamp=(new Date).getTime(),window.localStorage.setItem("res_"+e,JSON.stringify(n[e]))},_fetch:function(n,e,r){var t=e.ns,u={};if(e.dynamicLoad){var a=function(n,e){r(null,e)};if("function"==typeof e.customLoad)e.customLoad(n,t.namespaces,e,a);else{var s=p(e.resGetPath,{lng:n.join("+"),ns:t.namespaces.join("+")});E.ajax({url:s,success:function(n){E.log("loaded: "+s),a(null,n)},error:function(n,e,r){E.log("failed loading: "+s),a("failed loading resource.json error: "+r)},dataType:"json",async:e.getAsync})}}else{var o,i=t.namespaces.length*n.length;E.each(t.namespaces,function(t,a){E.each(n,function(n,t){var s=function(n,e){n&&(o=o||[],o.push(n)),u[t]=u[t]||{},u[t][a]=e,i--,0===i&&r(o,u)};"function"==typeof e.customLoad?e.customLoad(t,a,e,s):F._fetchOne(t,a,e,s)})})}},_fetchOne:function(n,e,r,t){var u=p(r.resGetPath,{lng:n,ns:e});E.ajax({url:u,success:function(n){E.log("loaded: "+u),t(null,n)},error:function(n,e,r){E.log("failed loading: "+u),t(r,{})},dataType:"json",async:r.getAsync})},postMissing:function(n,e,r,t,u){var a={};a[r]=t;var s=[];if("fallback"===A.sendMissingTo&&A.fallbackLng!==!1)s.push({lng:A.fallbackLng,url:p(A.resPostPath,{lng:A.fallbackLng,ns:e})});else if("current"===A.sendMissingTo||"fallback"===A.sendMissingTo&&A.fallbackLng===!1)s.push({lng:n,url:p(A.resPostPath,{lng:n,ns:e})});else if("all"===A.sendMissingTo)for(var o=0,i=u.length;i>o;o++)s.push({lng:u[o],url:p(A.resPostPath,{lng:u[o],ns:e})});for(var l=0,c=s.length;c>l;l++){var f=s[l];E.ajax({url:f.url,type:A.sendType,data:a,success:function(){E.log("posted missing key '"+r+"' to: "+f.url);for(var n=r.split("."),u=0,a=j[f.lng][e];n[u];)a=a[n[u]]=u===n.length-1?t:a[n[u]]||{},u++},error:function(){E.log("failed posting missing key '"+r+"' to: "+f.url)},dataType:"json",async:A.postAsync})}}},R={rules:{ach:{name:"Acholi",numbers:[1,2],plurals:function(n){return Number(n>1)}},af:{name:"Afrikaans",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ak:{name:"Akan",numbers:[1,2],plurals:function(n){return Number(n>1)}},am:{name:"Amharic",numbers:[1,2],plurals:function(n){return Number(n>1)}},an:{name:"Aragonese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ar:{name:"Arabic",numbers:[0,1,2,3,11,100],plurals:function(n){return Number(0===n?0:1==n?1:2==n?2:n%100>=3&&10>=n%100?3:n%100>=11?4:5)}},arn:{name:"Mapudungun",numbers:[1,2],plurals:function(n){return Number(n>1)}},ast:{name:"Asturian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ay:{name:"Aymará",numbers:[1],plurals:function(){return 0}},az:{name:"Azerbaijani",numbers:[1,2],plurals:function(n){return Number(1!=n)}},be:{name:"Belarusian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},bg:{name:"Bulgarian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},bn:{name:"Bengali",numbers:[1,2],plurals:function(n){return Number(1!=n)}},bo:{name:"Tibetan",numbers:[1],plurals:function(){return 0}},br:{name:"Breton",numbers:[1,2],plurals:function(n){return Number(n>1)}},bs:{name:"Bosnian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},ca:{name:"Catalan",numbers:[1,2],plurals:function(n){return Number(1!=n)}},cgg:{name:"Chiga",numbers:[1],plurals:function(){return 0}},cs:{name:"Czech",numbers:[1,2,5],plurals:function(n){return Number(1==n?0:n>=2&&4>=n?1:2)}},csb:{name:"Kashubian",numbers:[1,2,5],plurals:function(n){return Number(1==n?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},cy:{name:"Welsh",numbers:[1,2,3,8],plurals:function(n){return Number(1==n?0:2==n?1:8!=n&&11!=n?2:3)}},da:{name:"Danish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},de:{name:"German",numbers:[1,2],plurals:function(n){return Number(1!=n)}},dz:{name:"Dzongkha",numbers:[1],plurals:function(){return 0}},el:{name:"Greek",numbers:[1,2],plurals:function(n){return Number(1!=n)}},en:{name:"English",numbers:[1,2],plurals:function(n){return Number(1!=n)}},eo:{name:"Esperanto",numbers:[1,2],plurals:function(n){return Number(1!=n)}},es:{name:"Spanish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},es_ar:{name:"Argentinean Spanish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},et:{name:"Estonian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},eu:{name:"Basque",numbers:[1,2],plurals:function(n){return Number(1!=n)}},fa:{name:"Persian",numbers:[1],plurals:function(){return 0}},fi:{name:"Finnish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},fil:{name:"Filipino",numbers:[1,2],plurals:function(n){return Number(n>1)}},fo:{name:"Faroese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},fr:{name:"French",numbers:[1,2],plurals:function(n){return Number(n>1)}},fur:{name:"Friulian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},fy:{name:"Frisian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ga:{name:"Irish",numbers:[1,2,3,7,11],plurals:function(n){return Number(1==n?0:2==n?1:7>n?2:11>n?3:4)}},gd:{name:"Scottish Gaelic",numbers:[1,2,3,20],plurals:function(n){return Number(1==n||11==n?0:2==n||12==n?1:n>2&&20>n?2:3)}},gl:{name:"Galician",numbers:[1,2],plurals:function(n){return Number(1!=n)}},gu:{name:"Gujarati",numbers:[1,2],plurals:function(n){return Number(1!=n)}},gun:{name:"Gun",numbers:[1,2],plurals:function(n){return Number(n>1)}},ha:{name:"Hausa",numbers:[1,2],plurals:function(n){return Number(1!=n)}},he:{name:"Hebrew",numbers:[1,2],plurals:function(n){return Number(1!=n)}},hi:{name:"Hindi",numbers:[1,2],plurals:function(n){return Number(1!=n)}},hr:{name:"Croatian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},hu:{name:"Hungarian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},hy:{name:"Armenian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ia:{name:"Interlingua",numbers:[1,2],plurals:function(n){return Number(1!=n)}},id:{name:"Indonesian",numbers:[1],plurals:function(){return 0}},is:{name:"Icelandic",numbers:[1,2],plurals:function(n){return Number(1!=n%10||11==n%100)}},it:{name:"Italian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ja:{name:"Japanese",numbers:[1],plurals:function(){return 0}},jbo:{name:"Lojban",numbers:[1],plurals:function(){return 0}},jv:{name:"Javanese",numbers:[0,1],plurals:function(n){return Number(0!==n)}},ka:{name:"Georgian",numbers:[1],plurals:function(){return 0}},kk:{name:"Kazakh",numbers:[1],plurals:function(){return 0}},km:{name:"Khmer",numbers:[1],plurals:function(){return 0}},kn:{name:"Kannada",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ko:{name:"Korean",numbers:[1],plurals:function(){return 0}},ku:{name:"Kurdish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},kw:{name:"Cornish",numbers:[1,2,3,4],plurals:function(n){return Number(1==n?0:2==n?1:3==n?2:3)}},ky:{name:"Kyrgyz",numbers:[1],plurals:function(){return 0}},lb:{name:"Letzeburgesch",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ln:{name:"Lingala",numbers:[1,2],plurals:function(n){return Number(n>1)}},lo:{name:"Lao",numbers:[1],plurals:function(){return 0}},lt:{name:"Lithuanian",numbers:[1,2,10],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&(10>n%100||n%100>=20)?1:2)}},lv:{name:"Latvian",numbers:[0,1,2],plurals:function(n){return Number(1==n%10&&11!=n%100?0:0!==n?1:2)}},mai:{name:"Maithili",numbers:[1,2],plurals:function(n){return Number(1!=n)}},mfe:{name:"Mauritian Creole",numbers:[1,2],plurals:function(n){return Number(n>1)}},mg:{name:"Malagasy",numbers:[1,2],plurals:function(n){return Number(n>1)}},mi:{name:"Maori",numbers:[1,2],plurals:function(n){return Number(n>1)}},mk:{name:"Macedonian",numbers:[1,2],plurals:function(n){return Number(1==n||1==n%10?0:1)}},ml:{name:"Malayalam",numbers:[1,2],plurals:function(n){return Number(1!=n)}},mn:{name:"Mongolian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},mnk:{name:"Mandinka",numbers:[0,1,2],plurals:function(n){return Number(1==n?1:2)}},mr:{name:"Marathi",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ms:{name:"Malay",numbers:[1],plurals:function(){return 0}},mt:{name:"Maltese",numbers:[1,2,11,20],plurals:function(n){return Number(1==n?0:0===n||n%100>1&&11>n%100?1:n%100>10&&20>n%100?2:3)}},nah:{name:"Nahuatl",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nap:{name:"Neapolitan",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nb:{name:"Norwegian Bokmal",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ne:{name:"Nepali",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nl:{name:"Dutch",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nn:{name:"Norwegian Nynorsk",numbers:[1,2],plurals:function(n){return Number(1!=n)}},no:{name:"Norwegian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nso:{name:"Northern Sotho",numbers:[1,2],plurals:function(n){return Number(1!=n)}},oc:{name:"Occitan",numbers:[1,2],plurals:function(n){return Number(n>1)}},or:{name:"Oriya",numbers:[2,1],plurals:function(n){return Number(1!=n)}},pa:{name:"Punjabi",numbers:[1,2],plurals:function(n){return Number(1!=n)}},pap:{name:"Papiamento",numbers:[1,2],plurals:function(n){return Number(1!=n)}},pl:{name:"Polish",numbers:[1,2,5],plurals:function(n){return Number(1==n?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},pms:{name:"Piemontese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ps:{name:"Pashto",numbers:[1,2],plurals:function(n){return Number(1!=n)}},pt:{name:"Portuguese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},pt_br:{name:"Brazilian Portuguese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},rm:{name:"Romansh",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ro:{name:"Romanian",numbers:[1,2,20],plurals:function(n){return Number(1==n?0:0===n||n%100>0&&20>n%100?1:2)}},ru:{name:"Russian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},sah:{name:"Yakut",numbers:[1],plurals:function(){return 0}},sco:{name:"Scots",numbers:[1,2],plurals:function(n){return Number(1!=n)}},se:{name:"Northern Sami",numbers:[1,2],plurals:function(n){return Number(1!=n)}},si:{name:"Sinhala",numbers:[1,2],plurals:function(n){return Number(1!=n)}},sk:{name:"Slovak",numbers:[1,2,5],plurals:function(n){return Number(1==n?0:n>=2&&4>=n?1:2)}},sl:{name:"Slovenian",numbers:[5,1,2,3],plurals:function(n){return Number(1==n%100?1:2==n%100?2:3==n%100||4==n%100?3:0)}},so:{name:"Somali",numbers:[1,2],plurals:function(n){return Number(1!=n)}},son:{name:"Songhay",numbers:[1,2],plurals:function(n){return Number(1!=n)}},sq:{name:"Albanian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},sr:{name:"Serbian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},su:{name:"Sundanese",numbers:[1],plurals:function(){return 0}},sv:{name:"Swedish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},sw:{name:"Swahili",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ta:{name:"Tamil",numbers:[1,2],plurals:function(n){return Number(1!=n)}},te:{name:"Telugu",numbers:[1,2],plurals:function(n){return Number(1!=n)}},tg:{name:"Tajik",numbers:[1,2],plurals:function(n){return Number(n>1)}},th:{name:"Thai",numbers:[1],plurals:function(){return 0}},ti:{name:"Tigrinya",numbers:[1,2],plurals:function(n){return Number(n>1)}},tk:{name:"Turkmen",numbers:[1,2],plurals:function(n){return Number(1!=n)}},tr:{name:"Turkish",numbers:[1,2],plurals:function(n){return Number(n>1)}},tt:{name:"Tatar",numbers:[1],plurals:function(){return 0}},ug:{name:"Uyghur",numbers:[1],plurals:function(){return 0}},uk:{name:"Ukrainian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},ur:{name:"Urdu",numbers:[1,2],plurals:function(n){return Number(1!=n)}},uz:{name:"Uzbek",numbers:[1,2],plurals:function(n){return Number(n>1)}},vi:{name:"Vietnamese",numbers:[1],plurals:function(){return 0}},wa:{name:"Walloon",numbers:[1,2],plurals:function(n){return Number(n>1)}},wo:{name:"Wolof",numbers:[1],plurals:function(){return 0}},yo:{name:"Yoruba",numbers:[1,2],plurals:function(n){return Number(1!=n)}},zh:{name:"Chinese",numbers:[1],plurals:function(){return 0}}},addRule:function(n,e){R.rules[n]=e},setCurrentLng:function(n){if(!R.currentRule||R.currentRule.lng!==n){var e=n.split("-");R.currentRule={lng:n,rule:R.rules[e[0]]}}},get:function(n,e){function r(e,r){var t;if(t=R.currentRule&&R.currentRule.lng===n?R.currentRule.rule:R.rules[e]){var u=t.plurals(r),a=t.numbers[u];return 2===t.numbers.length&&1===t.numbers[0]&&(2===a?a=-1:1===a&&(a=1)),a}return 1===r?"1":"-1"}var t=n.split("-");return r(t[0],e)}},z={},D=function(n,e){z[n]=e},I=function(){function n(n){return Object.prototype.toString.call(n).slice(8,-1).toLowerCase()}function e(n,e){for(var r=[];e>0;r[--e]=n);return r.join("")}var r=function(){return r.cache.hasOwnProperty(arguments[0])||(r.cache[arguments[0]]=r.parse(arguments[0])),r.format.call(null,r.cache[arguments[0]],arguments)};return r.format=function(r,t){var u,a,s,o,i,l,c,f=1,m=r.length,p="",b=[];for(a=0;m>a;a++)if(p=n(r[a]),"string"===p)b.push(r[a]);else if("array"===p){if(o=r[a],o[2])for(u=t[f],s=0;o[2].length>s;s++){if(!u.hasOwnProperty(o[2][s]))throw I('[sprintf] property "%s" does not exist',o[2][s]);u=u[o[2][s]]}else u=o[1]?t[o[1]]:t[f++];if(/[^s]/.test(o[8])&&"number"!=n(u))throw I("[sprintf] expecting number but found %s",n(u));switch(o[8]){case"b":u=u.toString(2);break;case"c":u=String.fromCharCode(u);break;case"d":u=parseInt(u,10);break;case"e":u=o[7]?u.toExponential(o[7]):u.toExponential();break;case"f":u=o[7]?parseFloat(u).toFixed(o[7]):parseFloat(u);break;case"o":u=u.toString(8);break;case"s":u=(u+="")&&o[7]?u.substring(0,o[7]):u;break;case"u":u=Math.abs(u);break;case"x":u=u.toString(16);break;case"X":u=u.toString(16).toUpperCase()}u=/[def]/.test(o[8])&&o[3]&&u>=0?"+"+u:u,l=o[4]?"0"==o[4]?"0":o[4].charAt(1):" ",c=o[6]-(u+"").length,i=o[6]?e(l,c):"",b.push(o[5]?u+i:i+u)}return b.join("")},r.cache={},r.parse=function(n){for(var e=n,r=[],t=[],u=0;e;){if(null!==(r=/^[^\x25]+/.exec(e)))t.push(r[0]);else if(null!==(r=/^\x25{2}/.exec(e)))t.push("%");else{if(null===(r=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(e)))throw"[sprintf] huh?";if(r[2]){u|=1;var a=[],s=r[2],o=[];if(null===(o=/^([a-z_][a-z_\d]*)/i.exec(s)))throw"[sprintf] huh?";for(a.push(o[1]);""!==(s=s.substring(o[0].length));)if(null!==(o=/^\.([a-z_][a-z_\d]*)/i.exec(s)))a.push(o[1]);else{if(null===(o=/^\[(\d+)\]/.exec(s)))throw"[sprintf] huh?";a.push(o[1])}r[2]=a}else u|=2;if(3===u)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";t.push(r)}e=e.substring(r[0].length)}return t},r}(),G=function(n,e){return e.unshift(n),I.apply(null,e)};D("sprintf",function(n,e,r){return r.sprintf?"[object Array]"===Object.prototype.toString.apply(r.sprintf)?G(n,r.sprintf):"object"==typeof r.sprintf?I(n,r.sprintf):n:n}),w.init=u,w.setLng=c,w.preload=a,w.addResourceBundle=s,w.loadNamespace=i,w.loadNamespaces=l,w.setDefaultNamespace=o,w.t=N,w.translate=N,w.exists=h,w.detectLanguage=E.detectLanguage,w.pluralExtensions=R,w.sync=F,w.functions=E,w.lng=f,w.addPostProcessor=D,w.options=A})(); \ No newline at end of file diff --git a/libs/i18next/release/i18next-1.6.3.zip b/libs/i18next/release/i18next-1.6.3.zip new file mode 100644 index 00000000..583641a8 Binary files /dev/null and b/libs/i18next/release/i18next-1.6.3.zip differ diff --git a/libs/i18next/release/i18next-1.7.0.js b/libs/i18next/release/i18next-1.7.0.js new file mode 100644 index 00000000..a0636df2 --- /dev/null +++ b/libs/i18next/release/i18next-1.7.0.js @@ -0,0 +1,2662 @@ +// i18next, v1.7.0 +// Copyright (c)2013 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function() { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + var root = this + , $ = root.jQuery || root.Zepto + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = [] + , initialized = false; + + + // Export the i18next object for **CommonJS**. + // If we're not in CommonJS, add `i18n` to the + // global object or to jquery. + if (typeof module !== 'undefined' && module.exports) { + module.exports = i18n; + } else { + if ($) { + $.i18n = $.i18n || i18n; + } + + root.i18n = root.i18n || i18n; + } + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: 'dev', + fallbackNS: [], + detectLngQS: 'setLng', + ns: 'translation', + fallbackOnNull: true, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + cookieDomain: undefined, + + postProcess: undefined, + parseMissingKey: undefined, + + shortcutFunction: 'sprintf' // or: defaultValue + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + return JSON.parse(data); + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + if (status === 200) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes,domain) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + domain = (domain)? "domain="+domain+";" : ""; + document.cookie = name+"="+value+expires+";"+domain+"path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes,domain) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : _ajax, + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + toLanguages: function(lng) { + var languages = []; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + + if (o.load !== 'unspecific') languages.push(lng); + if (o.load !== 'current') languages.push(parts[0]); + } else { + languages.push(lng); + } + + if (languages.indexOf(o.fallbackLng) === -1 && o.fallbackLng) languages.push(o.fallbackLng); + + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + delete o.fixLng; /* passed in each time */ + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + if (o.lng) { + // set cookie with lng set (as detectLanguage will set cookie on need) + if (o.useCookie) f.cookie.create(o.cookieName, o.lng, o.cookieExpirationTime, o.cookieDomain); + } else { + o.lng = o.fallbackLng; + if (o.useCookie) f.cookie.remove(o.cookieName); + } + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + var lngTranslate = translate; + if (options.fixLng) { + lngTranslate = function(key, options) { + options = options || {}; + options.lng = options.lng || lngTranslate.lng; + return translate(key, options); + }; + lngTranslate.lng = currentLng; + } + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + initialized = true; + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + initialized = true; + + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + f.extend(resStore[lng][ns], resources); + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, options, cb) { + if (typeof options === 'function') { + cb = options; + options = {}; + } + options.lng = lng; + return init(options, cb); + } + + function lng() { + return currentLng; + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } + else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key && typeof key !== 'undefined' && key !== false) key = ele.text() || ele.val(); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + f.each(replacementHash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), value); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.escape(value)); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), value); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, translated_token); + } + return translated; + } + + function hasContext(options) { + return (options.context && typeof options.context == 'string'); + } + + function needsPlural(options) { + return (options.count !== undefined && typeof options.count != 'string' && options.count !== 1); + } + + function exists(key, options) { + options = options || {}; + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + if (!initialized) { + f.log('i18next not finished initialization. you might have called t function before loading resources finished.') + return options.defaultValue || ''; + }; + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _getDefaultValue(key, options) { + return (options.defaultValue !== undefined) ? options.defaultValue : key; + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(potentialKeys, options) { + if (typeof options == 'string') { + if (o.shortcutFunction === 'sprintf') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else if (o.shortcutFunction === 'defaultValue') { + options = { + defaultValue: options + } + } + } else { + options = options || {}; + } + + if (typeof potentialKeys == 'string') { + potentialKeys = [potentialKeys]; + } + + var key = null; + + for (var i = 0; i < potentialKeys.length; i++) { + key = potentialKeys[i]; + if (exists(key)) { + break; + } + } + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng) : languages + , ns = options.ns || o.ns.defaultNs + , parts; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing) { + if (options.lng) { + sync.postMissing(lngs[0], ns, key, notFound, lngs); + } else { + sync.postMissing(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found !== undefined && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + // process notFound if function exists + var splitNotFound = notFound; + if (notFound.indexOf(o.nsseparator) > -1) { + parts = notFound.split(o.nsseparator); + splitNotFound = parts[1]; + } + if (splitNotFound === key && o.parseMissingKey) { + notFound = o.parseMissingKey(notFound); + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessor && postProcessors[postProcessor]) { + var val = _getDefaultValue(key, options); + found = postProcessors[postProcessor](val, key, options); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options){ + options = options || {}; + + var optionWithoutCount, translated + , notFound = _getDefaultValue(key, options) + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + if (options.lng) { + lngs = f.toLanguages(options.lng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.count; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(lngs[0], options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + + translated = translate(pluralKey, optionWithoutCount); + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } // else continue translation with original/singular key + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (Object.prototype.toString.apply(value) === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned a object instead of string.'; + f.log(value); + } else if (typeof value !== 'number') { + var copy = {}; // apply child translation on a copy + f.each(value, function(m) { + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + }); + value = copy; + } + } + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length > 0))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + } + + return found; + } + function detectLanguage() { + var detectedLng; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var parms = query.split('&'); + for (var i=0; i 0) { + var key = parms[i].substring(0,pos); + var val = parms[i].substring(pos+1); + qsParm[key] = val; + } + } + })(); + if (qsParm[o.detectLngQS]) { + detectedLng = qsParm[o.detectLngQS]; + } + } + + // get from cookie + if (!detectedLng && typeof document !== 'undefined' && o.useCookie ) { + var c = f.cookie.read(o.cookieName); + if (c) detectedLng = c; + } + + // get from navigator + if (!detectedLng && typeof navigator !== 'undefined') { + detectedLng = (navigator.language) ? navigator.language : navigator.userLanguage; + } + + return detectedLng; + } + var sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + window.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback' && o.fallbackLng !== false) { + urls.push({lng: o.fallbackLng, url: applyReplacement(o.resPostPath, { lng: o.fallbackLng, ns: ns })}); + } else if (o.sendMissingTo === 'current' || (o.sendMissingTo === 'fallback' && o.fallbackLng === false) ) { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + } + }; + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + var pluralExtensions = { + + rules: { + "ach": { + "name": "Acholi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "af": { + "name": "Afrikaans", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ak": { + "name": "Akan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "am": { + "name": "Amharic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "an": { + "name": "Aragonese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ar": { + "name": "Arabic", + "numbers": [ + 0, + 1, + 2, + 3, + 11, + 100 + ], + "plurals": function(n) { return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5); } + }, + "arn": { + "name": "Mapudungun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ast": { + "name": "Asturian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ay": { + "name": "Aymar\u00e1", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "az": { + "name": "Azerbaijani", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "be": { + "name": "Belarusian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "bg": { + "name": "Bulgarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bn": { + "name": "Bengali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bo": { + "name": "Tibetan", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "br": { + "name": "Breton", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "bs": { + "name": "Bosnian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ca": { + "name": "Catalan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "cgg": { + "name": "Chiga", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "cs": { + "name": "Czech", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "csb": { + "name": "Kashubian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "cy": { + "name": "Welsh", + "numbers": [ + 1, + 2, + 3, + 8 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3); } + }, + "da": { + "name": "Danish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "de": { + "name": "German", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "dz": { + "name": "Dzongkha", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "el": { + "name": "Greek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "en": { + "name": "English", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eo": { + "name": "Esperanto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es": { + "name": "Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es_ar": { + "name": "Argentinean Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "et": { + "name": "Estonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eu": { + "name": "Basque", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fa": { + "name": "Persian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "fi": { + "name": "Finnish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fil": { + "name": "Filipino", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fo": { + "name": "Faroese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fr": { + "name": "French", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fur": { + "name": "Friulian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fy": { + "name": "Frisian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ga": { + "name": "Irish", + "numbers": [ + 1, + 2, + 3, + 7, + 11 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;} + }, + "gd": { + "name": "Scottish Gaelic", + "numbers": [ + 1, + 2, + 3, + 20 + ], + "plurals": function(n) { return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3); } + }, + "gl": { + "name": "Galician", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gu": { + "name": "Gujarati", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gun": { + "name": "Gun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ha": { + "name": "Hausa", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "he": { + "name": "Hebrew", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hi": { + "name": "Hindi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hr": { + "name": "Croatian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "hu": { + "name": "Hungarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hy": { + "name": "Armenian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ia": { + "name": "Interlingua", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "id": { + "name": "Indonesian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "is": { + "name": "Icelandic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n%10!=1 || n%100==11); } + }, + "it": { + "name": "Italian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ja": { + "name": "Japanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jbo": { + "name": "Lojban", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jv": { + "name": "Javanese", + "numbers": [ + 0, + 1 + ], + "plurals": function(n) { return Number(n !== 0); } + }, + "ka": { + "name": "Georgian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kk": { + "name": "Kazakh", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "km": { + "name": "Khmer", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kn": { + "name": "Kannada", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ko": { + "name": "Korean", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ku": { + "name": "Kurdish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "kw": { + "name": "Cornish", + "numbers": [ + 1, + 2, + 3, + 4 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3); } + }, + "ky": { + "name": "Kyrgyz", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lb": { + "name": "Letzeburgesch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ln": { + "name": "Lingala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "lo": { + "name": "Lao", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lt": { + "name": "Lithuanian", + "numbers": [ + 1, + 2, + 10 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "lv": { + "name": "Latvian", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2); } + }, + "mai": { + "name": "Maithili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mfe": { + "name": "Mauritian Creole", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mg": { + "name": "Malagasy", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mi": { + "name": "Maori", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mk": { + "name": "Macedonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 || n%10==1 ? 0 : 1); } + }, + "ml": { + "name": "Malayalam", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mn": { + "name": "Mongolian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mnk": { + "name": "Mandinka", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(0 ? 0 : n==1 ? 1 : 2); } + }, + "mr": { + "name": "Marathi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ms": { + "name": "Malay", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "mt": { + "name": "Maltese", + "numbers": [ + 1, + 2, + 11, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3); } + }, + "nah": { + "name": "Nahuatl", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nap": { + "name": "Neapolitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nb": { + "name": "Norwegian Bokmal", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ne": { + "name": "Nepali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nl": { + "name": "Dutch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nn": { + "name": "Norwegian Nynorsk", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "no": { + "name": "Norwegian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nso": { + "name": "Northern Sotho", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "oc": { + "name": "Occitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "or": { + "name": "Oriya", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pa": { + "name": "Punjabi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pap": { + "name": "Papiamento", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pl": { + "name": "Polish", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "pms": { + "name": "Piemontese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ps": { + "name": "Pashto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt": { + "name": "Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt_br": { + "name": "Brazilian Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "rm": { + "name": "Romansh", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ro": { + "name": "Romanian", + "numbers": [ + 1, + 2, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2); } + }, + "ru": { + "name": "Russian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "sah": { + "name": "Yakut", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sco": { + "name": "Scots", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "se": { + "name": "Northern Sami", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "si": { + "name": "Sinhala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sk": { + "name": "Slovak", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "sl": { + "name": "Slovenian", + "numbers": [ + 5, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }, + "so": { + "name": "Somali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "son": { + "name": "Songhay", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sq": { + "name": "Albanian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sr": { + "name": "Serbian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "su": { + "name": "Sundanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sv": { + "name": "Swedish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sw": { + "name": "Swahili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ta": { + "name": "Tamil", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "te": { + "name": "Telugu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tg": { + "name": "Tajik", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "th": { + "name": "Thai", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ti": { + "name": "Tigrinya", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tk": { + "name": "Turkmen", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tr": { + "name": "Turkish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tt": { + "name": "Tatar", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ug": { + "name": "Uyghur", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "uk": { + "name": "Ukrainian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ur": { + "name": "Urdu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "uz": { + "name": "Uzbek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "vi": { + "name": "Vietnamese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "wa": { + "name": "Walloon", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "wo": { + "name": "Wolof", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "yo": { + "name": "Yoruba", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "zh": { + "name": "Chinese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + } + }, + + // for demonstration only sl and ar is added but you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i = ext.plurals(c); + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[0], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + +})(); \ No newline at end of file diff --git a/libs/i18next/release/i18next-1.7.0.min.js b/libs/i18next/release/i18next-1.7.0.min.js new file mode 100644 index 00000000..50538edc --- /dev/null +++ b/libs/i18next/release/i18next-1.7.0.min.js @@ -0,0 +1,5 @@ +// i18next, v1.7.0 +// Copyright (c)2013 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +!function(){function a(a,b){if(!b||"function"==typeof b)return a;for(var c in b)a[c]=b[c];return a}function b(a,b,c){var d,e=0,f=a.length,g=void 0===f||"function"==typeof a;if(c)if(g){for(d in a)if(b.apply(a[d],c)===!1)break}else for(;f>e&&b.apply(a[e++],c)!==!1;);else if(g){for(d in a)if(b.call(a[d],d,a[d])===!1)break}else for(;f>e&&b.call(a[e],e,a[e++])!==!1;);return a}function c(a){return"string"==typeof a?a.replace(/[&<>"'\/]/g,function(a){return H[a]}):a}function d(a){var b=function(a){if(window.XMLHttpRequest)return a(null,new XMLHttpRequest);if(window.ActiveXObject)try{return a(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(b){return a(null,new ActiveXObject("Microsoft.XMLHTTP"))}return a(new Error)},c=function(a){if("string"==typeof a)return a;var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")},d=function(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;cd?b+=String.fromCharCode(d):d>127&&2048>d?(b+=String.fromCharCode(192|d>>6),b+=String.fromCharCode(128|63&d)):(b+=String.fromCharCode(224|d>>12),b+=String.fromCharCode(128|63&d>>6),b+=String.fromCharCode(128|63&d))}return b},e=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";a=d(a);var c,e,f,g,h,i,j,k="",l=0;do c=a.charCodeAt(l++),e=a.charCodeAt(l++),f=a.charCodeAt(l++),g=c>>2,h=(3&c)<<4|e>>4,i=(15&e)<<2|f>>6,j=63&f,isNaN(e)?i=j=64:isNaN(f)&&(j=64),k+=b.charAt(g)+b.charAt(h)+b.charAt(i)+b.charAt(j),c=e=f="",g=h=i=j="";while(l1&&(d+=d.indexOf("?")>-1?"&"+k:"?"+k),e.jsonp){var l=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=d,l.appendChild(m),void 0}}b(function(b,c){if(b)return h(b);c.open(a,d,e.async);for(var f in j)j.hasOwnProperty(f)&&c.setRequestHeader(f,j[f]);c.onreadystatechange=function(){if(4===c.readyState){var a=c.responseText||"";if(!h)return;h(c.status,{text:function(){return a},json:function(){return JSON.parse(a)}})}},c.send(i)})},h={authBasic:function(a,b){g.headers.Authorization="Basic "+e(a+":"+b)},connect:function(a,b,c){return g("CONNECT",a,b,c)},del:function(a,b,c){return g("DELETE",a,b,c)},get:function(a,b,c){return g("GET",a,b,c)},head:function(a,b,c){return g("HEAD",a,b,c)},headers:function(a){g.headers=a||{}},isAllowed:function(a,b,c){this.options(a,function(a,d){c(-1!==d.text().indexOf(b))})},options:function(a,b,c){return g("OPTIONS",a,b,c)},patch:function(a,b,c){return g("PATCH",a,b,c)},post:function(a,b,c){return g("POST",a,b,c)},put:function(a,b,c){return g("PUT",a,b,c)},trace:function(a,b,c){return g("TRACE",a,b,c)}},i=a.type?a.type.toLowerCase():"get";h[i](a.url,a,function(b,c){200===b?a.success(c.json(),b,null):a.error(c.text(),b,null)})}function e(a,b){"function"==typeof a&&(b=a,a={}),a=a||{},K.extend(G,a),delete G.fixLng,"string"==typeof G.ns&&(G.ns={namespaces:[G.ns],defaultNs:G.ns}),"string"==typeof G.fallbackNS&&(G.fallbackNS=[G.fallbackNS]),G.interpolationPrefixEscaped=K.regexEscape(G.interpolationPrefix),G.interpolationSuffixEscaped=K.regexEscape(G.interpolationSuffix),G.lng||(G.lng=K.detectLanguage()),G.lng?G.useCookie&&K.cookie.create(G.cookieName,G.lng,G.cookieExpirationTime,G.cookieDomain):(G.lng=G.fallbackLng,G.useCookie&&K.cookie.remove(G.cookieName)),E=K.toLanguages(G.lng),y=E[0],K.log("currentLng set to: "+y);var c=s;a.fixLng&&(c=function(a,b){return b=b||{},b.lng=b.lng||c.lng,s(a,b)},c.lng=y),M.setCurrentLng(y),A&&G.setJqueryExt&&m();var d;if(A&&A.Deferred&&(d=A.Deferred()),!G.resStore){var e=K.toLanguages(G.lng);"string"==typeof G.preload&&(G.preload=[G.preload]);for(var f=0,g=G.preload.length;g>f;f++)for(var h=K.toLanguages(G.preload[f]),i=0,j=h.length;j>i;i++)e.indexOf(h[i])<0&&e.push(h[i]);return B.sync.load(e,G,function(a,e){C=e,F=!0,b&&b(c),d&&d.resolve(c)}),d?d.promise():void 0}return C=G.resStore,F=!0,b&&b(c),d&&d.resolve(c),d?d.promise():void 0}function f(a,b){"string"==typeof a&&(a=[a]);for(var c=0,d=a.length;d>c;c++)G.preload.indexOf(a[c])<0&&G.preload.push(a[c]);return e(b)}function g(a,b,c){"string"!=typeof b?(c=b,b=G.ns.defaultNs):G.ns.namespaces.indexOf(b)<0&&G.ns.namespaces.push(b),C[a]=C[a]||{},C[a][b]=C[a][b]||{},K.extend(C[a][b],c)}function h(a){G.ns.defaultNs=a}function i(a,b){j([a],b)}function j(a,b){var c={dynamicLoad:G.dynamicLoad,resGetPath:G.resGetPath,getAsync:G.getAsync,customLoad:G.customLoad,ns:{namespaces:a,defaultNs:""}},d=K.toLanguages(G.lng);"string"==typeof G.preload&&(G.preload=[G.preload]);for(var e=0,f=G.preload.length;f>e;e++)for(var g=K.toLanguages(G.preload[e]),h=0,i=g.length;i>h;h++)d.indexOf(g[h])<0&&d.push(g[h]);for(var j=[],k=0,l=d.length;l>k;k++){var m=!1,n=C[d[k]];if(n)for(var o=0,p=a.length;p>o;o++)n[a[o]]||(m=!0);else m=!0;m&&j.push(d[k])}j.length?B.sync._fetch(j,c,function(c,d){var e=a.length*j.length;K.each(a,function(a,c){G.ns.namespaces.indexOf(c)<0&&G.ns.namespaces.push(c),K.each(j,function(a,f){C[f]=C[f]||{},C[f][c]=d[f][c],e--,0===e&&b&&(G.useLocalStorage&&B.sync._storeLocal(C),b())})})}):b&&b()}function k(a,b,c){return"function"==typeof b&&(c=b,b={}),b.lng=a,e(b,c)}function l(){return y}function m(){function a(a,b,c){if(0!==b.length){var d="text";if(0===b.indexOf("[")){var e=b.split("]");b=e[1],d=e[0].substr(1,e[0].length-1)}b.indexOf(";")===b.length-1&&(b=b.substr(0,b.length-2));var f;"html"===d?(f=G.defaultValueFromContent?A.extend({defaultValue:a.html()},c):c,a.html(A.t(b,f))):"text"===d?(f=G.defaultValueFromContent?A.extend({defaultValue:a.text()},c):c,a.text(A.t(b,f))):(f=G.defaultValueFromContent?A.extend({defaultValue:a.attr(d)},c):c,a.attr(d,A.t(b,f)))}}function b(b,c){var d=b.attr(G.selectorAttr);if(d||"undefined"==typeof d||d===!1||(d=b.text()||b.val()),d){var e=b,f=b.data("i18n-target");if(f&&(e=b.find(f)||b),c||G.useDataAttrOptions!==!0||(c=b.data("i18n-options")),c=c||{},d.indexOf(";")>=0){var g=d.split(";");A.each(g,function(b,d){""!==d&&a(e,d,c)})}else a(e,d,c);G.useDataAttrOptions===!0&&b.data("i18n-options",c)}}A.t=A.t||s,A.fn.i18n=function(a){return this.each(function(){b(A(this),a);var c=A(this).find("["+G.selectorAttr+"]");c.each(function(){b(A(this),a)})})}}function n(a,b,c,d){if(!a)return a;if(d=d||b,a.indexOf(d.interpolationPrefix||G.interpolationPrefix)<0)return a;var e=d.interpolationPrefix?K.regexEscape(d.interpolationPrefix):G.interpolationPrefixEscaped,f=d.interpolationSuffix?K.regexEscape(d.interpolationSuffix):G.interpolationSuffixEscaped,g="HTML"+f;return K.each(b,function(b,h){var i=c?c+G.keyseparator+b:b;"object"==typeof h&&null!==h?a=n(a,h,i,d):d.escapeInterpolation||G.escapeInterpolation?(a=a.replace(new RegExp([e,i,g].join(""),"g"),h),a=a.replace(new RegExp([e,i,f].join(""),"g"),K.escape(h))):a=a.replace(new RegExp([e,i,f].join(""),"g"),h)}),a}function o(a,b){var c=",",d="{",e="}",f=K.extend({},b);for(delete f.postProcess;-1!=a.indexOf(G.reusePrefix)&&(D++,!(D>G.maxRecursion));){var g=a.lastIndexOf(G.reusePrefix),h=a.indexOf(G.reuseSuffix,g)+G.reuseSuffix.length,i=a.substring(g,h),j=i.replace(G.reusePrefix,"").replace(G.reuseSuffix,"");if(-1!=j.indexOf(c)){var k=j.indexOf(c);if(-1!=j.indexOf(d,k)&&-1!=j.indexOf(e,k)){var l=j.indexOf(d,k),m=j.indexOf(e,l)+e.length;try{f=K.extend(f,JSON.parse(j.substring(l,m))),j=j.substring(0,k)}catch(n){}}}var o=v(j,f);a=a.replace(i,o)}return a}function p(a){return a.context&&"string"==typeof a.context}function q(a){return void 0!==a.count&&"string"!=typeof a.count&&1!==a.count}function r(a,b){b=b||{};var c=t(a,b),d=w(a,b);return void 0!==d||d===c}function s(a,b){return F?(D=0,v.apply(null,arguments)):(K.log("i18next not finished initialization. you might have called t function before loading resources finished."),b.defaultValue||"")}function t(a,b){return void 0!==b.defaultValue?b.defaultValue:a}function u(){for(var a=[],b=1;b-1&&(e=c.split(G.nsseparator),i=e[0],c=e[1]),void 0===g&&G.sendMissing&&(b.lng?L.postMissing(h[0],i,c,f,h):L.postMissing(G.lng,i,c,f,h));var j=b.postProcess||G.postProcess;void 0!==g&&j&&N[j]&&(g=N[j](g,c,b));var k=f;if(f.indexOf(G.nsseparator)>-1&&(e=f.split(G.nsseparator),k=e[1]),k===c&&G.parseMissingKey&&(f=G.parseMissingKey(f)),void 0===g&&(f=n(f,b),f=o(f,b),j&&N[j])){var l=t(c,b);g=N[j](l,c,b)}return void 0!==g?g:f}function w(a,b){b=b||{};var c,d,e=t(a,b),f=E;if(!C)return e;if(b.lng&&(f=K.toLanguages(b.lng),!C[f[0]])){var g=G.getAsync;G.getAsync=!1,B.sync.load(f,G,function(a,b){K.extend(C,b),G.getAsync=g})}var h=b.ns||G.ns.defaultNs;if(a.indexOf(G.nsseparator)>-1){var i=a.split(G.nsseparator);h=i[0],a=i[1]}if(p(b)){c=K.extend({},b),delete c.context,c.defaultValue=G.contextNotFound;var j=h+G.nsseparator+a+"_"+b.context;if(d=s(j,c),d!=G.contextNotFound)return n(d,{context:b.context})}if(q(b)){c=K.extend({},b),delete c.count,c.defaultValue=G.pluralNotFound;var k=h+G.nsseparator+a+G.pluralSuffix,l=M.get(f[0],b.count);if(l>=0?k=k+"_"+l:1===l&&(k=h+G.nsseparator+a),d=s(k,c),d!=G.pluralNotFound)return n(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix})}for(var m,r=a.split(G.keyseparator),u=0,x=f.length;x>u&&void 0===m;u++){for(var y=f[u],z=0,A=C[y]&&C[y][h];r[z];)A=A&&A[r[z]],z++;if(void 0!==A){if("string"==typeof A)A=n(A,b),A=o(A,b);else if("[object Array]"!==Object.prototype.toString.apply(A)||G.returnObjectTrees||b.returnObjectTrees){if(null===A&&G.fallbackOnNull===!0)A=void 0;else if(null!==A)if(G.returnObjectTrees||b.returnObjectTrees){if("number"!=typeof A){var D={};K.each(A,function(c){D[c]=v(h+G.nsseparator+a+G.keyseparator+c,b)}),A=D}}else A="key '"+h+":"+a+" ("+y+")' "+"returned a object instead of string.",K.log(A)}else A=A.join("\n"),A=n(A,b),A=o(A,b);m=A}}if(void 0===m&&!b.isFallbackLookup&&(G.fallbackToDefaultNS===!0||G.fallbackNS&&G.fallbackNS.length>0))if(b.isFallbackLookup=!0,G.fallbackNS.length){for(var F=0,H=G.fallbackNS.length;H>F;F++)if(m=w(G.fallbackNS[F]+G.nsseparator+a,b)){var I=m.indexOf(G.nsseparator)>-1?m.split(G.nsseparator)[1]:m,J=e.indexOf(G.nsseparator)>-1?e.split(G.nsseparator)[1]:e;if(I!==J)break}}else m=w(a,b);return m}function x(){var a,b=[];if("undefined"!=typeof window&&(!function(){for(var a=window.location.search.substring(1),c=a.split("&"),d=0;d0){var f=c[d].substring(0,e),g=c[d].substring(e+1);b[f]=g}}}(),b[G.detectLngQS]&&(a=b[G.detectLngQS])),!a&&"undefined"!=typeof document&&G.useCookie){var c=K.cookie.read(G.cookieName);c&&(a=c)}return a||"undefined"==typeof navigator||(a=navigator.language?navigator.language:navigator.userLanguage),a}Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>0&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&1/0!=d&&d!=-1/0&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=c;arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d))));for(var e=d>=0?Math.min(d,c-1):c-Math.abs(d);e>=0;e--)if(e in b&&b[e]===a)return e;return-1});var y,z=this,A=z.jQuery||z.Zepto,B={},C={},D=0,E=[],F=!1;"undefined"!=typeof module&&module.exports?module.exports=B:(A&&(A.i18n=A.i18n||B),z.i18n=z.i18n||B);var G={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:"dev",fallbackNS:[],detectLngQS:"setLng",ns:"translation",fallbackOnNull:!0,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",cookieDomain:void 0,postProcess:void 0,parseMissingKey:void 0,shortcutFunction:"sprintf"},H={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},I={create:function(a,b,c,d){var e;if(c){var f=new Date;f.setTime(f.getTime()+1e3*60*c),e="; expires="+f.toGMTString()}else e="";d=d?"domain="+d+";":"",document.cookie=a+"="+b+e+";"+d+"path=/"},read:function(a){for(var b=a+"=",c=document.cookie.split(";"),d=0;d-1){var c=a.split("-");a=G.lowerCaseLng?c[0].toLowerCase()+"-"+c[1].toLowerCase():c[0].toLowerCase()+"-"+c[1].toUpperCase(),"unspecific"!==G.load&&b.push(a),"current"!==G.load&&b.push(c[0])}else b.push(a);return-1===b.indexOf(G.fallbackLng)&&G.fallbackLng&&b.push(G.fallbackLng),b},regexEscape:function(a){return a.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}};K.applyReplacement=n;var L={load:function(a,b,c){b.useLocalStorage?L._loadLocal(a,b,function(d,e){for(var f=[],g=0,h=a.length;h>g;g++)e[a[g]]||f.push(a[g]);f.length>0?L._fetch(f,b,function(a,b){K.extend(e,b),L._storeLocal(b),c(null,e)}):c(null,e)}):L._fetch(a,b,function(a,b){c(null,b)})},_loadLocal:function(a,b,c){var d={},e=(new Date).getTime();if(window.localStorage){var f=a.length;K.each(a,function(a,g){var h=window.localStorage.getItem("res_"+g);h&&(h=JSON.parse(h),h.i18nStamp&&h.i18nStamp+b.localStorageExpirationTime>e&&(d[g]=h)),f--,0===f&&c(null,d)})}},_storeLocal:function(a){if(window.localStorage)for(var b in a)a[b].i18nStamp=(new Date).getTime(),window.localStorage.setItem("res_"+b,JSON.stringify(a[b]))},_fetch:function(a,b,c){var d=b.ns,e={};if(b.dynamicLoad){var f=function(a,b){c(null,b)};if("function"==typeof b.customLoad)b.customLoad(a,d.namespaces,b,f);else{var g=n(b.resGetPath,{lng:a.join("+"),ns:d.namespaces.join("+")});K.ajax({url:g,success:function(a){K.log("loaded: "+g),f(null,a)},error:function(a,b,c){K.log("failed loading: "+g),f("failed loading resource.json error: "+c)},dataType:"json",async:b.getAsync})}}else{var h,i=d.namespaces.length*a.length;K.each(d.namespaces,function(d,f){K.each(a,function(a,d){var g=function(a,b){a&&(h=h||[],h.push(a)),e[d]=e[d]||{},e[d][f]=b,i--,0===i&&c(h,e)};"function"==typeof b.customLoad?b.customLoad(d,f,b,g):L._fetchOne(d,f,b,g)})})}},_fetchOne:function(a,b,c,d){var e=n(c.resGetPath,{lng:a,ns:b});K.ajax({url:e,success:function(a){K.log("loaded: "+e),d(null,a)},error:function(a,b,c){K.log("failed loading: "+e),d(c,{})},dataType:"json",async:c.getAsync})},postMissing:function(a,b,c,d,e){var f={};f[c]=d;var g=[];if("fallback"===G.sendMissingTo&&G.fallbackLng!==!1)g.push({lng:G.fallbackLng,url:n(G.resPostPath,{lng:G.fallbackLng,ns:b})});else if("current"===G.sendMissingTo||"fallback"===G.sendMissingTo&&G.fallbackLng===!1)g.push({lng:a,url:n(G.resPostPath,{lng:a,ns:b})});else if("all"===G.sendMissingTo)for(var h=0,i=e.length;i>h;h++)g.push({lng:e[h],url:n(G.resPostPath,{lng:e[h],ns:b})});for(var j=0,k=g.length;k>j;j++){var l=g[j];K.ajax({url:l.url,type:G.sendType,data:f,success:function(){K.log("posted missing key '"+c+"' to: "+l.url);for(var a=c.split("."),e=0,f=C[l.lng][b];a[e];)f=f[a[e]]=e===a.length-1?d:f[a[e]]||{},e++},error:function(){K.log("failed posting missing key '"+c+"' to: "+l.url)},dataType:"json",async:G.postAsync})}}},M={rules:{ach:{name:"Acholi",numbers:[1,2],plurals:function(a){return Number(a>1)}},af:{name:"Afrikaans",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ak:{name:"Akan",numbers:[1,2],plurals:function(a){return Number(a>1)}},am:{name:"Amharic",numbers:[1,2],plurals:function(a){return Number(a>1)}},an:{name:"Aragonese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ar:{name:"Arabic",numbers:[0,1,2,3,11,100],plurals:function(a){return Number(0===a?0:1==a?1:2==a?2:a%100>=3&&10>=a%100?3:a%100>=11?4:5)}},arn:{name:"Mapudungun",numbers:[1,2],plurals:function(a){return Number(a>1)}},ast:{name:"Asturian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ay:{name:"Aymará",numbers:[1],plurals:function(){return 0}},az:{name:"Azerbaijani",numbers:[1,2],plurals:function(a){return Number(1!=a)}},be:{name:"Belarusian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},bg:{name:"Bulgarian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},bn:{name:"Bengali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},bo:{name:"Tibetan",numbers:[1],plurals:function(){return 0}},br:{name:"Breton",numbers:[1,2],plurals:function(a){return Number(a>1)}},bs:{name:"Bosnian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},ca:{name:"Catalan",numbers:[1,2],plurals:function(a){return Number(1!=a)}},cgg:{name:"Chiga",numbers:[1],plurals:function(){return 0}},cs:{name:"Czech",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)}},csb:{name:"Kashubian",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},cy:{name:"Welsh",numbers:[1,2,3,8],plurals:function(a){return Number(1==a?0:2==a?1:8!=a&&11!=a?2:3)}},da:{name:"Danish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},de:{name:"German",numbers:[1,2],plurals:function(a){return Number(1!=a)}},dz:{name:"Dzongkha",numbers:[1],plurals:function(){return 0}},el:{name:"Greek",numbers:[1,2],plurals:function(a){return Number(1!=a)}},en:{name:"English",numbers:[1,2],plurals:function(a){return Number(1!=a)}},eo:{name:"Esperanto",numbers:[1,2],plurals:function(a){return Number(1!=a)}},es:{name:"Spanish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},es_ar:{name:"Argentinean Spanish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},et:{name:"Estonian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},eu:{name:"Basque",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fa:{name:"Persian",numbers:[1],plurals:function(){return 0}},fi:{name:"Finnish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fil:{name:"Filipino",numbers:[1,2],plurals:function(a){return Number(a>1)}},fo:{name:"Faroese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fr:{name:"French",numbers:[1,2],plurals:function(a){return Number(a>1)}},fur:{name:"Friulian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fy:{name:"Frisian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ga:{name:"Irish",numbers:[1,2,3,7,11],plurals:function(a){return Number(1==a?0:2==a?1:7>a?2:11>a?3:4)}},gd:{name:"Scottish Gaelic",numbers:[1,2,3,20],plurals:function(a){return Number(1==a||11==a?0:2==a||12==a?1:a>2&&20>a?2:3)}},gl:{name:"Galician",numbers:[1,2],plurals:function(a){return Number(1!=a)}},gu:{name:"Gujarati",numbers:[1,2],plurals:function(a){return Number(1!=a)}},gun:{name:"Gun",numbers:[1,2],plurals:function(a){return Number(a>1)}},ha:{name:"Hausa",numbers:[1,2],plurals:function(a){return Number(1!=a)}},he:{name:"Hebrew",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hi:{name:"Hindi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hr:{name:"Croatian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},hu:{name:"Hungarian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hy:{name:"Armenian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ia:{name:"Interlingua",numbers:[1,2],plurals:function(a){return Number(1!=a)}},id:{name:"Indonesian",numbers:[1],plurals:function(){return 0}},is:{name:"Icelandic",numbers:[1,2],plurals:function(a){return Number(1!=a%10||11==a%100)}},it:{name:"Italian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ja:{name:"Japanese",numbers:[1],plurals:function(){return 0}},jbo:{name:"Lojban",numbers:[1],plurals:function(){return 0}},jv:{name:"Javanese",numbers:[0,1],plurals:function(a){return Number(0!==a)}},ka:{name:"Georgian",numbers:[1],plurals:function(){return 0}},kk:{name:"Kazakh",numbers:[1],plurals:function(){return 0}},km:{name:"Khmer",numbers:[1],plurals:function(){return 0}},kn:{name:"Kannada",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ko:{name:"Korean",numbers:[1],plurals:function(){return 0}},ku:{name:"Kurdish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},kw:{name:"Cornish",numbers:[1,2,3,4],plurals:function(a){return Number(1==a?0:2==a?1:3==a?2:3)}},ky:{name:"Kyrgyz",numbers:[1],plurals:function(){return 0}},lb:{name:"Letzeburgesch",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ln:{name:"Lingala",numbers:[1,2],plurals:function(a){return Number(a>1)}},lo:{name:"Lao",numbers:[1],plurals:function(){return 0}},lt:{name:"Lithuanian",numbers:[1,2,10],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&(10>a%100||a%100>=20)?1:2)}},lv:{name:"Latvian",numbers:[0,1,2],plurals:function(a){return Number(1==a%10&&11!=a%100?0:0!==a?1:2)}},mai:{name:"Maithili",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mfe:{name:"Mauritian Creole",numbers:[1,2],plurals:function(a){return Number(a>1)}},mg:{name:"Malagasy",numbers:[1,2],plurals:function(a){return Number(a>1)}},mi:{name:"Maori",numbers:[1,2],plurals:function(a){return Number(a>1)}},mk:{name:"Macedonian",numbers:[1,2],plurals:function(a){return Number(1==a||1==a%10?0:1)}},ml:{name:"Malayalam",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mn:{name:"Mongolian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mnk:{name:"Mandinka",numbers:[0,1,2],plurals:function(a){return Number(1==a?1:2)}},mr:{name:"Marathi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ms:{name:"Malay",numbers:[1],plurals:function(){return 0}},mt:{name:"Maltese",numbers:[1,2,11,20],plurals:function(a){return Number(1==a?0:0===a||a%100>1&&11>a%100?1:a%100>10&&20>a%100?2:3)}},nah:{name:"Nahuatl",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nap:{name:"Neapolitan",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nb:{name:"Norwegian Bokmal",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ne:{name:"Nepali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nl:{name:"Dutch",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nn:{name:"Norwegian Nynorsk",numbers:[1,2],plurals:function(a){return Number(1!=a)}},no:{name:"Norwegian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nso:{name:"Northern Sotho",numbers:[1,2],plurals:function(a){return Number(1!=a)}},oc:{name:"Occitan",numbers:[1,2],plurals:function(a){return Number(a>1)}},or:{name:"Oriya",numbers:[2,1],plurals:function(a){return Number(1!=a)}},pa:{name:"Punjabi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pap:{name:"Papiamento",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pl:{name:"Polish",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},pms:{name:"Piemontese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ps:{name:"Pashto",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pt:{name:"Portuguese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pt_br:{name:"Brazilian Portuguese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},rm:{name:"Romansh",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ro:{name:"Romanian",numbers:[1,2,20],plurals:function(a){return Number(1==a?0:0===a||a%100>0&&20>a%100?1:2)}},ru:{name:"Russian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},sah:{name:"Yakut",numbers:[1],plurals:function(){return 0}},sco:{name:"Scots",numbers:[1,2],plurals:function(a){return Number(1!=a)}},se:{name:"Northern Sami",numbers:[1,2],plurals:function(a){return Number(1!=a)}},si:{name:"Sinhala",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sk:{name:"Slovak",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)}},sl:{name:"Slovenian",numbers:[5,1,2,3],plurals:function(a){return Number(1==a%100?1:2==a%100?2:3==a%100||4==a%100?3:0)}},so:{name:"Somali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},son:{name:"Songhay",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sq:{name:"Albanian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sr:{name:"Serbian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},su:{name:"Sundanese",numbers:[1],plurals:function(){return 0}},sv:{name:"Swedish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sw:{name:"Swahili",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ta:{name:"Tamil",numbers:[1,2],plurals:function(a){return Number(1!=a)}},te:{name:"Telugu",numbers:[1,2],plurals:function(a){return Number(1!=a)}},tg:{name:"Tajik",numbers:[1,2],plurals:function(a){return Number(a>1)}},th:{name:"Thai",numbers:[1],plurals:function(){return 0}},ti:{name:"Tigrinya",numbers:[1,2],plurals:function(a){return Number(a>1)}},tk:{name:"Turkmen",numbers:[1,2],plurals:function(a){return Number(1!=a)}},tr:{name:"Turkish",numbers:[1,2],plurals:function(a){return Number(a>1)}},tt:{name:"Tatar",numbers:[1],plurals:function(){return 0}},ug:{name:"Uyghur",numbers:[1],plurals:function(){return 0}},uk:{name:"Ukrainian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},ur:{name:"Urdu",numbers:[1,2],plurals:function(a){return Number(1!=a)}},uz:{name:"Uzbek",numbers:[1,2],plurals:function(a){return Number(a>1)}},vi:{name:"Vietnamese",numbers:[1],plurals:function(){return 0}},wa:{name:"Walloon",numbers:[1,2],plurals:function(a){return Number(a>1)}},wo:{name:"Wolof",numbers:[1],plurals:function(){return 0}},yo:{name:"Yoruba",numbers:[1,2],plurals:function(a){return Number(1!=a)}},zh:{name:"Chinese",numbers:[1],plurals:function(){return 0}}},addRule:function(a,b){M.rules[a]=b},setCurrentLng:function(a){if(!M.currentRule||M.currentRule.lng!==a){var b=a.split("-");M.currentRule={lng:a,rule:M.rules[b[0]]}}},get:function(a,b){function c(b,c){var d;if(d=M.currentRule&&M.currentRule.lng===a?M.currentRule.rule:M.rules[b]){var e=d.plurals(c),f=d.numbers[e];return 2===d.numbers.length&&1===d.numbers[0]&&(2===f?f=-1:1===f&&(f=1)),f}return 1===c?"1":"-1"}var d=a.split("-");return c(d[0],b)}},N={},O=function(a,b){N[a]=b},P=function(){function a(a){return Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}function b(a,b){for(var c=[];b>0;c[--b]=a);return c.join("")}var c=function(){return c.cache.hasOwnProperty(arguments[0])||(c.cache[arguments[0]]=c.parse(arguments[0])),c.format.call(null,c.cache[arguments[0]],arguments)};return c.format=function(c,d){var e,f,g,h,i,j,k,l=1,m=c.length,n="",o=[];for(f=0;m>f;f++)if(n=a(c[f]),"string"===n)o.push(c[f]);else if("array"===n){if(h=c[f],h[2])for(e=d[l],g=0;g=0?"+"+e:e,j=h[4]?"0"==h[4]?"0":h[4].charAt(1):" ",k=h[6]-String(e).length,i=h[6]?b(j,k):"",o.push(h[5]?e+i:i+e)}return o.join("")},c.cache={},c.parse=function(a){for(var b=a,c=[],d=[],e=0;b;){if(null!==(c=/^[^\x25]+/.exec(b)))d.push(c[0]);else if(null!==(c=/^\x25{2}/.exec(b)))d.push("%");else{if(null===(c=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(b)))throw"[sprintf] huh?";if(c[2]){e|=1;var f=[],g=c[2],h=[];if(null===(h=/^([a-z_][a-z_\d]*)/i.exec(g)))throw"[sprintf] huh?";for(f.push(h[1]);""!==(g=g.substring(h[0].length));)if(null!==(h=/^\.([a-z_][a-z_\d]*)/i.exec(g)))f.push(h[1]);else{if(null===(h=/^\[(\d+)\]/.exec(g)))throw"[sprintf] huh?";f.push(h[1])}c[2]=f}else e|=2;if(3===e)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";d.push(c)}b=b.substring(c[0].length)}return d},c}(),Q=function(a,b){return b.unshift(a),P.apply(null,b)};O("sprintf",function(a,b,c){return c.sprintf?"[object Array]"===Object.prototype.toString.apply(c.sprintf)?Q(a,c.sprintf):"object"==typeof c.sprintf?P(a,c.sprintf):a:a}),B.init=e,B.setLng=k,B.preload=f,B.addResourceBundle=g,B.loadNamespace=i,B.loadNamespaces=j,B.setDefaultNamespace=h,B.t=s,B.translate=s,B.exists=r,B.detectLanguage=K.detectLanguage,B.pluralExtensions=M,B.sync=L,B.functions=K,B.lng=l,B.addPostProcessor=O,B.options=G}(); \ No newline at end of file diff --git a/libs/i18next/release/i18next-1.7.0.zip b/libs/i18next/release/i18next-1.7.0.zip new file mode 100644 index 00000000..a98a4e60 Binary files /dev/null and b/libs/i18next/release/i18next-1.7.0.zip differ diff --git a/libs/i18next/release/i18next-1.7.1.js b/libs/i18next/release/i18next-1.7.1.js new file mode 100644 index 00000000..2d858318 --- /dev/null +++ b/libs/i18next/release/i18next-1.7.1.js @@ -0,0 +1,2668 @@ +// i18next, v1.7.1 +// Copyright (c)2014 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function() { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + var root = this + , $ = root.jQuery || root.Zepto + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = [] + , initialized = false; + + + // Export the i18next object for **CommonJS**. + // If we're not in CommonJS, add `i18n` to the + // global object or to jquery. + if (typeof module !== 'undefined' && module.exports) { + module.exports = i18n; + } else { + if ($) { + $.i18n = $.i18n || i18n; + } + + root.i18n = root.i18n || i18n; + } + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: 'dev', + fallbackNS: [], + detectLngQS: 'setLng', + ns: 'translation', + fallbackOnNull: true, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + cookieDomain: undefined, + + postProcess: undefined, + parseMissingKey: undefined, + + shortcutFunction: 'sprintf' // or: defaultValue + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + return JSON.parse(data); + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + if (status === 200) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes,domain) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + domain = (domain)? "domain="+domain+";" : ""; + document.cookie = name+"="+value+expires+";"+domain+"path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes,domain) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : _ajax, + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + toLanguages: function(lng) { + var languages = []; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + + if (o.load !== 'unspecific') languages.push(lng); + if (o.load !== 'current') languages.push(parts[0]); + } else { + languages.push(lng); + } + + if (languages.indexOf(o.fallbackLng) === -1 && o.fallbackLng) languages.push(o.fallbackLng); + + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + delete o.fixLng; /* passed in each time */ + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + if (o.lng) { + // set cookie with lng set (as detectLanguage will set cookie on need) + if (o.useCookie) f.cookie.create(o.cookieName, o.lng, o.cookieExpirationTime, o.cookieDomain); + } else { + o.lng = o.fallbackLng; + if (o.useCookie) f.cookie.remove(o.cookieName); + } + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + var lngTranslate = translate; + if (options.fixLng) { + lngTranslate = function(key, options) { + options = options || {}; + options.lng = options.lng || lngTranslate.lng; + return translate(key, options); + }; + lngTranslate.lng = currentLng; + } + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + initialized = true; + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + initialized = true; + + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + f.extend(resStore[lng][ns], resources); + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, options, cb) { + if (typeof options === 'function') { + cb = options; + options = {}; + } + options.lng = lng; + return init(options, cb); + } + + function lng() { + return currentLng; + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } + else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key && typeof key !== 'undefined' && key !== false) key = ele.text() || ele.val(); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + f.each(replacementHash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), value); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.escape(value)); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), value); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, translated_token); + } + return translated; + } + + function hasContext(options) { + return (options.context && typeof options.context == 'string'); + } + + function needsPlural(options) { + return (options.count !== undefined && typeof options.count != 'string' && options.count !== 1); + } + + function exists(key, options) { + options = options || {}; + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + options = options || {}; + + if (!initialized) { + f.log('i18next not finished initialization. you might have called t function before loading resources finished.') + return options.defaultValue || ''; + }; + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _getDefaultValue(key, options) { + return (options.defaultValue !== undefined) ? options.defaultValue : key; + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(potentialKeys, options) { + if (typeof options == 'string') { + if (o.shortcutFunction === 'sprintf') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else if (o.shortcutFunction === 'defaultValue') { + options = { + defaultValue: options + } + } + } else { + options = options || {}; + } + + if (typeof potentialKeys == 'string') { + potentialKeys = [potentialKeys]; + } + + var key = null; + + for (var i = 0; i < potentialKeys.length; i++) { + key = potentialKeys[i]; + if (exists(key)) { + break; + } + } + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng) : languages + , ns = options.ns || o.ns.defaultNs + , parts; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing) { + if (options.lng) { + sync.postMissing(lngs[0], ns, key, notFound, lngs); + } else { + sync.postMissing(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found !== undefined && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + // process notFound if function exists + var splitNotFound = notFound; + if (notFound.indexOf(o.nsseparator) > -1) { + parts = notFound.split(o.nsseparator); + splitNotFound = parts[1]; + } + if (splitNotFound === key && o.parseMissingKey) { + notFound = o.parseMissingKey(notFound); + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessor && postProcessors[postProcessor]) { + var val = _getDefaultValue(key, options); + found = postProcessors[postProcessor](val, key, options); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options){ + options = options || {}; + + var optionWithoutCount, translated + , notFound = _getDefaultValue(key, options) + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + if (options.lng) { + lngs = f.toLanguages(options.lng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.count; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(lngs[0], options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + + translated = translate(pluralKey, optionWithoutCount); + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } // else continue translation with original/singular key + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (Object.prototype.toString.apply(value) === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned an object instead of string.'; + f.log(value); + } else if (typeof value !== 'number') { + var copy = {}; // apply child translation on a copy + f.each(value, function(m) { + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + }); + value = copy; + } + } + + if (typeof value === 'string' && value.trim() === '' && o.fallbackOnEmpty === true) + value = undefined; + + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length > 0))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + } + + return found; + } + function detectLanguage() { + var detectedLng; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var parms = query.split('&'); + for (var i=0; i 0) { + var key = parms[i].substring(0,pos); + var val = parms[i].substring(pos+1); + qsParm[key] = val; + } + } + })(); + if (qsParm[o.detectLngQS]) { + detectedLng = qsParm[o.detectLngQS]; + } + } + + // get from cookie + if (!detectedLng && typeof document !== 'undefined' && o.useCookie ) { + var c = f.cookie.read(o.cookieName); + if (c) detectedLng = c; + } + + // get from navigator + if (!detectedLng && typeof navigator !== 'undefined') { + detectedLng = (navigator.language) ? navigator.language : navigator.userLanguage; + } + + return detectedLng; + } + var sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + window.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback' && o.fallbackLng !== false) { + urls.push({lng: o.fallbackLng, url: applyReplacement(o.resPostPath, { lng: o.fallbackLng, ns: ns })}); + } else if (o.sendMissingTo === 'current' || (o.sendMissingTo === 'fallback' && o.fallbackLng === false) ) { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + } + }; + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + var pluralExtensions = { + + rules: { + "ach": { + "name": "Acholi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "af": { + "name": "Afrikaans", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ak": { + "name": "Akan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "am": { + "name": "Amharic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "an": { + "name": "Aragonese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ar": { + "name": "Arabic", + "numbers": [ + 0, + 1, + 2, + 3, + 11, + 100 + ], + "plurals": function(n) { return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5); } + }, + "arn": { + "name": "Mapudungun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ast": { + "name": "Asturian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ay": { + "name": "Aymar\u00e1", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "az": { + "name": "Azerbaijani", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "be": { + "name": "Belarusian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "bg": { + "name": "Bulgarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bn": { + "name": "Bengali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bo": { + "name": "Tibetan", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "br": { + "name": "Breton", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "bs": { + "name": "Bosnian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ca": { + "name": "Catalan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "cgg": { + "name": "Chiga", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "cs": { + "name": "Czech", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "csb": { + "name": "Kashubian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "cy": { + "name": "Welsh", + "numbers": [ + 1, + 2, + 3, + 8 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3); } + }, + "da": { + "name": "Danish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "de": { + "name": "German", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "dz": { + "name": "Dzongkha", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "el": { + "name": "Greek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "en": { + "name": "English", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eo": { + "name": "Esperanto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es": { + "name": "Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es_ar": { + "name": "Argentinean Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "et": { + "name": "Estonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eu": { + "name": "Basque", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fa": { + "name": "Persian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "fi": { + "name": "Finnish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fil": { + "name": "Filipino", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fo": { + "name": "Faroese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fr": { + "name": "French", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fur": { + "name": "Friulian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fy": { + "name": "Frisian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ga": { + "name": "Irish", + "numbers": [ + 1, + 2, + 3, + 7, + 11 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;} + }, + "gd": { + "name": "Scottish Gaelic", + "numbers": [ + 1, + 2, + 3, + 20 + ], + "plurals": function(n) { return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3); } + }, + "gl": { + "name": "Galician", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gu": { + "name": "Gujarati", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gun": { + "name": "Gun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ha": { + "name": "Hausa", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "he": { + "name": "Hebrew", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hi": { + "name": "Hindi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hr": { + "name": "Croatian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "hu": { + "name": "Hungarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hy": { + "name": "Armenian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ia": { + "name": "Interlingua", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "id": { + "name": "Indonesian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "is": { + "name": "Icelandic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n%10!=1 || n%100==11); } + }, + "it": { + "name": "Italian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ja": { + "name": "Japanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jbo": { + "name": "Lojban", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jv": { + "name": "Javanese", + "numbers": [ + 0, + 1 + ], + "plurals": function(n) { return Number(n !== 0); } + }, + "ka": { + "name": "Georgian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kk": { + "name": "Kazakh", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "km": { + "name": "Khmer", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kn": { + "name": "Kannada", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ko": { + "name": "Korean", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ku": { + "name": "Kurdish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "kw": { + "name": "Cornish", + "numbers": [ + 1, + 2, + 3, + 4 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3); } + }, + "ky": { + "name": "Kyrgyz", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lb": { + "name": "Letzeburgesch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ln": { + "name": "Lingala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "lo": { + "name": "Lao", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lt": { + "name": "Lithuanian", + "numbers": [ + 1, + 2, + 10 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "lv": { + "name": "Latvian", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2); } + }, + "mai": { + "name": "Maithili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mfe": { + "name": "Mauritian Creole", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mg": { + "name": "Malagasy", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mi": { + "name": "Maori", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mk": { + "name": "Macedonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 || n%10==1 ? 0 : 1); } + }, + "ml": { + "name": "Malayalam", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mn": { + "name": "Mongolian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mnk": { + "name": "Mandinka", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(0 ? 0 : n==1 ? 1 : 2); } + }, + "mr": { + "name": "Marathi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ms": { + "name": "Malay", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "mt": { + "name": "Maltese", + "numbers": [ + 1, + 2, + 11, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3); } + }, + "nah": { + "name": "Nahuatl", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nap": { + "name": "Neapolitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nb": { + "name": "Norwegian Bokmal", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ne": { + "name": "Nepali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nl": { + "name": "Dutch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nn": { + "name": "Norwegian Nynorsk", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "no": { + "name": "Norwegian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nso": { + "name": "Northern Sotho", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "oc": { + "name": "Occitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "or": { + "name": "Oriya", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pa": { + "name": "Punjabi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pap": { + "name": "Papiamento", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pl": { + "name": "Polish", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "pms": { + "name": "Piemontese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ps": { + "name": "Pashto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt": { + "name": "Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt_br": { + "name": "Brazilian Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "rm": { + "name": "Romansh", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ro": { + "name": "Romanian", + "numbers": [ + 1, + 2, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2); } + }, + "ru": { + "name": "Russian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "sah": { + "name": "Yakut", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sco": { + "name": "Scots", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "se": { + "name": "Northern Sami", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "si": { + "name": "Sinhala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sk": { + "name": "Slovak", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "sl": { + "name": "Slovenian", + "numbers": [ + 5, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }, + "so": { + "name": "Somali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "son": { + "name": "Songhay", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sq": { + "name": "Albanian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sr": { + "name": "Serbian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "su": { + "name": "Sundanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sv": { + "name": "Swedish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sw": { + "name": "Swahili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ta": { + "name": "Tamil", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "te": { + "name": "Telugu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tg": { + "name": "Tajik", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "th": { + "name": "Thai", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ti": { + "name": "Tigrinya", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tk": { + "name": "Turkmen", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tr": { + "name": "Turkish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tt": { + "name": "Tatar", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ug": { + "name": "Uyghur", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "uk": { + "name": "Ukrainian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ur": { + "name": "Urdu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "uz": { + "name": "Uzbek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "vi": { + "name": "Vietnamese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "wa": { + "name": "Walloon", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "wo": { + "name": "Wolof", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "yo": { + "name": "Yoruba", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "zh": { + "name": "Chinese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + } + }, + + // for demonstration only sl and ar is added but you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i = ext.plurals(c); + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[0], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + +})(); \ No newline at end of file diff --git a/libs/i18next/release/i18next-1.7.1.min.js b/libs/i18next/release/i18next-1.7.1.min.js new file mode 100644 index 00000000..162f6027 --- /dev/null +++ b/libs/i18next/release/i18next-1.7.1.min.js @@ -0,0 +1,5 @@ +// i18next, v1.7.1 +// Copyright (c)2014 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +!function(){function a(a,b){if(!b||"function"==typeof b)return a;for(var c in b)a[c]=b[c];return a}function b(a,b,c){var d,e=0,f=a.length,g=void 0===f||"function"==typeof a;if(c)if(g){for(d in a)if(b.apply(a[d],c)===!1)break}else for(;f>e&&b.apply(a[e++],c)!==!1;);else if(g){for(d in a)if(b.call(a[d],d,a[d])===!1)break}else for(;f>e&&b.call(a[e],e,a[e++])!==!1;);return a}function c(a){return"string"==typeof a?a.replace(/[&<>"'\/]/g,function(a){return H[a]}):a}function d(a){var b=function(a){if(window.XMLHttpRequest)return a(null,new XMLHttpRequest);if(window.ActiveXObject)try{return a(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(b){return a(null,new ActiveXObject("Microsoft.XMLHTTP"))}return a(new Error)},c=function(a){if("string"==typeof a)return a;var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")},d=function(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;cd?b+=String.fromCharCode(d):d>127&&2048>d?(b+=String.fromCharCode(d>>6|192),b+=String.fromCharCode(63&d|128)):(b+=String.fromCharCode(d>>12|224),b+=String.fromCharCode(d>>6&63|128),b+=String.fromCharCode(63&d|128))}return b},e=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";a=d(a);var c,e,f,g,h,i,j,k="",l=0;do c=a.charCodeAt(l++),e=a.charCodeAt(l++),f=a.charCodeAt(l++),g=c>>2,h=(3&c)<<4|e>>4,i=(15&e)<<2|f>>6,j=63&f,isNaN(e)?i=j=64:isNaN(f)&&(j=64),k+=b.charAt(g)+b.charAt(h)+b.charAt(i)+b.charAt(j),c=e=f="",g=h=i=j="";while(l1&&(d+=d.indexOf("?")>-1?"&"+k:"?"+k),e.jsonp){var l=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=d,void l.appendChild(m)}}b(function(b,c){if(b)return h(b);c.open(a,d,e.async);for(var f in j)j.hasOwnProperty(f)&&c.setRequestHeader(f,j[f]);c.onreadystatechange=function(){if(4===c.readyState){var a=c.responseText||"";if(!h)return;h(c.status,{text:function(){return a},json:function(){return JSON.parse(a)}})}},c.send(i)})},h={authBasic:function(a,b){g.headers.Authorization="Basic "+e(a+":"+b)},connect:function(a,b,c){return g("CONNECT",a,b,c)},del:function(a,b,c){return g("DELETE",a,b,c)},get:function(a,b,c){return g("GET",a,b,c)},head:function(a,b,c){return g("HEAD",a,b,c)},headers:function(a){g.headers=a||{}},isAllowed:function(a,b,c){this.options(a,function(a,d){c(-1!==d.text().indexOf(b))})},options:function(a,b,c){return g("OPTIONS",a,b,c)},patch:function(a,b,c){return g("PATCH",a,b,c)},post:function(a,b,c){return g("POST",a,b,c)},put:function(a,b,c){return g("PUT",a,b,c)},trace:function(a,b,c){return g("TRACE",a,b,c)}},i=a.type?a.type.toLowerCase():"get";h[i](a.url,a,function(b,c){200===b?a.success(c.json(),b,null):a.error(c.text(),b,null)})}function e(a,b){"function"==typeof a&&(b=a,a={}),a=a||{},K.extend(G,a),delete G.fixLng,"string"==typeof G.ns&&(G.ns={namespaces:[G.ns],defaultNs:G.ns}),"string"==typeof G.fallbackNS&&(G.fallbackNS=[G.fallbackNS]),G.interpolationPrefixEscaped=K.regexEscape(G.interpolationPrefix),G.interpolationSuffixEscaped=K.regexEscape(G.interpolationSuffix),G.lng||(G.lng=K.detectLanguage()),G.lng?G.useCookie&&K.cookie.create(G.cookieName,G.lng,G.cookieExpirationTime,G.cookieDomain):(G.lng=G.fallbackLng,G.useCookie&&K.cookie.remove(G.cookieName)),E=K.toLanguages(G.lng),y=E[0],K.log("currentLng set to: "+y);var c=s;a.fixLng&&(c=function(a,b){return b=b||{},b.lng=b.lng||c.lng,s(a,b)},c.lng=y),M.setCurrentLng(y),A&&G.setJqueryExt&&m();var d;if(A&&A.Deferred&&(d=A.Deferred()),!G.resStore){var e=K.toLanguages(G.lng);"string"==typeof G.preload&&(G.preload=[G.preload]);for(var f=0,g=G.preload.length;g>f;f++)for(var h=K.toLanguages(G.preload[f]),i=0,j=h.length;j>i;i++)e.indexOf(h[i])<0&&e.push(h[i]);return B.sync.load(e,G,function(a,e){C=e,F=!0,b&&b(c),d&&d.resolve(c)}),d?d.promise():void 0}return C=G.resStore,F=!0,b&&b(c),d&&d.resolve(c),d?d.promise():void 0}function f(a,b){"string"==typeof a&&(a=[a]);for(var c=0,d=a.length;d>c;c++)G.preload.indexOf(a[c])<0&&G.preload.push(a[c]);return e(b)}function g(a,b,c){"string"!=typeof b?(c=b,b=G.ns.defaultNs):G.ns.namespaces.indexOf(b)<0&&G.ns.namespaces.push(b),C[a]=C[a]||{},C[a][b]=C[a][b]||{},K.extend(C[a][b],c)}function h(a){G.ns.defaultNs=a}function i(a,b){j([a],b)}function j(a,b){var c={dynamicLoad:G.dynamicLoad,resGetPath:G.resGetPath,getAsync:G.getAsync,customLoad:G.customLoad,ns:{namespaces:a,defaultNs:""}},d=K.toLanguages(G.lng);"string"==typeof G.preload&&(G.preload=[G.preload]);for(var e=0,f=G.preload.length;f>e;e++)for(var g=K.toLanguages(G.preload[e]),h=0,i=g.length;i>h;h++)d.indexOf(g[h])<0&&d.push(g[h]);for(var j=[],k=0,l=d.length;l>k;k++){var m=!1,n=C[d[k]];if(n)for(var o=0,p=a.length;p>o;o++)n[a[o]]||(m=!0);else m=!0;m&&j.push(d[k])}j.length?B.sync._fetch(j,c,function(c,d){var e=a.length*j.length;K.each(a,function(a,c){G.ns.namespaces.indexOf(c)<0&&G.ns.namespaces.push(c),K.each(j,function(a,f){C[f]=C[f]||{},C[f][c]=d[f][c],e--,0===e&&b&&(G.useLocalStorage&&B.sync._storeLocal(C),b())})})}):b&&b()}function k(a,b,c){return"function"==typeof b&&(c=b,b={}),b.lng=a,e(b,c)}function l(){return y}function m(){function a(a,b,c){if(0!==b.length){var d="text";if(0===b.indexOf("[")){var e=b.split("]");b=e[1],d=e[0].substr(1,e[0].length-1)}b.indexOf(";")===b.length-1&&(b=b.substr(0,b.length-2));var f;"html"===d?(f=G.defaultValueFromContent?A.extend({defaultValue:a.html()},c):c,a.html(A.t(b,f))):"text"===d?(f=G.defaultValueFromContent?A.extend({defaultValue:a.text()},c):c,a.text(A.t(b,f))):(f=G.defaultValueFromContent?A.extend({defaultValue:a.attr(d)},c):c,a.attr(d,A.t(b,f)))}}function b(b,c){var d=b.attr(G.selectorAttr);if(d||"undefined"==typeof d||d===!1||(d=b.text()||b.val()),d){var e=b,f=b.data("i18n-target");if(f&&(e=b.find(f)||b),c||G.useDataAttrOptions!==!0||(c=b.data("i18n-options")),c=c||{},d.indexOf(";")>=0){var g=d.split(";");A.each(g,function(b,d){""!==d&&a(e,d,c)})}else a(e,d,c);G.useDataAttrOptions===!0&&b.data("i18n-options",c)}}A.t=A.t||s,A.fn.i18n=function(a){return this.each(function(){b(A(this),a);var c=A(this).find("["+G.selectorAttr+"]");c.each(function(){b(A(this),a)})})}}function n(a,b,c,d){if(!a)return a;if(d=d||b,a.indexOf(d.interpolationPrefix||G.interpolationPrefix)<0)return a;var e=d.interpolationPrefix?K.regexEscape(d.interpolationPrefix):G.interpolationPrefixEscaped,f=d.interpolationSuffix?K.regexEscape(d.interpolationSuffix):G.interpolationSuffixEscaped,g="HTML"+f;return K.each(b,function(b,h){var i=c?c+G.keyseparator+b:b;"object"==typeof h&&null!==h?a=n(a,h,i,d):d.escapeInterpolation||G.escapeInterpolation?(a=a.replace(new RegExp([e,i,g].join(""),"g"),h),a=a.replace(new RegExp([e,i,f].join(""),"g"),K.escape(h))):a=a.replace(new RegExp([e,i,f].join(""),"g"),h)}),a}function o(a,b){var c=",",d="{",e="}",f=K.extend({},b);for(delete f.postProcess;-1!=a.indexOf(G.reusePrefix)&&(D++,!(D>G.maxRecursion));){var g=a.lastIndexOf(G.reusePrefix),h=a.indexOf(G.reuseSuffix,g)+G.reuseSuffix.length,i=a.substring(g,h),j=i.replace(G.reusePrefix,"").replace(G.reuseSuffix,"");if(-1!=j.indexOf(c)){var k=j.indexOf(c);if(-1!=j.indexOf(d,k)&&-1!=j.indexOf(e,k)){var l=j.indexOf(d,k),m=j.indexOf(e,l)+e.length;try{f=K.extend(f,JSON.parse(j.substring(l,m))),j=j.substring(0,k)}catch(n){}}}var o=v(j,f);a=a.replace(i,o)}return a}function p(a){return a.context&&"string"==typeof a.context}function q(a){return void 0!==a.count&&"string"!=typeof a.count&&1!==a.count}function r(a,b){b=b||{};var c=t(a,b),d=w(a,b);return void 0!==d||d===c}function s(a,b){return b=b||{},F?(D=0,v.apply(null,arguments)):(K.log("i18next not finished initialization. you might have called t function before loading resources finished."),b.defaultValue||"")}function t(a,b){return void 0!==b.defaultValue?b.defaultValue:a}function u(){for(var a=[],b=1;b-1&&(e=c.split(G.nsseparator),i=e[0],c=e[1]),void 0===g&&G.sendMissing&&(b.lng?L.postMissing(h[0],i,c,f,h):L.postMissing(G.lng,i,c,f,h));var j=b.postProcess||G.postProcess;void 0!==g&&j&&N[j]&&(g=N[j](g,c,b));var k=f;if(f.indexOf(G.nsseparator)>-1&&(e=f.split(G.nsseparator),k=e[1]),k===c&&G.parseMissingKey&&(f=G.parseMissingKey(f)),void 0===g&&(f=n(f,b),f=o(f,b),j&&N[j])){var l=t(c,b);g=N[j](l,c,b)}return void 0!==g?g:f}function w(a,b){b=b||{};var c,d,e=t(a,b),f=E;if(!C)return e;if(b.lng&&(f=K.toLanguages(b.lng),!C[f[0]])){var g=G.getAsync;G.getAsync=!1,B.sync.load(f,G,function(a,b){K.extend(C,b),G.getAsync=g})}var h=b.ns||G.ns.defaultNs;if(a.indexOf(G.nsseparator)>-1){var i=a.split(G.nsseparator);h=i[0],a=i[1]}if(p(b)){c=K.extend({},b),delete c.context,c.defaultValue=G.contextNotFound;var j=h+G.nsseparator+a+"_"+b.context;if(d=s(j,c),d!=G.contextNotFound)return n(d,{context:b.context})}if(q(b)){c=K.extend({},b),delete c.count,c.defaultValue=G.pluralNotFound;var k=h+G.nsseparator+a+G.pluralSuffix,l=M.get(f[0],b.count);if(l>=0?k=k+"_"+l:1===l&&(k=h+G.nsseparator+a),d=s(k,c),d!=G.pluralNotFound)return n(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix})}for(var m,r=a.split(G.keyseparator),u=0,x=f.length;x>u&&void 0===m;u++){for(var y=f[u],z=0,A=C[y]&&C[y][h];r[z];)A=A&&A[r[z]],z++;if(void 0!==A){if("string"==typeof A)A=n(A,b),A=o(A,b);else if("[object Array]"!==Object.prototype.toString.apply(A)||G.returnObjectTrees||b.returnObjectTrees){if(null===A&&G.fallbackOnNull===!0)A=void 0;else if(null!==A)if(G.returnObjectTrees||b.returnObjectTrees){if("number"!=typeof A){var D={};K.each(A,function(c){D[c]=v(h+G.nsseparator+a+G.keyseparator+c,b)}),A=D}}else A="key '"+h+":"+a+" ("+y+")' returned an object instead of string.",K.log(A)}else A=A.join("\n"),A=n(A,b),A=o(A,b);"string"==typeof A&&""===A.trim()&&G.fallbackOnEmpty===!0&&(A=void 0),m=A}}if(void 0===m&&!b.isFallbackLookup&&(G.fallbackToDefaultNS===!0||G.fallbackNS&&G.fallbackNS.length>0))if(b.isFallbackLookup=!0,G.fallbackNS.length){for(var F=0,H=G.fallbackNS.length;H>F;F++)if(m=w(G.fallbackNS[F]+G.nsseparator+a,b)){var I=m.indexOf(G.nsseparator)>-1?m.split(G.nsseparator)[1]:m,J=e.indexOf(G.nsseparator)>-1?e.split(G.nsseparator)[1]:e;if(I!==J)break}}else m=w(a,b);return m}function x(){var a,b=[];if("undefined"!=typeof window&&(!function(){for(var a=window.location.search.substring(1),c=a.split("&"),d=0;d0){var f=c[d].substring(0,e),g=c[d].substring(e+1);b[f]=g}}}(),b[G.detectLngQS]&&(a=b[G.detectLngQS])),!a&&"undefined"!=typeof document&&G.useCookie){var c=K.cookie.read(G.cookieName);c&&(a=c)}return a||"undefined"==typeof navigator||(a=navigator.language?navigator.language:navigator.userLanguage),a}Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>0&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&1/0!=d&&d!=-1/0&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=c;arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d))));for(var e=d>=0?Math.min(d,c-1):c-Math.abs(d);e>=0;e--)if(e in b&&b[e]===a)return e;return-1});var y,z=this,A=z.jQuery||z.Zepto,B={},C={},D=0,E=[],F=!1;"undefined"!=typeof module&&module.exports?module.exports=B:(A&&(A.i18n=A.i18n||B),z.i18n=z.i18n||B);var G={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:"dev",fallbackNS:[],detectLngQS:"setLng",ns:"translation",fallbackOnNull:!0,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",cookieDomain:void 0,postProcess:void 0,parseMissingKey:void 0,shortcutFunction:"sprintf"},H={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},I={create:function(a,b,c,d){var e;if(c){var f=new Date;f.setTime(f.getTime()+60*c*1e3),e="; expires="+f.toGMTString()}else e="";d=d?"domain="+d+";":"",document.cookie=a+"="+b+e+";"+d+"path=/"},read:function(a){for(var b=a+"=",c=document.cookie.split(";"),d=0;d-1){var c=a.split("-");a=G.lowerCaseLng?c[0].toLowerCase()+"-"+c[1].toLowerCase():c[0].toLowerCase()+"-"+c[1].toUpperCase(),"unspecific"!==G.load&&b.push(a),"current"!==G.load&&b.push(c[0])}else b.push(a);return-1===b.indexOf(G.fallbackLng)&&G.fallbackLng&&b.push(G.fallbackLng),b},regexEscape:function(a){return a.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}};K.applyReplacement=n;var L={load:function(a,b,c){b.useLocalStorage?L._loadLocal(a,b,function(d,e){for(var f=[],g=0,h=a.length;h>g;g++)e[a[g]]||f.push(a[g]);f.length>0?L._fetch(f,b,function(a,b){K.extend(e,b),L._storeLocal(b),c(null,e)}):c(null,e)}):L._fetch(a,b,function(a,b){c(null,b)})},_loadLocal:function(a,b,c){var d={},e=(new Date).getTime();if(window.localStorage){var f=a.length;K.each(a,function(a,g){var h=window.localStorage.getItem("res_"+g);h&&(h=JSON.parse(h),h.i18nStamp&&h.i18nStamp+b.localStorageExpirationTime>e&&(d[g]=h)),f--,0===f&&c(null,d)})}},_storeLocal:function(a){if(window.localStorage)for(var b in a)a[b].i18nStamp=(new Date).getTime(),window.localStorage.setItem("res_"+b,JSON.stringify(a[b]))},_fetch:function(a,b,c){var d=b.ns,e={};if(b.dynamicLoad){var f=function(a,b){c(null,b)};if("function"==typeof b.customLoad)b.customLoad(a,d.namespaces,b,f);else{var g=n(b.resGetPath,{lng:a.join("+"),ns:d.namespaces.join("+")});K.ajax({url:g,success:function(a){K.log("loaded: "+g),f(null,a)},error:function(a,b,c){K.log("failed loading: "+g),f("failed loading resource.json error: "+c)},dataType:"json",async:b.getAsync})}}else{var h,i=d.namespaces.length*a.length;K.each(d.namespaces,function(d,f){K.each(a,function(a,d){var g=function(a,b){a&&(h=h||[],h.push(a)),e[d]=e[d]||{},e[d][f]=b,i--,0===i&&c(h,e)};"function"==typeof b.customLoad?b.customLoad(d,f,b,g):L._fetchOne(d,f,b,g)})})}},_fetchOne:function(a,b,c,d){var e=n(c.resGetPath,{lng:a,ns:b});K.ajax({url:e,success:function(a){K.log("loaded: "+e),d(null,a)},error:function(a,b,c){K.log("failed loading: "+e),d(c,{})},dataType:"json",async:c.getAsync})},postMissing:function(a,b,c,d,e){var f={};f[c]=d;var g=[];if("fallback"===G.sendMissingTo&&G.fallbackLng!==!1)g.push({lng:G.fallbackLng,url:n(G.resPostPath,{lng:G.fallbackLng,ns:b})});else if("current"===G.sendMissingTo||"fallback"===G.sendMissingTo&&G.fallbackLng===!1)g.push({lng:a,url:n(G.resPostPath,{lng:a,ns:b})});else if("all"===G.sendMissingTo)for(var h=0,i=e.length;i>h;h++)g.push({lng:e[h],url:n(G.resPostPath,{lng:e[h],ns:b})});for(var j=0,k=g.length;k>j;j++){var l=g[j];K.ajax({url:l.url,type:G.sendType,data:f,success:function(){K.log("posted missing key '"+c+"' to: "+l.url);for(var a=c.split("."),e=0,f=C[l.lng][b];a[e];)f=f[a[e]]=e===a.length-1?d:f[a[e]]||{},e++},error:function(){K.log("failed posting missing key '"+c+"' to: "+l.url)},dataType:"json",async:G.postAsync})}}},M={rules:{ach:{name:"Acholi",numbers:[1,2],plurals:function(a){return Number(a>1)}},af:{name:"Afrikaans",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ak:{name:"Akan",numbers:[1,2],plurals:function(a){return Number(a>1)}},am:{name:"Amharic",numbers:[1,2],plurals:function(a){return Number(a>1)}},an:{name:"Aragonese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ar:{name:"Arabic",numbers:[0,1,2,3,11,100],plurals:function(a){return Number(0===a?0:1==a?1:2==a?2:a%100>=3&&10>=a%100?3:a%100>=11?4:5)}},arn:{name:"Mapudungun",numbers:[1,2],plurals:function(a){return Number(a>1)}},ast:{name:"Asturian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ay:{name:"Aymará",numbers:[1],plurals:function(){return 0}},az:{name:"Azerbaijani",numbers:[1,2],plurals:function(a){return Number(1!=a)}},be:{name:"Belarusian",numbers:[1,2,5],plurals:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},bg:{name:"Bulgarian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},bn:{name:"Bengali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},bo:{name:"Tibetan",numbers:[1],plurals:function(){return 0}},br:{name:"Breton",numbers:[1,2],plurals:function(a){return Number(a>1)}},bs:{name:"Bosnian",numbers:[1,2,5],plurals:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},ca:{name:"Catalan",numbers:[1,2],plurals:function(a){return Number(1!=a)}},cgg:{name:"Chiga",numbers:[1],plurals:function(){return 0}},cs:{name:"Czech",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)}},csb:{name:"Kashubian",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},cy:{name:"Welsh",numbers:[1,2,3,8],plurals:function(a){return Number(1==a?0:2==a?1:8!=a&&11!=a?2:3)}},da:{name:"Danish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},de:{name:"German",numbers:[1,2],plurals:function(a){return Number(1!=a)}},dz:{name:"Dzongkha",numbers:[1],plurals:function(){return 0}},el:{name:"Greek",numbers:[1,2],plurals:function(a){return Number(1!=a)}},en:{name:"English",numbers:[1,2],plurals:function(a){return Number(1!=a)}},eo:{name:"Esperanto",numbers:[1,2],plurals:function(a){return Number(1!=a)}},es:{name:"Spanish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},es_ar:{name:"Argentinean Spanish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},et:{name:"Estonian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},eu:{name:"Basque",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fa:{name:"Persian",numbers:[1],plurals:function(){return 0}},fi:{name:"Finnish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fil:{name:"Filipino",numbers:[1,2],plurals:function(a){return Number(a>1)}},fo:{name:"Faroese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fr:{name:"French",numbers:[1,2],plurals:function(a){return Number(a>1)}},fur:{name:"Friulian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fy:{name:"Frisian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ga:{name:"Irish",numbers:[1,2,3,7,11],plurals:function(a){return Number(1==a?0:2==a?1:7>a?2:11>a?3:4)}},gd:{name:"Scottish Gaelic",numbers:[1,2,3,20],plurals:function(a){return Number(1==a||11==a?0:2==a||12==a?1:a>2&&20>a?2:3)}},gl:{name:"Galician",numbers:[1,2],plurals:function(a){return Number(1!=a)}},gu:{name:"Gujarati",numbers:[1,2],plurals:function(a){return Number(1!=a)}},gun:{name:"Gun",numbers:[1,2],plurals:function(a){return Number(a>1)}},ha:{name:"Hausa",numbers:[1,2],plurals:function(a){return Number(1!=a)}},he:{name:"Hebrew",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hi:{name:"Hindi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hr:{name:"Croatian",numbers:[1,2,5],plurals:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},hu:{name:"Hungarian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hy:{name:"Armenian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ia:{name:"Interlingua",numbers:[1,2],plurals:function(a){return Number(1!=a)}},id:{name:"Indonesian",numbers:[1],plurals:function(){return 0}},is:{name:"Icelandic",numbers:[1,2],plurals:function(a){return Number(a%10!=1||a%100==11)}},it:{name:"Italian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ja:{name:"Japanese",numbers:[1],plurals:function(){return 0}},jbo:{name:"Lojban",numbers:[1],plurals:function(){return 0}},jv:{name:"Javanese",numbers:[0,1],plurals:function(a){return Number(0!==a)}},ka:{name:"Georgian",numbers:[1],plurals:function(){return 0}},kk:{name:"Kazakh",numbers:[1],plurals:function(){return 0}},km:{name:"Khmer",numbers:[1],plurals:function(){return 0}},kn:{name:"Kannada",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ko:{name:"Korean",numbers:[1],plurals:function(){return 0}},ku:{name:"Kurdish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},kw:{name:"Cornish",numbers:[1,2,3,4],plurals:function(a){return Number(1==a?0:2==a?1:3==a?2:3)}},ky:{name:"Kyrgyz",numbers:[1],plurals:function(){return 0}},lb:{name:"Letzeburgesch",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ln:{name:"Lingala",numbers:[1,2],plurals:function(a){return Number(a>1)}},lo:{name:"Lao",numbers:[1],plurals:function(){return 0}},lt:{name:"Lithuanian",numbers:[1,2,10],plurals:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&(10>a%100||a%100>=20)?1:2)}},lv:{name:"Latvian",numbers:[0,1,2],plurals:function(a){return Number(a%10==1&&a%100!=11?0:0!==a?1:2)}},mai:{name:"Maithili",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mfe:{name:"Mauritian Creole",numbers:[1,2],plurals:function(a){return Number(a>1)}},mg:{name:"Malagasy",numbers:[1,2],plurals:function(a){return Number(a>1)}},mi:{name:"Maori",numbers:[1,2],plurals:function(a){return Number(a>1)}},mk:{name:"Macedonian",numbers:[1,2],plurals:function(a){return Number(1==a||a%10==1?0:1)}},ml:{name:"Malayalam",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mn:{name:"Mongolian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mnk:{name:"Mandinka",numbers:[0,1,2],plurals:function(a){return Number(1==a?1:2)}},mr:{name:"Marathi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ms:{name:"Malay",numbers:[1],plurals:function(){return 0}},mt:{name:"Maltese",numbers:[1,2,11,20],plurals:function(a){return Number(1==a?0:0===a||a%100>1&&11>a%100?1:a%100>10&&20>a%100?2:3)}},nah:{name:"Nahuatl",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nap:{name:"Neapolitan",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nb:{name:"Norwegian Bokmal",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ne:{name:"Nepali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nl:{name:"Dutch",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nn:{name:"Norwegian Nynorsk",numbers:[1,2],plurals:function(a){return Number(1!=a)}},no:{name:"Norwegian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nso:{name:"Northern Sotho",numbers:[1,2],plurals:function(a){return Number(1!=a)}},oc:{name:"Occitan",numbers:[1,2],plurals:function(a){return Number(a>1)}},or:{name:"Oriya",numbers:[2,1],plurals:function(a){return Number(1!=a)}},pa:{name:"Punjabi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pap:{name:"Papiamento",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pl:{name:"Polish",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},pms:{name:"Piemontese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ps:{name:"Pashto",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pt:{name:"Portuguese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pt_br:{name:"Brazilian Portuguese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},rm:{name:"Romansh",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ro:{name:"Romanian",numbers:[1,2,20],plurals:function(a){return Number(1==a?0:0===a||a%100>0&&20>a%100?1:2)}},ru:{name:"Russian",numbers:[1,2,5],plurals:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},sah:{name:"Yakut",numbers:[1],plurals:function(){return 0}},sco:{name:"Scots",numbers:[1,2],plurals:function(a){return Number(1!=a)}},se:{name:"Northern Sami",numbers:[1,2],plurals:function(a){return Number(1!=a)}},si:{name:"Sinhala",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sk:{name:"Slovak",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)}},sl:{name:"Slovenian",numbers:[5,1,2,3],plurals:function(a){return Number(a%100==1?1:a%100==2?2:a%100==3||a%100==4?3:0)}},so:{name:"Somali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},son:{name:"Songhay",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sq:{name:"Albanian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sr:{name:"Serbian",numbers:[1,2,5],plurals:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},su:{name:"Sundanese",numbers:[1],plurals:function(){return 0}},sv:{name:"Swedish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sw:{name:"Swahili",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ta:{name:"Tamil",numbers:[1,2],plurals:function(a){return Number(1!=a)}},te:{name:"Telugu",numbers:[1,2],plurals:function(a){return Number(1!=a)}},tg:{name:"Tajik",numbers:[1,2],plurals:function(a){return Number(a>1)}},th:{name:"Thai",numbers:[1],plurals:function(){return 0}},ti:{name:"Tigrinya",numbers:[1,2],plurals:function(a){return Number(a>1)}},tk:{name:"Turkmen",numbers:[1,2],plurals:function(a){return Number(1!=a)}},tr:{name:"Turkish",numbers:[1,2],plurals:function(a){return Number(a>1)}},tt:{name:"Tatar",numbers:[1],plurals:function(){return 0}},ug:{name:"Uyghur",numbers:[1],plurals:function(){return 0}},uk:{name:"Ukrainian",numbers:[1,2,5],plurals:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},ur:{name:"Urdu",numbers:[1,2],plurals:function(a){return Number(1!=a)}},uz:{name:"Uzbek",numbers:[1,2],plurals:function(a){return Number(a>1)}},vi:{name:"Vietnamese",numbers:[1],plurals:function(){return 0}},wa:{name:"Walloon",numbers:[1,2],plurals:function(a){return Number(a>1)}},wo:{name:"Wolof",numbers:[1],plurals:function(){return 0}},yo:{name:"Yoruba",numbers:[1,2],plurals:function(a){return Number(1!=a)}},zh:{name:"Chinese",numbers:[1],plurals:function(){return 0}}},addRule:function(a,b){M.rules[a]=b},setCurrentLng:function(a){if(!M.currentRule||M.currentRule.lng!==a){var b=a.split("-");M.currentRule={lng:a,rule:M.rules[b[0]]}}},get:function(a,b){function c(b,c){var d;if(d=M.currentRule&&M.currentRule.lng===a?M.currentRule.rule:M.rules[b]){var e=d.plurals(c),f=d.numbers[e];return 2===d.numbers.length&&1===d.numbers[0]&&(2===f?f=-1:1===f&&(f=1)),f}return 1===c?"1":"-1"}var d=a.split("-");return c(d[0],b)}},N={},O=function(a,b){N[a]=b},P=function(){function a(a){return Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}function b(a,b){for(var c=[];b>0;c[--b]=a);return c.join("")}var c=function(){return c.cache.hasOwnProperty(arguments[0])||(c.cache[arguments[0]]=c.parse(arguments[0])),c.format.call(null,c.cache[arguments[0]],arguments)};return c.format=function(c,d){var e,f,g,h,i,j,k,l=1,m=c.length,n="",o=[];for(f=0;m>f;f++)if(n=a(c[f]),"string"===n)o.push(c[f]);else if("array"===n){if(h=c[f],h[2])for(e=d[l],g=0;g=0?"+"+e:e,j=h[4]?"0"==h[4]?"0":h[4].charAt(1):" ",k=h[6]-String(e).length,i=h[6]?b(j,k):"",o.push(h[5]?e+i:i+e)}return o.join("")},c.cache={},c.parse=function(a){for(var b=a,c=[],d=[],e=0;b;){if(null!==(c=/^[^\x25]+/.exec(b)))d.push(c[0]);else if(null!==(c=/^\x25{2}/.exec(b)))d.push("%");else{if(null===(c=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(b)))throw"[sprintf] huh?";if(c[2]){e|=1;var f=[],g=c[2],h=[];if(null===(h=/^([a-z_][a-z_\d]*)/i.exec(g)))throw"[sprintf] huh?";for(f.push(h[1]);""!==(g=g.substring(h[0].length));)if(null!==(h=/^\.([a-z_][a-z_\d]*)/i.exec(g)))f.push(h[1]);else{if(null===(h=/^\[(\d+)\]/.exec(g)))throw"[sprintf] huh?";f.push(h[1])}c[2]=f}else e|=2;if(3===e)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";d.push(c)}b=b.substring(c[0].length)}return d},c}(),Q=function(a,b){return b.unshift(a),P.apply(null,b)};O("sprintf",function(a,b,c){return c.sprintf?"[object Array]"===Object.prototype.toString.apply(c.sprintf)?Q(a,c.sprintf):"object"==typeof c.sprintf?P(a,c.sprintf):a:a}),B.init=e,B.setLng=k,B.preload=f,B.addResourceBundle=g,B.loadNamespace=i,B.loadNamespaces=j,B.setDefaultNamespace=h,B.t=s,B.translate=s,B.exists=r,B.detectLanguage=K.detectLanguage,B.pluralExtensions=M,B.sync=L,B.functions=K,B.lng=l,B.addPostProcessor=O,B.options=G}(); \ No newline at end of file diff --git a/libs/i18next/release/i18next-1.7.1.zip b/libs/i18next/release/i18next-1.7.1.zip new file mode 100644 index 00000000..188e2f62 Binary files /dev/null and b/libs/i18next/release/i18next-1.7.1.zip differ diff --git a/libs/i18next/release/i18next-1.7.2.js b/libs/i18next/release/i18next-1.7.2.js new file mode 100644 index 00000000..1f1ab361 --- /dev/null +++ b/libs/i18next/release/i18next-1.7.2.js @@ -0,0 +1,2705 @@ +// i18next, v1.7.2 +// Copyright (c)2014 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function() { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + var root = this + , $ = root.jQuery || root.Zepto + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = [] + , initialized = false; + + + // Export the i18next object for **CommonJS**. + // If we're not in CommonJS, add `i18n` to the + // global object or to jquery. + if (typeof module !== 'undefined' && module.exports) { + module.exports = i18n; + } else { + if ($) { + $.i18n = $.i18n || i18n; + } + + root.i18n = root.i18n || i18n; + } + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: 'dev', + fallbackNS: [], + detectLngQS: 'setLng', + ns: 'translation', + fallbackOnNull: true, + fallbackOnEmpty: false, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + cookieDomain: undefined, + + objectTreeKeyHandler: undefined, + postProcess: undefined, + parseMissingKey: undefined, + + shortcutFunction: 'sprintf' // or: defaultValue + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + return JSON.parse(data); + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + if (status === 200) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes,domain) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + domain = (domain)? "domain="+domain+";" : ""; + document.cookie = name+"="+value+expires+";"+domain+"path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes,domain) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : (typeof document !== 'undefined' ? _ajax : function() {}), + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + toLanguages: function(lng) { + var languages = []; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + + if (o.load !== 'unspecific') languages.push(lng); + if (o.load !== 'current') languages.push(parts[0]); + } else { + languages.push(lng); + } + + if (languages.indexOf(o.fallbackLng) === -1 && o.fallbackLng) languages.push(o.fallbackLng); + + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + delete o.fixLng; /* passed in each time */ + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + if (o.lng) { + // set cookie with lng set (as detectLanguage will set cookie on need) + if (o.useCookie) f.cookie.create(o.cookieName, o.lng, o.cookieExpirationTime, o.cookieDomain); + } else { + o.lng = o.fallbackLng; + if (o.useCookie) f.cookie.remove(o.cookieName); + } + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + var lngTranslate = translate; + if (options.fixLng) { + lngTranslate = function(key, options) { + options = options || {}; + options.lng = options.lng || lngTranslate.lng; + return translate(key, options); + }; + lngTranslate.lng = currentLng; + } + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + initialized = true; + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + initialized = true; + + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + f.extend(resStore[lng][ns], resources); + } + + function removeResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = {}; + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, options, cb) { + if (typeof options === 'function') { + cb = options; + options = {}; + } else if (!options) { + options = {}; + } + + options.lng = lng; + return init(options, cb); + } + + function lng() { + return currentLng; + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else if (attr === 'prepend') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.prepend($.t(key, optionsToUse)); + } else if (attr === 'append') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.append($.t(key, optionsToUse)); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key && typeof key !== 'undefined' && key !== false) key = ele.text() || ele.val(); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + f.each(replacementHash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), value); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.escape(value)); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), value); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, translated_token); + } + return translated; + } + + function hasContext(options) { + return (options.context && (typeof options.context == 'string' || typeof options.context == 'number')); + } + + function needsPlural(options) { + return (options.count !== undefined && typeof options.count != 'string' && options.count !== 1); + } + + function exists(key, options) { + options = options || {}; + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + options = options || {}; + + if (!initialized) { + f.log('i18next not finished initialization. you might have called t function before loading resources finished.') + return options.defaultValue || ''; + }; + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _getDefaultValue(key, options) { + return (options.defaultValue !== undefined) ? options.defaultValue : key; + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(potentialKeys, options) { + if (typeof options == 'string') { + if (o.shortcutFunction === 'sprintf') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else if (o.shortcutFunction === 'defaultValue') { + options = { + defaultValue: options + } + } + } else { + options = options || {}; + } + + if (potentialKeys === undefined || potentialKeys === null) return ''; + + if (typeof potentialKeys == 'string') { + potentialKeys = [potentialKeys]; + } + + var key = potentialKeys[0]; + + if (potentialKeys.length > 1) { + for (var i = 0; i < potentialKeys.length; i++) { + key = potentialKeys[i]; + if (exists(key)) { + break; + } + } + } + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng) : languages + , ns = options.ns || o.ns.defaultNs + , parts; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing) { + if (options.lng) { + sync.postMissing(lngs[0], ns, key, notFound, lngs); + } else { + sync.postMissing(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found !== undefined && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + // process notFound if function exists + var splitNotFound = notFound; + if (notFound.indexOf(o.nsseparator) > -1) { + parts = notFound.split(o.nsseparator); + splitNotFound = parts[1]; + } + if (splitNotFound === key && o.parseMissingKey) { + notFound = o.parseMissingKey(notFound); + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessor && postProcessors[postProcessor]) { + var val = _getDefaultValue(key, options); + found = postProcessors[postProcessor](val, key, options); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options) { + options = options || {}; + + var optionWithoutCount, translated + , notFound = _getDefaultValue(key, options) + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + if (options.lng) { + lngs = f.toLanguages(options.lng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.count; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(lngs[0], options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + + translated = translate(pluralKey, optionWithoutCount); + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } // else continue translation with original/singular key + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + var valueType = Object.prototype.toString.apply(value); + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (valueType === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + if (o.objectTreeKeyHandler && typeof o.objectTreeKeyHandler == 'function') { + value = o.objectTreeKeyHandler(key, value, l, ns, options); + } else { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned an object instead of string.'; + f.log(value); + } + } else if (valueType !== '[object Number]' && valueType !== '[object Function]' && valueType !== '[object RegExp]') { + var copy = (valueType === '[object Array]') ? [] : {}; // apply child translation on a copy + f.each(value, function(m) { + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + }); + value = copy; + } + } + + if (typeof value === 'string' && value.trim() === '' && o.fallbackOnEmpty === true) + value = undefined; + + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length > 0))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + } + + return found; + } + function detectLanguage() { + var detectedLng; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var parms = query.split('&'); + for (var i=0; i 0) { + var key = parms[i].substring(0,pos); + var val = parms[i].substring(pos+1); + qsParm[key] = val; + } + } + })(); + if (qsParm[o.detectLngQS]) { + detectedLng = qsParm[o.detectLngQS]; + } + } + + // get from cookie + if (!detectedLng && typeof document !== 'undefined' && o.useCookie ) { + var c = f.cookie.read(o.cookieName); + if (c) detectedLng = c; + } + + // get from navigator + if (!detectedLng && typeof navigator !== 'undefined') { + detectedLng = (navigator.language) ? navigator.language : navigator.userLanguage; + } + + return detectedLng; + } + var sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + window.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + if (error.status == 200) { + // file loaded but invalid json, stop waste time ! + f.log('There is a typo in: ' + url); + } else if (error.status == 404) { + f.log('Does not exist: ' + url); + } else { + f.log(error.status + ' when loading ' + url); + } + + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback' && o.fallbackLng !== false) { + urls.push({lng: o.fallbackLng, url: applyReplacement(o.resPostPath, { lng: o.fallbackLng, ns: ns })}); + } else if (o.sendMissingTo === 'current' || (o.sendMissingTo === 'fallback' && o.fallbackLng === false) ) { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + } + }; + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + var pluralExtensions = { + + rules: { + "ach": { + "name": "Acholi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "af": { + "name": "Afrikaans", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ak": { + "name": "Akan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "am": { + "name": "Amharic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "an": { + "name": "Aragonese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ar": { + "name": "Arabic", + "numbers": [ + 0, + 1, + 2, + 3, + 11, + 100 + ], + "plurals": function(n) { return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5); } + }, + "arn": { + "name": "Mapudungun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ast": { + "name": "Asturian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ay": { + "name": "Aymar\u00e1", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "az": { + "name": "Azerbaijani", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "be": { + "name": "Belarusian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "bg": { + "name": "Bulgarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bn": { + "name": "Bengali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bo": { + "name": "Tibetan", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "br": { + "name": "Breton", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "bs": { + "name": "Bosnian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ca": { + "name": "Catalan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "cgg": { + "name": "Chiga", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "cs": { + "name": "Czech", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "csb": { + "name": "Kashubian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "cy": { + "name": "Welsh", + "numbers": [ + 1, + 2, + 3, + 8 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3); } + }, + "da": { + "name": "Danish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "de": { + "name": "German", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "dz": { + "name": "Dzongkha", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "el": { + "name": "Greek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "en": { + "name": "English", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eo": { + "name": "Esperanto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es": { + "name": "Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es_ar": { + "name": "Argentinean Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "et": { + "name": "Estonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eu": { + "name": "Basque", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fa": { + "name": "Persian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "fi": { + "name": "Finnish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fil": { + "name": "Filipino", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fo": { + "name": "Faroese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fr": { + "name": "French", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fur": { + "name": "Friulian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fy": { + "name": "Frisian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ga": { + "name": "Irish", + "numbers": [ + 1, + 2, + 3, + 7, + 11 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;} + }, + "gd": { + "name": "Scottish Gaelic", + "numbers": [ + 1, + 2, + 3, + 20 + ], + "plurals": function(n) { return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3); } + }, + "gl": { + "name": "Galician", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gu": { + "name": "Gujarati", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gun": { + "name": "Gun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ha": { + "name": "Hausa", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "he": { + "name": "Hebrew", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hi": { + "name": "Hindi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hr": { + "name": "Croatian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "hu": { + "name": "Hungarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hy": { + "name": "Armenian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ia": { + "name": "Interlingua", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "id": { + "name": "Indonesian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "is": { + "name": "Icelandic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n%10!=1 || n%100==11); } + }, + "it": { + "name": "Italian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ja": { + "name": "Japanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jbo": { + "name": "Lojban", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jv": { + "name": "Javanese", + "numbers": [ + 0, + 1 + ], + "plurals": function(n) { return Number(n !== 0); } + }, + "ka": { + "name": "Georgian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kk": { + "name": "Kazakh", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "km": { + "name": "Khmer", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kn": { + "name": "Kannada", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ko": { + "name": "Korean", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ku": { + "name": "Kurdish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "kw": { + "name": "Cornish", + "numbers": [ + 1, + 2, + 3, + 4 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3); } + }, + "ky": { + "name": "Kyrgyz", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lb": { + "name": "Letzeburgesch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ln": { + "name": "Lingala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "lo": { + "name": "Lao", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lt": { + "name": "Lithuanian", + "numbers": [ + 1, + 2, + 10 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "lv": { + "name": "Latvian", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2); } + }, + "mai": { + "name": "Maithili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mfe": { + "name": "Mauritian Creole", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mg": { + "name": "Malagasy", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mi": { + "name": "Maori", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mk": { + "name": "Macedonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 || n%10==1 ? 0 : 1); } + }, + "ml": { + "name": "Malayalam", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mn": { + "name": "Mongolian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mnk": { + "name": "Mandinka", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(0 ? 0 : n==1 ? 1 : 2); } + }, + "mr": { + "name": "Marathi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ms": { + "name": "Malay", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "mt": { + "name": "Maltese", + "numbers": [ + 1, + 2, + 11, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3); } + }, + "nah": { + "name": "Nahuatl", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nap": { + "name": "Neapolitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nb": { + "name": "Norwegian Bokmal", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ne": { + "name": "Nepali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nl": { + "name": "Dutch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nn": { + "name": "Norwegian Nynorsk", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "no": { + "name": "Norwegian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nso": { + "name": "Northern Sotho", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "oc": { + "name": "Occitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "or": { + "name": "Oriya", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pa": { + "name": "Punjabi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pap": { + "name": "Papiamento", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pl": { + "name": "Polish", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "pms": { + "name": "Piemontese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ps": { + "name": "Pashto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt": { + "name": "Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt_br": { + "name": "Brazilian Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "rm": { + "name": "Romansh", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ro": { + "name": "Romanian", + "numbers": [ + 1, + 2, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2); } + }, + "ru": { + "name": "Russian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "sah": { + "name": "Yakut", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sco": { + "name": "Scots", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "se": { + "name": "Northern Sami", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "si": { + "name": "Sinhala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sk": { + "name": "Slovak", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "sl": { + "name": "Slovenian", + "numbers": [ + 5, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }, + "so": { + "name": "Somali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "son": { + "name": "Songhay", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sq": { + "name": "Albanian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sr": { + "name": "Serbian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "su": { + "name": "Sundanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sv": { + "name": "Swedish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sw": { + "name": "Swahili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ta": { + "name": "Tamil", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "te": { + "name": "Telugu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tg": { + "name": "Tajik", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "th": { + "name": "Thai", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ti": { + "name": "Tigrinya", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tk": { + "name": "Turkmen", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tr": { + "name": "Turkish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tt": { + "name": "Tatar", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ug": { + "name": "Uyghur", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "uk": { + "name": "Ukrainian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ur": { + "name": "Urdu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "uz": { + "name": "Uzbek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "vi": { + "name": "Vietnamese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "wa": { + "name": "Walloon", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "wo": { + "name": "Wolof", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "yo": { + "name": "Yoruba", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "zh": { + "name": "Chinese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + } + }, + + // for demonstration only sl and ar is added but you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i = ext.plurals(c); + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[0], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.removeResourceBundle = removeResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + +})(); \ No newline at end of file diff --git a/libs/i18next/release/i18next-1.7.2.min.js b/libs/i18next/release/i18next-1.7.2.min.js new file mode 100644 index 00000000..46f2be8b --- /dev/null +++ b/libs/i18next/release/i18next-1.7.2.min.js @@ -0,0 +1,5 @@ +// i18next, v1.7.2 +// Copyright (c)2014 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +!function(){function a(a,b){if(!b||"function"==typeof b)return a;for(var c in b)a[c]=b[c];return a}function b(a,b,c){var d,e=0,f=a.length,g=void 0===f||"function"==typeof a;if(c)if(g){for(d in a)if(b.apply(a[d],c)===!1)break}else for(;f>e&&b.apply(a[e++],c)!==!1;);else if(g){for(d in a)if(b.call(a[d],d,a[d])===!1)break}else for(;f>e&&b.call(a[e],e,a[e++])!==!1;);return a}function c(a){return"string"==typeof a?a.replace(/[&<>"'\/]/g,function(a){return I[a]}):a}function d(a){var b=function(a){if(window.XMLHttpRequest)return a(null,new XMLHttpRequest);if(window.ActiveXObject)try{return a(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(b){return a(null,new ActiveXObject("Microsoft.XMLHTTP"))}return a(new Error)},c=function(a){if("string"==typeof a)return a;var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")},d=function(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;cd?b+=String.fromCharCode(d):d>127&&2048>d?(b+=String.fromCharCode(192|d>>6),b+=String.fromCharCode(128|63&d)):(b+=String.fromCharCode(224|d>>12),b+=String.fromCharCode(128|63&d>>6),b+=String.fromCharCode(128|63&d))}return b},e=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";a=d(a);var c,e,f,g,h,i,j,k="",l=0;do c=a.charCodeAt(l++),e=a.charCodeAt(l++),f=a.charCodeAt(l++),g=c>>2,h=(3&c)<<4|e>>4,i=(15&e)<<2|f>>6,j=63&f,isNaN(e)?i=j=64:isNaN(f)&&(j=64),k+=b.charAt(g)+b.charAt(h)+b.charAt(i)+b.charAt(j),c=e=f="",g=h=i=j="";while(l1&&(d+=d.indexOf("?")>-1?"&"+k:"?"+k),e.jsonp){var l=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=d,l.appendChild(m),void 0}}b(function(b,c){if(b)return h(b);c.open(a,d,e.async);for(var f in j)j.hasOwnProperty(f)&&c.setRequestHeader(f,j[f]);c.onreadystatechange=function(){if(4===c.readyState){var a=c.responseText||"";if(!h)return;h(c.status,{text:function(){return a},json:function(){return JSON.parse(a)}})}},c.send(i)})},h={authBasic:function(a,b){g.headers.Authorization="Basic "+e(a+":"+b)},connect:function(a,b,c){return g("CONNECT",a,b,c)},del:function(a,b,c){return g("DELETE",a,b,c)},get:function(a,b,c){return g("GET",a,b,c)},head:function(a,b,c){return g("HEAD",a,b,c)},headers:function(a){g.headers=a||{}},isAllowed:function(a,b,c){this.options(a,function(a,d){c(-1!==d.text().indexOf(b))})},options:function(a,b,c){return g("OPTIONS",a,b,c)},patch:function(a,b,c){return g("PATCH",a,b,c)},post:function(a,b,c){return g("POST",a,b,c)},put:function(a,b,c){return g("PUT",a,b,c)},trace:function(a,b,c){return g("TRACE",a,b,c)}},i=a.type?a.type.toLowerCase():"get";h[i](a.url,a,function(b,c){200===b?a.success(c.json(),b,null):a.error(c.text(),b,null)})}function e(a,b){"function"==typeof a&&(b=a,a={}),a=a||{},L.extend(H,a),delete H.fixLng,"string"==typeof H.ns&&(H.ns={namespaces:[H.ns],defaultNs:H.ns}),"string"==typeof H.fallbackNS&&(H.fallbackNS=[H.fallbackNS]),H.interpolationPrefixEscaped=L.regexEscape(H.interpolationPrefix),H.interpolationSuffixEscaped=L.regexEscape(H.interpolationSuffix),H.lng||(H.lng=L.detectLanguage()),H.lng?H.useCookie&&L.cookie.create(H.cookieName,H.lng,H.cookieExpirationTime,H.cookieDomain):(H.lng=H.fallbackLng,H.useCookie&&L.cookie.remove(H.cookieName)),F=L.toLanguages(H.lng),z=F[0],L.log("currentLng set to: "+z);var c=t;a.fixLng&&(c=function(a,b){return b=b||{},b.lng=b.lng||c.lng,t(a,b)},c.lng=z),N.setCurrentLng(z),B&&H.setJqueryExt&&n();var d;if(B&&B.Deferred&&(d=B.Deferred()),!H.resStore){var e=L.toLanguages(H.lng);"string"==typeof H.preload&&(H.preload=[H.preload]);for(var f=0,g=H.preload.length;g>f;f++)for(var h=L.toLanguages(H.preload[f]),i=0,j=h.length;j>i;i++)e.indexOf(h[i])<0&&e.push(h[i]);return C.sync.load(e,H,function(a,e){D=e,G=!0,b&&b(c),d&&d.resolve(c)}),d?d.promise():void 0}return D=H.resStore,G=!0,b&&b(c),d&&d.resolve(c),d?d.promise():void 0}function f(a,b){"string"==typeof a&&(a=[a]);for(var c=0,d=a.length;d>c;c++)H.preload.indexOf(a[c])<0&&H.preload.push(a[c]);return e(b)}function g(a,b,c){"string"!=typeof b?(c=b,b=H.ns.defaultNs):H.ns.namespaces.indexOf(b)<0&&H.ns.namespaces.push(b),D[a]=D[a]||{},D[a][b]=D[a][b]||{},L.extend(D[a][b],c)}function h(a,b){"string"!=typeof b&&(b=H.ns.defaultNs),D[a]=D[a]||{},D[a][b]={}}function i(a){H.ns.defaultNs=a}function j(a,b){k([a],b)}function k(a,b){var c={dynamicLoad:H.dynamicLoad,resGetPath:H.resGetPath,getAsync:H.getAsync,customLoad:H.customLoad,ns:{namespaces:a,defaultNs:""}},d=L.toLanguages(H.lng);"string"==typeof H.preload&&(H.preload=[H.preload]);for(var e=0,f=H.preload.length;f>e;e++)for(var g=L.toLanguages(H.preload[e]),h=0,i=g.length;i>h;h++)d.indexOf(g[h])<0&&d.push(g[h]);for(var j=[],k=0,l=d.length;l>k;k++){var m=!1,n=D[d[k]];if(n)for(var o=0,p=a.length;p>o;o++)n[a[o]]||(m=!0);else m=!0;m&&j.push(d[k])}j.length?C.sync._fetch(j,c,function(c,d){var e=a.length*j.length;L.each(a,function(a,c){H.ns.namespaces.indexOf(c)<0&&H.ns.namespaces.push(c),L.each(j,function(a,f){D[f]=D[f]||{},D[f][c]=d[f][c],e--,0===e&&b&&(H.useLocalStorage&&C.sync._storeLocal(D),b())})})}):b&&b()}function l(a,b,c){return"function"==typeof b?(c=b,b={}):b||(b={}),b.lng=a,e(b,c)}function m(){return z}function n(){function a(a,b,c){if(0!==b.length){var d="text";if(0===b.indexOf("[")){var e=b.split("]");b=e[1],d=e[0].substr(1,e[0].length-1)}b.indexOf(";")===b.length-1&&(b=b.substr(0,b.length-2));var f;"html"===d?(f=H.defaultValueFromContent?B.extend({defaultValue:a.html()},c):c,a.html(B.t(b,f))):"text"===d?(f=H.defaultValueFromContent?B.extend({defaultValue:a.text()},c):c,a.text(B.t(b,f))):"prepend"===d?(f=H.defaultValueFromContent?B.extend({defaultValue:a.html()},c):c,a.prepend(B.t(b,f))):"append"===d?(f=H.defaultValueFromContent?B.extend({defaultValue:a.html()},c):c,a.append(B.t(b,f))):(f=H.defaultValueFromContent?B.extend({defaultValue:a.attr(d)},c):c,a.attr(d,B.t(b,f)))}}function b(b,c){var d=b.attr(H.selectorAttr);if(d||"undefined"==typeof d||d===!1||(d=b.text()||b.val()),d){var e=b,f=b.data("i18n-target");if(f&&(e=b.find(f)||b),c||H.useDataAttrOptions!==!0||(c=b.data("i18n-options")),c=c||{},d.indexOf(";")>=0){var g=d.split(";");B.each(g,function(b,d){""!==d&&a(e,d,c)})}else a(e,d,c);H.useDataAttrOptions===!0&&b.data("i18n-options",c)}}B.t=B.t||t,B.fn.i18n=function(a){return this.each(function(){b(B(this),a);var c=B(this).find("["+H.selectorAttr+"]");c.each(function(){b(B(this),a)})})}}function o(a,b,c,d){if(!a)return a;if(d=d||b,a.indexOf(d.interpolationPrefix||H.interpolationPrefix)<0)return a;var e=d.interpolationPrefix?L.regexEscape(d.interpolationPrefix):H.interpolationPrefixEscaped,f=d.interpolationSuffix?L.regexEscape(d.interpolationSuffix):H.interpolationSuffixEscaped,g="HTML"+f;return L.each(b,function(b,h){var i=c?c+H.keyseparator+b:b;"object"==typeof h&&null!==h?a=o(a,h,i,d):d.escapeInterpolation||H.escapeInterpolation?(a=a.replace(new RegExp([e,i,g].join(""),"g"),h),a=a.replace(new RegExp([e,i,f].join(""),"g"),L.escape(h))):a=a.replace(new RegExp([e,i,f].join(""),"g"),h)}),a}function p(a,b){var c=",",d="{",e="}",f=L.extend({},b);for(delete f.postProcess;-1!=a.indexOf(H.reusePrefix)&&(E++,!(E>H.maxRecursion));){var g=a.lastIndexOf(H.reusePrefix),h=a.indexOf(H.reuseSuffix,g)+H.reuseSuffix.length,i=a.substring(g,h),j=i.replace(H.reusePrefix,"").replace(H.reuseSuffix,"");if(-1!=j.indexOf(c)){var k=j.indexOf(c);if(-1!=j.indexOf(d,k)&&-1!=j.indexOf(e,k)){var l=j.indexOf(d,k),m=j.indexOf(e,l)+e.length;try{f=L.extend(f,JSON.parse(j.substring(l,m))),j=j.substring(0,k)}catch(n){}}}var o=w(j,f);a=a.replace(i,o)}return a}function q(a){return a.context&&("string"==typeof a.context||"number"==typeof a.context)}function r(a){return void 0!==a.count&&"string"!=typeof a.count&&1!==a.count}function s(a,b){b=b||{};var c=u(a,b),d=x(a,b);return void 0!==d||d===c}function t(a,b){return b=b||{},G?(E=0,w.apply(null,arguments)):(L.log("i18next not finished initialization. you might have called t function before loading resources finished."),b.defaultValue||"")}function u(a,b){return void 0!==b.defaultValue?b.defaultValue:a}function v(){for(var a=[],b=1;b1)for(var d=0;d-1&&(e=c.split(H.nsseparator),i=e[0],c=e[1]),void 0===g&&H.sendMissing&&(b.lng?M.postMissing(h[0],i,c,f,h):M.postMissing(H.lng,i,c,f,h));var j=b.postProcess||H.postProcess;void 0!==g&&j&&O[j]&&(g=O[j](g,c,b));var k=f;if(f.indexOf(H.nsseparator)>-1&&(e=f.split(H.nsseparator),k=e[1]),k===c&&H.parseMissingKey&&(f=H.parseMissingKey(f)),void 0===g&&(f=o(f,b),f=p(f,b),j&&O[j])){var l=u(c,b);g=O[j](l,c,b)}return void 0!==g?g:f}function x(a,b){b=b||{};var c,d,e=u(a,b),f=F;if(!D)return e;if(b.lng&&(f=L.toLanguages(b.lng),!D[f[0]])){var g=H.getAsync;H.getAsync=!1,C.sync.load(f,H,function(a,b){L.extend(D,b),H.getAsync=g})}var h=b.ns||H.ns.defaultNs;if(a.indexOf(H.nsseparator)>-1){var i=a.split(H.nsseparator);h=i[0],a=i[1]}if(q(b)){c=L.extend({},b),delete c.context,c.defaultValue=H.contextNotFound;var j=h+H.nsseparator+a+"_"+b.context;if(d=t(j,c),d!=H.contextNotFound)return o(d,{context:b.context})}if(r(b)){c=L.extend({},b),delete c.count,c.defaultValue=H.pluralNotFound;var k=h+H.nsseparator+a+H.pluralSuffix,l=N.get(f[0],b.count);if(l>=0?k=k+"_"+l:1===l&&(k=h+H.nsseparator+a),d=t(k,c),d!=H.pluralNotFound)return o(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix})}for(var m,n=a.split(H.keyseparator),s=0,v=f.length;v>s&&void 0===m;s++){for(var y=f[s],z=0,A=D[y]&&D[y][h];n[z];)A=A&&A[n[z]],z++;if(void 0!==A){var B=Object.prototype.toString.apply(A);if("string"==typeof A)A=o(A,b),A=p(A,b);else if("[object Array]"!==B||H.returnObjectTrees||b.returnObjectTrees){if(null===A&&H.fallbackOnNull===!0)A=void 0;else if(null!==A)if(H.returnObjectTrees||b.returnObjectTrees){if("[object Number]"!==B&&"[object Function]"!==B&&"[object RegExp]"!==B){var E="[object Array]"===B?[]:{};L.each(A,function(c){E[c]=w(h+H.nsseparator+a+H.keyseparator+c,b)}),A=E}}else H.objectTreeKeyHandler&&"function"==typeof H.objectTreeKeyHandler?A=H.objectTreeKeyHandler(a,A,y,h,b):(A="key '"+h+":"+a+" ("+y+")' "+"returned an object instead of string.",L.log(A))}else A=A.join("\n"),A=o(A,b),A=p(A,b);"string"==typeof A&&""===A.trim()&&H.fallbackOnEmpty===!0&&(A=void 0),m=A}}if(void 0===m&&!b.isFallbackLookup&&(H.fallbackToDefaultNS===!0||H.fallbackNS&&H.fallbackNS.length>0))if(b.isFallbackLookup=!0,H.fallbackNS.length){for(var G=0,I=H.fallbackNS.length;I>G;G++)if(m=x(H.fallbackNS[G]+H.nsseparator+a,b)){var J=m.indexOf(H.nsseparator)>-1?m.split(H.nsseparator)[1]:m,K=e.indexOf(H.nsseparator)>-1?e.split(H.nsseparator)[1]:e;if(J!==K)break}}else m=x(a,b);return m}function y(){var a,b=[];if("undefined"!=typeof window&&(!function(){for(var a=window.location.search.substring(1),c=a.split("&"),d=0;d0){var f=c[d].substring(0,e),g=c[d].substring(e+1);b[f]=g}}}(),b[H.detectLngQS]&&(a=b[H.detectLngQS])),!a&&"undefined"!=typeof document&&H.useCookie){var c=L.cookie.read(H.cookieName);c&&(a=c)}return a||"undefined"==typeof navigator||(a=navigator.language?navigator.language:navigator.userLanguage),a}Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>0&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&1/0!=d&&d!=-1/0&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=c;arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d))));for(var e=d>=0?Math.min(d,c-1):c-Math.abs(d);e>=0;e--)if(e in b&&b[e]===a)return e;return-1});var z,A=this,B=A.jQuery||A.Zepto,C={},D={},E=0,F=[],G=!1;"undefined"!=typeof module&&module.exports?module.exports=C:(B&&(B.i18n=B.i18n||C),A.i18n=A.i18n||C);var H={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:"dev",fallbackNS:[],detectLngQS:"setLng",ns:"translation",fallbackOnNull:!0,fallbackOnEmpty:!1,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",cookieDomain:void 0,objectTreeKeyHandler:void 0,postProcess:void 0,parseMissingKey:void 0,shortcutFunction:"sprintf"},I={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},J={create:function(a,b,c,d){var e;if(c){var f=new Date;f.setTime(f.getTime()+1e3*60*c),e="; expires="+f.toGMTString()}else e="";d=d?"domain="+d+";":"",document.cookie=a+"="+b+e+";"+d+"path=/"},read:function(a){for(var b=a+"=",c=document.cookie.split(";"),d=0;d-1){var c=a.split("-");a=H.lowerCaseLng?c[0].toLowerCase()+"-"+c[1].toLowerCase():c[0].toLowerCase()+"-"+c[1].toUpperCase(),"unspecific"!==H.load&&b.push(a),"current"!==H.load&&b.push(c[0])}else b.push(a);return-1===b.indexOf(H.fallbackLng)&&H.fallbackLng&&b.push(H.fallbackLng),b},regexEscape:function(a){return a.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}};L.applyReplacement=o;var M={load:function(a,b,c){b.useLocalStorage?M._loadLocal(a,b,function(d,e){for(var f=[],g=0,h=a.length;h>g;g++)e[a[g]]||f.push(a[g]);f.length>0?M._fetch(f,b,function(a,b){L.extend(e,b),M._storeLocal(b),c(null,e)}):c(null,e)}):M._fetch(a,b,function(a,b){c(null,b)})},_loadLocal:function(a,b,c){var d={},e=(new Date).getTime();if(window.localStorage){var f=a.length;L.each(a,function(a,g){var h=window.localStorage.getItem("res_"+g);h&&(h=JSON.parse(h),h.i18nStamp&&h.i18nStamp+b.localStorageExpirationTime>e&&(d[g]=h)),f--,0===f&&c(null,d)})}},_storeLocal:function(a){if(window.localStorage)for(var b in a)a[b].i18nStamp=(new Date).getTime(),window.localStorage.setItem("res_"+b,JSON.stringify(a[b]))},_fetch:function(a,b,c){var d=b.ns,e={};if(b.dynamicLoad){var f=function(a,b){c(null,b)};if("function"==typeof b.customLoad)b.customLoad(a,d.namespaces,b,f);else{var g=o(b.resGetPath,{lng:a.join("+"),ns:d.namespaces.join("+")});L.ajax({url:g,success:function(a){L.log("loaded: "+g),f(null,a)},error:function(a,b,c){L.log("failed loading: "+g),f("failed loading resource.json error: "+c)},dataType:"json",async:b.getAsync})}}else{var h,i=d.namespaces.length*a.length;L.each(d.namespaces,function(d,f){L.each(a,function(a,d){var g=function(a,b){a&&(h=h||[],h.push(a)),e[d]=e[d]||{},e[d][f]=b,i--,0===i&&c(h,e)};"function"==typeof b.customLoad?b.customLoad(d,f,b,g):M._fetchOne(d,f,b,g)})})}},_fetchOne:function(a,b,c,d){var e=o(c.resGetPath,{lng:a,ns:b});L.ajax({url:e,success:function(a){L.log("loaded: "+e),d(null,a)},error:function(a,b,c){200==c.status?L.log("There is a typo in: "+e):404==c.status?L.log("Does not exist: "+e):L.log(c.status+" when loading "+e),d(c,{})},dataType:"json",async:c.getAsync})},postMissing:function(a,b,c,d,e){var f={};f[c]=d;var g=[];if("fallback"===H.sendMissingTo&&H.fallbackLng!==!1)g.push({lng:H.fallbackLng,url:o(H.resPostPath,{lng:H.fallbackLng,ns:b})});else if("current"===H.sendMissingTo||"fallback"===H.sendMissingTo&&H.fallbackLng===!1)g.push({lng:a,url:o(H.resPostPath,{lng:a,ns:b})});else if("all"===H.sendMissingTo)for(var h=0,i=e.length;i>h;h++)g.push({lng:e[h],url:o(H.resPostPath,{lng:e[h],ns:b})});for(var j=0,k=g.length;k>j;j++){var l=g[j];L.ajax({url:l.url,type:H.sendType,data:f,success:function(){L.log("posted missing key '"+c+"' to: "+l.url);for(var a=c.split("."),e=0,f=D[l.lng][b];a[e];)f=f[a[e]]=e===a.length-1?d:f[a[e]]||{},e++},error:function(){L.log("failed posting missing key '"+c+"' to: "+l.url)},dataType:"json",async:H.postAsync})}}},N={rules:{ach:{name:"Acholi",numbers:[1,2],plurals:function(a){return Number(a>1)}},af:{name:"Afrikaans",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ak:{name:"Akan",numbers:[1,2],plurals:function(a){return Number(a>1)}},am:{name:"Amharic",numbers:[1,2],plurals:function(a){return Number(a>1)}},an:{name:"Aragonese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ar:{name:"Arabic",numbers:[0,1,2,3,11,100],plurals:function(a){return Number(0===a?0:1==a?1:2==a?2:a%100>=3&&10>=a%100?3:a%100>=11?4:5)}},arn:{name:"Mapudungun",numbers:[1,2],plurals:function(a){return Number(a>1)}},ast:{name:"Asturian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ay:{name:"Aymará",numbers:[1],plurals:function(){return 0}},az:{name:"Azerbaijani",numbers:[1,2],plurals:function(a){return Number(1!=a)}},be:{name:"Belarusian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},bg:{name:"Bulgarian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},bn:{name:"Bengali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},bo:{name:"Tibetan",numbers:[1],plurals:function(){return 0}},br:{name:"Breton",numbers:[1,2],plurals:function(a){return Number(a>1)}},bs:{name:"Bosnian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},ca:{name:"Catalan",numbers:[1,2],plurals:function(a){return Number(1!=a)}},cgg:{name:"Chiga",numbers:[1],plurals:function(){return 0}},cs:{name:"Czech",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)}},csb:{name:"Kashubian",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},cy:{name:"Welsh",numbers:[1,2,3,8],plurals:function(a){return Number(1==a?0:2==a?1:8!=a&&11!=a?2:3)}},da:{name:"Danish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},de:{name:"German",numbers:[1,2],plurals:function(a){return Number(1!=a)}},dz:{name:"Dzongkha",numbers:[1],plurals:function(){return 0}},el:{name:"Greek",numbers:[1,2],plurals:function(a){return Number(1!=a)}},en:{name:"English",numbers:[1,2],plurals:function(a){return Number(1!=a)}},eo:{name:"Esperanto",numbers:[1,2],plurals:function(a){return Number(1!=a)}},es:{name:"Spanish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},es_ar:{name:"Argentinean Spanish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},et:{name:"Estonian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},eu:{name:"Basque",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fa:{name:"Persian",numbers:[1],plurals:function(){return 0}},fi:{name:"Finnish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fil:{name:"Filipino",numbers:[1,2],plurals:function(a){return Number(a>1)}},fo:{name:"Faroese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fr:{name:"French",numbers:[1,2],plurals:function(a){return Number(a>1)}},fur:{name:"Friulian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fy:{name:"Frisian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ga:{name:"Irish",numbers:[1,2,3,7,11],plurals:function(a){return Number(1==a?0:2==a?1:7>a?2:11>a?3:4)}},gd:{name:"Scottish Gaelic",numbers:[1,2,3,20],plurals:function(a){return Number(1==a||11==a?0:2==a||12==a?1:a>2&&20>a?2:3)}},gl:{name:"Galician",numbers:[1,2],plurals:function(a){return Number(1!=a)}},gu:{name:"Gujarati",numbers:[1,2],plurals:function(a){return Number(1!=a)}},gun:{name:"Gun",numbers:[1,2],plurals:function(a){return Number(a>1)}},ha:{name:"Hausa",numbers:[1,2],plurals:function(a){return Number(1!=a)}},he:{name:"Hebrew",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hi:{name:"Hindi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hr:{name:"Croatian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},hu:{name:"Hungarian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hy:{name:"Armenian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ia:{name:"Interlingua",numbers:[1,2],plurals:function(a){return Number(1!=a)}},id:{name:"Indonesian",numbers:[1],plurals:function(){return 0}},is:{name:"Icelandic",numbers:[1,2],plurals:function(a){return Number(1!=a%10||11==a%100)}},it:{name:"Italian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ja:{name:"Japanese",numbers:[1],plurals:function(){return 0}},jbo:{name:"Lojban",numbers:[1],plurals:function(){return 0}},jv:{name:"Javanese",numbers:[0,1],plurals:function(a){return Number(0!==a)}},ka:{name:"Georgian",numbers:[1],plurals:function(){return 0}},kk:{name:"Kazakh",numbers:[1],plurals:function(){return 0}},km:{name:"Khmer",numbers:[1],plurals:function(){return 0}},kn:{name:"Kannada",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ko:{name:"Korean",numbers:[1],plurals:function(){return 0}},ku:{name:"Kurdish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},kw:{name:"Cornish",numbers:[1,2,3,4],plurals:function(a){return Number(1==a?0:2==a?1:3==a?2:3)}},ky:{name:"Kyrgyz",numbers:[1],plurals:function(){return 0}},lb:{name:"Letzeburgesch",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ln:{name:"Lingala",numbers:[1,2],plurals:function(a){return Number(a>1)}},lo:{name:"Lao",numbers:[1],plurals:function(){return 0}},lt:{name:"Lithuanian",numbers:[1,2,10],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&(10>a%100||a%100>=20)?1:2)}},lv:{name:"Latvian",numbers:[0,1,2],plurals:function(a){return Number(1==a%10&&11!=a%100?0:0!==a?1:2)}},mai:{name:"Maithili",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mfe:{name:"Mauritian Creole",numbers:[1,2],plurals:function(a){return Number(a>1)}},mg:{name:"Malagasy",numbers:[1,2],plurals:function(a){return Number(a>1)}},mi:{name:"Maori",numbers:[1,2],plurals:function(a){return Number(a>1)}},mk:{name:"Macedonian",numbers:[1,2],plurals:function(a){return Number(1==a||1==a%10?0:1)}},ml:{name:"Malayalam",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mn:{name:"Mongolian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mnk:{name:"Mandinka",numbers:[0,1,2],plurals:function(a){return Number(1==a?1:2)}},mr:{name:"Marathi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ms:{name:"Malay",numbers:[1],plurals:function(){return 0}},mt:{name:"Maltese",numbers:[1,2,11,20],plurals:function(a){return Number(1==a?0:0===a||a%100>1&&11>a%100?1:a%100>10&&20>a%100?2:3)}},nah:{name:"Nahuatl",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nap:{name:"Neapolitan",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nb:{name:"Norwegian Bokmal",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ne:{name:"Nepali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nl:{name:"Dutch",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nn:{name:"Norwegian Nynorsk",numbers:[1,2],plurals:function(a){return Number(1!=a)}},no:{name:"Norwegian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nso:{name:"Northern Sotho",numbers:[1,2],plurals:function(a){return Number(1!=a)}},oc:{name:"Occitan",numbers:[1,2],plurals:function(a){return Number(a>1)}},or:{name:"Oriya",numbers:[2,1],plurals:function(a){return Number(1!=a)}},pa:{name:"Punjabi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pap:{name:"Papiamento",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pl:{name:"Polish",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},pms:{name:"Piemontese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ps:{name:"Pashto",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pt:{name:"Portuguese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pt_br:{name:"Brazilian Portuguese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},rm:{name:"Romansh",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ro:{name:"Romanian",numbers:[1,2,20],plurals:function(a){return Number(1==a?0:0===a||a%100>0&&20>a%100?1:2)}},ru:{name:"Russian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},sah:{name:"Yakut",numbers:[1],plurals:function(){return 0}},sco:{name:"Scots",numbers:[1,2],plurals:function(a){return Number(1!=a)}},se:{name:"Northern Sami",numbers:[1,2],plurals:function(a){return Number(1!=a)}},si:{name:"Sinhala",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sk:{name:"Slovak",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)}},sl:{name:"Slovenian",numbers:[5,1,2,3],plurals:function(a){return Number(1==a%100?1:2==a%100?2:3==a%100||4==a%100?3:0)}},so:{name:"Somali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},son:{name:"Songhay",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sq:{name:"Albanian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sr:{name:"Serbian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},su:{name:"Sundanese",numbers:[1],plurals:function(){return 0}},sv:{name:"Swedish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sw:{name:"Swahili",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ta:{name:"Tamil",numbers:[1,2],plurals:function(a){return Number(1!=a)}},te:{name:"Telugu",numbers:[1,2],plurals:function(a){return Number(1!=a)}},tg:{name:"Tajik",numbers:[1,2],plurals:function(a){return Number(a>1)}},th:{name:"Thai",numbers:[1],plurals:function(){return 0}},ti:{name:"Tigrinya",numbers:[1,2],plurals:function(a){return Number(a>1)}},tk:{name:"Turkmen",numbers:[1,2],plurals:function(a){return Number(1!=a)}},tr:{name:"Turkish",numbers:[1,2],plurals:function(a){return Number(a>1)}},tt:{name:"Tatar",numbers:[1],plurals:function(){return 0}},ug:{name:"Uyghur",numbers:[1],plurals:function(){return 0}},uk:{name:"Ukrainian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},ur:{name:"Urdu",numbers:[1,2],plurals:function(a){return Number(1!=a)}},uz:{name:"Uzbek",numbers:[1,2],plurals:function(a){return Number(a>1)}},vi:{name:"Vietnamese",numbers:[1],plurals:function(){return 0}},wa:{name:"Walloon",numbers:[1,2],plurals:function(a){return Number(a>1)}},wo:{name:"Wolof",numbers:[1],plurals:function(){return 0}},yo:{name:"Yoruba",numbers:[1,2],plurals:function(a){return Number(1!=a)}},zh:{name:"Chinese",numbers:[1],plurals:function(){return 0}}},addRule:function(a,b){N.rules[a]=b},setCurrentLng:function(a){if(!N.currentRule||N.currentRule.lng!==a){var b=a.split("-");N.currentRule={lng:a,rule:N.rules[b[0]]}}},get:function(a,b){function c(b,c){var d;if(d=N.currentRule&&N.currentRule.lng===a?N.currentRule.rule:N.rules[b]){var e=d.plurals(c),f=d.numbers[e];return 2===d.numbers.length&&1===d.numbers[0]&&(2===f?f=-1:1===f&&(f=1)),f}return 1===c?"1":"-1"}var d=a.split("-");return c(d[0],b)}},O={},P=function(a,b){O[a]=b},Q=function(){function a(a){return Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}function b(a,b){for(var c=[];b>0;c[--b]=a);return c.join("")}var c=function(){return c.cache.hasOwnProperty(arguments[0])||(c.cache[arguments[0]]=c.parse(arguments[0])),c.format.call(null,c.cache[arguments[0]],arguments)};return c.format=function(c,d){var e,f,g,h,i,j,k,l=1,m=c.length,n="",o=[];for(f=0;m>f;f++)if(n=a(c[f]),"string"===n)o.push(c[f]);else if("array"===n){if(h=c[f],h[2])for(e=d[l],g=0;g=0?"+"+e:e,j=h[4]?"0"==h[4]?"0":h[4].charAt(1):" ",k=h[6]-String(e).length,i=h[6]?b(j,k):"",o.push(h[5]?e+i:i+e)}return o.join("")},c.cache={},c.parse=function(a){for(var b=a,c=[],d=[],e=0;b;){if(null!==(c=/^[^\x25]+/.exec(b)))d.push(c[0]);else if(null!==(c=/^\x25{2}/.exec(b)))d.push("%");else{if(null===(c=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(b)))throw"[sprintf] huh?";if(c[2]){e|=1;var f=[],g=c[2],h=[];if(null===(h=/^([a-z_][a-z_\d]*)/i.exec(g)))throw"[sprintf] huh?";for(f.push(h[1]);""!==(g=g.substring(h[0].length));)if(null!==(h=/^\.([a-z_][a-z_\d]*)/i.exec(g)))f.push(h[1]);else{if(null===(h=/^\[(\d+)\]/.exec(g)))throw"[sprintf] huh?";f.push(h[1])}c[2]=f}else e|=2;if(3===e)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";d.push(c)}b=b.substring(c[0].length)}return d},c}(),R=function(a,b){return b.unshift(a),Q.apply(null,b)};P("sprintf",function(a,b,c){return c.sprintf?"[object Array]"===Object.prototype.toString.apply(c.sprintf)?R(a,c.sprintf):"object"==typeof c.sprintf?Q(a,c.sprintf):a:a}),C.init=e,C.setLng=l,C.preload=f,C.addResourceBundle=g,C.removeResourceBundle=h,C.loadNamespace=j,C.loadNamespaces=k,C.setDefaultNamespace=i,C.t=t,C.translate=t,C.exists=s,C.detectLanguage=L.detectLanguage,C.pluralExtensions=N,C.sync=M,C.functions=L,C.lng=m,C.addPostProcessor=P,C.options=H}(); \ No newline at end of file diff --git a/libs/i18next/release/i18next-1.7.2.zip b/libs/i18next/release/i18next-1.7.2.zip new file mode 100644 index 00000000..99e005c1 Binary files /dev/null and b/libs/i18next/release/i18next-1.7.2.zip differ diff --git a/libs/i18next/release/i18next-1.7.3.js b/libs/i18next/release/i18next-1.7.3.js new file mode 100644 index 00000000..8f6db5d6 --- /dev/null +++ b/libs/i18next/release/i18next-1.7.3.js @@ -0,0 +1,2746 @@ +// i18next, v1.7.3 +// Copyright (c)2014 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function() { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + // Add string trim for IE8. + if (typeof String.prototype.trim !== 'function') { + String.prototype.trim = function() { + return this.replace(/^\s+|\s+$/g, ''); + } + } + + var root = this + , $ = root.jQuery || root.Zepto + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = [] + , initialized = false; + + + // Export the i18next object for **CommonJS**. + // If we're not in CommonJS, add `i18n` to the + // global object or to jquery. + if (typeof module !== 'undefined' && module.exports) { + module.exports = i18n; + } else { + if ($) { + $.i18n = $.i18n || i18n; + } + + root.i18n = root.i18n || i18n; + } + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: ['dev'], + fallbackNS: [], + detectLngQS: 'setLng', + ns: 'translation', + fallbackOnNull: true, + fallbackOnEmpty: false, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + cookieDomain: undefined, + + objectTreeKeyHandler: undefined, + postProcess: undefined, + parseMissingKey: undefined, + + shortcutFunction: 'sprintf' // or: defaultValue + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || Object.prototype.toString.apply(object) !== '[object Array]' || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + return JSON.parse(data); + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + if (status === 200) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes,domain) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + domain = (domain)? "domain="+domain+";" : ""; + document.cookie = name+"="+value+expires+";"+domain+"path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes,domain) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : (typeof document !== 'undefined' ? _ajax : function() {}), + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + toLanguages: function(lng) { + var log = this.log; + var languages = []; + var whitelist = o.langWhitelist || false; + var addLanguage = function(language){ + //reject langs not whitelisted + if(!whitelist || whitelist.indexOf(language) > -1){ + languages.push(language); + }else{ + log('rejecting non-whitelisted language: ' + language); + } + }; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + + if (o.load !== 'unspecific') addLanguage(lng); + if (o.load !== 'current') addLanguage(parts[0]); + } else { + addLanguage(lng); + } + + for (var i = 0; i < o.fallbackLng.length; i++) { + if (languages.indexOf(o.fallbackLng[i]) === -1 && o.fallbackLng[i]) languages.push(o.fallbackLng[i]); + } + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + delete o.fixLng; /* passed in each time */ + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // fallback languages + if (typeof o.fallbackLng == 'string' || typeof o.fallbackLng == 'boolean') { + o.fallbackLng = [o.fallbackLng]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + if (o.useCookie && f.cookie.read(o.cookieName) !== currentLng){ //cookie is unset or invalid + f.cookie.create(o.cookieName, currentLng, o.cookieExpirationTime, o.cookieDomain); + } + + + var lngTranslate = translate; + if (options.fixLng) { + lngTranslate = function(key, options) { + options = options || {}; + options.lng = options.lng || lngTranslate.lng; + return translate(key, options); + }; + lngTranslate.lng = currentLng; + } + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + initialized = true; + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + initialized = true; + + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + f.extend(resStore[lng][ns], resources); + } + + function removeResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = {}; + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, options, cb) { + if (typeof options === 'function') { + cb = options; + options = {}; + } else if (!options) { + options = {}; + } + + options.lng = lng; + return init(options, cb); + } + + function lng() { + return currentLng; + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else if (attr === 'prepend') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.prepend($.t(key, optionsToUse)); + } else if (attr === 'append') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.append($.t(key, optionsToUse)); + } else if (attr.indexOf("data-") === 0) { + var dataAttr = attr.substr(("data-").length); + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.data(dataAttr) }, options) : options; + var translated = $.t(key, optionsToUse); + //we change into the data cache + ele.data(dataAttr, translated); + //we change into the dom + ele.attr(attr, translated); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key && typeof key !== 'undefined' && key !== false) key = ele.text() || ele.val(); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + f.each(replacementHash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), value); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.escape(value)); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), value); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, translated_token); + } + return translated; + } + + function hasContext(options) { + return (options.context && (typeof options.context == 'string' || typeof options.context == 'number')); + } + + function needsPlural(options) { + return (options.count !== undefined && typeof options.count != 'string' && options.count !== 1); + } + + function exists(key, options) { + options = options || {}; + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + options = options || {}; + + if (!initialized) { + f.log('i18next not finished initialization. you might have called t function before loading resources finished.') + return options.defaultValue || ''; + }; + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _getDefaultValue(key, options) { + return (options.defaultValue !== undefined) ? options.defaultValue : key; + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(potentialKeys, options) { + if (options && typeof options !== 'object') { + if (o.shortcutFunction === 'sprintf') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else if (o.shortcutFunction === 'defaultValue') { + options = { + defaultValue: options + } + } + } else { + options = options || {}; + } + + if (potentialKeys === undefined || potentialKeys === null) return ''; + + if (typeof potentialKeys == 'string') { + potentialKeys = [potentialKeys]; + } + + var key = potentialKeys[0]; + + if (potentialKeys.length > 1) { + for (var i = 0; i < potentialKeys.length; i++) { + key = potentialKeys[i]; + if (exists(key, options)) { + break; + } + } + } + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng) : languages + , ns = options.ns || o.ns.defaultNs + , parts; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing) { + if (options.lng) { + sync.postMissing(lngs[0], ns, key, notFound, lngs); + } else { + sync.postMissing(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found !== undefined && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + // process notFound if function exists + var splitNotFound = notFound; + if (notFound.indexOf(o.nsseparator) > -1) { + parts = notFound.split(o.nsseparator); + splitNotFound = parts[1]; + } + if (splitNotFound === key && o.parseMissingKey) { + notFound = o.parseMissingKey(notFound); + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessor && postProcessors[postProcessor]) { + var val = _getDefaultValue(key, options); + found = postProcessors[postProcessor](val, key, options); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options) { + options = options || {}; + + var optionWithoutCount, translated + , notFound = _getDefaultValue(key, options) + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + // CI mode + if (lngs[0].toLowerCase() === 'cimode') return notFound; + + // passed in lng + if (options.lng) { + lngs = f.toLanguages(options.lng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.count; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(lngs[0], options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + + translated = translate(pluralKey, optionWithoutCount); + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } // else continue translation with original/singular key + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + var valueType = Object.prototype.toString.apply(value); + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (valueType === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + if (o.objectTreeKeyHandler && typeof o.objectTreeKeyHandler == 'function') { + value = o.objectTreeKeyHandler(key, value, l, ns, options); + } else { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned an object instead of string.'; + f.log(value); + } + } else if (valueType !== '[object Number]' && valueType !== '[object Function]' && valueType !== '[object RegExp]') { + var copy = (valueType === '[object Array]') ? [] : {}; // apply child translation on a copy + f.each(value, function(m) { + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + }); + value = copy; + } + } + + if (typeof value === 'string' && value.trim() === '' && o.fallbackOnEmpty === true) + value = undefined; + + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length > 0))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + } + + return found; + } + function detectLanguage() { + var detectedLng; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var parms = query.split('&'); + for (var i=0; i 0) { + var key = parms[i].substring(0,pos); + var val = parms[i].substring(pos+1); + qsParm[key] = val; + } + } + })(); + if (qsParm[o.detectLngQS]) { + detectedLng = qsParm[o.detectLngQS]; + } + } + + // get from cookie + if (!detectedLng && typeof document !== 'undefined' && o.useCookie ) { + var c = f.cookie.read(o.cookieName); + if (c) detectedLng = c; + } + + // get from navigator + if (!detectedLng && typeof navigator !== 'undefined') { + detectedLng = (navigator.language) ? navigator.language : navigator.userLanguage; + } + + //fallback + if(!detectedLng){ + detectedLng = o.fallbackLng[0]; + } + + return detectedLng; + } + var sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + window.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + if ((status && status == 200) || (xhr && xhr.status && xhr.status == 200)) { + // file loaded but invalid json, stop waste time ! + f.log('There is a typo in: ' + url); + } else if ((status && status == 404) || (xhr && xhr.status && xhr.status == 404)) { + f.log('Does not exist: ' + url); + } else { + var theStatus = status ? status : ((xhr && xhr.status) ? xhr.status : null); + f.log(theStatus + ' when loading ' + url); + } + + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback' && o.fallbackLng[0] !== false) { + for (var i = 0; i < o.fallbackLng.length; i++) { + urls.push({lng: o.fallbackLng[i], url: applyReplacement(o.resPostPath, { lng: o.fallbackLng[i], ns: ns })}); + } + } else if (o.sendMissingTo === 'current' || (o.sendMissingTo === 'fallback' && o.fallbackLng[0] === false) ) { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + } + }; + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + var pluralExtensions = { + + rules: { + "ach": { + "name": "Acholi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "af": { + "name": "Afrikaans", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ak": { + "name": "Akan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "am": { + "name": "Amharic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "an": { + "name": "Aragonese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ar": { + "name": "Arabic", + "numbers": [ + 0, + 1, + 2, + 3, + 11, + 100 + ], + "plurals": function(n) { return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5); } + }, + "arn": { + "name": "Mapudungun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ast": { + "name": "Asturian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ay": { + "name": "Aymar\u00e1", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "az": { + "name": "Azerbaijani", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "be": { + "name": "Belarusian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "bg": { + "name": "Bulgarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bn": { + "name": "Bengali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bo": { + "name": "Tibetan", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "br": { + "name": "Breton", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "bs": { + "name": "Bosnian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ca": { + "name": "Catalan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "cgg": { + "name": "Chiga", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "cs": { + "name": "Czech", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "csb": { + "name": "Kashubian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "cy": { + "name": "Welsh", + "numbers": [ + 1, + 2, + 3, + 8 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3); } + }, + "da": { + "name": "Danish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "de": { + "name": "German", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "dz": { + "name": "Dzongkha", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "el": { + "name": "Greek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "en": { + "name": "English", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eo": { + "name": "Esperanto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es": { + "name": "Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es_ar": { + "name": "Argentinean Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "et": { + "name": "Estonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eu": { + "name": "Basque", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fa": { + "name": "Persian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "fi": { + "name": "Finnish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fil": { + "name": "Filipino", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fo": { + "name": "Faroese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fr": { + "name": "French", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fur": { + "name": "Friulian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fy": { + "name": "Frisian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ga": { + "name": "Irish", + "numbers": [ + 1, + 2, + 3, + 7, + 11 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;} + }, + "gd": { + "name": "Scottish Gaelic", + "numbers": [ + 1, + 2, + 3, + 20 + ], + "plurals": function(n) { return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3); } + }, + "gl": { + "name": "Galician", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gu": { + "name": "Gujarati", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gun": { + "name": "Gun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ha": { + "name": "Hausa", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "he": { + "name": "Hebrew", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hi": { + "name": "Hindi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hr": { + "name": "Croatian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "hu": { + "name": "Hungarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hy": { + "name": "Armenian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ia": { + "name": "Interlingua", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "id": { + "name": "Indonesian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "is": { + "name": "Icelandic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n%10!=1 || n%100==11); } + }, + "it": { + "name": "Italian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ja": { + "name": "Japanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jbo": { + "name": "Lojban", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jv": { + "name": "Javanese", + "numbers": [ + 0, + 1 + ], + "plurals": function(n) { return Number(n !== 0); } + }, + "ka": { + "name": "Georgian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kk": { + "name": "Kazakh", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "km": { + "name": "Khmer", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kn": { + "name": "Kannada", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ko": { + "name": "Korean", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ku": { + "name": "Kurdish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "kw": { + "name": "Cornish", + "numbers": [ + 1, + 2, + 3, + 4 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3); } + }, + "ky": { + "name": "Kyrgyz", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lb": { + "name": "Letzeburgesch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ln": { + "name": "Lingala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "lo": { + "name": "Lao", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lt": { + "name": "Lithuanian", + "numbers": [ + 1, + 2, + 10 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "lv": { + "name": "Latvian", + "numbers": [ + 1, + 2, + 0 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2); } + }, + "mai": { + "name": "Maithili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mfe": { + "name": "Mauritian Creole", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mg": { + "name": "Malagasy", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mi": { + "name": "Maori", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mk": { + "name": "Macedonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 || n%10==1 ? 0 : 1); } + }, + "ml": { + "name": "Malayalam", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mn": { + "name": "Mongolian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mnk": { + "name": "Mandinka", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(0 ? 0 : n==1 ? 1 : 2); } + }, + "mr": { + "name": "Marathi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ms": { + "name": "Malay", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "mt": { + "name": "Maltese", + "numbers": [ + 1, + 2, + 11, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3); } + }, + "nah": { + "name": "Nahuatl", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nap": { + "name": "Neapolitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nb": { + "name": "Norwegian Bokmal", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ne": { + "name": "Nepali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nl": { + "name": "Dutch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nn": { + "name": "Norwegian Nynorsk", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "no": { + "name": "Norwegian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nso": { + "name": "Northern Sotho", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "oc": { + "name": "Occitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "or": { + "name": "Oriya", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pa": { + "name": "Punjabi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pap": { + "name": "Papiamento", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pl": { + "name": "Polish", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "pms": { + "name": "Piemontese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ps": { + "name": "Pashto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt": { + "name": "Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt_br": { + "name": "Brazilian Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "rm": { + "name": "Romansh", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ro": { + "name": "Romanian", + "numbers": [ + 1, + 2, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2); } + }, + "ru": { + "name": "Russian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "sah": { + "name": "Yakut", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sco": { + "name": "Scots", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "se": { + "name": "Northern Sami", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "si": { + "name": "Sinhala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sk": { + "name": "Slovak", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "sl": { + "name": "Slovenian", + "numbers": [ + 5, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }, + "so": { + "name": "Somali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "son": { + "name": "Songhay", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sq": { + "name": "Albanian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sr": { + "name": "Serbian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "su": { + "name": "Sundanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sv": { + "name": "Swedish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sw": { + "name": "Swahili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ta": { + "name": "Tamil", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "te": { + "name": "Telugu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tg": { + "name": "Tajik", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "th": { + "name": "Thai", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ti": { + "name": "Tigrinya", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tk": { + "name": "Turkmen", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tr": { + "name": "Turkish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tt": { + "name": "Tatar", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ug": { + "name": "Uyghur", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "uk": { + "name": "Ukrainian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ur": { + "name": "Urdu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "uz": { + "name": "Uzbek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "vi": { + "name": "Vietnamese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "wa": { + "name": "Walloon", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "wo": { + "name": "Wolof", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "yo": { + "name": "Yoruba", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "zh": { + "name": "Chinese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + } + }, + + // for demonstration only sl and ar is added but you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i = ext.plurals(c); + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[0], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.removeResourceBundle = removeResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + +})(); \ No newline at end of file diff --git a/libs/i18next/release/i18next-1.7.3.min.js b/libs/i18next/release/i18next-1.7.3.min.js new file mode 100644 index 00000000..5542179a --- /dev/null +++ b/libs/i18next/release/i18next-1.7.3.min.js @@ -0,0 +1,6 @@ +// i18next, v1.7.3 +// Copyright (c)2014 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +!function(){function a(a,b){if(!b||"function"==typeof b)return a;for(var c in b)a[c]=b[c];return a}function b(a,b,c){var d,e=0,f=a.length,g=void 0===f||"[object Array]"!==Object.prototype.toString.apply(a)||"function"==typeof a;if(c)if(g){for(d in a)if(b.apply(a[d],c)===!1)break}else for(;f>e&&b.apply(a[e++],c)!==!1;);else if(g){for(d in a)if(b.call(a[d],d,a[d])===!1)break}else for(;f>e&&b.call(a[e],e,a[e++])!==!1;);return a}function c(a){return"string"==typeof a?a.replace(/[&<>"'\/]/g,function(a){return I[a]}):a}function d(a){var b=function(a){if(window.XMLHttpRequest)return a(null,new XMLHttpRequest);if(window.ActiveXObject)try{return a(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(b){return a(null,new ActiveXObject("Microsoft.XMLHTTP"))}return a(new Error)},c=function(a){if("string"==typeof a)return a;var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")},d=function(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;cd?b+=String.fromCharCode(d):d>127&&2048>d?(b+=String.fromCharCode(d>>6|192),b+=String.fromCharCode(63&d|128)):(b+=String.fromCharCode(d>>12|224),b+=String.fromCharCode(d>>6&63|128),b+=String.fromCharCode(63&d|128))}return b},e=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";a=d(a);var c,e,f,g,h,i,j,k="",l=0;do c=a.charCodeAt(l++),e=a.charCodeAt(l++),f=a.charCodeAt(l++),g=c>>2,h=(3&c)<<4|e>>4,i=(15&e)<<2|f>>6,j=63&f,isNaN(e)?i=j=64:isNaN(f)&&(j=64),k+=b.charAt(g)+b.charAt(h)+b.charAt(i)+b.charAt(j),c=e=f="",g=h=i=j="";while(l1&&(d+=d.indexOf("?")>-1?"&"+k:"?"+k),e.jsonp){var l=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=d,void l.appendChild(m)}}b(function(b,c){if(b)return h(b);c.open(a,d,e.async);for(var f in j)j.hasOwnProperty(f)&&c.setRequestHeader(f,j[f]);c.onreadystatechange=function(){if(4===c.readyState){var a=c.responseText||"";if(!h)return;h(c.status,{text:function(){return a},json:function(){return JSON.parse(a)}})}},c.send(i)})},h={authBasic:function(a,b){g.headers.Authorization="Basic "+e(a+":"+b)},connect:function(a,b,c){return g("CONNECT",a,b,c)},del:function(a,b,c){return g("DELETE",a,b,c)},get:function(a,b,c){return g("GET",a,b,c)},head:function(a,b,c){return g("HEAD",a,b,c)},headers:function(a){g.headers=a||{}},isAllowed:function(a,b,c){this.options(a,function(a,d){c(-1!==d.text().indexOf(b))})},options:function(a,b,c){return g("OPTIONS",a,b,c)},patch:function(a,b,c){return g("PATCH",a,b,c)},post:function(a,b,c){return g("POST",a,b,c)},put:function(a,b,c){return g("PUT",a,b,c)},trace:function(a,b,c){return g("TRACE",a,b,c)}},i=a.type?a.type.toLowerCase():"get";h[i](a.url,a,function(b,c){200===b?a.success(c.json(),b,null):a.error(c.text(),b,null)})}function e(a,b){"function"==typeof a&&(b=a,a={}),a=a||{},L.extend(H,a),delete H.fixLng,"string"==typeof H.ns&&(H.ns={namespaces:[H.ns],defaultNs:H.ns}),"string"==typeof H.fallbackNS&&(H.fallbackNS=[H.fallbackNS]),("string"==typeof H.fallbackLng||"boolean"==typeof H.fallbackLng)&&(H.fallbackLng=[H.fallbackLng]),H.interpolationPrefixEscaped=L.regexEscape(H.interpolationPrefix),H.interpolationSuffixEscaped=L.regexEscape(H.interpolationSuffix),H.lng||(H.lng=L.detectLanguage()),F=L.toLanguages(H.lng),z=F[0],L.log("currentLng set to: "+z),H.useCookie&&L.cookie.read(H.cookieName)!==z&&L.cookie.create(H.cookieName,z,H.cookieExpirationTime,H.cookieDomain);var c=t;a.fixLng&&(c=function(a,b){return b=b||{},b.lng=b.lng||c.lng,t(a,b)},c.lng=z),N.setCurrentLng(z),B&&H.setJqueryExt&&n();var d;if(B&&B.Deferred&&(d=B.Deferred()),!H.resStore){var e=L.toLanguages(H.lng);"string"==typeof H.preload&&(H.preload=[H.preload]);for(var f=0,g=H.preload.length;g>f;f++)for(var h=L.toLanguages(H.preload[f]),i=0,j=h.length;j>i;i++)e.indexOf(h[i])<0&&e.push(h[i]);return C.sync.load(e,H,function(a,e){D=e,G=!0,b&&b(c),d&&d.resolve(c)}),d?d.promise():void 0}return D=H.resStore,G=!0,b&&b(c),d&&d.resolve(c),d?d.promise():void 0}function f(a,b){"string"==typeof a&&(a=[a]);for(var c=0,d=a.length;d>c;c++)H.preload.indexOf(a[c])<0&&H.preload.push(a[c]);return e(b)}function g(a,b,c){"string"!=typeof b?(c=b,b=H.ns.defaultNs):H.ns.namespaces.indexOf(b)<0&&H.ns.namespaces.push(b),D[a]=D[a]||{},D[a][b]=D[a][b]||{},L.extend(D[a][b],c)}function h(a,b){"string"!=typeof b&&(b=H.ns.defaultNs),D[a]=D[a]||{},D[a][b]={}}function i(a){H.ns.defaultNs=a}function j(a,b){k([a],b)}function k(a,b){var c={dynamicLoad:H.dynamicLoad,resGetPath:H.resGetPath,getAsync:H.getAsync,customLoad:H.customLoad,ns:{namespaces:a,defaultNs:""}},d=L.toLanguages(H.lng);"string"==typeof H.preload&&(H.preload=[H.preload]);for(var e=0,f=H.preload.length;f>e;e++)for(var g=L.toLanguages(H.preload[e]),h=0,i=g.length;i>h;h++)d.indexOf(g[h])<0&&d.push(g[h]);for(var j=[],k=0,l=d.length;l>k;k++){var m=!1,n=D[d[k]];if(n)for(var o=0,p=a.length;p>o;o++)n[a[o]]||(m=!0);else m=!0;m&&j.push(d[k])}j.length?C.sync._fetch(j,c,function(c,d){var e=a.length*j.length;L.each(a,function(a,c){H.ns.namespaces.indexOf(c)<0&&H.ns.namespaces.push(c),L.each(j,function(a,f){D[f]=D[f]||{},D[f][c]=d[f][c],e--,0===e&&b&&(H.useLocalStorage&&C.sync._storeLocal(D),b())})})}):b&&b()}function l(a,b,c){return"function"==typeof b?(c=b,b={}):b||(b={}),b.lng=a,e(b,c)}function m(){return z}function n(){function a(a,b,c){if(0!==b.length){var d="text";if(0===b.indexOf("[")){var e=b.split("]");b=e[1],d=e[0].substr(1,e[0].length-1)}b.indexOf(";")===b.length-1&&(b=b.substr(0,b.length-2));var f;if("html"===d)f=H.defaultValueFromContent?B.extend({defaultValue:a.html()},c):c,a.html(B.t(b,f));else if("text"===d)f=H.defaultValueFromContent?B.extend({defaultValue:a.text()},c):c,a.text(B.t(b,f));else if("prepend"===d)f=H.defaultValueFromContent?B.extend({defaultValue:a.html()},c):c,a.prepend(B.t(b,f));else if("append"===d)f=H.defaultValueFromContent?B.extend({defaultValue:a.html()},c):c,a.append(B.t(b,f));else if(0===d.indexOf("data-")){var g=d.substr("data-".length);f=H.defaultValueFromContent?B.extend({defaultValue:a.data(g)},c):c;var h=B.t(b,f);a.data(g,h),a.attr(d,h)}else f=H.defaultValueFromContent?B.extend({defaultValue:a.attr(d)},c):c,a.attr(d,B.t(b,f))}}function b(b,c){var d=b.attr(H.selectorAttr);if(d||"undefined"==typeof d||d===!1||(d=b.text()||b.val()),d){var e=b,f=b.data("i18n-target");if(f&&(e=b.find(f)||b),c||H.useDataAttrOptions!==!0||(c=b.data("i18n-options")),c=c||{},d.indexOf(";")>=0){var g=d.split(";");B.each(g,function(b,d){""!==d&&a(e,d,c)})}else a(e,d,c);H.useDataAttrOptions===!0&&b.data("i18n-options",c)}}B.t=B.t||t,B.fn.i18n=function(a){return this.each(function(){b(B(this),a);var c=B(this).find("["+H.selectorAttr+"]");c.each(function(){b(B(this),a)})})}}function o(a,b,c,d){if(!a)return a;if(d=d||b,a.indexOf(d.interpolationPrefix||H.interpolationPrefix)<0)return a;var e=d.interpolationPrefix?L.regexEscape(d.interpolationPrefix):H.interpolationPrefixEscaped,f=d.interpolationSuffix?L.regexEscape(d.interpolationSuffix):H.interpolationSuffixEscaped,g="HTML"+f;return L.each(b,function(b,h){var i=c?c+H.keyseparator+b:b;"object"==typeof h&&null!==h?a=o(a,h,i,d):d.escapeInterpolation||H.escapeInterpolation?(a=a.replace(new RegExp([e,i,g].join(""),"g"),h),a=a.replace(new RegExp([e,i,f].join(""),"g"),L.escape(h))):a=a.replace(new RegExp([e,i,f].join(""),"g"),h)}),a}function p(a,b){var c=",",d="{",e="}",f=L.extend({},b);for(delete f.postProcess;-1!=a.indexOf(H.reusePrefix)&&(E++,!(E>H.maxRecursion));){var g=a.lastIndexOf(H.reusePrefix),h=a.indexOf(H.reuseSuffix,g)+H.reuseSuffix.length,i=a.substring(g,h),j=i.replace(H.reusePrefix,"").replace(H.reuseSuffix,"");if(-1!=j.indexOf(c)){var k=j.indexOf(c);if(-1!=j.indexOf(d,k)&&-1!=j.indexOf(e,k)){var l=j.indexOf(d,k),m=j.indexOf(e,l)+e.length;try{f=L.extend(f,JSON.parse(j.substring(l,m))),j=j.substring(0,k)}catch(n){}}}var o=w(j,f);a=a.replace(i,o)}return a}function q(a){return a.context&&("string"==typeof a.context||"number"==typeof a.context)}function r(a){return void 0!==a.count&&"string"!=typeof a.count&&1!==a.count}function s(a,b){b=b||{};var c=u(a,b),d=x(a,b);return void 0!==d||d===c}function t(a,b){return b=b||{},G?(E=0,w.apply(null,arguments)):(L.log("i18next not finished initialization. you might have called t function before loading resources finished."),b.defaultValue||"")}function u(a,b){return void 0!==b.defaultValue?b.defaultValue:a}function v(){for(var a=[],b=1;b1)for(var d=0;d-1&&(e=c.split(H.nsseparator),i=e[0],c=e[1]),void 0===g&&H.sendMissing&&(b.lng?M.postMissing(h[0],i,c,f,h):M.postMissing(H.lng,i,c,f,h));var j=b.postProcess||H.postProcess;void 0!==g&&j&&O[j]&&(g=O[j](g,c,b));var k=f;if(f.indexOf(H.nsseparator)>-1&&(e=f.split(H.nsseparator),k=e[1]),k===c&&H.parseMissingKey&&(f=H.parseMissingKey(f)),void 0===g&&(f=o(f,b),f=p(f,b),j&&O[j])){var l=u(c,b);g=O[j](l,c,b)}return void 0!==g?g:f}function x(a,b){b=b||{};var c,d,e=u(a,b),f=F;if(!D)return e;if("cimode"===f[0].toLowerCase())return e;if(b.lng&&(f=L.toLanguages(b.lng),!D[f[0]])){var g=H.getAsync;H.getAsync=!1,C.sync.load(f,H,function(a,b){L.extend(D,b),H.getAsync=g})}var h=b.ns||H.ns.defaultNs;if(a.indexOf(H.nsseparator)>-1){var i=a.split(H.nsseparator);h=i[0],a=i[1]}if(q(b)){c=L.extend({},b),delete c.context,c.defaultValue=H.contextNotFound;var j=h+H.nsseparator+a+"_"+b.context;if(d=t(j,c),d!=H.contextNotFound)return o(d,{context:b.context})}if(r(b)){c=L.extend({},b),delete c.count,c.defaultValue=H.pluralNotFound;var k=h+H.nsseparator+a+H.pluralSuffix,l=N.get(f[0],b.count);if(l>=0?k=k+"_"+l:1===l&&(k=h+H.nsseparator+a),d=t(k,c),d!=H.pluralNotFound)return o(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix})}for(var m,n=a.split(H.keyseparator),s=0,v=f.length;v>s&&void 0===m;s++){for(var y=f[s],z=0,A=D[y]&&D[y][h];n[z];)A=A&&A[n[z]],z++;if(void 0!==A){var B=Object.prototype.toString.apply(A);if("string"==typeof A)A=o(A,b),A=p(A,b);else if("[object Array]"!==B||H.returnObjectTrees||b.returnObjectTrees){if(null===A&&H.fallbackOnNull===!0)A=void 0;else if(null!==A)if(H.returnObjectTrees||b.returnObjectTrees){if("[object Number]"!==B&&"[object Function]"!==B&&"[object RegExp]"!==B){var E="[object Array]"===B?[]:{};L.each(A,function(c){E[c]=w(h+H.nsseparator+a+H.keyseparator+c,b)}),A=E}}else H.objectTreeKeyHandler&&"function"==typeof H.objectTreeKeyHandler?A=H.objectTreeKeyHandler(a,A,y,h,b):(A="key '"+h+":"+a+" ("+y+")' returned an object instead of string.",L.log(A))}else A=A.join("\n"),A=o(A,b),A=p(A,b);"string"==typeof A&&""===A.trim()&&H.fallbackOnEmpty===!0&&(A=void 0),m=A}}if(void 0===m&&!b.isFallbackLookup&&(H.fallbackToDefaultNS===!0||H.fallbackNS&&H.fallbackNS.length>0))if(b.isFallbackLookup=!0,H.fallbackNS.length){for(var G=0,I=H.fallbackNS.length;I>G;G++)if(m=x(H.fallbackNS[G]+H.nsseparator+a,b)){var J=m.indexOf(H.nsseparator)>-1?m.split(H.nsseparator)[1]:m,K=e.indexOf(H.nsseparator)>-1?e.split(H.nsseparator)[1]:e;if(J!==K)break}}else m=x(a,b);return m}function y(){var a,b=[];if("undefined"!=typeof window&&(!function(){for(var a=window.location.search.substring(1),c=a.split("&"),d=0;d0){var f=c[d].substring(0,e),g=c[d].substring(e+1);b[f]=g}}}(),b[H.detectLngQS]&&(a=b[H.detectLngQS])),!a&&"undefined"!=typeof document&&H.useCookie){var c=L.cookie.read(H.cookieName);c&&(a=c)}return a||"undefined"==typeof navigator||(a=navigator.language?navigator.language:navigator.userLanguage),a||(a=H.fallbackLng[0]),a}Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>0&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&1/0!=d&&d!=-1/0&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=c;arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d))));for(var e=d>=0?Math.min(d,c-1):c-Math.abs(d);e>=0;e--)if(e in b&&b[e]===a)return e;return-1}),"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")});var z,A=this,B=A.jQuery||A.Zepto,C={},D={},E=0,F=[],G=!1;"undefined"!=typeof module&&module.exports?module.exports=C:(B&&(B.i18n=B.i18n||C),A.i18n=A.i18n||C);var H={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:["dev"],fallbackNS:[],detectLngQS:"setLng",ns:"translation",fallbackOnNull:!0,fallbackOnEmpty:!1,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",cookieDomain:void 0,objectTreeKeyHandler:void 0,postProcess:void 0,parseMissingKey:void 0,shortcutFunction:"sprintf"},I={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},J={create:function(a,b,c,d){var e;if(c){var f=new Date;f.setTime(f.getTime()+60*c*1e3),e="; expires="+f.toGMTString()}else e="";d=d?"domain="+d+";":"",document.cookie=a+"="+b+e+";"+d+"path=/"},read:function(a){for(var b=a+"=",c=document.cookie.split(";"),d=0;d-1?c.push(a):b("rejecting non-whitelisted language: "+a)};if("string"==typeof a&&a.indexOf("-")>-1){var f=a.split("-");a=H.lowerCaseLng?f[0].toLowerCase()+"-"+f[1].toLowerCase():f[0].toLowerCase()+"-"+f[1].toUpperCase(),"unspecific"!==H.load&&e(a),"current"!==H.load&&e(f[0])}else e(a);for(var g=0;gg;g++)e[a[g]]||f.push(a[g]);f.length>0?M._fetch(f,b,function(a,b){L.extend(e,b),M._storeLocal(b),c(null,e)}):c(null,e)}):M._fetch(a,b,function(a,b){c(null,b)})},_loadLocal:function(a,b,c){var d={},e=(new Date).getTime();if(window.localStorage){var f=a.length;L.each(a,function(a,g){var h=window.localStorage.getItem("res_"+g);h&&(h=JSON.parse(h),h.i18nStamp&&h.i18nStamp+b.localStorageExpirationTime>e&&(d[g]=h)),f--,0===f&&c(null,d)})}},_storeLocal:function(a){if(window.localStorage)for(var b in a)a[b].i18nStamp=(new Date).getTime(),window.localStorage.setItem("res_"+b,JSON.stringify(a[b]))},_fetch:function(a,b,c){var d=b.ns,e={};if(b.dynamicLoad){var f=function(a,b){c(null,b)};if("function"==typeof b.customLoad)b.customLoad(a,d.namespaces,b,f);else{var g=o(b.resGetPath,{lng:a.join("+"),ns:d.namespaces.join("+")});L.ajax({url:g,success:function(a){L.log("loaded: "+g),f(null,a)},error:function(a,b,c){L.log("failed loading: "+g),f("failed loading resource.json error: "+c)},dataType:"json",async:b.getAsync})}}else{var h,i=d.namespaces.length*a.length;L.each(d.namespaces,function(d,f){L.each(a,function(a,d){var g=function(a,b){a&&(h=h||[],h.push(a)),e[d]=e[d]||{},e[d][f]=b,i--,0===i&&c(h,e)};"function"==typeof b.customLoad?b.customLoad(d,f,b,g):M._fetchOne(d,f,b,g)})})}},_fetchOne:function(a,b,c,d){var e=o(c.resGetPath,{lng:a,ns:b});L.ajax({url:e,success:function(a){L.log("loaded: "+e),d(null,a)},error:function(a,b,c){if(b&&200==b||a&&a.status&&200==a.status)L.log("There is a typo in: "+e);else if(b&&404==b||a&&a.status&&404==a.status)L.log("Does not exist: "+e);else{var f=b?b:a&&a.status?a.status:null;L.log(f+" when loading "+e)}d(c,{})},dataType:"json",async:c.getAsync})},postMissing:function(a,b,c,d,e){var f={};f[c]=d;var g=[];if("fallback"===H.sendMissingTo&&H.fallbackLng[0]!==!1)for(var h=0;hh;h++)g.push({lng:e[h],url:o(H.resPostPath,{lng:e[h],ns:b})});for(var j=0,k=g.length;k>j;j++){var l=g[j];L.ajax({url:l.url,type:H.sendType,data:f,success:function(){L.log("posted missing key '"+c+"' to: "+l.url);for(var a=c.split("."),e=0,f=D[l.lng][b];a[e];)f=f[a[e]]=e===a.length-1?d:f[a[e]]||{},e++},error:function(){L.log("failed posting missing key '"+c+"' to: "+l.url)},dataType:"json",async:H.postAsync})}}},N={rules:{ach:{name:"Acholi",numbers:[1,2],plurals:function(a){return Number(a>1)}},af:{name:"Afrikaans",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ak:{name:"Akan",numbers:[1,2],plurals:function(a){return Number(a>1)}},am:{name:"Amharic",numbers:[1,2],plurals:function(a){return Number(a>1)}},an:{name:"Aragonese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ar:{name:"Arabic",numbers:[0,1,2,3,11,100],plurals:function(a){return Number(0===a?0:1==a?1:2==a?2:a%100>=3&&10>=a%100?3:a%100>=11?4:5)}},arn:{name:"Mapudungun",numbers:[1,2],plurals:function(a){return Number(a>1)}},ast:{name:"Asturian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ay:{name:"Aymará",numbers:[1],plurals:function(){return 0}},az:{name:"Azerbaijani",numbers:[1,2],plurals:function(a){return Number(1!=a)}},be:{name:"Belarusian",numbers:[1,2,5],plurals:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},bg:{name:"Bulgarian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},bn:{name:"Bengali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},bo:{name:"Tibetan",numbers:[1],plurals:function(){return 0}},br:{name:"Breton",numbers:[1,2],plurals:function(a){return Number(a>1)}},bs:{name:"Bosnian",numbers:[1,2,5],plurals:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},ca:{name:"Catalan",numbers:[1,2],plurals:function(a){return Number(1!=a)}},cgg:{name:"Chiga",numbers:[1],plurals:function(){return 0}},cs:{name:"Czech",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)}},csb:{name:"Kashubian",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},cy:{name:"Welsh",numbers:[1,2,3,8],plurals:function(a){return Number(1==a?0:2==a?1:8!=a&&11!=a?2:3)}},da:{name:"Danish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},de:{name:"German",numbers:[1,2],plurals:function(a){return Number(1!=a)}},dz:{name:"Dzongkha",numbers:[1],plurals:function(){return 0}},el:{name:"Greek",numbers:[1,2],plurals:function(a){return Number(1!=a)}},en:{name:"English",numbers:[1,2],plurals:function(a){return Number(1!=a)}},eo:{name:"Esperanto",numbers:[1,2],plurals:function(a){return Number(1!=a)}},es:{name:"Spanish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},es_ar:{name:"Argentinean Spanish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},et:{name:"Estonian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},eu:{name:"Basque",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fa:{name:"Persian",numbers:[1],plurals:function(){return 0}},fi:{name:"Finnish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fil:{name:"Filipino",numbers:[1,2],plurals:function(a){return Number(a>1)}},fo:{name:"Faroese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fr:{name:"French",numbers:[1,2],plurals:function(a){return Number(a>1)}},fur:{name:"Friulian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fy:{name:"Frisian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ga:{name:"Irish",numbers:[1,2,3,7,11],plurals:function(a){return Number(1==a?0:2==a?1:7>a?2:11>a?3:4)}},gd:{name:"Scottish Gaelic",numbers:[1,2,3,20],plurals:function(a){return Number(1==a||11==a?0:2==a||12==a?1:a>2&&20>a?2:3)}},gl:{name:"Galician",numbers:[1,2],plurals:function(a){return Number(1!=a)}},gu:{name:"Gujarati",numbers:[1,2],plurals:function(a){return Number(1!=a)}},gun:{name:"Gun",numbers:[1,2],plurals:function(a){return Number(a>1)}},ha:{name:"Hausa",numbers:[1,2],plurals:function(a){return Number(1!=a)}},he:{name:"Hebrew",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hi:{name:"Hindi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hr:{name:"Croatian",numbers:[1,2,5],plurals:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},hu:{name:"Hungarian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hy:{name:"Armenian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ia:{name:"Interlingua",numbers:[1,2],plurals:function(a){return Number(1!=a)}},id:{name:"Indonesian",numbers:[1],plurals:function(){return 0}},is:{name:"Icelandic",numbers:[1,2],plurals:function(a){return Number(a%10!=1||a%100==11)}},it:{name:"Italian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ja:{name:"Japanese",numbers:[1],plurals:function(){return 0}},jbo:{name:"Lojban",numbers:[1],plurals:function(){return 0}},jv:{name:"Javanese",numbers:[0,1],plurals:function(a){return Number(0!==a)}},ka:{name:"Georgian",numbers:[1],plurals:function(){return 0}},kk:{name:"Kazakh",numbers:[1],plurals:function(){return 0}},km:{name:"Khmer",numbers:[1],plurals:function(){return 0}},kn:{name:"Kannada",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ko:{name:"Korean",numbers:[1],plurals:function(){return 0}},ku:{name:"Kurdish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},kw:{name:"Cornish",numbers:[1,2,3,4],plurals:function(a){return Number(1==a?0:2==a?1:3==a?2:3)}},ky:{name:"Kyrgyz",numbers:[1],plurals:function(){return 0}},lb:{name:"Letzeburgesch",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ln:{name:"Lingala",numbers:[1,2],plurals:function(a){return Number(a>1)}},lo:{name:"Lao",numbers:[1],plurals:function(){return 0}},lt:{name:"Lithuanian",numbers:[1,2,10],plurals:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&(10>a%100||a%100>=20)?1:2)}},lv:{name:"Latvian",numbers:[1,2,0],plurals:function(a){return Number(a%10==1&&a%100!=11?0:0!==a?1:2)}},mai:{name:"Maithili",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mfe:{name:"Mauritian Creole",numbers:[1,2],plurals:function(a){return Number(a>1)}},mg:{name:"Malagasy",numbers:[1,2],plurals:function(a){return Number(a>1)}},mi:{name:"Maori",numbers:[1,2],plurals:function(a){return Number(a>1)}},mk:{name:"Macedonian",numbers:[1,2],plurals:function(a){return Number(1==a||a%10==1?0:1)}},ml:{name:"Malayalam",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mn:{name:"Mongolian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mnk:{name:"Mandinka",numbers:[0,1,2],plurals:function(a){return Number(1==a?1:2)}},mr:{name:"Marathi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ms:{name:"Malay",numbers:[1],plurals:function(){return 0}},mt:{name:"Maltese",numbers:[1,2,11,20],plurals:function(a){return Number(1==a?0:0===a||a%100>1&&11>a%100?1:a%100>10&&20>a%100?2:3)}},nah:{name:"Nahuatl",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nap:{name:"Neapolitan",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nb:{name:"Norwegian Bokmal",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ne:{name:"Nepali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nl:{name:"Dutch",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nn:{name:"Norwegian Nynorsk",numbers:[1,2],plurals:function(a){return Number(1!=a)}},no:{name:"Norwegian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nso:{name:"Northern Sotho",numbers:[1,2],plurals:function(a){return Number(1!=a)}},oc:{name:"Occitan",numbers:[1,2],plurals:function(a){return Number(a>1)}},or:{name:"Oriya",numbers:[2,1],plurals:function(a){return Number(1!=a)}},pa:{name:"Punjabi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pap:{name:"Papiamento",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pl:{name:"Polish",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},pms:{name:"Piemontese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ps:{name:"Pashto",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pt:{name:"Portuguese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pt_br:{name:"Brazilian Portuguese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},rm:{name:"Romansh",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ro:{name:"Romanian",numbers:[1,2,20],plurals:function(a){return Number(1==a?0:0===a||a%100>0&&20>a%100?1:2)}},ru:{name:"Russian",numbers:[1,2,5],plurals:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},sah:{name:"Yakut",numbers:[1],plurals:function(){return 0}},sco:{name:"Scots",numbers:[1,2],plurals:function(a){return Number(1!=a)}},se:{name:"Northern Sami",numbers:[1,2],plurals:function(a){return Number(1!=a)}},si:{name:"Sinhala",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sk:{name:"Slovak",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)}},sl:{name:"Slovenian",numbers:[5,1,2,3],plurals:function(a){return Number(a%100==1?1:a%100==2?2:a%100==3||a%100==4?3:0)}},so:{name:"Somali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},son:{name:"Songhay",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sq:{name:"Albanian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sr:{name:"Serbian",numbers:[1,2,5],plurals:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},su:{name:"Sundanese",numbers:[1],plurals:function(){return 0}},sv:{name:"Swedish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sw:{name:"Swahili",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ta:{name:"Tamil",numbers:[1,2],plurals:function(a){return Number(1!=a)}},te:{name:"Telugu",numbers:[1,2],plurals:function(a){return Number(1!=a)}},tg:{name:"Tajik",numbers:[1,2],plurals:function(a){return Number(a>1)}},th:{name:"Thai",numbers:[1],plurals:function(){return 0}},ti:{name:"Tigrinya",numbers:[1,2],plurals:function(a){return Number(a>1)}},tk:{name:"Turkmen",numbers:[1,2],plurals:function(a){return Number(1!=a)}},tr:{name:"Turkish",numbers:[1,2],plurals:function(a){return Number(a>1)}},tt:{name:"Tatar",numbers:[1],plurals:function(){return 0}},ug:{name:"Uyghur",numbers:[1],plurals:function(){return 0}},uk:{name:"Ukrainian",numbers:[1,2,5],plurals:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},ur:{name:"Urdu",numbers:[1,2],plurals:function(a){return Number(1!=a)}},uz:{name:"Uzbek",numbers:[1,2],plurals:function(a){return Number(a>1)}},vi:{name:"Vietnamese",numbers:[1],plurals:function(){return 0}},wa:{name:"Walloon",numbers:[1,2],plurals:function(a){return Number(a>1)}},wo:{name:"Wolof",numbers:[1],plurals:function(){return 0}},yo:{name:"Yoruba",numbers:[1,2],plurals:function(a){return Number(1!=a)}},zh:{name:"Chinese",numbers:[1],plurals:function(){return 0}}},addRule:function(a,b){N.rules[a]=b},setCurrentLng:function(a){if(!N.currentRule||N.currentRule.lng!==a){var b=a.split("-");N.currentRule={lng:a,rule:N.rules[b[0]]}}},get:function(a,b){function c(b,c){var d;if(d=N.currentRule&&N.currentRule.lng===a?N.currentRule.rule:N.rules[b]){var e=d.plurals(c),f=d.numbers[e];return 2===d.numbers.length&&1===d.numbers[0]&&(2===f?f=-1:1===f&&(f=1)),f}return 1===c?"1":"-1"}var d=a.split("-");return c(d[0],b)}},O={},P=function(a,b){O[a]=b},Q=function(){function a(a){return Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}function b(a,b){for(var c=[];b>0;c[--b]=a);return c.join("")}var c=function(){return c.cache.hasOwnProperty(arguments[0])||(c.cache[arguments[0]]=c.parse(arguments[0])),c.format.call(null,c.cache[arguments[0]],arguments)};return c.format=function(c,d){var e,f,g,h,i,j,k,l=1,m=c.length,n="",o=[];for(f=0;m>f;f++)if(n=a(c[f]),"string"===n)o.push(c[f]);else if("array"===n){if(h=c[f],h[2])for(e=d[l],g=0;g=0?"+"+e:e,j=h[4]?"0"==h[4]?"0":h[4].charAt(1):" ",k=h[6]-String(e).length,i=h[6]?b(j,k):"",o.push(h[5]?e+i:i+e)}return o.join("")},c.cache={},c.parse=function(a){for(var b=a,c=[],d=[],e=0;b;){if(null!==(c=/^[^\x25]+/.exec(b)))d.push(c[0]);else if(null!==(c=/^\x25{2}/.exec(b)))d.push("%");else{if(null===(c=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(b)))throw"[sprintf] huh?";if(c[2]){e|=1;var f=[],g=c[2],h=[];if(null===(h=/^([a-z_][a-z_\d]*)/i.exec(g)))throw"[sprintf] huh?";for(f.push(h[1]);""!==(g=g.substring(h[0].length));)if(null!==(h=/^\.([a-z_][a-z_\d]*)/i.exec(g)))f.push(h[1]);else{if(null===(h=/^\[(\d+)\]/.exec(g)))throw"[sprintf] huh?";f.push(h[1])}c[2]=f}else e|=2;if(3===e)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";d.push(c)}b=b.substring(c[0].length)}return d},c}(),R=function(a,b){return b.unshift(a),Q.apply(null,b)};P("sprintf",function(a,b,c){return c.sprintf?"[object Array]"===Object.prototype.toString.apply(c.sprintf)?R(a,c.sprintf):"object"==typeof c.sprintf?Q(a,c.sprintf):a:a +}),C.init=e,C.setLng=l,C.preload=f,C.addResourceBundle=g,C.removeResourceBundle=h,C.loadNamespace=j,C.loadNamespaces=k,C.setDefaultNamespace=i,C.t=t,C.translate=t,C.exists=s,C.detectLanguage=L.detectLanguage,C.pluralExtensions=N,C.sync=M,C.functions=L,C.lng=m,C.addPostProcessor=P,C.options=H}(); \ No newline at end of file diff --git a/libs/i18next/release/i18next-1.7.3.zip b/libs/i18next/release/i18next-1.7.3.zip new file mode 100644 index 00000000..3a09dc05 Binary files /dev/null and b/libs/i18next/release/i18next-1.7.3.zip differ diff --git a/libs/i18next/release/i18next-1.7.4.js b/libs/i18next/release/i18next-1.7.4.js new file mode 100644 index 00000000..7e678fce --- /dev/null +++ b/libs/i18next/release/i18next-1.7.4.js @@ -0,0 +1,2889 @@ +// i18next, v1.7.4 +// Copyright (c)2014 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function() { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + // Add string trim for IE8. + if (typeof String.prototype.trim !== 'function') { + String.prototype.trim = function() { + return this.replace(/^\s+|\s+$/g, ''); + } + } + + var root = this + , $ = root.jQuery || root.Zepto + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = [] + , initialized = false + , sync = {}; + + + + // Export the i18next object for **CommonJS**. + // If we're not in CommonJS, add `i18n` to the + // global object or to jquery. + if (typeof module !== 'undefined' && module.exports) { + if (!$) { + try { + $ = require('jquery'); + } catch(e) { + // just ignore + } + } + if ($) { + $.i18n = $.i18n || i18n; + } + module.exports = i18n; + } else { + if ($) { + $.i18n = $.i18n || i18n; + } + + root.i18n = root.i18n || i18n; + } + sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + window.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + if ((status && status == 200) || (xhr && xhr.status && xhr.status == 200)) { + // file loaded but invalid json, stop waste time ! + f.error('There is a typo in: ' + url); + } else if ((status && status == 404) || (xhr && xhr.status && xhr.status == 404)) { + f.log('Does not exist: ' + url); + } else { + var theStatus = status ? status : ((xhr && xhr.status) ? xhr.status : null); + f.log(theStatus + ' when loading ' + url); + } + + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback' && o.fallbackLng[0] !== false) { + for (var i = 0; i < o.fallbackLng.length; i++) { + urls.push({lng: o.fallbackLng[i], url: applyReplacement(o.resPostPath, { lng: o.fallbackLng[i], ns: ns })}); + } + } else if (o.sendMissingTo === 'current' || (o.sendMissingTo === 'fallback' && o.fallbackLng[0] === false) ) { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + } + }; + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: ['dev'], + fallbackNS: [], + detectLngQS: 'setLng', + detectLngFromLocalStorage: false, + ns: 'translation', + fallbackOnNull: true, + fallbackOnEmpty: false, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + indefiniteSuffix: '_indefinite', + indefiniteNotFound: ['indefinite_not_found', Math.random()].join(''), + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + cookieDomain: undefined, + + objectTreeKeyHandler: undefined, + postProcess: undefined, + parseMissingKey: undefined, + missingKeyHandler: sync.postMissing, + + shortcutFunction: 'sprintf' // or: defaultValue + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _deepExtend(target, source) { + for (var prop in source) + if (prop in target) + _deepExtend(target[prop], source[prop]); + else + target[prop] = source[prop]; + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || Object.prototype.toString.apply(object) !== '[object Array]' || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + return JSON.parse(data); + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + // file: protocol always gives status code 0, so check for data + if (status === 200 || (status === 0 && data.text())) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes,domain) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + domain = (domain)? "domain="+domain+";" : ""; + document.cookie = name+"="+value+expires+";"+domain+"path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes,domain) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + deepExtend: _deepExtend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : (typeof document !== 'undefined' ? _ajax : function() {}), + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + error: function(str) { + if (typeof console !== "undefined") console.error(str); + }, + getCountyIndexOfLng: function(lng) { + var lng_index = 0; + if (lng === 'nb-NO' || lng === 'nn-NO') lng_index = 1; + return lng_index; + }, + toLanguages: function(lng) { + var log = this.log; + + var languages = []; + var whitelist = o.lngWhitelist || false; + var addLanguage = function(language){ + //reject langs not whitelisted + if(!whitelist || whitelist.indexOf(language) > -1){ + languages.push(language); + }else{ + log('rejecting non-whitelisted language: ' + language); + } + }; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + + if (o.load !== 'unspecific') addLanguage(lng); + if (o.load !== 'current') addLanguage(parts[this.getCountyIndexOfLng(lng)]); + } else { + addLanguage(lng); + } + + for (var i = 0; i < o.fallbackLng.length; i++) { + if (languages.indexOf(o.fallbackLng[i]) === -1 && o.fallbackLng[i]) languages.push(o.fallbackLng[i]); + } + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + }, + regexReplacementEscape: function(strOrFn) { + if (typeof strOrFn === 'string') { + return strOrFn.replace(/\$/g, "$$$$"); + } else { + return strOrFn; + } + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + delete o.fixLng; /* passed in each time */ + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // fallback languages + if (typeof o.fallbackLng == 'string' || typeof o.fallbackLng == 'boolean') { + o.fallbackLng = [o.fallbackLng]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + if (o.useCookie && f.cookie.read(o.cookieName) !== currentLng){ //cookie is unset or invalid + f.cookie.create(o.cookieName, currentLng, o.cookieExpirationTime, o.cookieDomain); + } + if (o.detectLngFromLocalStorage && typeof document !== 'undefined' && window.localstorage) { + window.localStorage.setItem('i18next_lng', currentLng); + } + + var lngTranslate = translate; + if (options.fixLng) { + lngTranslate = function(key, options) { + options = options || {}; + options.lng = options.lng || lngTranslate.lng; + return translate(key, options); + }; + lngTranslate.lng = currentLng; + } + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + initialized = true; + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + initialized = true; + + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources, deep) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + if (deep) { + f.deepExtend(resStore[lng][ns], resources); + } else { + f.extend(resStore[lng][ns], resources); + } + } + + function removeResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = {}; + } + + function addResource(lng, ns, key, value) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + var keys = key.split(o.keyseparator); + var x = 0; + var node = resStore[o.lng][ns]; + var origRef = node; + + while (keys[x]) { + if (x == keys.length - 1) + node[keys[x]] = value; + else { + if (node[keys[x]] == null) + node[keys[x]] = {}; + + node = node[keys[x]]; + } + x++; + } + } + + function addResources(lng, ns, resources) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + for (var m in resources) { + if (typeof resources[m] === 'string') addResource(lng, ns, m, resources[m]); + } + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, options, cb) { + if (typeof options === 'function') { + cb = options; + options = {}; + } else if (!options) { + options = {}; + } + + options.lng = lng; + return init(options, cb); + } + + function lng() { + return currentLng; + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else if (attr === 'prepend') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.prepend($.t(key, optionsToUse)); + } else if (attr === 'append') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.append($.t(key, optionsToUse)); + } else if (attr.indexOf("data-") === 0) { + var dataAttr = attr.substr(("data-").length); + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.data(dataAttr) }, options) : options; + var translated = $.t(key, optionsToUse); + //we change into the data cache + ele.data(dataAttr, translated); + //we change into the dom + ele.attr(attr, translated); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key && typeof key !== 'undefined' && key !== false) key = ele.text() || ele.val(); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + var hash = replacementHash.replace && typeof replacementHash.replace === 'object' ? replacementHash.replace : replacementHash; + f.each(hash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), f.regexReplacementEscape(value)); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(f.escape(value))); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(value)); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + if (index_of_end_of_closing <= index_of_opening) { + f.error('there is an missing closing in following translation value', translated); + return ''; + } + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, f.regexReplacementEscape(translated_token)); + } + return translated; + } + + function hasContext(options) { + return (options.context && (typeof options.context == 'string' || typeof options.context == 'number')); + } + + function needsPlural(options, lng) { + return (options.count !== undefined && typeof options.count != 'string' && pluralExtensions.needsPlural(lng, options.count)); + } + + function needsIndefiniteArticle(options) { + return (options.indefinite_article !== undefined && typeof options.indefinite_article != 'string' && options.indefinite_article); + } + + function exists(key, options) { + options = options || {}; + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + options = options || {}; + + if (!initialized) { + f.log('i18next not finished initialization. you might have called t function before loading resources finished.') + return options.defaultValue || ''; + }; + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _getDefaultValue(key, options) { + return (options.defaultValue !== undefined) ? options.defaultValue : key; + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(potentialKeys, options) { + if (options && typeof options !== 'object') { + if (o.shortcutFunction === 'sprintf') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else if (o.shortcutFunction === 'defaultValue') { + options = { + defaultValue: options + } + } + } else { + options = options || {}; + } + + if (potentialKeys === undefined || potentialKeys === null || potentialKeys === '') return ''; + + if (typeof potentialKeys == 'string') { + potentialKeys = [potentialKeys]; + } + + var key = potentialKeys[0]; + + if (potentialKeys.length > 1) { + for (var i = 0; i < potentialKeys.length; i++) { + key = potentialKeys[i]; + if (exists(key, options)) { + break; + } + } + } + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng, options.fallbackLng) : languages + , ns = options.ns || o.ns.defaultNs + , parts; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing && typeof o.missingKeyHandler === 'function') { + if (options.lng) { + o.missingKeyHandler(lngs[0], ns, key, notFound, lngs); + } else { + o.missingKeyHandler(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found !== undefined && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + // process notFound if function exists + var splitNotFound = notFound; + if (notFound.indexOf(o.nsseparator) > -1) { + parts = notFound.split(o.nsseparator); + splitNotFound = parts[1]; + } + if (splitNotFound === key && o.parseMissingKey) { + notFound = o.parseMissingKey(notFound); + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessor && postProcessors[postProcessor]) { + var val = _getDefaultValue(key, options); + found = postProcessors[postProcessor](val, key, options); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options) { + options = options || {}; + + var optionWithoutCount, translated + , notFound = _getDefaultValue(key, options) + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + // CI mode + if (lngs[0].toLowerCase() === 'cimode') return notFound; + + // passed in lng + if (options.lng) { + lngs = f.toLanguages(options.lng, options.fallbackLng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options, lngs[0])) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.count; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(lngs[0], options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + + translated = translate(pluralKey, optionWithoutCount); + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } // else continue translation with original/singular key + } + + if (needsIndefiniteArticle(options)) { + var optionsWithoutIndef = f.extend({}, options); + delete optionsWithoutIndef.indefinite_article; + optionsWithoutIndef.defaultValue = o.indefiniteNotFound; + // If we don't have a count, we want the indefinite, if we do have a count, and needsPlural is false + var indefiniteKey = ns + o.nsseparator + key + (((options.count && !needsPlural(options, lngs[0])) || !options.count) ? o.indefiniteSuffix : ""); + translated = translate(indefiniteKey, optionsWithoutIndef); + if (translated != o.indefiniteNotFound) { + return translated; + } + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + var valueType = Object.prototype.toString.apply(value); + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (valueType === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + if (o.objectTreeKeyHandler && typeof o.objectTreeKeyHandler == 'function') { + value = o.objectTreeKeyHandler(key, value, l, ns, options); + } else { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned an object instead of string.'; + f.log(value); + } + } else if (valueType !== '[object Number]' && valueType !== '[object Function]' && valueType !== '[object RegExp]') { + var copy = (valueType === '[object Array]') ? [] : {}; // apply child translation on a copy + f.each(value, function(m) { + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + }); + value = copy; + } + } + + if (typeof value === 'string' && value.trim() === '' && o.fallbackOnEmpty === true) + value = undefined; + + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length > 0))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + options.isFallbackLookup = false; + } + + return found; + } + function detectLanguage() { + var detectedLng; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var parms = query.split('&'); + for (var i=0; i 0) { + var key = parms[i].substring(0,pos); + var val = parms[i].substring(pos+1); + qsParm[key] = val; + } + } + })(); + if (qsParm[o.detectLngQS]) { + detectedLng = qsParm[o.detectLngQS]; + } + } + + // get from cookie + if (!detectedLng && typeof document !== 'undefined' && o.useCookie ) { + var c = f.cookie.read(o.cookieName); + if (c) detectedLng = c; + } + + // get from localstorage + if (!detectedLng && typeof document !== 'undefined' && window.localstorage && o.detectLngFromLocalStorage) { + detectedLng = window.localStorage.getItem('i18next_lng'); + } + + // get from navigator + if (!detectedLng && typeof navigator !== 'undefined') { + detectedLng = (navigator.language) ? navigator.language : navigator.userLanguage; + } + + //fallback + if(!detectedLng){ + detectedLng = o.fallbackLng[0]; + } + + return detectedLng; + } + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + var pluralExtensions = { + + rules: { + "ach": { + "name": "Acholi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "af": { + "name": "Afrikaans", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ak": { + "name": "Akan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "am": { + "name": "Amharic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "an": { + "name": "Aragonese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ar": { + "name": "Arabic", + "numbers": [ + 0, + 1, + 2, + 3, + 11, + 100 + ], + "plurals": function(n) { return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5); } + }, + "arn": { + "name": "Mapudungun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ast": { + "name": "Asturian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ay": { + "name": "Aymar\u00e1", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "az": { + "name": "Azerbaijani", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "be": { + "name": "Belarusian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "bg": { + "name": "Bulgarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bn": { + "name": "Bengali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bo": { + "name": "Tibetan", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "br": { + "name": "Breton", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "bs": { + "name": "Bosnian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ca": { + "name": "Catalan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "cgg": { + "name": "Chiga", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "cs": { + "name": "Czech", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "csb": { + "name": "Kashubian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "cy": { + "name": "Welsh", + "numbers": [ + 1, + 2, + 3, + 8 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3); } + }, + "da": { + "name": "Danish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "de": { + "name": "German", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "dz": { + "name": "Dzongkha", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "el": { + "name": "Greek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "en": { + "name": "English", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eo": { + "name": "Esperanto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es": { + "name": "Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es_ar": { + "name": "Argentinean Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "et": { + "name": "Estonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eu": { + "name": "Basque", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fa": { + "name": "Persian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "fi": { + "name": "Finnish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fil": { + "name": "Filipino", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fo": { + "name": "Faroese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fr": { + "name": "French", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n >= 2); } + }, + "fur": { + "name": "Friulian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fy": { + "name": "Frisian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ga": { + "name": "Irish", + "numbers": [ + 1, + 2, + 3, + 7, + 11 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;} + }, + "gd": { + "name": "Scottish Gaelic", + "numbers": [ + 1, + 2, + 3, + 20 + ], + "plurals": function(n) { return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3); } + }, + "gl": { + "name": "Galician", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gu": { + "name": "Gujarati", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gun": { + "name": "Gun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ha": { + "name": "Hausa", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "he": { + "name": "Hebrew", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hi": { + "name": "Hindi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hr": { + "name": "Croatian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "hu": { + "name": "Hungarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hy": { + "name": "Armenian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ia": { + "name": "Interlingua", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "id": { + "name": "Indonesian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "is": { + "name": "Icelandic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n%10!=1 || n%100==11); } + }, + "it": { + "name": "Italian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ja": { + "name": "Japanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jbo": { + "name": "Lojban", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jv": { + "name": "Javanese", + "numbers": [ + 0, + 1 + ], + "plurals": function(n) { return Number(n !== 0); } + }, + "ka": { + "name": "Georgian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kk": { + "name": "Kazakh", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "km": { + "name": "Khmer", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kn": { + "name": "Kannada", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ko": { + "name": "Korean", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ku": { + "name": "Kurdish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "kw": { + "name": "Cornish", + "numbers": [ + 1, + 2, + 3, + 4 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3); } + }, + "ky": { + "name": "Kyrgyz", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lb": { + "name": "Letzeburgesch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ln": { + "name": "Lingala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "lo": { + "name": "Lao", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lt": { + "name": "Lithuanian", + "numbers": [ + 1, + 2, + 10 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "lv": { + "name": "Latvian", + "numbers": [ + 1, + 2, + 0 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2); } + }, + "mai": { + "name": "Maithili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mfe": { + "name": "Mauritian Creole", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mg": { + "name": "Malagasy", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mi": { + "name": "Maori", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mk": { + "name": "Macedonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 || n%10==1 ? 0 : 1); } + }, + "ml": { + "name": "Malayalam", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mn": { + "name": "Mongolian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mnk": { + "name": "Mandinka", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(0 ? 0 : n==1 ? 1 : 2); } + }, + "mr": { + "name": "Marathi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ms": { + "name": "Malay", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "mt": { + "name": "Maltese", + "numbers": [ + 1, + 2, + 11, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3); } + }, + "nah": { + "name": "Nahuatl", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nap": { + "name": "Neapolitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nb": { + "name": "Norwegian Bokmal", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ne": { + "name": "Nepali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nl": { + "name": "Dutch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nn": { + "name": "Norwegian Nynorsk", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "no": { + "name": "Norwegian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nso": { + "name": "Northern Sotho", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "oc": { + "name": "Occitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "or": { + "name": "Oriya", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pa": { + "name": "Punjabi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pap": { + "name": "Papiamento", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pl": { + "name": "Polish", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "pms": { + "name": "Piemontese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ps": { + "name": "Pashto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt": { + "name": "Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt_br": { + "name": "Brazilian Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "rm": { + "name": "Romansh", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ro": { + "name": "Romanian", + "numbers": [ + 1, + 2, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2); } + }, + "ru": { + "name": "Russian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "sah": { + "name": "Yakut", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sco": { + "name": "Scots", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "se": { + "name": "Northern Sami", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "si": { + "name": "Sinhala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sk": { + "name": "Slovak", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "sl": { + "name": "Slovenian", + "numbers": [ + 5, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }, + "so": { + "name": "Somali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "son": { + "name": "Songhay", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sq": { + "name": "Albanian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sr": { + "name": "Serbian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "su": { + "name": "Sundanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sv": { + "name": "Swedish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sw": { + "name": "Swahili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ta": { + "name": "Tamil", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "te": { + "name": "Telugu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tg": { + "name": "Tajik", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "th": { + "name": "Thai", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ti": { + "name": "Tigrinya", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tk": { + "name": "Turkmen", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tr": { + "name": "Turkish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tt": { + "name": "Tatar", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ug": { + "name": "Uyghur", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "uk": { + "name": "Ukrainian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ur": { + "name": "Urdu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "uz": { + "name": "Uzbek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "vi": { + "name": "Vietnamese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "wa": { + "name": "Walloon", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "wo": { + "name": "Wolof", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "yo": { + "name": "Yoruba", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "zh": { + "name": "Chinese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + } + }, + + // for demonstration only sl and ar is added but you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + needsPlural: function(lng, count) { + var parts = lng.split('-'); + + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[parts[f.getCountyIndexOfLng(lng)]]; + } + + if (ext && ext.numbers.length <= 1) { + return false; + } else { + return this.get(lng, count) !== 1; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i; + if (ext.noAbs) { + i = ext.plurals(c); + } else { + i = ext.plurals(Math.abs(c)); + } + + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[f.getCountyIndexOfLng(lng)], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.addResource = addResource; + i18n.addResources = addResources; + i18n.removeResourceBundle = removeResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + +})(); \ No newline at end of file diff --git a/libs/i18next/release/i18next-1.7.4.min.js b/libs/i18next/release/i18next-1.7.4.min.js new file mode 100644 index 00000000..ae1cd6c2 --- /dev/null +++ b/libs/i18next/release/i18next-1.7.4.min.js @@ -0,0 +1,6 @@ +// i18next, v1.7.4 +// Copyright (c)2014 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +!function(){function a(a,b){if(!b||"function"==typeof b)return a;for(var c in b)a[c]=b[c];return a}function b(a,c){for(var d in c)d in a?b(a[d],c[d]):a[d]=c[d];return a}function c(a,b,c){var d,e=0,f=a.length,g=void 0===f||"[object Array]"!==Object.prototype.toString.apply(a)||"function"==typeof a;if(c)if(g){for(d in a)if(b.apply(a[d],c)===!1)break}else for(;f>e&&b.apply(a[e++],c)!==!1;);else if(g){for(d in a)if(b.call(a[d],d,a[d])===!1)break}else for(;f>e&&b.call(a[e],e,a[e++])!==!1;);return a}function d(a){return"string"==typeof a?a.replace(/[&<>"'\/]/g,function(a){return O[a]}):a}function e(a){var b=function(a){if(window.XMLHttpRequest)return a(null,new XMLHttpRequest);if(window.ActiveXObject)try{return a(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(b){return a(null,new ActiveXObject("Microsoft.XMLHTTP"))}return a(new Error)},c=function(a){if("string"==typeof a)return a;var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")},d=function(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;cd?b+=String.fromCharCode(d):d>127&&2048>d?(b+=String.fromCharCode(192|d>>6),b+=String.fromCharCode(128|63&d)):(b+=String.fromCharCode(224|d>>12),b+=String.fromCharCode(128|63&d>>6),b+=String.fromCharCode(128|63&d))}return b},e=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";a=d(a);var c,e,f,g,h,i,j,k="",l=0;do c=a.charCodeAt(l++),e=a.charCodeAt(l++),f=a.charCodeAt(l++),g=c>>2,h=(3&c)<<4|e>>4,i=(15&e)<<2|f>>6,j=63&f,isNaN(e)?i=j=64:isNaN(f)&&(j=64),k+=b.charAt(g)+b.charAt(h)+b.charAt(i)+b.charAt(j),c=e=f="",g=h=i=j="";while(l1&&(d+=d.indexOf("?")>-1?"&"+k:"?"+k),e.jsonp){var l=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=d,l.appendChild(m),void 0}}b(function(b,c){if(b)return h(b);c.open(a,d,e.async);for(var f in j)j.hasOwnProperty(f)&&c.setRequestHeader(f,j[f]);c.onreadystatechange=function(){if(4===c.readyState){var a=c.responseText||"";if(!h)return;h(c.status,{text:function(){return a},json:function(){return JSON.parse(a)}})}},c.send(i)})},h={authBasic:function(a,b){g.headers.Authorization="Basic "+e(a+":"+b)},connect:function(a,b,c){return g("CONNECT",a,b,c)},del:function(a,b,c){return g("DELETE",a,b,c)},get:function(a,b,c){return g("GET",a,b,c)},head:function(a,b,c){return g("HEAD",a,b,c)},headers:function(a){g.headers=a||{}},isAllowed:function(a,b,c){this.options(a,function(a,d){c(-1!==d.text().indexOf(b))})},options:function(a,b,c){return g("OPTIONS",a,b,c)},patch:function(a,b,c){return g("PATCH",a,b,c)},post:function(a,b,c){return g("POST",a,b,c)},put:function(a,b,c){return g("PUT",a,b,c)},trace:function(a,b,c){return g("TRACE",a,b,c)}},i=a.type?a.type.toLowerCase():"get";h[i](a.url,a,function(b,c){200===b||0===b&&c.text()?a.success(c.json(),b,null):a.error(c.text(),b,null)})}function f(a,b){"function"==typeof a&&(b=a,a={}),a=a||{},R.extend(N,a),delete N.fixLng,"string"==typeof N.ns&&(N.ns={namespaces:[N.ns],defaultNs:N.ns}),"string"==typeof N.fallbackNS&&(N.fallbackNS=[N.fallbackNS]),("string"==typeof N.fallbackLng||"boolean"==typeof N.fallbackLng)&&(N.fallbackLng=[N.fallbackLng]),N.interpolationPrefixEscaped=R.regexEscape(N.interpolationPrefix),N.interpolationSuffixEscaped=R.regexEscape(N.interpolationSuffix),N.lng||(N.lng=R.detectLanguage()),J=R.toLanguages(N.lng),D=J[0],R.log("currentLng set to: "+D),N.useCookie&&R.cookie.read(N.cookieName)!==D&&R.cookie.create(N.cookieName,D,N.cookieExpirationTime,N.cookieDomain),N.detectLngFromLocalStorage&&"undefined"!=typeof document&&window.localstorage&&window.localStorage.setItem("i18next_lng",D);var c=x;a.fixLng&&(c=function(a,b){return b=b||{},b.lng=b.lng||c.lng,x(a,b)},c.lng=D),S.setCurrentLng(D),F&&N.setJqueryExt&&q();var d;if(F&&F.Deferred&&(d=F.Deferred()),!N.resStore){var e=R.toLanguages(N.lng);"string"==typeof N.preload&&(N.preload=[N.preload]);for(var f=0,g=N.preload.length;g>f;f++)for(var h=R.toLanguages(N.preload[f]),i=0,j=h.length;j>i;i++)e.indexOf(h[i])<0&&e.push(h[i]);return G.sync.load(e,N,function(a,e){H=e,K=!0,b&&b(c),d&&d.resolve(c)}),d?d.promise():void 0}return H=N.resStore,K=!0,b&&b(c),d&&d.resolve(c),d?d.promise():void 0}function g(a,b){"string"==typeof a&&(a=[a]);for(var c=0,d=a.length;d>c;c++)N.preload.indexOf(a[c])<0&&N.preload.push(a[c]);return f(b)}function h(a,b,c,d){"string"!=typeof b?(c=b,b=N.ns.defaultNs):N.ns.namespaces.indexOf(b)<0&&N.ns.namespaces.push(b),H[a]=H[a]||{},H[a][b]=H[a][b]||{},d?R.deepExtend(H[a][b],c):R.extend(H[a][b],c)}function i(a,b){"string"!=typeof b&&(b=N.ns.defaultNs),H[a]=H[a]||{},H[a][b]={}}function j(a,b,c,d){"string"!=typeof b?(resource=b,b=N.ns.defaultNs):N.ns.namespaces.indexOf(b)<0&&N.ns.namespaces.push(b),H[a]=H[a]||{},H[a][b]=H[a][b]||{};for(var e=c.split(N.keyseparator),f=0,g=H[N.lng][b];e[f];)f==e.length-1?g[e[f]]=d:(null==g[e[f]]&&(g[e[f]]={}),g=g[e[f]]),f++}function k(a,b,c){"string"!=typeof b?(resource=b,b=N.ns.defaultNs):N.ns.namespaces.indexOf(b)<0&&N.ns.namespaces.push(b);for(var d in c)"string"==typeof c[d]&&j(a,b,d,c[d])}function l(a){N.ns.defaultNs=a}function m(a,b){n([a],b)}function n(a,b){var c={dynamicLoad:N.dynamicLoad,resGetPath:N.resGetPath,getAsync:N.getAsync,customLoad:N.customLoad,ns:{namespaces:a,defaultNs:""}},d=R.toLanguages(N.lng);"string"==typeof N.preload&&(N.preload=[N.preload]);for(var e=0,f=N.preload.length;f>e;e++)for(var g=R.toLanguages(N.preload[e]),h=0,i=g.length;i>h;h++)d.indexOf(g[h])<0&&d.push(g[h]);for(var j=[],k=0,l=d.length;l>k;k++){var m=!1,n=H[d[k]];if(n)for(var o=0,p=a.length;p>o;o++)n[a[o]]||(m=!0);else m=!0;m&&j.push(d[k])}j.length?G.sync._fetch(j,c,function(c,d){var e=a.length*j.length;R.each(a,function(a,c){N.ns.namespaces.indexOf(c)<0&&N.ns.namespaces.push(c),R.each(j,function(a,f){H[f]=H[f]||{},H[f][c]=d[f][c],e--,0===e&&b&&(N.useLocalStorage&&G.sync._storeLocal(H),b())})})}):b&&b()}function o(a,b,c){return"function"==typeof b?(c=b,b={}):b||(b={}),b.lng=a,f(b,c)}function p(){return D}function q(){function a(a,b,c){if(0!==b.length){var d="text";if(0===b.indexOf("[")){var e=b.split("]");b=e[1],d=e[0].substr(1,e[0].length-1)}b.indexOf(";")===b.length-1&&(b=b.substr(0,b.length-2));var f;if("html"===d)f=N.defaultValueFromContent?F.extend({defaultValue:a.html()},c):c,a.html(F.t(b,f));else if("text"===d)f=N.defaultValueFromContent?F.extend({defaultValue:a.text()},c):c,a.text(F.t(b,f));else if("prepend"===d)f=N.defaultValueFromContent?F.extend({defaultValue:a.html()},c):c,a.prepend(F.t(b,f));else if("append"===d)f=N.defaultValueFromContent?F.extend({defaultValue:a.html()},c):c,a.append(F.t(b,f));else if(0===d.indexOf("data-")){var g=d.substr("data-".length);f=N.defaultValueFromContent?F.extend({defaultValue:a.data(g)},c):c;var h=F.t(b,f);a.data(g,h),a.attr(d,h)}else f=N.defaultValueFromContent?F.extend({defaultValue:a.attr(d)},c):c,a.attr(d,F.t(b,f))}}function b(b,c){var d=b.attr(N.selectorAttr);if(d||"undefined"==typeof d||d===!1||(d=b.text()||b.val()),d){var e=b,f=b.data("i18n-target");if(f&&(e=b.find(f)||b),c||N.useDataAttrOptions!==!0||(c=b.data("i18n-options")),c=c||{},d.indexOf(";")>=0){var g=d.split(";");F.each(g,function(b,d){""!==d&&a(e,d,c)})}else a(e,d,c);N.useDataAttrOptions===!0&&b.data("i18n-options",c)}}F.t=F.t||x,F.fn.i18n=function(a){return this.each(function(){b(F(this),a);var c=F(this).find("["+N.selectorAttr+"]");c.each(function(){b(F(this),a)})})}}function r(a,b,c,d){if(!a)return a;if(d=d||b,a.indexOf(d.interpolationPrefix||N.interpolationPrefix)<0)return a;var e=d.interpolationPrefix?R.regexEscape(d.interpolationPrefix):N.interpolationPrefixEscaped,f=d.interpolationSuffix?R.regexEscape(d.interpolationSuffix):N.interpolationSuffixEscaped,g="HTML"+f,h=b.replace&&"object"==typeof b.replace?b.replace:b;return R.each(h,function(b,h){var i=c?c+N.keyseparator+b:b;"object"==typeof h&&null!==h?a=r(a,h,i,d):d.escapeInterpolation||N.escapeInterpolation?(a=a.replace(new RegExp([e,i,g].join(""),"g"),R.regexReplacementEscape(h)),a=a.replace(new RegExp([e,i,f].join(""),"g"),R.regexReplacementEscape(R.escape(h)))):a=a.replace(new RegExp([e,i,f].join(""),"g"),R.regexReplacementEscape(h))}),a}function s(a,b){var c=",",d="{",e="}",f=R.extend({},b);for(delete f.postProcess;-1!=a.indexOf(N.reusePrefix)&&(I++,!(I>N.maxRecursion));){var g=a.lastIndexOf(N.reusePrefix),h=a.indexOf(N.reuseSuffix,g)+N.reuseSuffix.length,i=a.substring(g,h),j=i.replace(N.reusePrefix,"").replace(N.reuseSuffix,"");if(g>=h)return R.error("there is an missing closing in following translation value",a),"";if(-1!=j.indexOf(c)){var k=j.indexOf(c);if(-1!=j.indexOf(d,k)&&-1!=j.indexOf(e,k)){var l=j.indexOf(d,k),m=j.indexOf(e,l)+e.length;try{f=R.extend(f,JSON.parse(j.substring(l,m))),j=j.substring(0,k)}catch(n){}}}var o=A(j,f);a=a.replace(i,R.regexReplacementEscape(o))}return a}function t(a){return a.context&&("string"==typeof a.context||"number"==typeof a.context)}function u(a,b){return void 0!==a.count&&"string"!=typeof a.count&&S.needsPlural(b,a.count)}function v(a){return void 0!==a.indefinite_article&&"string"!=typeof a.indefinite_article&&a.indefinite_article}function w(a,b){b=b||{};var c=y(a,b),d=B(a,b);return void 0!==d||d===c}function x(a,b){return b=b||{},K?(I=0,A.apply(null,arguments)):(R.log("i18next not finished initialization. you might have called t function before loading resources finished."),b.defaultValue||"")}function y(a,b){return void 0!==b.defaultValue?b.defaultValue:a}function z(){for(var a=[],b=1;b1)for(var d=0;d-1&&(e=c.split(N.nsseparator),i=e[0],c=e[1]),void 0===g&&N.sendMissing&&"function"==typeof N.missingKeyHandler&&(b.lng?N.missingKeyHandler(h[0],i,c,f,h):N.missingKeyHandler(N.lng,i,c,f,h));var j=b.postProcess||N.postProcess;void 0!==g&&j&&T[j]&&(g=T[j](g,c,b));var k=f;if(f.indexOf(N.nsseparator)>-1&&(e=f.split(N.nsseparator),k=e[1]),k===c&&N.parseMissingKey&&(f=N.parseMissingKey(f)),void 0===g&&(f=r(f,b),f=s(f,b),j&&T[j])){var l=y(c,b);g=T[j](l,c,b)}return void 0!==g?g:f}function B(a,b){b=b||{};var c,d,e=y(a,b),f=J;if(!H)return e;if("cimode"===f[0].toLowerCase())return e;if(b.lng&&(f=R.toLanguages(b.lng,b.fallbackLng),!H[f[0]])){var g=N.getAsync;N.getAsync=!1,G.sync.load(f,N,function(a,b){R.extend(H,b),N.getAsync=g})}var h=b.ns||N.ns.defaultNs;if(a.indexOf(N.nsseparator)>-1){var i=a.split(N.nsseparator);h=i[0],a=i[1]}if(t(b)){c=R.extend({},b),delete c.context,c.defaultValue=N.contextNotFound;var j=h+N.nsseparator+a+"_"+b.context;if(d=x(j,c),d!=N.contextNotFound)return r(d,{context:b.context})}if(u(b,f[0])){c=R.extend({},b),delete c.count,c.defaultValue=N.pluralNotFound;var k=h+N.nsseparator+a+N.pluralSuffix,l=S.get(f[0],b.count);if(l>=0?k=k+"_"+l:1===l&&(k=h+N.nsseparator+a),d=x(k,c),d!=N.pluralNotFound)return r(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix})}if(v(b)){var m=R.extend({},b);delete m.indefinite_article,m.defaultValue=N.indefiniteNotFound;var n=h+N.nsseparator+a+(b.count&&!u(b,f[0])||!b.count?N.indefiniteSuffix:"");if(d=x(n,m),d!=N.indefiniteNotFound)return d}for(var o,p=a.split(N.keyseparator),q=0,w=f.length;w>q&&void 0===o;q++){for(var z=f[q],C=0,D=H[z]&&H[z][h];p[C];)D=D&&D[p[C]],C++;if(void 0!==D){var E=Object.prototype.toString.apply(D);if("string"==typeof D)D=r(D,b),D=s(D,b);else if("[object Array]"!==E||N.returnObjectTrees||b.returnObjectTrees){if(null===D&&N.fallbackOnNull===!0)D=void 0;else if(null!==D)if(N.returnObjectTrees||b.returnObjectTrees){if("[object Number]"!==E&&"[object Function]"!==E&&"[object RegExp]"!==E){var F="[object Array]"===E?[]:{};R.each(D,function(c){F[c]=A(h+N.nsseparator+a+N.keyseparator+c,b)}),D=F}}else N.objectTreeKeyHandler&&"function"==typeof N.objectTreeKeyHandler?D=N.objectTreeKeyHandler(a,D,z,h,b):(D="key '"+h+":"+a+" ("+z+")' "+"returned an object instead of string.",R.log(D))}else D=D.join("\n"),D=r(D,b),D=s(D,b);"string"==typeof D&&""===D.trim()&&N.fallbackOnEmpty===!0&&(D=void 0),o=D}}if(void 0===o&&!b.isFallbackLookup&&(N.fallbackToDefaultNS===!0||N.fallbackNS&&N.fallbackNS.length>0)){if(b.isFallbackLookup=!0,N.fallbackNS.length){for(var I=0,K=N.fallbackNS.length;K>I;I++)if(o=B(N.fallbackNS[I]+N.nsseparator+a,b)){var L=o.indexOf(N.nsseparator)>-1?o.split(N.nsseparator)[1]:o,M=e.indexOf(N.nsseparator)>-1?e.split(N.nsseparator)[1]:e;if(L!==M)break}}else o=B(a,b);b.isFallbackLookup=!1}return o}function C(){var a,b=[];if("undefined"!=typeof window&&(!function(){for(var a=window.location.search.substring(1),c=a.split("&"),d=0;d0){var f=c[d].substring(0,e),g=c[d].substring(e+1);b[f]=g}}}(),b[N.detectLngQS]&&(a=b[N.detectLngQS])),!a&&"undefined"!=typeof document&&N.useCookie){var c=R.cookie.read(N.cookieName);c&&(a=c)}return!a&&"undefined"!=typeof document&&window.localstorage&&N.detectLngFromLocalStorage&&(a=window.localStorage.getItem("i18next_lng")),a||"undefined"==typeof navigator||(a=navigator.language?navigator.language:navigator.userLanguage),a||(a=N.fallbackLng[0]),a}Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>0&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&1/0!=d&&d!=-1/0&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=c;arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d))));for(var e=d>=0?Math.min(d,c-1):c-Math.abs(d);e>=0;e--)if(e in b&&b[e]===a)return e;return-1}),"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")});var D,E=this,F=E.jQuery||E.Zepto,G={},H={},I=0,J=[],K=!1,L={};if("undefined"!=typeof module&&module.exports){if(!F)try{F=require("jquery")}catch(M){}F&&(F.i18n=F.i18n||G),module.exports=G}else F&&(F.i18n=F.i18n||G),E.i18n=E.i18n||G;L={load:function(a,b,c){b.useLocalStorage?L._loadLocal(a,b,function(d,e){for(var f=[],g=0,h=a.length;h>g;g++)e[a[g]]||f.push(a[g]);f.length>0?L._fetch(f,b,function(a,b){R.extend(e,b),L._storeLocal(b),c(null,e)}):c(null,e)}):L._fetch(a,b,function(a,b){c(null,b)})},_loadLocal:function(a,b,c){var d={},e=(new Date).getTime();if(window.localStorage){var f=a.length;R.each(a,function(a,g){var h=window.localStorage.getItem("res_"+g);h&&(h=JSON.parse(h),h.i18nStamp&&h.i18nStamp+b.localStorageExpirationTime>e&&(d[g]=h)),f--,0===f&&c(null,d)})}},_storeLocal:function(a){if(window.localStorage)for(var b in a)a[b].i18nStamp=(new Date).getTime(),window.localStorage.setItem("res_"+b,JSON.stringify(a[b]))},_fetch:function(a,b,c){var d=b.ns,e={};if(b.dynamicLoad){var f=function(a,b){c(null,b)};if("function"==typeof b.customLoad)b.customLoad(a,d.namespaces,b,f);else{var g=r(b.resGetPath,{lng:a.join("+"),ns:d.namespaces.join("+")});R.ajax({url:g,success:function(a){R.log("loaded: "+g),f(null,a)},error:function(a,b,c){R.log("failed loading: "+g),f("failed loading resource.json error: "+c)},dataType:"json",async:b.getAsync})}}else{var h,i=d.namespaces.length*a.length;R.each(d.namespaces,function(d,f){R.each(a,function(a,d){var g=function(a,b){a&&(h=h||[],h.push(a)),e[d]=e[d]||{},e[d][f]=b,i--,0===i&&c(h,e)};"function"==typeof b.customLoad?b.customLoad(d,f,b,g):L._fetchOne(d,f,b,g)})})}},_fetchOne:function(a,b,c,d){var e=r(c.resGetPath,{lng:a,ns:b});R.ajax({url:e,success:function(a){R.log("loaded: "+e),d(null,a)},error:function(a,b,c){if(b&&200==b||a&&a.status&&200==a.status)R.error("There is a typo in: "+e);else if(b&&404==b||a&&a.status&&404==a.status)R.log("Does not exist: "+e);else{var f=b?b:a&&a.status?a.status:null;R.log(f+" when loading "+e)}d(c,{})},dataType:"json",async:c.getAsync})},postMissing:function(a,b,c,d,e){var f={};f[c]=d;var g=[];if("fallback"===N.sendMissingTo&&N.fallbackLng[0]!==!1)for(var h=0;hh;h++)g.push({lng:e[h],url:r(N.resPostPath,{lng:e[h],ns:b})});for(var j=0,k=g.length;k>j;j++){var l=g[j];R.ajax({url:l.url,type:N.sendType,data:f,success:function(){R.log("posted missing key '"+c+"' to: "+l.url);for(var a=c.split("."),e=0,f=H[l.lng][b];a[e];)f=f[a[e]]=e===a.length-1?d:f[a[e]]||{},e++},error:function(){R.log("failed posting missing key '"+c+"' to: "+l.url)},dataType:"json",async:N.postAsync})}}};var N={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:["dev"],fallbackNS:[],detectLngQS:"setLng",detectLngFromLocalStorage:!1,ns:"translation",fallbackOnNull:!0,fallbackOnEmpty:!1,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,indefiniteSuffix:"_indefinite",indefiniteNotFound:["indefinite_not_found",Math.random()].join(""),setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",cookieDomain:void 0,objectTreeKeyHandler:void 0,postProcess:void 0,parseMissingKey:void 0,missingKeyHandler:L.postMissing,shortcutFunction:"sprintf"},O={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},P={create:function(a,b,c,d){var e;if(c){var f=new Date;f.setTime(f.getTime()+1e3*60*c),e="; expires="+f.toGMTString()}else e="";d=d?"domain="+d+";":"",document.cookie=a+"="+b+e+";"+d+"path=/"},read:function(a){for(var b=a+"=",c=document.cookie.split(";"),d=0;d-1?c.push(a):b("rejecting non-whitelisted language: "+a)};if("string"==typeof a&&a.indexOf("-")>-1){var f=a.split("-");a=N.lowerCaseLng?f[0].toLowerCase()+"-"+f[1].toLowerCase():f[0].toLowerCase()+"-"+f[1].toUpperCase(),"unspecific"!==N.load&&e(a),"current"!==N.load&&e(f[this.getCountyIndexOfLng(a)])}else e(a);for(var g=0;g1)}},af:{name:"Afrikaans",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ak:{name:"Akan",numbers:[1,2],plurals:function(a){return Number(a>1)}},am:{name:"Amharic",numbers:[1,2],plurals:function(a){return Number(a>1)}},an:{name:"Aragonese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ar:{name:"Arabic",numbers:[0,1,2,3,11,100],plurals:function(a){return Number(0===a?0:1==a?1:2==a?2:a%100>=3&&10>=a%100?3:a%100>=11?4:5)}},arn:{name:"Mapudungun",numbers:[1,2],plurals:function(a){return Number(a>1)}},ast:{name:"Asturian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ay:{name:"Aymará",numbers:[1],plurals:function(){return 0}},az:{name:"Azerbaijani",numbers:[1,2],plurals:function(a){return Number(1!=a)}},be:{name:"Belarusian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},bg:{name:"Bulgarian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},bn:{name:"Bengali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},bo:{name:"Tibetan",numbers:[1],plurals:function(){return 0}},br:{name:"Breton",numbers:[1,2],plurals:function(a){return Number(a>1)}},bs:{name:"Bosnian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},ca:{name:"Catalan",numbers:[1,2],plurals:function(a){return Number(1!=a)}},cgg:{name:"Chiga",numbers:[1],plurals:function(){return 0}},cs:{name:"Czech",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)}},csb:{name:"Kashubian",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},cy:{name:"Welsh",numbers:[1,2,3,8],plurals:function(a){return Number(1==a?0:2==a?1:8!=a&&11!=a?2:3)}},da:{name:"Danish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},de:{name:"German",numbers:[1,2],plurals:function(a){return Number(1!=a)}},dz:{name:"Dzongkha",numbers:[1],plurals:function(){return 0}},el:{name:"Greek",numbers:[1,2],plurals:function(a){return Number(1!=a)}},en:{name:"English",numbers:[1,2],plurals:function(a){return Number(1!=a)}},eo:{name:"Esperanto",numbers:[1,2],plurals:function(a){return Number(1!=a)}},es:{name:"Spanish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},es_ar:{name:"Argentinean Spanish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},et:{name:"Estonian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},eu:{name:"Basque",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fa:{name:"Persian",numbers:[1],plurals:function(){return 0}},fi:{name:"Finnish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fil:{name:"Filipino",numbers:[1,2],plurals:function(a){return Number(a>1)}},fo:{name:"Faroese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fr:{name:"French",numbers:[1,2],plurals:function(a){return Number(a>=2)}},fur:{name:"Friulian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fy:{name:"Frisian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ga:{name:"Irish",numbers:[1,2,3,7,11],plurals:function(a){return Number(1==a?0:2==a?1:7>a?2:11>a?3:4)}},gd:{name:"Scottish Gaelic",numbers:[1,2,3,20],plurals:function(a){return Number(1==a||11==a?0:2==a||12==a?1:a>2&&20>a?2:3)}},gl:{name:"Galician",numbers:[1,2],plurals:function(a){return Number(1!=a)}},gu:{name:"Gujarati",numbers:[1,2],plurals:function(a){return Number(1!=a)}},gun:{name:"Gun",numbers:[1,2],plurals:function(a){return Number(a>1)}},ha:{name:"Hausa",numbers:[1,2],plurals:function(a){return Number(1!=a)}},he:{name:"Hebrew",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hi:{name:"Hindi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hr:{name:"Croatian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},hu:{name:"Hungarian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hy:{name:"Armenian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ia:{name:"Interlingua",numbers:[1,2],plurals:function(a){return Number(1!=a)}},id:{name:"Indonesian",numbers:[1],plurals:function(){return 0}},is:{name:"Icelandic",numbers:[1,2],plurals:function(a){return Number(1!=a%10||11==a%100)}},it:{name:"Italian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ja:{name:"Japanese",numbers:[1],plurals:function(){return 0}},jbo:{name:"Lojban",numbers:[1],plurals:function(){return 0}},jv:{name:"Javanese",numbers:[0,1],plurals:function(a){return Number(0!==a)}},ka:{name:"Georgian",numbers:[1],plurals:function(){return 0}},kk:{name:"Kazakh",numbers:[1],plurals:function(){return 0}},km:{name:"Khmer",numbers:[1],plurals:function(){return 0}},kn:{name:"Kannada",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ko:{name:"Korean",numbers:[1],plurals:function(){return 0}},ku:{name:"Kurdish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},kw:{name:"Cornish",numbers:[1,2,3,4],plurals:function(a){return Number(1==a?0:2==a?1:3==a?2:3)}},ky:{name:"Kyrgyz",numbers:[1],plurals:function(){return 0}},lb:{name:"Letzeburgesch",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ln:{name:"Lingala",numbers:[1,2],plurals:function(a){return Number(a>1)}},lo:{name:"Lao",numbers:[1],plurals:function(){return 0}},lt:{name:"Lithuanian",numbers:[1,2,10],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&(10>a%100||a%100>=20)?1:2)}},lv:{name:"Latvian",numbers:[1,2,0],plurals:function(a){return Number(1==a%10&&11!=a%100?0:0!==a?1:2)}},mai:{name:"Maithili",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mfe:{name:"Mauritian Creole",numbers:[1,2],plurals:function(a){return Number(a>1)}},mg:{name:"Malagasy",numbers:[1,2],plurals:function(a){return Number(a>1)}},mi:{name:"Maori",numbers:[1,2],plurals:function(a){return Number(a>1)}},mk:{name:"Macedonian",numbers:[1,2],plurals:function(a){return Number(1==a||1==a%10?0:1)}},ml:{name:"Malayalam",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mn:{name:"Mongolian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mnk:{name:"Mandinka",numbers:[0,1,2],plurals:function(a){return Number(1==a?1:2)}},mr:{name:"Marathi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ms:{name:"Malay",numbers:[1],plurals:function(){return 0}},mt:{name:"Maltese",numbers:[1,2,11,20],plurals:function(a){return Number(1==a?0:0===a||a%100>1&&11>a%100?1:a%100>10&&20>a%100?2:3)}},nah:{name:"Nahuatl",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nap:{name:"Neapolitan",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nb:{name:"Norwegian Bokmal",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ne:{name:"Nepali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nl:{name:"Dutch",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nn:{name:"Norwegian Nynorsk",numbers:[1,2],plurals:function(a){return Number(1!=a)}},no:{name:"Norwegian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nso:{name:"Northern Sotho",numbers:[1,2],plurals:function(a){return Number(1!=a)}},oc:{name:"Occitan",numbers:[1,2],plurals:function(a){return Number(a>1)}},or:{name:"Oriya",numbers:[2,1],plurals:function(a){return Number(1!=a)}},pa:{name:"Punjabi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pap:{name:"Papiamento",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pl:{name:"Polish",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},pms:{name:"Piemontese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ps:{name:"Pashto",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pt:{name:"Portuguese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pt_br:{name:"Brazilian Portuguese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},rm:{name:"Romansh",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ro:{name:"Romanian",numbers:[1,2,20],plurals:function(a){return Number(1==a?0:0===a||a%100>0&&20>a%100?1:2)}},ru:{name:"Russian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},sah:{name:"Yakut",numbers:[1],plurals:function(){return 0}},sco:{name:"Scots",numbers:[1,2],plurals:function(a){return Number(1!=a)}},se:{name:"Northern Sami",numbers:[1,2],plurals:function(a){return Number(1!=a)}},si:{name:"Sinhala",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sk:{name:"Slovak",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)}},sl:{name:"Slovenian",numbers:[5,1,2,3],plurals:function(a){return Number(1==a%100?1:2==a%100?2:3==a%100||4==a%100?3:0)}},so:{name:"Somali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},son:{name:"Songhay",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sq:{name:"Albanian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sr:{name:"Serbian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},su:{name:"Sundanese",numbers:[1],plurals:function(){return 0}},sv:{name:"Swedish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sw:{name:"Swahili",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ta:{name:"Tamil",numbers:[1,2],plurals:function(a){return Number(1!=a)}},te:{name:"Telugu",numbers:[1,2],plurals:function(a){return Number(1!=a)}},tg:{name:"Tajik",numbers:[1,2],plurals:function(a){return Number(a>1)}},th:{name:"Thai",numbers:[1],plurals:function(){return 0}},ti:{name:"Tigrinya",numbers:[1,2],plurals:function(a){return Number(a>1)}},tk:{name:"Turkmen",numbers:[1,2],plurals:function(a){return Number(1!=a)}},tr:{name:"Turkish",numbers:[1,2],plurals:function(a){return Number(a>1)}},tt:{name:"Tatar",numbers:[1],plurals:function(){return 0}},ug:{name:"Uyghur",numbers:[1],plurals:function(){return 0}},uk:{name:"Ukrainian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},ur:{name:"Urdu",numbers:[1,2],plurals:function(a){return Number(1!=a)}},uz:{name:"Uzbek",numbers:[1,2],plurals:function(a){return Number(a>1)}},vi:{name:"Vietnamese",numbers:[1],plurals:function(){return 0}},wa:{name:"Walloon",numbers:[1,2],plurals:function(a){return Number(a>1)}},wo:{name:"Wolof",numbers:[1],plurals:function(){return 0}},yo:{name:"Yoruba",numbers:[1,2],plurals:function(a){return Number(1!=a)}},zh:{name:"Chinese",numbers:[1],plurals:function(){return 0}}},addRule:function(a,b){S.rules[a]=b},setCurrentLng:function(a){if(!S.currentRule||S.currentRule.lng!==a){var b=a.split("-");S.currentRule={lng:a,rule:S.rules[b[0]]}}},needsPlural:function(a,b){var c,d=a.split("-");return c=S.currentRule&&S.currentRule.lng===a?S.currentRule.rule:S.rules[d[R.getCountyIndexOfLng(a)]],c&&c.numbers.length<=1?!1:1!==this.get(a,b)},get:function(a,b){function c(b,c){var d;if(d=S.currentRule&&S.currentRule.lng===a?S.currentRule.rule:S.rules[b]){var e;e=d.noAbs?d.plurals(c):d.plurals(Math.abs(c));var f=d.numbers[e];return 2===d.numbers.length&&1===d.numbers[0]&&(2===f?f=-1:1===f&&(f=1)),f}return 1===c?"1":"-1"}var d=a.split("-"); +return c(d[R.getCountyIndexOfLng(a)],b)}},T={},U=function(a,b){T[a]=b},V=function(){function a(a){return Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}function b(a,b){for(var c=[];b>0;c[--b]=a);return c.join("")}var c=function(){return c.cache.hasOwnProperty(arguments[0])||(c.cache[arguments[0]]=c.parse(arguments[0])),c.format.call(null,c.cache[arguments[0]],arguments)};return c.format=function(c,d){var e,f,g,h,i,j,k,l=1,m=c.length,n="",o=[];for(f=0;m>f;f++)if(n=a(c[f]),"string"===n)o.push(c[f]);else if("array"===n){if(h=c[f],h[2])for(e=d[l],g=0;g=0?"+"+e:e,j=h[4]?"0"==h[4]?"0":h[4].charAt(1):" ",k=h[6]-String(e).length,i=h[6]?b(j,k):"",o.push(h[5]?e+i:i+e)}return o.join("")},c.cache={},c.parse=function(a){for(var b=a,c=[],d=[],e=0;b;){if(null!==(c=/^[^\x25]+/.exec(b)))d.push(c[0]);else if(null!==(c=/^\x25{2}/.exec(b)))d.push("%");else{if(null===(c=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(b)))throw"[sprintf] huh?";if(c[2]){e|=1;var f=[],g=c[2],h=[];if(null===(h=/^([a-z_][a-z_\d]*)/i.exec(g)))throw"[sprintf] huh?";for(f.push(h[1]);""!==(g=g.substring(h[0].length));)if(null!==(h=/^\.([a-z_][a-z_\d]*)/i.exec(g)))f.push(h[1]);else{if(null===(h=/^\[(\d+)\]/.exec(g)))throw"[sprintf] huh?";f.push(h[1])}c[2]=f}else e|=2;if(3===e)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";d.push(c)}b=b.substring(c[0].length)}return d},c}(),W=function(a,b){return b.unshift(a),V.apply(null,b)};U("sprintf",function(a,b,c){return c.sprintf?"[object Array]"===Object.prototype.toString.apply(c.sprintf)?W(a,c.sprintf):"object"==typeof c.sprintf?V(a,c.sprintf):a:a}),G.init=f,G.setLng=o,G.preload=g,G.addResourceBundle=h,G.addResource=j,G.addResources=k,G.removeResourceBundle=i,G.loadNamespace=m,G.loadNamespaces=n,G.setDefaultNamespace=l,G.t=x,G.translate=x,G.exists=w,G.detectLanguage=R.detectLanguage,G.pluralExtensions=S,G.sync=L,G.functions=R,G.lng=p,G.addPostProcessor=U,G.options=N}(); \ No newline at end of file diff --git a/libs/i18next/release/i18next-1.7.4.zip b/libs/i18next/release/i18next-1.7.4.zip new file mode 100644 index 00000000..bda4bf62 Binary files /dev/null and b/libs/i18next/release/i18next-1.7.4.zip differ diff --git a/libs/i18next/release/i18next-1.7.5.js b/libs/i18next/release/i18next-1.7.5.js new file mode 100644 index 00000000..6a32eed9 --- /dev/null +++ b/libs/i18next/release/i18next-1.7.5.js @@ -0,0 +1,2112 @@ +// i18next, v1.7.5 +// Copyright (c)2014 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function() { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + // Add string trim for IE8. + if (typeof String.prototype.trim !== 'function') { + String.prototype.trim = function() { + return this.replace(/^\s+|\s+$/g, ''); + } + } + + var root = this + , $ = root.jQuery || root.Zepto + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = [] + , initialized = false + , sync = {}; + + + + // Export the i18next object for **CommonJS**. + // If we're not in CommonJS, add `i18n` to the + // global object or to jquery. + if (typeof module !== 'undefined' && module.exports) { + if (!$) { + try { + $ = require('jquery'); + } catch(e) { + // just ignore + } + } + if ($) { + $.i18n = $.i18n || i18n; + } + module.exports = i18n; + } else { + if ($) { + $.i18n = $.i18n || i18n; + } + + root.i18n = root.i18n || i18n; + } + sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + f.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + if ((status && status == 200) || (xhr && xhr.status && xhr.status == 200)) { + // file loaded but invalid json, stop waste time ! + f.error('There is a typo in: ' + url); + } else if ((status && status == 404) || (xhr && xhr.status && xhr.status == 404)) { + f.log('Does not exist: ' + url); + } else { + var theStatus = status ? status : ((xhr && xhr.status) ? xhr.status : null); + f.log(theStatus + ' when loading ' + url); + } + + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback' && o.fallbackLng[0] !== false) { + for (var i = 0; i < o.fallbackLng.length; i++) { + urls.push({lng: o.fallbackLng[i], url: applyReplacement(o.resPostPath, { lng: o.fallbackLng[i], ns: ns })}); + } + } else if (o.sendMissingTo === 'current' || (o.sendMissingTo === 'fallback' && o.fallbackLng[0] === false) ) { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + }, + + reload: reload + }; + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: ['dev'], + fallbackNS: [], + detectLngQS: 'setLng', + detectLngFromLocalStorage: false, + ns: 'translation', + fallbackOnNull: true, + fallbackOnEmpty: false, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + defaultVariables: false, + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + indefiniteSuffix: '_indefinite', + indefiniteNotFound: ['indefinite_not_found', Math.random()].join(''), + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + cookieDomain: undefined, + + objectTreeKeyHandler: undefined, + postProcess: undefined, + parseMissingKey: undefined, + missingKeyHandler: sync.postMissing, + + shortcutFunction: 'sprintf' // or: defaultValue + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _deepExtend(target, source) { + for (var prop in source) + if (prop in target) + _deepExtend(target[prop], source[prop]); + else + target[prop] = source[prop]; + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || Object.prototype.toString.apply(object) !== '[object Array]' || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + try { + return JSON.parse(data) + } catch (e) { + f.error('Can not parse JSON. URL: ' + url); + return {}; + } + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + // file: protocol always gives status code 0, so check for data + if (status === 200 || (status === 0 && data.text())) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes,domain) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + domain = (domain)? "domain="+domain+";" : ""; + document.cookie = name+"="+value+expires+";"+domain+"path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes,domain) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + deepExtend: _deepExtend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : (typeof document !== 'undefined' ? _ajax : function() {}), + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + error: function(str) { + if (typeof console !== "undefined") console.error(str); + }, + getCountyIndexOfLng: function(lng) { + var lng_index = 0; + if (lng === 'nb-NO' || lng === 'nn-NO' || lng === 'nb-no' || lng === 'nn-no') lng_index = 1; + return lng_index; + }, + toLanguages: function(lng) { + var log = this.log; + + function applyCase(l) { + var ret = l; + + if (typeof l === 'string' && l.indexOf('-') > -1) { + var parts = l.split('-'); + + ret = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } else { + ret = o.lowerCaseLng ? l.toLowerCase() : l; + } + + return ret; + } + + var languages = []; + var whitelist = o.lngWhitelist || false; + var addLanguage = function(language){ + //reject langs not whitelisted + if(!whitelist || whitelist.indexOf(language) > -1){ + languages.push(language); + }else{ + log('rejecting non-whitelisted language: ' + language); + } + }; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + if (o.load !== 'unspecific') addLanguage(applyCase(lng)); + if (o.load !== 'current') addLanguage(applyCase(parts[this.getCountyIndexOfLng(lng)])); + } else { + addLanguage(applyCase(lng)); + } + + for (var i = 0; i < o.fallbackLng.length; i++) { + if (languages.indexOf(o.fallbackLng[i]) === -1 && o.fallbackLng[i]) languages.push(applyCase(o.fallbackLng[i])); + } + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + }, + regexReplacementEscape: function(strOrFn) { + if (typeof strOrFn === 'string') { + return strOrFn.replace(/\$/g, "$$$$"); + } else { + return strOrFn; + } + }, + localStorage: { + setItem: function(key, value) { + if (window.localStorage) { + try { + window.localStorage.setItem(key, value); + } catch (e) { + f.log('failed to set value for key "' + key + '" to localStorage.'); + } + } + } + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + delete o.fixLng; /* passed in each time */ + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // fallback languages + if (typeof o.fallbackLng == 'string' || typeof o.fallbackLng == 'boolean') { + o.fallbackLng = [o.fallbackLng]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + if (o.useCookie && f.cookie.read(o.cookieName) !== currentLng){ //cookie is unset or invalid + f.cookie.create(o.cookieName, currentLng, o.cookieExpirationTime, o.cookieDomain); + } + if (o.detectLngFromLocalStorage && typeof document !== 'undefined' && window.localStorage) { + f.localStorage.setItem('i18next_lng', currentLng); + } + + var lngTranslate = translate; + if (options.fixLng) { + lngTranslate = function(key, options) { + options = options || {}; + options.lng = options.lng || lngTranslate.lng; + return translate(key, options); + }; + lngTranslate.lng = currentLng; + } + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + initialized = true; + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + initialized = true; + + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources, deep) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + if (deep) { + f.deepExtend(resStore[lng][ns], resources); + } else { + f.extend(resStore[lng][ns], resources); + } + } + + function hasResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + var res = resStore[lng][ns] || {}; + + var hasValues = false; + for(var prop in res) { + if (res.hasOwnProperty(prop)) { + hasValues = true; + } + } + + return hasValues; + } + + function removeResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = {}; + } + + function addResource(lng, ns, key, value) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + var keys = key.split(o.keyseparator); + var x = 0; + var node = resStore[lng][ns]; + var origRef = node; + + while (keys[x]) { + if (x == keys.length - 1) + node[keys[x]] = value; + else { + if (node[keys[x]] == null) + node[keys[x]] = {}; + + node = node[keys[x]]; + } + x++; + } + } + + function addResources(lng, ns, resources) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + for (var m in resources) { + if (typeof resources[m] === 'string') addResource(lng, ns, m, resources[m]); + } + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, options, cb) { + if (typeof options === 'function') { + cb = options; + options = {}; + } else if (!options) { + options = {}; + } + + options.lng = lng; + return init(options, cb); + } + + function lng() { + return currentLng; + } + + function reload(cb) { + resStore = {}; + setLng(currentLng, cb); + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else if (attr === 'prepend') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.prepend($.t(key, optionsToUse)); + } else if (attr === 'append') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.append($.t(key, optionsToUse)); + } else if (attr.indexOf("data-") === 0) { + var dataAttr = attr.substr(("data-").length); + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.data(dataAttr) }, options) : options; + var translated = $.t(key, optionsToUse); + //we change into the data cache + ele.data(dataAttr, translated); + //we change into the dom + ele.attr(attr, translated); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key && typeof key !== 'undefined' && key !== false) key = ele.text() || ele.val(); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + var hash = replacementHash.replace && typeof replacementHash.replace === 'object' ? replacementHash.replace : replacementHash; + f.each(hash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), f.regexReplacementEscape(value)); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(f.escape(value))); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(value)); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + if (index_of_end_of_closing <= index_of_opening) { + f.error('there is an missing closing in following translation value', translated); + return ''; + } + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, f.regexReplacementEscape(translated_token)); + } + return translated; + } + + function hasContext(options) { + return (options.context && (typeof options.context == 'string' || typeof options.context == 'number')); + } + + function needsPlural(options, lng) { + return (options.count !== undefined && typeof options.count != 'string'/* && pluralExtensions.needsPlural(lng, options.count)*/); + } + + function needsIndefiniteArticle(options) { + return (options.indefinite_article !== undefined && typeof options.indefinite_article != 'string' && options.indefinite_article); + } + + function exists(key, options) { + options = options || {}; + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + options = options || {}; + + if (!initialized) { + f.log('i18next not finished initialization. you might have called t function before loading resources finished.') + return options.defaultValue || ''; + }; + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _getDefaultValue(key, options) { + return (options.defaultValue !== undefined) ? options.defaultValue : key; + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(potentialKeys, options) { + if (options && typeof options !== 'object') { + if (o.shortcutFunction === 'sprintf') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else if (o.shortcutFunction === 'defaultValue') { + options = { + defaultValue: options + } + } + } else { + options = options || {}; + } + + if (typeof o.defaultVariables === 'object') { + options = f.extend({}, o.defaultVariables, options); + } + + if (potentialKeys === undefined || potentialKeys === null || potentialKeys === '') return ''; + + if (typeof potentialKeys === 'string') { + potentialKeys = [potentialKeys]; + } + + var key = potentialKeys[0]; + + if (potentialKeys.length > 1) { + for (var i = 0; i < potentialKeys.length; i++) { + key = potentialKeys[i]; + if (exists(key, options)) { + break; + } + } + } + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng, options.fallbackLng) : languages + , ns = options.ns || o.ns.defaultNs + , parts; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing && typeof o.missingKeyHandler === 'function') { + if (options.lng) { + o.missingKeyHandler(lngs[0], ns, key, notFound, lngs); + } else { + o.missingKeyHandler(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found !== undefined && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + // process notFound if function exists + var splitNotFound = notFound; + if (notFound.indexOf(o.nsseparator) > -1) { + parts = notFound.split(o.nsseparator); + splitNotFound = parts[1]; + } + if (splitNotFound === key && o.parseMissingKey) { + notFound = o.parseMissingKey(notFound); + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessor && postProcessors[postProcessor]) { + var val = _getDefaultValue(key, options); + found = postProcessors[postProcessor](val, key, options); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options) { + options = options || {}; + + var optionWithoutCount, translated + , notFound = _getDefaultValue(key, options) + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + // CI mode + if (lngs[0].toLowerCase() === 'cimode') return notFound; + + // passed in lng + if (options.lngs) lngs = options.lngs; + if (options.lng) { + lngs = f.toLanguages(options.lng, options.fallbackLng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options, lngs[0])) { + optionWithoutCount = f.extend({ lngs: [lngs[0]]}, options); + delete optionWithoutCount.count; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey; + if (!pluralExtensions.needsPlural(lngs[0], options.count)) { + pluralKey = ns + o.nsseparator + key; + } else { + pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(lngs[0], options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + } + + translated = translate(pluralKey, optionWithoutCount); + + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } else if (lngs.length > 1) { + // remove failed lng + var clone = lngs.slice(); + clone.shift(); + options = f.extend(options, { lngs: clone }); + // retry with fallbacks + translated = translate(ns + o.nsseparator + key, options); + if (translated != o.pluralNotFound) return translated; + } + } + + if (needsIndefiniteArticle(options)) { + var optionsWithoutIndef = f.extend({}, options); + delete optionsWithoutIndef.indefinite_article; + optionsWithoutIndef.defaultValue = o.indefiniteNotFound; + // If we don't have a count, we want the indefinite, if we do have a count, and needsPlural is false + var indefiniteKey = ns + o.nsseparator + key + (((options.count && !needsPlural(options, lngs[0])) || !options.count) ? o.indefiniteSuffix : ""); + translated = translate(indefiniteKey, optionsWithoutIndef); + if (translated != o.indefiniteNotFound) { + return translated; + } + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + var valueType = Object.prototype.toString.apply(value); + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (valueType === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + if (o.objectTreeKeyHandler && typeof o.objectTreeKeyHandler == 'function') { + value = o.objectTreeKeyHandler(key, value, l, ns, options); + } else { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned an object instead of string.'; + f.log(value); + } + } else if (valueType !== '[object Number]' && valueType !== '[object Function]' && valueType !== '[object RegExp]') { + var copy = (valueType === '[object Array]') ? [] : {}; // apply child translation on a copy + f.each(value, function(m) { + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + }); + value = copy; + } + } + + if (typeof value === 'string' && value.trim() === '' && o.fallbackOnEmpty === true) + value = undefined; + + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length > 0))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + options.isFallbackLookup = false; + } + + return found; + } + function detectLanguage() { + var detectedLng; + var whitelist = o.lngWhitelist || []; + var userLngChoices = []; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var params = query.split('&'); + for (var i=0; i 0) { + var key = params[i].substring(0,pos); + if (key == o.detectLngQS) { + userLngChoices.push(params[i].substring(pos+1)); + } + } + } + })(); + } + + // get from cookie + if (o.useCookie && typeof document !== 'undefined') { + var c = f.cookie.read(o.cookieName); + if (c) userLngChoices.push(c); + } + + // get from localStorage + if (o.detectLngFromLocalStorage && typeof window !== 'undefined' && window.localStorage) { + userLngChoices.push(window.localStorage.getItem('i18next_lng')); + } + + // get from navigator + if (typeof navigator !== 'undefined') { + if (navigator.languages) { // chrome only; not an array, so can't use .push.apply instead of iterating + for (var i=0;i -1) { + var parts = lng.split('-'); + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } + + if (whitelist.length === 0 || whitelist.indexOf(lng) > -1) { + detectedLng = lng; + break; + } + } + })(); + + //fallback + if (!detectedLng){ + detectedLng = o.fallbackLng[0]; + } + + return detectedLng; + } + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + + /* [code, name, numbers, pluralsType] */ + var _rules = [ + ["ach", "Acholi", [1,2], 1], + ["af", "Afrikaans",[1,2], 2], + ["ak", "Akan", [1,2], 1], + ["am", "Amharic", [1,2], 1], + ["an", "Aragonese",[1,2], 2], + ["ar", "Arabic", [0,1,2,3,11,100],5], + ["arn", "Mapudungun",[1,2], 1], + ["ast", "Asturian", [1,2], 2], + ["ay", "Aymará", [1], 3], + ["az", "Azerbaijani",[1,2],2], + ["be", "Belarusian",[1,2,5],4], + ["bg", "Bulgarian",[1,2], 2], + ["bn", "Bengali", [1,2], 2], + ["bo", "Tibetan", [1], 3], + ["br", "Breton", [1,2], 1], + ["bs", "Bosnian", [1,2,5],4], + ["ca", "Catalan", [1,2], 2], + ["cgg", "Chiga", [1], 3], + ["cs", "Czech", [1,2,5],6], + ["csb", "Kashubian",[1,2,5],7], + ["cy", "Welsh", [1,2,3,8],8], + ["da", "Danish", [1,2], 2], + ["de", "German", [1,2], 2], + ["dev", "Development Fallback", [1,2], 2], + ["dz", "Dzongkha", [1], 3], + ["el", "Greek", [1,2], 2], + ["en", "English", [1,2], 2], + ["eo", "Esperanto",[1,2], 2], + ["es", "Spanish", [1,2], 2], + ["es_ar","Argentinean Spanish", [1,2], 2], + ["et", "Estonian", [1,2], 2], + ["eu", "Basque", [1,2], 2], + ["fa", "Persian", [1], 3], + ["fi", "Finnish", [1,2], 2], + ["fil", "Filipino", [1,2], 1], + ["fo", "Faroese", [1,2], 2], + ["fr", "French", [1,2], 9], + ["fur", "Friulian", [1,2], 2], + ["fy", "Frisian", [1,2], 2], + ["ga", "Irish", [1,2,3,7,11],10], + ["gd", "Scottish Gaelic",[1,2,3,20],11], + ["gl", "Galician", [1,2], 2], + ["gu", "Gujarati", [1,2], 2], + ["gun", "Gun", [1,2], 1], + ["ha", "Hausa", [1,2], 2], + ["he", "Hebrew", [1,2], 2], + ["hi", "Hindi", [1,2], 2], + ["hr", "Croatian", [1,2,5],4], + ["hu", "Hungarian",[1,2], 2], + ["hy", "Armenian", [1,2], 2], + ["ia", "Interlingua",[1,2],2], + ["id", "Indonesian",[1], 3], + ["is", "Icelandic",[1,2], 12], + ["it", "Italian", [1,2], 2], + ["ja", "Japanese", [1], 3], + ["jbo", "Lojban", [1], 3], + ["jv", "Javanese", [0,1], 13], + ["ka", "Georgian", [1], 3], + ["kk", "Kazakh", [1], 3], + ["km", "Khmer", [1], 3], + ["kn", "Kannada", [1,2], 2], + ["ko", "Korean", [1], 3], + ["ku", "Kurdish", [1,2], 2], + ["kw", "Cornish", [1,2,3,4],14], + ["ky", "Kyrgyz", [1], 3], + ["lb", "Letzeburgesch",[1,2],2], + ["ln", "Lingala", [1,2], 1], + ["lo", "Lao", [1], 3], + ["lt", "Lithuanian",[1,2,10],15], + ["lv", "Latvian", [1,2,0],16], + ["mai", "Maithili", [1,2], 2], + ["mfe", "Mauritian Creole",[1,2],1], + ["mg", "Malagasy", [1,2], 1], + ["mi", "Maori", [1,2], 1], + ["mk", "Macedonian",[1,2],17], + ["ml", "Malayalam",[1,2], 2], + ["mn", "Mongolian",[1,2], 2], + ["mnk", "Mandinka", [0,1,2],18], + ["mr", "Marathi", [1,2], 2], + ["ms", "Malay", [1], 3], + ["mt", "Maltese", [1,2,11,20],19], + ["nah", "Nahuatl", [1,2], 2], + ["nap", "Neapolitan",[1,2], 2], + ["nb", "Norwegian Bokmal",[1,2],2], + ["ne", "Nepali", [1,2], 2], + ["nl", "Dutch", [1,2], 2], + ["nn", "Norwegian Nynorsk",[1,2],2], + ["no", "Norwegian",[1,2], 2], + ["nso", "Northern Sotho",[1,2],2], + ["oc", "Occitan", [1,2], 1], + ["or", "Oriya", [2,1], 2], + ["pa", "Punjabi", [1,2], 2], + ["pap", "Papiamento",[1,2], 2], + ["pl", "Polish", [1,2,5],7], + ["pms", "Piemontese",[1,2], 2], + ["ps", "Pashto", [1,2], 2], + ["pt", "Portuguese",[1,2], 2], + ["pt_br","Brazilian Portuguese",[1,2], 2], + ["rm", "Romansh", [1,2], 2], + ["ro", "Romanian", [1,2,20],20], + ["ru", "Russian", [1,2,5],4], + ["sah", "Yakut", [1], 3], + ["sco", "Scots", [1,2], 2], + ["se", "Northern Sami",[1,2], 2], + ["si", "Sinhala", [1,2], 2], + ["sk", "Slovak", [1,2,5],6], + ["sl", "Slovenian",[5,1,2,3],21], + ["so", "Somali", [1,2], 2], + ["son", "Songhay", [1,2], 2], + ["sq", "Albanian", [1,2], 2], + ["sr", "Serbian", [1,2,5],4], + ["su", "Sundanese",[1], 3], + ["sv", "Swedish", [1,2], 2], + ["sw", "Swahili", [1,2], 2], + ["ta", "Tamil", [1,2], 2], + ["te", "Telugu", [1,2], 2], + ["tg", "Tajik", [1,2], 1], + ["th", "Thai", [1], 3], + ["ti", "Tigrinya", [1,2], 1], + ["tk", "Turkmen", [1,2], 2], + ["tr", "Turkish", [1,2], 1], + ["tt", "Tatar", [1], 3], + ["ug", "Uyghur", [1], 3], + ["uk", "Ukrainian",[1,2,5],4], + ["ur", "Urdu", [1,2], 2], + ["uz", "Uzbek", [1,2], 1], + ["vi", "Vietnamese",[1], 3], + ["wa", "Walloon", [1,2], 1], + ["wo", "Wolof", [1], 3], + ["yo", "Yoruba", [1,2], 2], + ["zh", "Chinese", [1], 3] + ]; + + var _rulesPluralsTypes = { + 1: function(n) {return Number(n > 1);}, + 2: function(n) {return Number(n != 1);}, + 3: function(n) {return 0;}, + 4: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 5: function(n) {return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5);}, + 6: function(n) {return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2);}, + 7: function(n) {return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 8: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3);}, + 9: function(n) {return Number(n >= 2);}, + 10: function(n) {return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;}, + 11: function(n) {return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3);}, + 12: function(n) {return Number(n%10!=1 || n%100==11);}, + 13: function(n) {return Number(n !== 0);}, + 14: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3);}, + 15: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 16: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2);}, + 17: function(n) {return Number(n==1 || n%10==1 ? 0 : 1);}, + 18: function(n) {return Number(0 ? 0 : n==1 ? 1 : 2);}, + 19: function(n) {return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3);}, + 20: function(n) {return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2);}, + 21: function(n) {return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }; + + var pluralExtensions = { + + rules: (function () { + var l, rules = {}; + for (l=_rules.length; l-- ;) { + rules[_rules[l][0]] = { + name: _rules[l][1], + numbers: _rules[l][2], + plurals: _rulesPluralsTypes[_rules[l][3]] + } + } + return rules; + }()), + + // you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + needsPlural: function(lng, count) { + var parts = lng.split('-'); + + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[parts[f.getCountyIndexOfLng(lng)]]; + } + + if (ext && ext.numbers.length <= 1) { + return false; + } else { + return this.get(lng, count) !== 1; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i; + if (ext.noAbs) { + i = ext.plurals(c); + } else { + i = ext.plurals(Math.abs(c)); + } + + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[f.getCountyIndexOfLng(lng)], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.hasResourceBundle = hasResourceBundle; + i18n.addResource = addResource; + i18n.addResources = addResources; + i18n.removeResourceBundle = removeResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + +})(); \ No newline at end of file diff --git a/libs/i18next/release/i18next-1.7.5.min.js b/libs/i18next/release/i18next-1.7.5.min.js new file mode 100644 index 00000000..dcade802 --- /dev/null +++ b/libs/i18next/release/i18next-1.7.5.min.js @@ -0,0 +1,5 @@ +// i18next, v1.7.5 +// Copyright (c)2014 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +!function(){function a(a,b){if(!b||"function"==typeof b)return a;for(var c in b)a[c]=b[c];return a}function b(a,c){for(var d in c)d in a?b(a[d],c[d]):a[d]=c[d];return a}function c(a,b,c){var d,e=0,f=a.length,g=void 0===f||"[object Array]"!==Object.prototype.toString.apply(a)||"function"==typeof a;if(c)if(g){for(d in a)if(b.apply(a[d],c)===!1)break}else for(;f>e&&b.apply(a[e++],c)!==!1;);else if(g){for(d in a)if(b.call(a[d],d,a[d])===!1)break}else for(;f>e&&b.call(a[e],e,a[e++])!==!1;);return a}function d(a){return"string"==typeof a?a.replace(/[&<>"'\/]/g,function(a){return Q[a]}):a}function e(a){var b=function(a){if(window.XMLHttpRequest)return a(null,new XMLHttpRequest);if(window.ActiveXObject)try{return a(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(b){return a(null,new ActiveXObject("Microsoft.XMLHTTP"))}return a(new Error)},c=function(a){if("string"==typeof a)return a;var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")},d=function(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;cd?b+=String.fromCharCode(d):d>127&&2048>d?(b+=String.fromCharCode(192|d>>6),b+=String.fromCharCode(128|63&d)):(b+=String.fromCharCode(224|d>>12),b+=String.fromCharCode(128|63&d>>6),b+=String.fromCharCode(128|63&d))}return b},e=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";a=d(a);var c,e,f,g,h,i,j,k="",l=0;do c=a.charCodeAt(l++),e=a.charCodeAt(l++),f=a.charCodeAt(l++),g=c>>2,h=(3&c)<<4|e>>4,i=(15&e)<<2|f>>6,j=63&f,isNaN(e)?i=j=64:isNaN(f)&&(j=64),k+=b.charAt(g)+b.charAt(h)+b.charAt(i)+b.charAt(j),c=e=f="",g=h=i=j="";while(l1&&(d+=d.indexOf("?")>-1?"&"+k:"?"+k),e.jsonp){var l=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=d,l.appendChild(m),void 0}}b(function(b,c){if(b)return h(b);c.open(a,d,e.async);for(var f in j)j.hasOwnProperty(f)&&c.setRequestHeader(f,j[f]);c.onreadystatechange=function(){if(4===c.readyState){var a=c.responseText||"";if(!h)return;h(c.status,{text:function(){return a},json:function(){try{return JSON.parse(a)}catch(b){return T.error("Can not parse JSON. URL: "+d),{}}}})}},c.send(i)})},h={authBasic:function(a,b){g.headers.Authorization="Basic "+e(a+":"+b)},connect:function(a,b,c){return g("CONNECT",a,b,c)},del:function(a,b,c){return g("DELETE",a,b,c)},get:function(a,b,c){return g("GET",a,b,c)},head:function(a,b,c){return g("HEAD",a,b,c)},headers:function(a){g.headers=a||{}},isAllowed:function(a,b,c){this.options(a,function(a,d){c(-1!==d.text().indexOf(b))})},options:function(a,b,c){return g("OPTIONS",a,b,c)},patch:function(a,b,c){return g("PATCH",a,b,c)},post:function(a,b,c){return g("POST",a,b,c)},put:function(a,b,c){return g("PUT",a,b,c)},trace:function(a,b,c){return g("TRACE",a,b,c)}},i=a.type?a.type.toLowerCase():"get";h[i](a.url,a,function(b,c){200===b||0===b&&c.text()?a.success(c.json(),b,null):a.error(c.text(),b,null)})}function f(a,b){"function"==typeof a&&(b=a,a={}),a=a||{},T.extend(P,a),delete P.fixLng,"string"==typeof P.ns&&(P.ns={namespaces:[P.ns],defaultNs:P.ns}),"string"==typeof P.fallbackNS&&(P.fallbackNS=[P.fallbackNS]),("string"==typeof P.fallbackLng||"boolean"==typeof P.fallbackLng)&&(P.fallbackLng=[P.fallbackLng]),P.interpolationPrefixEscaped=T.regexEscape(P.interpolationPrefix),P.interpolationSuffixEscaped=T.regexEscape(P.interpolationSuffix),P.lng||(P.lng=T.detectLanguage()),L=T.toLanguages(P.lng),F=L[0],T.log("currentLng set to: "+F),P.useCookie&&T.cookie.read(P.cookieName)!==F&&T.cookie.create(P.cookieName,F,P.cookieExpirationTime,P.cookieDomain),P.detectLngFromLocalStorage&&"undefined"!=typeof document&&window.localStorage&&T.localStorage.setItem("i18next_lng",F);var c=z;a.fixLng&&(c=function(a,b){return b=b||{},b.lng=b.lng||c.lng,z(a,b)},c.lng=F),W.setCurrentLng(F),H&&P.setJqueryExt&&s();var d;if(H&&H.Deferred&&(d=H.Deferred()),!P.resStore){var e=T.toLanguages(P.lng);"string"==typeof P.preload&&(P.preload=[P.preload]);for(var f=0,g=P.preload.length;g>f;f++)for(var h=T.toLanguages(P.preload[f]),i=0,j=h.length;j>i;i++)e.indexOf(h[i])<0&&e.push(h[i]);return I.sync.load(e,P,function(a,e){J=e,M=!0,b&&b(c),d&&d.resolve(c)}),d?d.promise():void 0}return J=P.resStore,M=!0,b&&b(c),d&&d.resolve(c),d?d.promise():void 0}function g(a,b){"string"==typeof a&&(a=[a]);for(var c=0,d=a.length;d>c;c++)P.preload.indexOf(a[c])<0&&P.preload.push(a[c]);return f(b)}function h(a,b,c,d){"string"!=typeof b?(c=b,b=P.ns.defaultNs):P.ns.namespaces.indexOf(b)<0&&P.ns.namespaces.push(b),J[a]=J[a]||{},J[a][b]=J[a][b]||{},d?T.deepExtend(J[a][b],c):T.extend(J[a][b],c)}function i(a,b){"string"!=typeof b&&(b=P.ns.defaultNs),J[a]=J[a]||{};var c=J[a][b]||{},d=!1;for(var e in c)c.hasOwnProperty(e)&&(d=!0);return d}function j(a,b){"string"!=typeof b&&(b=P.ns.defaultNs),J[a]=J[a]||{},J[a][b]={}}function k(a,b,c,d){"string"!=typeof b?(resource=b,b=P.ns.defaultNs):P.ns.namespaces.indexOf(b)<0&&P.ns.namespaces.push(b),J[a]=J[a]||{},J[a][b]=J[a][b]||{};for(var e=c.split(P.keyseparator),f=0,g=J[a][b];e[f];)f==e.length-1?g[e[f]]=d:(null==g[e[f]]&&(g[e[f]]={}),g=g[e[f]]),f++}function l(a,b,c){"string"!=typeof b?(resource=b,b=P.ns.defaultNs):P.ns.namespaces.indexOf(b)<0&&P.ns.namespaces.push(b);for(var d in c)"string"==typeof c[d]&&k(a,b,d,c[d])}function m(a){P.ns.defaultNs=a}function n(a,b){o([a],b)}function o(a,b){var c={dynamicLoad:P.dynamicLoad,resGetPath:P.resGetPath,getAsync:P.getAsync,customLoad:P.customLoad,ns:{namespaces:a,defaultNs:""}},d=T.toLanguages(P.lng);"string"==typeof P.preload&&(P.preload=[P.preload]);for(var e=0,f=P.preload.length;f>e;e++)for(var g=T.toLanguages(P.preload[e]),h=0,i=g.length;i>h;h++)d.indexOf(g[h])<0&&d.push(g[h]);for(var j=[],k=0,l=d.length;l>k;k++){var m=!1,n=J[d[k]];if(n)for(var o=0,p=a.length;p>o;o++)n[a[o]]||(m=!0);else m=!0;m&&j.push(d[k])}j.length?I.sync._fetch(j,c,function(c,d){var e=a.length*j.length;T.each(a,function(a,c){P.ns.namespaces.indexOf(c)<0&&P.ns.namespaces.push(c),T.each(j,function(a,f){J[f]=J[f]||{},J[f][c]=d[f][c],e--,0===e&&b&&(P.useLocalStorage&&I.sync._storeLocal(J),b())})})}):b&&b()}function p(a,b,c){return"function"==typeof b?(c=b,b={}):b||(b={}),b.lng=a,f(b,c)}function q(){return F}function r(a){J={},p(F,a)}function s(){function a(a,b,c){if(0!==b.length){var d="text";if(0===b.indexOf("[")){var e=b.split("]");b=e[1],d=e[0].substr(1,e[0].length-1)}b.indexOf(";")===b.length-1&&(b=b.substr(0,b.length-2));var f;if("html"===d)f=P.defaultValueFromContent?H.extend({defaultValue:a.html()},c):c,a.html(H.t(b,f));else if("text"===d)f=P.defaultValueFromContent?H.extend({defaultValue:a.text()},c):c,a.text(H.t(b,f));else if("prepend"===d)f=P.defaultValueFromContent?H.extend({defaultValue:a.html()},c):c,a.prepend(H.t(b,f));else if("append"===d)f=P.defaultValueFromContent?H.extend({defaultValue:a.html()},c):c,a.append(H.t(b,f));else if(0===d.indexOf("data-")){var g=d.substr("data-".length);f=P.defaultValueFromContent?H.extend({defaultValue:a.data(g)},c):c;var h=H.t(b,f);a.data(g,h),a.attr(d,h)}else f=P.defaultValueFromContent?H.extend({defaultValue:a.attr(d)},c):c,a.attr(d,H.t(b,f))}}function b(b,c){var d=b.attr(P.selectorAttr);if(d||"undefined"==typeof d||d===!1||(d=b.text()||b.val()),d){var e=b,f=b.data("i18n-target");if(f&&(e=b.find(f)||b),c||P.useDataAttrOptions!==!0||(c=b.data("i18n-options")),c=c||{},d.indexOf(";")>=0){var g=d.split(";");H.each(g,function(b,d){""!==d&&a(e,d,c)})}else a(e,d,c);P.useDataAttrOptions===!0&&b.data("i18n-options",c)}}H.t=H.t||z,H.fn.i18n=function(a){return this.each(function(){b(H(this),a);var c=H(this).find("["+P.selectorAttr+"]");c.each(function(){b(H(this),a)})})}}function t(a,b,c,d){if(!a)return a;if(d=d||b,a.indexOf(d.interpolationPrefix||P.interpolationPrefix)<0)return a;var e=d.interpolationPrefix?T.regexEscape(d.interpolationPrefix):P.interpolationPrefixEscaped,f=d.interpolationSuffix?T.regexEscape(d.interpolationSuffix):P.interpolationSuffixEscaped,g="HTML"+f,h=b.replace&&"object"==typeof b.replace?b.replace:b;return T.each(h,function(b,h){var i=c?c+P.keyseparator+b:b;"object"==typeof h&&null!==h?a=t(a,h,i,d):d.escapeInterpolation||P.escapeInterpolation?(a=a.replace(new RegExp([e,i,g].join(""),"g"),T.regexReplacementEscape(h)),a=a.replace(new RegExp([e,i,f].join(""),"g"),T.regexReplacementEscape(T.escape(h)))):a=a.replace(new RegExp([e,i,f].join(""),"g"),T.regexReplacementEscape(h))}),a}function u(a,b){var c=",",d="{",e="}",f=T.extend({},b);for(delete f.postProcess;-1!=a.indexOf(P.reusePrefix)&&(K++,!(K>P.maxRecursion));){var g=a.lastIndexOf(P.reusePrefix),h=a.indexOf(P.reuseSuffix,g)+P.reuseSuffix.length,i=a.substring(g,h),j=i.replace(P.reusePrefix,"").replace(P.reuseSuffix,"");if(g>=h)return T.error("there is an missing closing in following translation value",a),"";if(-1!=j.indexOf(c)){var k=j.indexOf(c);if(-1!=j.indexOf(d,k)&&-1!=j.indexOf(e,k)){var l=j.indexOf(d,k),m=j.indexOf(e,l)+e.length;try{f=T.extend(f,JSON.parse(j.substring(l,m))),j=j.substring(0,k)}catch(n){}}}var o=C(j,f);a=a.replace(i,T.regexReplacementEscape(o))}return a}function v(a){return a.context&&("string"==typeof a.context||"number"==typeof a.context)}function w(a){return void 0!==a.count&&"string"!=typeof a.count}function x(a){return void 0!==a.indefinite_article&&"string"!=typeof a.indefinite_article&&a.indefinite_article}function y(a,b){b=b||{};var c=A(a,b),d=D(a,b);return void 0!==d||d===c}function z(a,b){return b=b||{},M?(K=0,C.apply(null,arguments)):(T.log("i18next not finished initialization. you might have called t function before loading resources finished."),b.defaultValue||"")}function A(a,b){return void 0!==b.defaultValue?b.defaultValue:a}function B(){for(var a=[],b=1;b1)for(var d=0;d-1&&(e=c.split(P.nsseparator),i=e[0],c=e[1]),void 0===g&&P.sendMissing&&"function"==typeof P.missingKeyHandler&&(b.lng?P.missingKeyHandler(h[0],i,c,f,h):P.missingKeyHandler(P.lng,i,c,f,h));var j=b.postProcess||P.postProcess;void 0!==g&&j&&X[j]&&(g=X[j](g,c,b));var k=f;if(f.indexOf(P.nsseparator)>-1&&(e=f.split(P.nsseparator),k=e[1]),k===c&&P.parseMissingKey&&(f=P.parseMissingKey(f)),void 0===g&&(f=t(f,b),f=u(f,b),j&&X[j])){var l=A(c,b);g=X[j](l,c,b)}return void 0!==g?g:f}function D(a,b){b=b||{};var c,d,e=A(a,b),f=L;if(!J)return e;if("cimode"===f[0].toLowerCase())return e;if(b.lngs&&(f=b.lngs),b.lng&&(f=T.toLanguages(b.lng,b.fallbackLng),!J[f[0]])){var g=P.getAsync;P.getAsync=!1,I.sync.load(f,P,function(a,b){T.extend(J,b),P.getAsync=g})}var h=b.ns||P.ns.defaultNs;if(a.indexOf(P.nsseparator)>-1){var i=a.split(P.nsseparator);h=i[0],a=i[1]}if(v(b)){c=T.extend({},b),delete c.context,c.defaultValue=P.contextNotFound;var j=h+P.nsseparator+a+"_"+b.context;if(d=z(j,c),d!=P.contextNotFound)return t(d,{context:b.context})}if(w(b,f[0])){c=T.extend({lngs:[f[0]]},b),delete c.count,c.defaultValue=P.pluralNotFound;var k;if(W.needsPlural(f[0],b.count)){k=h+P.nsseparator+a+P.pluralSuffix;var l=W.get(f[0],b.count);l>=0?k=k+"_"+l:1===l&&(k=h+P.nsseparator+a)}else k=h+P.nsseparator+a;if(d=z(k,c),d!=P.pluralNotFound)return t(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix});if(f.length>1){var m=f.slice();if(m.shift(),b=T.extend(b,{lngs:m}),d=z(h+P.nsseparator+a,b),d!=P.pluralNotFound)return d}}if(x(b)){var n=T.extend({},b);delete n.indefinite_article,n.defaultValue=P.indefiniteNotFound;var o=h+P.nsseparator+a+(b.count&&!w(b,f[0])||!b.count?P.indefiniteSuffix:"");if(d=z(o,n),d!=P.indefiniteNotFound)return d}for(var p,q=a.split(P.keyseparator),r=0,s=f.length;s>r&&void 0===p;r++){for(var y=f[r],B=0,E=J[y]&&J[y][h];q[B];)E=E&&E[q[B]],B++;if(void 0!==E){var F=Object.prototype.toString.apply(E);if("string"==typeof E)E=t(E,b),E=u(E,b);else if("[object Array]"!==F||P.returnObjectTrees||b.returnObjectTrees){if(null===E&&P.fallbackOnNull===!0)E=void 0;else if(null!==E)if(P.returnObjectTrees||b.returnObjectTrees){if("[object Number]"!==F&&"[object Function]"!==F&&"[object RegExp]"!==F){var G="[object Array]"===F?[]:{};T.each(E,function(c){G[c]=C(h+P.nsseparator+a+P.keyseparator+c,b)}),E=G}}else P.objectTreeKeyHandler&&"function"==typeof P.objectTreeKeyHandler?E=P.objectTreeKeyHandler(a,E,y,h,b):(E="key '"+h+":"+a+" ("+y+")' "+"returned an object instead of string.",T.log(E))}else E=E.join("\n"),E=t(E,b),E=u(E,b);"string"==typeof E&&""===E.trim()&&P.fallbackOnEmpty===!0&&(E=void 0),p=E}}if(void 0===p&&!b.isFallbackLookup&&(P.fallbackToDefaultNS===!0||P.fallbackNS&&P.fallbackNS.length>0)){if(b.isFallbackLookup=!0,P.fallbackNS.length){for(var H=0,K=P.fallbackNS.length;K>H;H++)if(p=D(P.fallbackNS[H]+P.nsseparator+a,b)){var M=p.indexOf(P.nsseparator)>-1?p.split(P.nsseparator)[1]:p,N=e.indexOf(P.nsseparator)>-1?e.split(P.nsseparator)[1]:e;if(M!==N)break}}else p=D(a,b);b.isFallbackLookup=!1}return p}function E(){var a,b=P.lngWhitelist||[],c=[];if("undefined"!=typeof window&&!function(){for(var a=window.location.search.substring(1),b=a.split("&"),d=0;d0){var f=b[d].substring(0,e);f==P.detectLngQS&&c.push(b[d].substring(e+1))}}}(),P.useCookie&&"undefined"!=typeof document){var d=T.cookie.read(P.cookieName);d&&c.push(d)}if(P.detectLngFromLocalStorage&&"undefined"!=typeof window&&window.localStorage&&c.push(window.localStorage.getItem("i18next_lng")),"undefined"!=typeof navigator){if(navigator.languages)for(var e=0;e-1){var f=e.split("-");e=P.lowerCaseLng?f[0].toLowerCase()+"-"+f[1].toLowerCase():f[0].toLowerCase()+"-"+f[1].toUpperCase()}if(0===b.length||b.indexOf(e)>-1){a=e;break}}}(),a||(a=P.fallbackLng[0]),a}Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>0&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&1/0!=d&&d!=-1/0&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=c;arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d))));for(var e=d>=0?Math.min(d,c-1):c-Math.abs(d);e>=0;e--)if(e in b&&b[e]===a)return e;return-1}),"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")});var F,G=this,H=G.jQuery||G.Zepto,I={},J={},K=0,L=[],M=!1,N={};if("undefined"!=typeof module&&module.exports){if(!H)try{H=require("jquery")}catch(O){}H&&(H.i18n=H.i18n||I),module.exports=I}else H&&(H.i18n=H.i18n||I),G.i18n=G.i18n||I;N={load:function(a,b,c){b.useLocalStorage?N._loadLocal(a,b,function(d,e){for(var f=[],g=0,h=a.length;h>g;g++)e[a[g]]||f.push(a[g]);f.length>0?N._fetch(f,b,function(a,b){T.extend(e,b),N._storeLocal(b),c(null,e)}):c(null,e)}):N._fetch(a,b,function(a,b){c(null,b)})},_loadLocal:function(a,b,c){var d={},e=(new Date).getTime();if(window.localStorage){var f=a.length;T.each(a,function(a,g){var h=window.localStorage.getItem("res_"+g);h&&(h=JSON.parse(h),h.i18nStamp&&h.i18nStamp+b.localStorageExpirationTime>e&&(d[g]=h)),f--,0===f&&c(null,d)})}},_storeLocal:function(a){if(window.localStorage)for(var b in a)a[b].i18nStamp=(new Date).getTime(),T.localStorage.setItem("res_"+b,JSON.stringify(a[b]))},_fetch:function(a,b,c){var d=b.ns,e={};if(b.dynamicLoad){var f=function(a,b){c(null,b)};if("function"==typeof b.customLoad)b.customLoad(a,d.namespaces,b,f);else{var g=t(b.resGetPath,{lng:a.join("+"),ns:d.namespaces.join("+")});T.ajax({url:g,success:function(a){T.log("loaded: "+g),f(null,a)},error:function(a,b,c){T.log("failed loading: "+g),f("failed loading resource.json error: "+c)},dataType:"json",async:b.getAsync})}}else{var h,i=d.namespaces.length*a.length;T.each(d.namespaces,function(d,f){T.each(a,function(a,d){var g=function(a,b){a&&(h=h||[],h.push(a)),e[d]=e[d]||{},e[d][f]=b,i--,0===i&&c(h,e)};"function"==typeof b.customLoad?b.customLoad(d,f,b,g):N._fetchOne(d,f,b,g)})})}},_fetchOne:function(a,b,c,d){var e=t(c.resGetPath,{lng:a,ns:b});T.ajax({url:e,success:function(a){T.log("loaded: "+e),d(null,a)},error:function(a,b,c){if(b&&200==b||a&&a.status&&200==a.status)T.error("There is a typo in: "+e);else if(b&&404==b||a&&a.status&&404==a.status)T.log("Does not exist: "+e);else{var f=b?b:a&&a.status?a.status:null;T.log(f+" when loading "+e)}d(c,{})},dataType:"json",async:c.getAsync})},postMissing:function(a,b,c,d,e){var f={};f[c]=d;var g=[];if("fallback"===P.sendMissingTo&&P.fallbackLng[0]!==!1)for(var h=0;hh;h++)g.push({lng:e[h],url:t(P.resPostPath,{lng:e[h],ns:b})});for(var j=0,k=g.length;k>j;j++){var l=g[j];T.ajax({url:l.url,type:P.sendType,data:f,success:function(){T.log("posted missing key '"+c+"' to: "+l.url);for(var a=c.split("."),e=0,f=J[l.lng][b];a[e];)f=f[a[e]]=e===a.length-1?d:f[a[e]]||{},e++},error:function(){T.log("failed posting missing key '"+c+"' to: "+l.url)},dataType:"json",async:P.postAsync})}},reload:r};var P={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:["dev"],fallbackNS:[],detectLngQS:"setLng",detectLngFromLocalStorage:!1,ns:"translation",fallbackOnNull:!0,fallbackOnEmpty:!1,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",defaultVariables:!1,reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,indefiniteSuffix:"_indefinite",indefiniteNotFound:["indefinite_not_found",Math.random()].join(""),setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",cookieDomain:void 0,objectTreeKeyHandler:void 0,postProcess:void 0,parseMissingKey:void 0,missingKeyHandler:N.postMissing,shortcutFunction:"sprintf"},Q={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},R={create:function(a,b,c,d){var e;if(c){var f=new Date;f.setTime(f.getTime()+1e3*60*c),e="; expires="+f.toGMTString()}else e="";d=d?"domain="+d+";":"",document.cookie=a+"="+b+e+";"+d+"path=/"},read:function(a){for(var b=a+"=",c=document.cookie.split(";"),d=0;d-1){var c=a.split("-");b=P.lowerCaseLng?c[0].toLowerCase()+"-"+c[1].toLowerCase():c[0].toLowerCase()+"-"+c[1].toUpperCase()}else b=P.lowerCaseLng?a.toLowerCase():a;return b}var c=this.log,d=[],e=P.lngWhitelist||!1,f=function(a){!e||e.indexOf(a)>-1?d.push(a):c("rejecting non-whitelisted language: "+a)};if("string"==typeof a&&a.indexOf("-")>-1){var g=a.split("-");"unspecific"!==P.load&&f(b(a)),"current"!==P.load&&f(b(g[this.getCountyIndexOfLng(a)]))}else f(b(a));for(var h=0;h1)},2:function(a){return Number(1!=a)},3:function(){return 0},4:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},5:function(a){return Number(0===a?0:1==a?1:2==a?2:a%100>=3&&10>=a%100?3:a%100>=11?4:5)},6:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)},7:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},8:function(a){return Number(1==a?0:2==a?1:8!=a&&11!=a?2:3)},9:function(a){return Number(a>=2)},10:function(a){return Number(1==a?0:2==a?1:7>a?2:11>a?3:4)},11:function(a){return Number(1==a||11==a?0:2==a||12==a?1:a>2&&20>a?2:3)},12:function(a){return Number(1!=a%10||11==a%100)},13:function(a){return Number(0!==a)},14:function(a){return Number(1==a?0:2==a?1:3==a?2:3)},15:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&(10>a%100||a%100>=20)?1:2)},16:function(a){return Number(1==a%10&&11!=a%100?0:0!==a?1:2)},17:function(a){return Number(1==a||1==a%10?0:1)},18:function(a){return Number(1==a?1:2)},19:function(a){return Number(1==a?0:0===a||a%100>1&&11>a%100?1:a%100>10&&20>a%100?2:3)},20:function(a){return Number(1==a?0:0===a||a%100>0&&20>a%100?1:2)},21:function(a){return Number(1==a%100?1:2==a%100?2:3==a%100||4==a%100?3:0)}},W={rules:function(){var a,b={};for(a=U.length;a--;)b[U[a][0]]={name:U[a][1],numbers:U[a][2],plurals:V[U[a][3]]};return b}(),addRule:function(a,b){W.rules[a]=b},setCurrentLng:function(a){if(!W.currentRule||W.currentRule.lng!==a){var b=a.split("-");W.currentRule={lng:a,rule:W.rules[b[0]]}}},needsPlural:function(a,b){var c,d=a.split("-");return c=W.currentRule&&W.currentRule.lng===a?W.currentRule.rule:W.rules[d[T.getCountyIndexOfLng(a)]],c&&c.numbers.length<=1?!1:1!==this.get(a,b)},get:function(a,b){function c(b,c){var d;if(d=W.currentRule&&W.currentRule.lng===a?W.currentRule.rule:W.rules[b]){var e;e=d.noAbs?d.plurals(c):d.plurals(Math.abs(c));var f=d.numbers[e];return 2===d.numbers.length&&1===d.numbers[0]&&(2===f?f=-1:1===f&&(f=1)),f}return 1===c?"1":"-1"}var d=a.split("-");return c(d[T.getCountyIndexOfLng(a)],b)}},X={},Y=function(a,b){X[a]=b},Z=function(){function a(a){return Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}function b(a,b){for(var c=[];b>0;c[--b]=a);return c.join("")}var c=function(){return c.cache.hasOwnProperty(arguments[0])||(c.cache[arguments[0]]=c.parse(arguments[0])),c.format.call(null,c.cache[arguments[0]],arguments)};return c.format=function(c,d){var e,f,g,h,i,j,k,l=1,m=c.length,n="",o=[];for(f=0;m>f;f++)if(n=a(c[f]),"string"===n)o.push(c[f]);else if("array"===n){if(h=c[f],h[2])for(e=d[l],g=0;g=0?"+"+e:e,j=h[4]?"0"==h[4]?"0":h[4].charAt(1):" ",k=h[6]-String(e).length,i=h[6]?b(j,k):"",o.push(h[5]?e+i:i+e)}return o.join("")},c.cache={},c.parse=function(a){for(var b=a,c=[],d=[],e=0;b;){if(null!==(c=/^[^\x25]+/.exec(b)))d.push(c[0]);else if(null!==(c=/^\x25{2}/.exec(b)))d.push("%");else{if(null===(c=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(b)))throw"[sprintf] huh?";if(c[2]){e|=1;var f=[],g=c[2],h=[];if(null===(h=/^([a-z_][a-z_\d]*)/i.exec(g)))throw"[sprintf] huh?";for(f.push(h[1]);""!==(g=g.substring(h[0].length));)if(null!==(h=/^\.([a-z_][a-z_\d]*)/i.exec(g)))f.push(h[1]);else{if(null===(h=/^\[(\d+)\]/.exec(g)))throw"[sprintf] huh?";f.push(h[1])}c[2]=f}else e|=2;if(3===e)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";d.push(c)}b=b.substring(c[0].length)}return d},c}(),$=function(a,b){return b.unshift(a),Z.apply(null,b)};Y("sprintf",function(a,b,c){return c.sprintf?"[object Array]"===Object.prototype.toString.apply(c.sprintf)?$(a,c.sprintf):"object"==typeof c.sprintf?Z(a,c.sprintf):a:a}),I.init=f,I.setLng=p,I.preload=g,I.addResourceBundle=h,I.hasResourceBundle=i,I.addResource=k,I.addResources=l,I.removeResourceBundle=j,I.loadNamespace=n,I.loadNamespaces=o,I.setDefaultNamespace=m,I.t=z,I.translate=z,I.exists=y,I.detectLanguage=T.detectLanguage,I.pluralExtensions=W,I.sync=N,I.functions=T,I.lng=q,I.addPostProcessor=Y,I.options=P}(); \ No newline at end of file diff --git a/libs/i18next/release/i18next-1.7.5.zip b/libs/i18next/release/i18next-1.7.5.zip new file mode 100644 index 00000000..6dbde0c2 Binary files /dev/null and b/libs/i18next/release/i18next-1.7.5.zip differ diff --git a/libs/i18next/release/i18next-1.7.7.js b/libs/i18next/release/i18next-1.7.7.js new file mode 100644 index 00000000..bd3ecdde --- /dev/null +++ b/libs/i18next/release/i18next-1.7.7.js @@ -0,0 +1,2122 @@ +// i18next, v1.7.7 +// Copyright (c)2014 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function() { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + // Add string trim for IE8. + if (typeof String.prototype.trim !== 'function') { + String.prototype.trim = function() { + return this.replace(/^\s+|\s+$/g, ''); + } + } + + var root = this + , $ = root.jQuery || root.Zepto + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = [] + , initialized = false + , sync = {}; + + + + // Export the i18next object for **CommonJS**. + // If we're not in CommonJS, add `i18n` to the + // global object or to jquery. + if (typeof module !== 'undefined' && module.exports) { + if (!$) { + try { + $ = require('jquery'); + } catch(e) { + // just ignore + } + } + if ($) { + $.i18n = $.i18n || i18n; + } + module.exports = i18n; + } else { + if ($) { + $.i18n = $.i18n || i18n; + } + + root.i18n = root.i18n || i18n; + } + sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + f.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + if ((status && status == 200) || (xhr && xhr.status && xhr.status == 200)) { + // file loaded but invalid json, stop waste time ! + f.error('There is a typo in: ' + url); + } else if ((status && status == 404) || (xhr && xhr.status && xhr.status == 404)) { + f.log('Does not exist: ' + url); + } else { + var theStatus = status ? status : ((xhr && xhr.status) ? xhr.status : null); + f.log(theStatus + ' when loading ' + url); + } + + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback' && o.fallbackLng[0] !== false) { + for (var i = 0; i < o.fallbackLng.length; i++) { + urls.push({lng: o.fallbackLng[i], url: applyReplacement(o.resPostPath, { lng: o.fallbackLng[i], ns: ns })}); + } + } else if (o.sendMissingTo === 'current' || (o.sendMissingTo === 'fallback' && o.fallbackLng[0] === false) ) { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + }, + + reload: reload + }; + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: ['dev'], + fallbackNS: [], + detectLngQS: 'setLng', + detectLngFromLocalStorage: false, + ns: 'translation', + fallbackOnNull: true, + fallbackOnEmpty: false, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + defaultVariables: false, + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + indefiniteSuffix: '_indefinite', + indefiniteNotFound: ['indefinite_not_found', Math.random()].join(''), + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + cookieDomain: undefined, + + objectTreeKeyHandler: undefined, + postProcess: undefined, + parseMissingKey: undefined, + missingKeyHandler: sync.postMissing, + + shortcutFunction: 'sprintf' // or: defaultValue + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _deepExtend(target, source) { + for (var prop in source) + if (prop in target) + _deepExtend(target[prop], source[prop]); + else + target[prop] = source[prop]; + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || Object.prototype.toString.apply(object) !== '[object Array]' || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + try { + return JSON.parse(data) + } catch (e) { + f.error('Can not parse JSON. URL: ' + url); + return {}; + } + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + // file: protocol always gives status code 0, so check for data + if (status === 200 || (status === 0 && data.text())) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes,domain) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + domain = (domain)? "domain="+domain+";" : ""; + document.cookie = name+"="+value+expires+";"+domain+"path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes,domain) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + deepExtend: _deepExtend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : (typeof document !== 'undefined' ? _ajax : function() {}), + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + error: function(str) { + if (typeof console !== "undefined") console.error(str); + }, + getCountyIndexOfLng: function(lng) { + var lng_index = 0; + if (lng === 'nb-NO' || lng === 'nn-NO' || lng === 'nb-no' || lng === 'nn-no') lng_index = 1; + return lng_index; + }, + toLanguages: function(lng) { + var log = this.log; + + function applyCase(l) { + var ret = l; + + if (typeof l === 'string' && l.indexOf('-') > -1) { + var parts = l.split('-'); + + ret = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } else { + ret = o.lowerCaseLng ? l.toLowerCase() : l; + } + + return ret; + } + + var languages = []; + var whitelist = o.lngWhitelist || false; + var addLanguage = function(language){ + //reject langs not whitelisted + if(!whitelist || whitelist.indexOf(language) > -1){ + languages.push(language); + }else{ + log('rejecting non-whitelisted language: ' + language); + } + }; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + if (o.load !== 'unspecific') addLanguage(applyCase(lng)); + if (o.load !== 'current') addLanguage(applyCase(parts[this.getCountyIndexOfLng(lng)])); + } else { + addLanguage(applyCase(lng)); + } + + for (var i = 0; i < o.fallbackLng.length; i++) { + if (languages.indexOf(o.fallbackLng[i]) === -1 && o.fallbackLng[i]) languages.push(applyCase(o.fallbackLng[i])); + } + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + }, + regexReplacementEscape: function(strOrFn) { + if (typeof strOrFn === 'string') { + return strOrFn.replace(/\$/g, "$$$$"); + } else { + return strOrFn; + } + }, + localStorage: { + setItem: function(key, value) { + if (window.localStorage) { + try { + window.localStorage.setItem(key, value); + } catch (e) { + f.log('failed to set value for key "' + key + '" to localStorage.'); + } + } + } + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + delete o.fixLng; /* passed in each time */ + + // override functions: .log(), .detectLanguage(), etc + if (o.functions) { + delete o.functions; + f.extend(f, options.functions); + } + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // fallback languages + if (typeof o.fallbackLng == 'string' || typeof o.fallbackLng == 'boolean') { + o.fallbackLng = [o.fallbackLng]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + if (o.useCookie && f.cookie.read(o.cookieName) !== currentLng){ //cookie is unset or invalid + f.cookie.create(o.cookieName, currentLng, o.cookieExpirationTime, o.cookieDomain); + } + if (o.detectLngFromLocalStorage && typeof document !== 'undefined' && window.localStorage) { + f.localStorage.setItem('i18next_lng', currentLng); + } + + var lngTranslate = translate; + if (options.fixLng) { + lngTranslate = function(key, options) { + options = options || {}; + options.lng = options.lng || lngTranslate.lng; + return translate(key, options); + }; + lngTranslate.lng = currentLng; + } + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + initialized = true; + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + initialized = true; + + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources, deep) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + if (deep) { + f.deepExtend(resStore[lng][ns], resources); + } else { + f.extend(resStore[lng][ns], resources); + } + } + + function hasResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + var res = resStore[lng][ns] || {}; + + var hasValues = false; + for(var prop in res) { + if (res.hasOwnProperty(prop)) { + hasValues = true; + } + } + + return hasValues; + } + + function removeResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = {}; + } + + function addResource(lng, ns, key, value) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + var keys = key.split(o.keyseparator); + var x = 0; + var node = resStore[lng][ns]; + var origRef = node; + + while (keys[x]) { + if (x == keys.length - 1) + node[keys[x]] = value; + else { + if (node[keys[x]] == null) + node[keys[x]] = {}; + + node = node[keys[x]]; + } + x++; + } + } + + function addResources(lng, ns, resources) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + for (var m in resources) { + if (typeof resources[m] === 'string') addResource(lng, ns, m, resources[m]); + } + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, options, cb) { + if (typeof options === 'function') { + cb = options; + options = {}; + } else if (!options) { + options = {}; + } + + options.lng = lng; + return init(options, cb); + } + + function lng() { + return currentLng; + } + + function reload(cb) { + resStore = {}; + setLng(currentLng, cb); + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else if (attr === 'prepend') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.prepend($.t(key, optionsToUse)); + } else if (attr === 'append') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.append($.t(key, optionsToUse)); + } else if (attr.indexOf("data-") === 0) { + var dataAttr = attr.substr(("data-").length); + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.data(dataAttr) }, options) : options; + var translated = $.t(key, optionsToUse); + //we change into the data cache + ele.data(dataAttr, translated); + //we change into the dom + ele.attr(attr, translated); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key && typeof key !== 'undefined' && key !== false) key = ele.text() || ele.val(); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + var hash = replacementHash.replace && typeof replacementHash.replace === 'object' ? replacementHash.replace : replacementHash; + f.each(hash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), f.regexReplacementEscape(value)); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(f.escape(value))); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(value)); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + if (index_of_end_of_closing <= index_of_opening) { + f.error('there is an missing closing in following translation value', translated); + return ''; + } + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, f.regexReplacementEscape(translated_token)); + } + return translated; + } + + function hasContext(options) { + return (options.context && (typeof options.context == 'string' || typeof options.context == 'number')); + } + + function needsPlural(options, lng) { + return (options.count !== undefined && typeof options.count != 'string'/* && pluralExtensions.needsPlural(lng, options.count)*/); + } + + function needsIndefiniteArticle(options) { + return (options.indefinite_article !== undefined && typeof options.indefinite_article != 'string' && options.indefinite_article); + } + + function exists(key, options) { + options = options || {}; + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + options = options || {}; + + if (!initialized) { + f.log('i18next not finished initialization. you might have called t function before loading resources finished.') + return options.defaultValue || ''; + }; + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _getDefaultValue(key, options) { + return (options.defaultValue !== undefined) ? options.defaultValue : key; + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(potentialKeys, options) { + if (options && typeof options !== 'object') { + if (o.shortcutFunction === 'sprintf') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else if (o.shortcutFunction === 'defaultValue') { + options = { + defaultValue: options + } + } + } else { + options = options || {}; + } + + if (typeof o.defaultVariables === 'object') { + options = f.extend({}, o.defaultVariables, options); + } + + if (potentialKeys === undefined || potentialKeys === null || potentialKeys === '') return ''; + + if (typeof potentialKeys === 'string') { + potentialKeys = [potentialKeys]; + } + + var key = potentialKeys[0]; + + if (potentialKeys.length > 1) { + for (var i = 0; i < potentialKeys.length; i++) { + key = potentialKeys[i]; + if (exists(key, options)) { + break; + } + } + } + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng, options.fallbackLng) : languages + , ns = options.ns || o.ns.defaultNs + , parts; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing && typeof o.missingKeyHandler === 'function') { + if (options.lng) { + o.missingKeyHandler(lngs[0], ns, key, notFound, lngs); + } else { + o.missingKeyHandler(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found !== undefined && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + // process notFound if function exists + var splitNotFound = notFound; + if (notFound.indexOf(o.nsseparator) > -1) { + parts = notFound.split(o.nsseparator); + splitNotFound = parts[1]; + } + if (splitNotFound === key && o.parseMissingKey) { + notFound = o.parseMissingKey(notFound); + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessor && postProcessors[postProcessor]) { + var val = _getDefaultValue(key, options); + found = postProcessors[postProcessor](val, key, options); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options) { + options = options || {}; + + var optionWithoutCount, translated + , notFound = _getDefaultValue(key, options) + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + // CI mode + if (lngs[0].toLowerCase() === 'cimode') return notFound; + + // passed in lng + if (options.lngs) lngs = options.lngs; + if (options.lng) { + lngs = f.toLanguages(options.lng, options.fallbackLng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options, lngs[0])) { + optionWithoutCount = f.extend({ lngs: [lngs[0]]}, options); + delete optionWithoutCount.count; + delete optionWithoutCount.lng; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey; + if (!pluralExtensions.needsPlural(lngs[0], options.count)) { + pluralKey = ns + o.nsseparator + key; + } else { + pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(lngs[0], options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + } + + translated = translate(pluralKey, optionWithoutCount); + + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } else if (lngs.length > 1) { + // remove failed lng + var clone = lngs.slice(); + clone.shift(); + options = f.extend(options, { lngs: clone }); + delete options.lng; + // retry with fallbacks + translated = translate(ns + o.nsseparator + key, options); + if (translated != o.pluralNotFound) return translated; + } else { + return translated; + } + } + + if (needsIndefiniteArticle(options)) { + var optionsWithoutIndef = f.extend({}, options); + delete optionsWithoutIndef.indefinite_article; + optionsWithoutIndef.defaultValue = o.indefiniteNotFound; + // If we don't have a count, we want the indefinite, if we do have a count, and needsPlural is false + var indefiniteKey = ns + o.nsseparator + key + (((options.count && !needsPlural(options, lngs[0])) || !options.count) ? o.indefiniteSuffix : ""); + translated = translate(indefiniteKey, optionsWithoutIndef); + if (translated != o.indefiniteNotFound) { + return translated; + } + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + var valueType = Object.prototype.toString.apply(value); + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (valueType === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + if (o.objectTreeKeyHandler && typeof o.objectTreeKeyHandler == 'function') { + value = o.objectTreeKeyHandler(key, value, l, ns, options); + } else { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned an object instead of string.'; + f.log(value); + } + } else if (valueType !== '[object Number]' && valueType !== '[object Function]' && valueType !== '[object RegExp]') { + var copy = (valueType === '[object Array]') ? [] : {}; // apply child translation on a copy + f.each(value, function(m) { + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + }); + value = copy; + } + } + + if (typeof value === 'string' && value.trim() === '' && o.fallbackOnEmpty === true) + value = undefined; + + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length > 0))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found || (found==="" && o.fallbackOnEmpty === false)) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + options.isFallbackLookup = false; + } + + return found; + } + function detectLanguage() { + var detectedLng; + var whitelist = o.lngWhitelist || []; + var userLngChoices = []; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var params = query.split('&'); + for (var i=0; i 0) { + var key = params[i].substring(0,pos); + if (key == o.detectLngQS) { + userLngChoices.push(params[i].substring(pos+1)); + } + } + } + })(); + } + + // get from cookie + if (o.useCookie && typeof document !== 'undefined') { + var c = f.cookie.read(o.cookieName); + if (c) userLngChoices.push(c); + } + + // get from localStorage + if (o.detectLngFromLocalStorage && typeof window !== 'undefined' && window.localStorage) { + userLngChoices.push(window.localStorage.getItem('i18next_lng')); + } + + // get from navigator + if (typeof navigator !== 'undefined') { + if (navigator.languages) { // chrome only; not an array, so can't use .push.apply instead of iterating + for (var i=0;i -1) { + var parts = lng.split('-'); + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } + + if (whitelist.length === 0 || whitelist.indexOf(lng) > -1) { + detectedLng = lng; + break; + } + } + })(); + + //fallback + if (!detectedLng){ + detectedLng = o.fallbackLng[0]; + } + + return detectedLng; + } + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + + /* [code, name, numbers, pluralsType] */ + var _rules = [ + ["ach", "Acholi", [1,2], 1], + ["af", "Afrikaans",[1,2], 2], + ["ak", "Akan", [1,2], 1], + ["am", "Amharic", [1,2], 1], + ["an", "Aragonese",[1,2], 2], + ["ar", "Arabic", [0,1,2,3,11,100],5], + ["arn", "Mapudungun",[1,2], 1], + ["ast", "Asturian", [1,2], 2], + ["ay", "Aymará", [1], 3], + ["az", "Azerbaijani",[1,2],2], + ["be", "Belarusian",[1,2,5],4], + ["bg", "Bulgarian",[1,2], 2], + ["bn", "Bengali", [1,2], 2], + ["bo", "Tibetan", [1], 3], + ["br", "Breton", [1,2], 1], + ["bs", "Bosnian", [1,2,5],4], + ["ca", "Catalan", [1,2], 2], + ["cgg", "Chiga", [1], 3], + ["cs", "Czech", [1,2,5],6], + ["csb", "Kashubian",[1,2,5],7], + ["cy", "Welsh", [1,2,3,8],8], + ["da", "Danish", [1,2], 2], + ["de", "German", [1,2], 2], + ["dev", "Development Fallback", [1,2], 2], + ["dz", "Dzongkha", [1], 3], + ["el", "Greek", [1,2], 2], + ["en", "English", [1,2], 2], + ["eo", "Esperanto",[1,2], 2], + ["es", "Spanish", [1,2], 2], + ["es_ar","Argentinean Spanish", [1,2], 2], + ["et", "Estonian", [1,2], 2], + ["eu", "Basque", [1,2], 2], + ["fa", "Persian", [1], 3], + ["fi", "Finnish", [1,2], 2], + ["fil", "Filipino", [1,2], 1], + ["fo", "Faroese", [1,2], 2], + ["fr", "French", [1,2], 9], + ["fur", "Friulian", [1,2], 2], + ["fy", "Frisian", [1,2], 2], + ["ga", "Irish", [1,2,3,7,11],10], + ["gd", "Scottish Gaelic",[1,2,3,20],11], + ["gl", "Galician", [1,2], 2], + ["gu", "Gujarati", [1,2], 2], + ["gun", "Gun", [1,2], 1], + ["ha", "Hausa", [1,2], 2], + ["he", "Hebrew", [1,2], 2], + ["hi", "Hindi", [1,2], 2], + ["hr", "Croatian", [1,2,5],4], + ["hu", "Hungarian",[1,2], 2], + ["hy", "Armenian", [1,2], 2], + ["ia", "Interlingua",[1,2],2], + ["id", "Indonesian",[1], 3], + ["is", "Icelandic",[1,2], 12], + ["it", "Italian", [1,2], 2], + ["ja", "Japanese", [1], 3], + ["jbo", "Lojban", [1], 3], + ["jv", "Javanese", [0,1], 13], + ["ka", "Georgian", [1], 3], + ["kk", "Kazakh", [1], 3], + ["km", "Khmer", [1], 3], + ["kn", "Kannada", [1,2], 2], + ["ko", "Korean", [1], 3], + ["ku", "Kurdish", [1,2], 2], + ["kw", "Cornish", [1,2,3,4],14], + ["ky", "Kyrgyz", [1], 3], + ["lb", "Letzeburgesch",[1,2],2], + ["ln", "Lingala", [1,2], 1], + ["lo", "Lao", [1], 3], + ["lt", "Lithuanian",[1,2,10],15], + ["lv", "Latvian", [1,2,0],16], + ["mai", "Maithili", [1,2], 2], + ["mfe", "Mauritian Creole",[1,2],1], + ["mg", "Malagasy", [1,2], 1], + ["mi", "Maori", [1,2], 1], + ["mk", "Macedonian",[1,2],17], + ["ml", "Malayalam",[1,2], 2], + ["mn", "Mongolian",[1,2], 2], + ["mnk", "Mandinka", [0,1,2],18], + ["mr", "Marathi", [1,2], 2], + ["ms", "Malay", [1], 3], + ["mt", "Maltese", [1,2,11,20],19], + ["nah", "Nahuatl", [1,2], 2], + ["nap", "Neapolitan",[1,2], 2], + ["nb", "Norwegian Bokmal",[1,2],2], + ["ne", "Nepali", [1,2], 2], + ["nl", "Dutch", [1,2], 2], + ["nn", "Norwegian Nynorsk",[1,2],2], + ["no", "Norwegian",[1,2], 2], + ["nso", "Northern Sotho",[1,2],2], + ["oc", "Occitan", [1,2], 1], + ["or", "Oriya", [2,1], 2], + ["pa", "Punjabi", [1,2], 2], + ["pap", "Papiamento",[1,2], 2], + ["pl", "Polish", [1,2,5],7], + ["pms", "Piemontese",[1,2], 2], + ["ps", "Pashto", [1,2], 2], + ["pt", "Portuguese",[1,2], 2], + ["pt_br","Brazilian Portuguese",[1,2], 2], + ["rm", "Romansh", [1,2], 2], + ["ro", "Romanian", [1,2,20],20], + ["ru", "Russian", [1,2,5],4], + ["sah", "Yakut", [1], 3], + ["sco", "Scots", [1,2], 2], + ["se", "Northern Sami",[1,2], 2], + ["si", "Sinhala", [1,2], 2], + ["sk", "Slovak", [1,2,5],6], + ["sl", "Slovenian",[5,1,2,3],21], + ["so", "Somali", [1,2], 2], + ["son", "Songhay", [1,2], 2], + ["sq", "Albanian", [1,2], 2], + ["sr", "Serbian", [1,2,5],4], + ["su", "Sundanese",[1], 3], + ["sv", "Swedish", [1,2], 2], + ["sw", "Swahili", [1,2], 2], + ["ta", "Tamil", [1,2], 2], + ["te", "Telugu", [1,2], 2], + ["tg", "Tajik", [1,2], 1], + ["th", "Thai", [1], 3], + ["ti", "Tigrinya", [1,2], 1], + ["tk", "Turkmen", [1,2], 2], + ["tr", "Turkish", [1,2], 1], + ["tt", "Tatar", [1], 3], + ["ug", "Uyghur", [1], 3], + ["uk", "Ukrainian",[1,2,5],4], + ["ur", "Urdu", [1,2], 2], + ["uz", "Uzbek", [1,2], 1], + ["vi", "Vietnamese",[1], 3], + ["wa", "Walloon", [1,2], 1], + ["wo", "Wolof", [1], 3], + ["yo", "Yoruba", [1,2], 2], + ["zh", "Chinese", [1], 3] + ]; + + var _rulesPluralsTypes = { + 1: function(n) {return Number(n > 1);}, + 2: function(n) {return Number(n != 1);}, + 3: function(n) {return 0;}, + 4: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 5: function(n) {return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5);}, + 6: function(n) {return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2);}, + 7: function(n) {return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 8: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3);}, + 9: function(n) {return Number(n >= 2);}, + 10: function(n) {return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;}, + 11: function(n) {return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3);}, + 12: function(n) {return Number(n%10!=1 || n%100==11);}, + 13: function(n) {return Number(n !== 0);}, + 14: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3);}, + 15: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 16: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2);}, + 17: function(n) {return Number(n==1 || n%10==1 ? 0 : 1);}, + 18: function(n) {return Number(0 ? 0 : n==1 ? 1 : 2);}, + 19: function(n) {return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3);}, + 20: function(n) {return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2);}, + 21: function(n) {return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }; + + var pluralExtensions = { + + rules: (function () { + var l, rules = {}; + for (l=_rules.length; l-- ;) { + rules[_rules[l][0]] = { + name: _rules[l][1], + numbers: _rules[l][2], + plurals: _rulesPluralsTypes[_rules[l][3]] + } + } + return rules; + }()), + + // you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + needsPlural: function(lng, count) { + var parts = lng.split('-'); + + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[parts[f.getCountyIndexOfLng(lng)]]; + } + + if (ext && ext.numbers.length <= 1) { + return false; + } else { + return this.get(lng, count) !== 1; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i; + if (ext.noAbs) { + i = ext.plurals(c); + } else { + i = ext.plurals(Math.abs(c)); + } + + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[f.getCountyIndexOfLng(lng)], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.hasResourceBundle = hasResourceBundle; + i18n.addResource = addResource; + i18n.addResources = addResources; + i18n.removeResourceBundle = removeResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + +})(); \ No newline at end of file diff --git a/libs/i18next/release/i18next-1.7.7.min.js b/libs/i18next/release/i18next-1.7.7.min.js new file mode 100644 index 00000000..56b93e14 --- /dev/null +++ b/libs/i18next/release/i18next-1.7.7.min.js @@ -0,0 +1,5 @@ +// i18next, v1.7.7 +// Copyright (c)2014 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +!function(){function a(a,b){if(!b||"function"==typeof b)return a;for(var c in b)a[c]=b[c];return a}function b(a,c){for(var d in c)d in a?b(a[d],c[d]):a[d]=c[d];return a}function c(a,b,c){var d,e=0,f=a.length,g=void 0===f||"[object Array]"!==Object.prototype.toString.apply(a)||"function"==typeof a;if(c)if(g){for(d in a)if(b.apply(a[d],c)===!1)break}else for(;f>e&&b.apply(a[e++],c)!==!1;);else if(g){for(d in a)if(b.call(a[d],d,a[d])===!1)break}else for(;f>e&&b.call(a[e],e,a[e++])!==!1;);return a}function d(a){return"string"==typeof a?a.replace(/[&<>"'\/]/g,function(a){return Q[a]}):a}function e(a){var b=function(a){if(window.XMLHttpRequest)return a(null,new XMLHttpRequest);if(window.ActiveXObject)try{return a(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(b){return a(null,new ActiveXObject("Microsoft.XMLHTTP"))}return a(new Error)},c=function(a){if("string"==typeof a)return a;var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")},d=function(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;cd?b+=String.fromCharCode(d):d>127&&2048>d?(b+=String.fromCharCode(192|d>>6),b+=String.fromCharCode(128|63&d)):(b+=String.fromCharCode(224|d>>12),b+=String.fromCharCode(128|63&d>>6),b+=String.fromCharCode(128|63&d))}return b},e=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";a=d(a);var c,e,f,g,h,i,j,k="",l=0;do c=a.charCodeAt(l++),e=a.charCodeAt(l++),f=a.charCodeAt(l++),g=c>>2,h=(3&c)<<4|e>>4,i=(15&e)<<2|f>>6,j=63&f,isNaN(e)?i=j=64:isNaN(f)&&(j=64),k+=b.charAt(g)+b.charAt(h)+b.charAt(i)+b.charAt(j),c=e=f="",g=h=i=j="";while(l1&&(d+=d.indexOf("?")>-1?"&"+k:"?"+k),e.jsonp){var l=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=d,l.appendChild(m),void 0}}b(function(b,c){if(b)return h(b);c.open(a,d,e.async);for(var f in j)j.hasOwnProperty(f)&&c.setRequestHeader(f,j[f]);c.onreadystatechange=function(){if(4===c.readyState){var a=c.responseText||"";if(!h)return;h(c.status,{text:function(){return a},json:function(){try{return JSON.parse(a)}catch(b){return T.error("Can not parse JSON. URL: "+d),{}}}})}},c.send(i)})},h={authBasic:function(a,b){g.headers.Authorization="Basic "+e(a+":"+b)},connect:function(a,b,c){return g("CONNECT",a,b,c)},del:function(a,b,c){return g("DELETE",a,b,c)},get:function(a,b,c){return g("GET",a,b,c)},head:function(a,b,c){return g("HEAD",a,b,c)},headers:function(a){g.headers=a||{}},isAllowed:function(a,b,c){this.options(a,function(a,d){c(-1!==d.text().indexOf(b))})},options:function(a,b,c){return g("OPTIONS",a,b,c)},patch:function(a,b,c){return g("PATCH",a,b,c)},post:function(a,b,c){return g("POST",a,b,c)},put:function(a,b,c){return g("PUT",a,b,c)},trace:function(a,b,c){return g("TRACE",a,b,c)}},i=a.type?a.type.toLowerCase():"get";h[i](a.url,a,function(b,c){200===b||0===b&&c.text()?a.success(c.json(),b,null):a.error(c.text(),b,null)})}function f(a,b){"function"==typeof a&&(b=a,a={}),a=a||{},T.extend(P,a),delete P.fixLng,P.functions&&(delete P.functions,T.extend(T,a.functions)),"string"==typeof P.ns&&(P.ns={namespaces:[P.ns],defaultNs:P.ns}),"string"==typeof P.fallbackNS&&(P.fallbackNS=[P.fallbackNS]),("string"==typeof P.fallbackLng||"boolean"==typeof P.fallbackLng)&&(P.fallbackLng=[P.fallbackLng]),P.interpolationPrefixEscaped=T.regexEscape(P.interpolationPrefix),P.interpolationSuffixEscaped=T.regexEscape(P.interpolationSuffix),P.lng||(P.lng=T.detectLanguage()),L=T.toLanguages(P.lng),F=L[0],T.log("currentLng set to: "+F),P.useCookie&&T.cookie.read(P.cookieName)!==F&&T.cookie.create(P.cookieName,F,P.cookieExpirationTime,P.cookieDomain),P.detectLngFromLocalStorage&&"undefined"!=typeof document&&window.localStorage&&T.localStorage.setItem("i18next_lng",F);var c=z;a.fixLng&&(c=function(a,b){return b=b||{},b.lng=b.lng||c.lng,z(a,b)},c.lng=F),W.setCurrentLng(F),H&&P.setJqueryExt&&s();var d;if(H&&H.Deferred&&(d=H.Deferred()),!P.resStore){var e=T.toLanguages(P.lng);"string"==typeof P.preload&&(P.preload=[P.preload]);for(var f=0,g=P.preload.length;g>f;f++)for(var h=T.toLanguages(P.preload[f]),i=0,j=h.length;j>i;i++)e.indexOf(h[i])<0&&e.push(h[i]);return I.sync.load(e,P,function(a,e){J=e,M=!0,b&&b(c),d&&d.resolve(c)}),d?d.promise():void 0}return J=P.resStore,M=!0,b&&b(c),d&&d.resolve(c),d?d.promise():void 0}function g(a,b){"string"==typeof a&&(a=[a]);for(var c=0,d=a.length;d>c;c++)P.preload.indexOf(a[c])<0&&P.preload.push(a[c]);return f(b)}function h(a,b,c,d){"string"!=typeof b?(c=b,b=P.ns.defaultNs):P.ns.namespaces.indexOf(b)<0&&P.ns.namespaces.push(b),J[a]=J[a]||{},J[a][b]=J[a][b]||{},d?T.deepExtend(J[a][b],c):T.extend(J[a][b],c)}function i(a,b){"string"!=typeof b&&(b=P.ns.defaultNs),J[a]=J[a]||{};var c=J[a][b]||{},d=!1;for(var e in c)c.hasOwnProperty(e)&&(d=!0);return d}function j(a,b){"string"!=typeof b&&(b=P.ns.defaultNs),J[a]=J[a]||{},J[a][b]={}}function k(a,b,c,d){"string"!=typeof b?(resource=b,b=P.ns.defaultNs):P.ns.namespaces.indexOf(b)<0&&P.ns.namespaces.push(b),J[a]=J[a]||{},J[a][b]=J[a][b]||{};for(var e=c.split(P.keyseparator),f=0,g=J[a][b];e[f];)f==e.length-1?g[e[f]]=d:(null==g[e[f]]&&(g[e[f]]={}),g=g[e[f]]),f++}function l(a,b,c){"string"!=typeof b?(resource=b,b=P.ns.defaultNs):P.ns.namespaces.indexOf(b)<0&&P.ns.namespaces.push(b);for(var d in c)"string"==typeof c[d]&&k(a,b,d,c[d])}function m(a){P.ns.defaultNs=a}function n(a,b){o([a],b)}function o(a,b){var c={dynamicLoad:P.dynamicLoad,resGetPath:P.resGetPath,getAsync:P.getAsync,customLoad:P.customLoad,ns:{namespaces:a,defaultNs:""}},d=T.toLanguages(P.lng);"string"==typeof P.preload&&(P.preload=[P.preload]);for(var e=0,f=P.preload.length;f>e;e++)for(var g=T.toLanguages(P.preload[e]),h=0,i=g.length;i>h;h++)d.indexOf(g[h])<0&&d.push(g[h]);for(var j=[],k=0,l=d.length;l>k;k++){var m=!1,n=J[d[k]];if(n)for(var o=0,p=a.length;p>o;o++)n[a[o]]||(m=!0);else m=!0;m&&j.push(d[k])}j.length?I.sync._fetch(j,c,function(c,d){var e=a.length*j.length;T.each(a,function(a,c){P.ns.namespaces.indexOf(c)<0&&P.ns.namespaces.push(c),T.each(j,function(a,f){J[f]=J[f]||{},J[f][c]=d[f][c],e--,0===e&&b&&(P.useLocalStorage&&I.sync._storeLocal(J),b())})})}):b&&b()}function p(a,b,c){return"function"==typeof b?(c=b,b={}):b||(b={}),b.lng=a,f(b,c)}function q(){return F}function r(a){J={},p(F,a)}function s(){function a(a,b,c){if(0!==b.length){var d="text";if(0===b.indexOf("[")){var e=b.split("]");b=e[1],d=e[0].substr(1,e[0].length-1)}b.indexOf(";")===b.length-1&&(b=b.substr(0,b.length-2));var f;if("html"===d)f=P.defaultValueFromContent?H.extend({defaultValue:a.html()},c):c,a.html(H.t(b,f));else if("text"===d)f=P.defaultValueFromContent?H.extend({defaultValue:a.text()},c):c,a.text(H.t(b,f));else if("prepend"===d)f=P.defaultValueFromContent?H.extend({defaultValue:a.html()},c):c,a.prepend(H.t(b,f));else if("append"===d)f=P.defaultValueFromContent?H.extend({defaultValue:a.html()},c):c,a.append(H.t(b,f));else if(0===d.indexOf("data-")){var g=d.substr("data-".length);f=P.defaultValueFromContent?H.extend({defaultValue:a.data(g)},c):c;var h=H.t(b,f);a.data(g,h),a.attr(d,h)}else f=P.defaultValueFromContent?H.extend({defaultValue:a.attr(d)},c):c,a.attr(d,H.t(b,f))}}function b(b,c){var d=b.attr(P.selectorAttr);if(d||"undefined"==typeof d||d===!1||(d=b.text()||b.val()),d){var e=b,f=b.data("i18n-target");if(f&&(e=b.find(f)||b),c||P.useDataAttrOptions!==!0||(c=b.data("i18n-options")),c=c||{},d.indexOf(";")>=0){var g=d.split(";");H.each(g,function(b,d){""!==d&&a(e,d,c)})}else a(e,d,c);P.useDataAttrOptions===!0&&b.data("i18n-options",c)}}H.t=H.t||z,H.fn.i18n=function(a){return this.each(function(){b(H(this),a);var c=H(this).find("["+P.selectorAttr+"]");c.each(function(){b(H(this),a)})})}}function t(a,b,c,d){if(!a)return a;if(d=d||b,a.indexOf(d.interpolationPrefix||P.interpolationPrefix)<0)return a;var e=d.interpolationPrefix?T.regexEscape(d.interpolationPrefix):P.interpolationPrefixEscaped,f=d.interpolationSuffix?T.regexEscape(d.interpolationSuffix):P.interpolationSuffixEscaped,g="HTML"+f,h=b.replace&&"object"==typeof b.replace?b.replace:b;return T.each(h,function(b,h){var i=c?c+P.keyseparator+b:b;"object"==typeof h&&null!==h?a=t(a,h,i,d):d.escapeInterpolation||P.escapeInterpolation?(a=a.replace(new RegExp([e,i,g].join(""),"g"),T.regexReplacementEscape(h)),a=a.replace(new RegExp([e,i,f].join(""),"g"),T.regexReplacementEscape(T.escape(h)))):a=a.replace(new RegExp([e,i,f].join(""),"g"),T.regexReplacementEscape(h))}),a}function u(a,b){var c=",",d="{",e="}",f=T.extend({},b);for(delete f.postProcess;-1!=a.indexOf(P.reusePrefix)&&(K++,!(K>P.maxRecursion));){var g=a.lastIndexOf(P.reusePrefix),h=a.indexOf(P.reuseSuffix,g)+P.reuseSuffix.length,i=a.substring(g,h),j=i.replace(P.reusePrefix,"").replace(P.reuseSuffix,"");if(g>=h)return T.error("there is an missing closing in following translation value",a),"";if(-1!=j.indexOf(c)){var k=j.indexOf(c);if(-1!=j.indexOf(d,k)&&-1!=j.indexOf(e,k)){var l=j.indexOf(d,k),m=j.indexOf(e,l)+e.length;try{f=T.extend(f,JSON.parse(j.substring(l,m))),j=j.substring(0,k)}catch(n){}}}var o=C(j,f);a=a.replace(i,T.regexReplacementEscape(o))}return a}function v(a){return a.context&&("string"==typeof a.context||"number"==typeof a.context)}function w(a){return void 0!==a.count&&"string"!=typeof a.count}function x(a){return void 0!==a.indefinite_article&&"string"!=typeof a.indefinite_article&&a.indefinite_article}function y(a,b){b=b||{};var c=A(a,b),d=D(a,b);return void 0!==d||d===c}function z(a,b){return b=b||{},M?(K=0,C.apply(null,arguments)):(T.log("i18next not finished initialization. you might have called t function before loading resources finished."),b.defaultValue||"")}function A(a,b){return void 0!==b.defaultValue?b.defaultValue:a}function B(){for(var a=[],b=1;b1)for(var d=0;d-1&&(e=c.split(P.nsseparator),i=e[0],c=e[1]),void 0===g&&P.sendMissing&&"function"==typeof P.missingKeyHandler&&(b.lng?P.missingKeyHandler(h[0],i,c,f,h):P.missingKeyHandler(P.lng,i,c,f,h));var j=b.postProcess||P.postProcess;void 0!==g&&j&&X[j]&&(g=X[j](g,c,b));var k=f;if(f.indexOf(P.nsseparator)>-1&&(e=f.split(P.nsseparator),k=e[1]),k===c&&P.parseMissingKey&&(f=P.parseMissingKey(f)),void 0===g&&(f=t(f,b),f=u(f,b),j&&X[j])){var l=A(c,b);g=X[j](l,c,b)}return void 0!==g?g:f}function D(a,b){b=b||{};var c,d,e=A(a,b),f=L;if(!J)return e;if("cimode"===f[0].toLowerCase())return e;if(b.lngs&&(f=b.lngs),b.lng&&(f=T.toLanguages(b.lng,b.fallbackLng),!J[f[0]])){var g=P.getAsync;P.getAsync=!1,I.sync.load(f,P,function(a,b){T.extend(J,b),P.getAsync=g})}var h=b.ns||P.ns.defaultNs;if(a.indexOf(P.nsseparator)>-1){var i=a.split(P.nsseparator);h=i[0],a=i[1]}if(v(b)){c=T.extend({},b),delete c.context,c.defaultValue=P.contextNotFound;var j=h+P.nsseparator+a+"_"+b.context;if(d=z(j,c),d!=P.contextNotFound)return t(d,{context:b.context})}if(w(b,f[0])){c=T.extend({lngs:[f[0]]},b),delete c.count,delete c.lng,c.defaultValue=P.pluralNotFound;var k;if(W.needsPlural(f[0],b.count)){k=h+P.nsseparator+a+P.pluralSuffix;var l=W.get(f[0],b.count);l>=0?k=k+"_"+l:1===l&&(k=h+P.nsseparator+a)}else k=h+P.nsseparator+a;if(d=z(k,c),d!=P.pluralNotFound)return t(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix});if(!(f.length>1))return d;var m=f.slice();if(m.shift(),b=T.extend(b,{lngs:m}),delete b.lng,d=z(h+P.nsseparator+a,b),d!=P.pluralNotFound)return d}if(x(b)){var n=T.extend({},b);delete n.indefinite_article,n.defaultValue=P.indefiniteNotFound;var o=h+P.nsseparator+a+(b.count&&!w(b,f[0])||!b.count?P.indefiniteSuffix:"");if(d=z(o,n),d!=P.indefiniteNotFound)return d}for(var p,q=a.split(P.keyseparator),r=0,s=f.length;s>r&&void 0===p;r++){for(var y=f[r],B=0,E=J[y]&&J[y][h];q[B];)E=E&&E[q[B]],B++;if(void 0!==E){var F=Object.prototype.toString.apply(E);if("string"==typeof E)E=t(E,b),E=u(E,b);else if("[object Array]"!==F||P.returnObjectTrees||b.returnObjectTrees){if(null===E&&P.fallbackOnNull===!0)E=void 0;else if(null!==E)if(P.returnObjectTrees||b.returnObjectTrees){if("[object Number]"!==F&&"[object Function]"!==F&&"[object RegExp]"!==F){var G="[object Array]"===F?[]:{};T.each(E,function(c){G[c]=C(h+P.nsseparator+a+P.keyseparator+c,b)}),E=G}}else P.objectTreeKeyHandler&&"function"==typeof P.objectTreeKeyHandler?E=P.objectTreeKeyHandler(a,E,y,h,b):(E="key '"+h+":"+a+" ("+y+")' "+"returned an object instead of string.",T.log(E))}else E=E.join("\n"),E=t(E,b),E=u(E,b);"string"==typeof E&&""===E.trim()&&P.fallbackOnEmpty===!0&&(E=void 0),p=E}}if(void 0===p&&!b.isFallbackLookup&&(P.fallbackToDefaultNS===!0||P.fallbackNS&&P.fallbackNS.length>0)){if(b.isFallbackLookup=!0,P.fallbackNS.length){for(var H=0,K=P.fallbackNS.length;K>H;H++)if(p=D(P.fallbackNS[H]+P.nsseparator+a,b),p||""===p&&P.fallbackOnEmpty===!1){var M=p.indexOf(P.nsseparator)>-1?p.split(P.nsseparator)[1]:p,N=e.indexOf(P.nsseparator)>-1?e.split(P.nsseparator)[1]:e;if(M!==N)break}}else p=D(a,b);b.isFallbackLookup=!1}return p}function E(){var a,b=P.lngWhitelist||[],c=[];if("undefined"!=typeof window&&!function(){for(var a=window.location.search.substring(1),b=a.split("&"),d=0;d0){var f=b[d].substring(0,e);f==P.detectLngQS&&c.push(b[d].substring(e+1))}}}(),P.useCookie&&"undefined"!=typeof document){var d=T.cookie.read(P.cookieName);d&&c.push(d)}if(P.detectLngFromLocalStorage&&"undefined"!=typeof window&&window.localStorage&&c.push(window.localStorage.getItem("i18next_lng")),"undefined"!=typeof navigator){if(navigator.languages)for(var e=0;e-1){var f=e.split("-");e=P.lowerCaseLng?f[0].toLowerCase()+"-"+f[1].toLowerCase():f[0].toLowerCase()+"-"+f[1].toUpperCase()}if(0===b.length||b.indexOf(e)>-1){a=e;break}}}(),a||(a=P.fallbackLng[0]),a}Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>0&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&1/0!=d&&d!=-1/0&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=c;arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d))));for(var e=d>=0?Math.min(d,c-1):c-Math.abs(d);e>=0;e--)if(e in b&&b[e]===a)return e;return-1}),"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")});var F,G=this,H=G.jQuery||G.Zepto,I={},J={},K=0,L=[],M=!1,N={};if("undefined"!=typeof module&&module.exports){if(!H)try{H=require("jquery")}catch(O){}H&&(H.i18n=H.i18n||I),module.exports=I}else H&&(H.i18n=H.i18n||I),G.i18n=G.i18n||I;N={load:function(a,b,c){b.useLocalStorage?N._loadLocal(a,b,function(d,e){for(var f=[],g=0,h=a.length;h>g;g++)e[a[g]]||f.push(a[g]);f.length>0?N._fetch(f,b,function(a,b){T.extend(e,b),N._storeLocal(b),c(null,e)}):c(null,e)}):N._fetch(a,b,function(a,b){c(null,b)})},_loadLocal:function(a,b,c){var d={},e=(new Date).getTime();if(window.localStorage){var f=a.length;T.each(a,function(a,g){var h=window.localStorage.getItem("res_"+g);h&&(h=JSON.parse(h),h.i18nStamp&&h.i18nStamp+b.localStorageExpirationTime>e&&(d[g]=h)),f--,0===f&&c(null,d)})}},_storeLocal:function(a){if(window.localStorage)for(var b in a)a[b].i18nStamp=(new Date).getTime(),T.localStorage.setItem("res_"+b,JSON.stringify(a[b]))},_fetch:function(a,b,c){var d=b.ns,e={};if(b.dynamicLoad){var f=function(a,b){c(null,b)};if("function"==typeof b.customLoad)b.customLoad(a,d.namespaces,b,f);else{var g=t(b.resGetPath,{lng:a.join("+"),ns:d.namespaces.join("+")});T.ajax({url:g,success:function(a){T.log("loaded: "+g),f(null,a)},error:function(a,b,c){T.log("failed loading: "+g),f("failed loading resource.json error: "+c)},dataType:"json",async:b.getAsync})}}else{var h,i=d.namespaces.length*a.length;T.each(d.namespaces,function(d,f){T.each(a,function(a,d){var g=function(a,b){a&&(h=h||[],h.push(a)),e[d]=e[d]||{},e[d][f]=b,i--,0===i&&c(h,e)};"function"==typeof b.customLoad?b.customLoad(d,f,b,g):N._fetchOne(d,f,b,g)})})}},_fetchOne:function(a,b,c,d){var e=t(c.resGetPath,{lng:a,ns:b});T.ajax({url:e,success:function(a){T.log("loaded: "+e),d(null,a)},error:function(a,b,c){if(b&&200==b||a&&a.status&&200==a.status)T.error("There is a typo in: "+e);else if(b&&404==b||a&&a.status&&404==a.status)T.log("Does not exist: "+e);else{var f=b?b:a&&a.status?a.status:null;T.log(f+" when loading "+e)}d(c,{})},dataType:"json",async:c.getAsync})},postMissing:function(a,b,c,d,e){var f={};f[c]=d;var g=[];if("fallback"===P.sendMissingTo&&P.fallbackLng[0]!==!1)for(var h=0;hh;h++)g.push({lng:e[h],url:t(P.resPostPath,{lng:e[h],ns:b})});for(var j=0,k=g.length;k>j;j++){var l=g[j];T.ajax({url:l.url,type:P.sendType,data:f,success:function(){T.log("posted missing key '"+c+"' to: "+l.url);for(var a=c.split("."),e=0,f=J[l.lng][b];a[e];)f=f[a[e]]=e===a.length-1?d:f[a[e]]||{},e++},error:function(){T.log("failed posting missing key '"+c+"' to: "+l.url)},dataType:"json",async:P.postAsync})}},reload:r};var P={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:["dev"],fallbackNS:[],detectLngQS:"setLng",detectLngFromLocalStorage:!1,ns:"translation",fallbackOnNull:!0,fallbackOnEmpty:!1,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",defaultVariables:!1,reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,indefiniteSuffix:"_indefinite",indefiniteNotFound:["indefinite_not_found",Math.random()].join(""),setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",cookieDomain:void 0,objectTreeKeyHandler:void 0,postProcess:void 0,parseMissingKey:void 0,missingKeyHandler:N.postMissing,shortcutFunction:"sprintf"},Q={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},R={create:function(a,b,c,d){var e;if(c){var f=new Date;f.setTime(f.getTime()+1e3*60*c),e="; expires="+f.toGMTString()}else e="";d=d?"domain="+d+";":"",document.cookie=a+"="+b+e+";"+d+"path=/"},read:function(a){for(var b=a+"=",c=document.cookie.split(";"),d=0;d-1){var c=a.split("-");b=P.lowerCaseLng?c[0].toLowerCase()+"-"+c[1].toLowerCase():c[0].toLowerCase()+"-"+c[1].toUpperCase()}else b=P.lowerCaseLng?a.toLowerCase():a;return b}var c=this.log,d=[],e=P.lngWhitelist||!1,f=function(a){!e||e.indexOf(a)>-1?d.push(a):c("rejecting non-whitelisted language: "+a)};if("string"==typeof a&&a.indexOf("-")>-1){var g=a.split("-");"unspecific"!==P.load&&f(b(a)),"current"!==P.load&&f(b(g[this.getCountyIndexOfLng(a)]))}else f(b(a));for(var h=0;h1)},2:function(a){return Number(1!=a)},3:function(){return 0},4:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},5:function(a){return Number(0===a?0:1==a?1:2==a?2:a%100>=3&&10>=a%100?3:a%100>=11?4:5)},6:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)},7:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},8:function(a){return Number(1==a?0:2==a?1:8!=a&&11!=a?2:3)},9:function(a){return Number(a>=2)},10:function(a){return Number(1==a?0:2==a?1:7>a?2:11>a?3:4)},11:function(a){return Number(1==a||11==a?0:2==a||12==a?1:a>2&&20>a?2:3)},12:function(a){return Number(1!=a%10||11==a%100)},13:function(a){return Number(0!==a)},14:function(a){return Number(1==a?0:2==a?1:3==a?2:3)},15:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&(10>a%100||a%100>=20)?1:2)},16:function(a){return Number(1==a%10&&11!=a%100?0:0!==a?1:2)},17:function(a){return Number(1==a||1==a%10?0:1)},18:function(a){return Number(1==a?1:2)},19:function(a){return Number(1==a?0:0===a||a%100>1&&11>a%100?1:a%100>10&&20>a%100?2:3)},20:function(a){return Number(1==a?0:0===a||a%100>0&&20>a%100?1:2)},21:function(a){return Number(1==a%100?1:2==a%100?2:3==a%100||4==a%100?3:0)}},W={rules:function(){var a,b={};for(a=U.length;a--;)b[U[a][0]]={name:U[a][1],numbers:U[a][2],plurals:V[U[a][3]]};return b}(),addRule:function(a,b){W.rules[a]=b},setCurrentLng:function(a){if(!W.currentRule||W.currentRule.lng!==a){var b=a.split("-");W.currentRule={lng:a,rule:W.rules[b[0]]}}},needsPlural:function(a,b){var c,d=a.split("-");return c=W.currentRule&&W.currentRule.lng===a?W.currentRule.rule:W.rules[d[T.getCountyIndexOfLng(a)]],c&&c.numbers.length<=1?!1:1!==this.get(a,b)},get:function(a,b){function c(b,c){var d;if(d=W.currentRule&&W.currentRule.lng===a?W.currentRule.rule:W.rules[b]){var e;e=d.noAbs?d.plurals(c):d.plurals(Math.abs(c));var f=d.numbers[e];return 2===d.numbers.length&&1===d.numbers[0]&&(2===f?f=-1:1===f&&(f=1)),f}return 1===c?"1":"-1"}var d=a.split("-");return c(d[T.getCountyIndexOfLng(a)],b)}},X={},Y=function(a,b){X[a]=b},Z=function(){function a(a){return Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}function b(a,b){for(var c=[];b>0;c[--b]=a);return c.join("")}var c=function(){return c.cache.hasOwnProperty(arguments[0])||(c.cache[arguments[0]]=c.parse(arguments[0])),c.format.call(null,c.cache[arguments[0]],arguments)};return c.format=function(c,d){var e,f,g,h,i,j,k,l=1,m=c.length,n="",o=[];for(f=0;m>f;f++)if(n=a(c[f]),"string"===n)o.push(c[f]);else if("array"===n){if(h=c[f],h[2])for(e=d[l],g=0;g=0?"+"+e:e,j=h[4]?"0"==h[4]?"0":h[4].charAt(1):" ",k=h[6]-String(e).length,i=h[6]?b(j,k):"",o.push(h[5]?e+i:i+e)}return o.join("")},c.cache={},c.parse=function(a){for(var b=a,c=[],d=[],e=0;b;){if(null!==(c=/^[^\x25]+/.exec(b)))d.push(c[0]);else if(null!==(c=/^\x25{2}/.exec(b)))d.push("%");else{if(null===(c=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(b)))throw"[sprintf] huh?";if(c[2]){e|=1;var f=[],g=c[2],h=[];if(null===(h=/^([a-z_][a-z_\d]*)/i.exec(g)))throw"[sprintf] huh?";for(f.push(h[1]);""!==(g=g.substring(h[0].length));)if(null!==(h=/^\.([a-z_][a-z_\d]*)/i.exec(g)))f.push(h[1]);else{if(null===(h=/^\[(\d+)\]/.exec(g)))throw"[sprintf] huh?";f.push(h[1])}c[2]=f}else e|=2;if(3===e)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";d.push(c)}b=b.substring(c[0].length)}return d},c}(),$=function(a,b){return b.unshift(a),Z.apply(null,b)};Y("sprintf",function(a,b,c){return c.sprintf?"[object Array]"===Object.prototype.toString.apply(c.sprintf)?$(a,c.sprintf):"object"==typeof c.sprintf?Z(a,c.sprintf):a:a}),I.init=f,I.setLng=p,I.preload=g,I.addResourceBundle=h,I.hasResourceBundle=i,I.addResource=k,I.addResources=l,I.removeResourceBundle=j,I.loadNamespace=n,I.loadNamespaces=o,I.setDefaultNamespace=m,I.t=z,I.translate=z,I.exists=y,I.detectLanguage=T.detectLanguage,I.pluralExtensions=W,I.sync=N,I.functions=T,I.lng=q,I.addPostProcessor=Y,I.options=P}(); \ No newline at end of file diff --git a/libs/i18next/release/i18next-1.7.7.zip b/libs/i18next/release/i18next-1.7.7.zip new file mode 100644 index 00000000..16102722 Binary files /dev/null and b/libs/i18next/release/i18next-1.7.7.zip differ diff --git a/libs/i18next/release/i18next-1.8.0.js b/libs/i18next/release/i18next-1.8.0.js new file mode 100644 index 00000000..2ea95d91 --- /dev/null +++ b/libs/i18next/release/i18next-1.8.0.js @@ -0,0 +1,2175 @@ +// i18next, v1.8.0 +// Copyright (c)2015 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function(root) { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + // Add string trim for IE8. + if (typeof String.prototype.trim !== 'function') { + String.prototype.trim = function() { + return this.replace(/^\s+|\s+$/g, ''); + } + } + + var $ = root.jQuery || root.Zepto + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = [] + , initialized = false + , sync = {}; + + + + // Export the i18next object for **CommonJS**. + // If we're not in CommonJS, add `i18n` to the + // global object or to jquery. + if (typeof module !== 'undefined' && module.exports) { + module.exports = i18n; + } else { + if ($) { + $.i18n = $.i18n || i18n; + } + + root.i18n = root.i18n || i18n; + } + sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = f.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + f.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + if ((status && status == 200) || (xhr && xhr.status && xhr.status == 200)) { + // file loaded but invalid json, stop waste time ! + f.error('There is a typo in: ' + url); + } else if ((status && status == 404) || (xhr && xhr.status && xhr.status == 404)) { + f.log('Does not exist: ' + url); + } else { + var theStatus = status ? status : ((xhr && xhr.status) ? xhr.status : null); + f.log(theStatus + ' when loading ' + url); + } + + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback' && o.fallbackLng[0] !== false) { + for (var i = 0; i < o.fallbackLng.length; i++) { + urls.push({lng: o.fallbackLng[i], url: applyReplacement(o.resPostPath, { lng: o.fallbackLng[i], ns: ns })}); + } + } else if (o.sendMissingTo === 'current' || (o.sendMissingTo === 'fallback' && o.fallbackLng[0] === false) ) { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + }, + + reload: reload + }; + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: ['dev'], + fallbackNS: [], + detectLngQS: 'setLng', + detectLngFromLocalStorage: false, + ns: 'translation', + fallbackOnNull: true, + fallbackOnEmpty: false, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + defaultVariables: false, + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + indefiniteSuffix: '_indefinite', + indefiniteNotFound: ['indefinite_not_found', Math.random()].join(''), + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + cookieDomain: undefined, + + objectTreeKeyHandler: undefined, + postProcess: undefined, + parseMissingKey: undefined, + missingKeyHandler: sync.postMissing, + + shortcutFunction: 'sprintf' // or: defaultValue + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _deepExtend(target, source) { + for (var prop in source) + if (prop in target) + _deepExtend(target[prop], source[prop]); + else + target[prop] = source[prop]; + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || Object.prototype.toString.apply(object) !== '[object Array]' || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + try { + return JSON.parse(data) + } catch (e) { + f.error('Can not parse JSON. URL: ' + url); + return {}; + } + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + // file: protocol always gives status code 0, so check for data + if (status === 200 || (status === 0 && data.text())) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes,domain) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + domain = (domain)? "domain="+domain+";" : ""; + document.cookie = name+"="+value+expires+";"+domain+"path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes,domain) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + deepExtend: _deepExtend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : (typeof document !== 'undefined' ? _ajax : function() {}), + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + error: function(str) { + if (typeof console !== "undefined") console.error(str); + }, + getCountyIndexOfLng: function(lng) { + var lng_index = 0; + if (lng === 'nb-NO' || lng === 'nn-NO' || lng === 'nb-no' || lng === 'nn-no') lng_index = 1; + return lng_index; + }, + toLanguages: function(lng) { + var log = this.log; + + function applyCase(l) { + var ret = l; + + if (typeof l === 'string' && l.indexOf('-') > -1) { + var parts = l.split('-'); + + ret = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } else { + ret = o.lowerCaseLng ? l.toLowerCase() : l; + } + + return ret; + } + + var languages = []; + var whitelist = o.lngWhitelist || false; + var addLanguage = function(language){ + //reject langs not whitelisted + if(!whitelist || whitelist.indexOf(language) > -1){ + languages.push(language); + }else{ + log('rejecting non-whitelisted language: ' + language); + } + }; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + if (o.load !== 'unspecific') addLanguage(applyCase(lng)); + if (o.load !== 'current') addLanguage(applyCase(parts[this.getCountyIndexOfLng(lng)])); + } else { + addLanguage(applyCase(lng)); + } + + for (var i = 0; i < o.fallbackLng.length; i++) { + if (languages.indexOf(o.fallbackLng[i]) === -1 && o.fallbackLng[i]) languages.push(applyCase(o.fallbackLng[i])); + } + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + }, + regexReplacementEscape: function(strOrFn) { + if (typeof strOrFn === 'string') { + return strOrFn.replace(/\$/g, "$$$$"); + } else { + return strOrFn; + } + }, + localStorage: { + setItem: function(key, value) { + if (window.localStorage) { + try { + window.localStorage.setItem(key, value); + } catch (e) { + f.log('failed to set value for key "' + key + '" to localStorage.'); + } + } + }, + getItem: function(key, value) { + if (window.localStorage) { + try { + return window.localStorage.getItem(key, value); + } catch (e) { + f.log('failed to get value for key "' + key + '" from localStorage.'); + return undefined; + } + } + } + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + delete o.fixLng; /* passed in each time */ + + // override functions: .log(), .detectLanguage(), etc + if (o.functions) { + delete o.functions; + f.extend(f, options.functions); + } + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // fallback languages + if (typeof o.fallbackLng == 'string' || typeof o.fallbackLng == 'boolean') { + o.fallbackLng = [o.fallbackLng]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + if (o.useCookie && f.cookie.read(o.cookieName) !== currentLng){ //cookie is unset or invalid + f.cookie.create(o.cookieName, currentLng, o.cookieExpirationTime, o.cookieDomain); + } + if (o.detectLngFromLocalStorage && typeof document !== 'undefined' && window.localStorage) { + f.localStorage.setItem('i18next_lng', currentLng); + } + + var lngTranslate = translate; + if (options.fixLng) { + lngTranslate = function(key, options) { + options = options || {}; + options.lng = options.lng || lngTranslate.lng; + return translate(key, options); + }; + lngTranslate.lng = currentLng; + } + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + initialized = true; + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + initialized = true; + + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources, deep) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + if (deep) { + f.deepExtend(resStore[lng][ns], resources); + } else { + f.extend(resStore[lng][ns], resources); + } + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function hasResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + var res = resStore[lng][ns] || {}; + + var hasValues = false; + for(var prop in res) { + if (res.hasOwnProperty(prop)) { + hasValues = true; + } + } + + return hasValues; + } + + function getResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + return f.extend({}, resStore[lng][ns]); + } + + function removeResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = {}; + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function addResource(lng, ns, key, value) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + var keys = key.split(o.keyseparator); + var x = 0; + var node = resStore[lng][ns]; + var origRef = node; + + while (keys[x]) { + if (x == keys.length - 1) + node[keys[x]] = value; + else { + if (node[keys[x]] == null) + node[keys[x]] = {}; + + node = node[keys[x]]; + } + x++; + } + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function addResources(lng, ns, resources) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + for (var m in resources) { + if (typeof resources[m] === 'string') addResource(lng, ns, m, resources[m]); + } + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, options, cb) { + if (typeof options === 'function') { + cb = options; + options = {}; + } else if (!options) { + options = {}; + } + + options.lng = lng; + return init(options, cb); + } + + function lng() { + return currentLng; + } + + function reload(cb) { + resStore = {}; + setLng(currentLng, cb); + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else if (attr === 'prepend') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.prepend($.t(key, optionsToUse)); + } else if (attr === 'append') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.append($.t(key, optionsToUse)); + } else if (attr.indexOf("data-") === 0) { + var dataAttr = attr.substr(("data-").length); + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.data(dataAttr) }, options) : options; + var translated = $.t(key, optionsToUse); + //we change into the data cache + ele.data(dataAttr, translated); + //we change into the dom + ele.attr(attr, translated); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key && typeof key !== 'undefined' && key !== false) key = ele.text() || ele.val(); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + var hash = replacementHash.replace && typeof replacementHash.replace === 'object' ? replacementHash.replace : replacementHash; + f.each(hash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), f.regexReplacementEscape(value)); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(f.escape(value))); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(value)); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + if (index_of_end_of_closing <= index_of_opening) { + f.error('there is an missing closing in following translation value', translated); + return ''; + } + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, f.regexReplacementEscape(translated_token)); + } + return translated; + } + + function hasContext(options) { + return (options.context && (typeof options.context == 'string' || typeof options.context == 'number')); + } + + function needsPlural(options, lng) { + return (options.count !== undefined && typeof options.count != 'string'/* && pluralExtensions.needsPlural(lng, options.count)*/); + } + + function needsIndefiniteArticle(options) { + return (options.indefinite_article !== undefined && typeof options.indefinite_article != 'string' && options.indefinite_article); + } + + function exists(key, options) { + options = options || {}; + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + options = options || {}; + + if (!initialized) { + f.log('i18next not finished initialization. you might have called t function before loading resources finished.') + return options.defaultValue || ''; + }; + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _getDefaultValue(key, options) { + return (options.defaultValue !== undefined) ? options.defaultValue : key; + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(potentialKeys, options) { + if (options && typeof options !== 'object') { + if (o.shortcutFunction === 'sprintf') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else if (o.shortcutFunction === 'defaultValue') { + options = { + defaultValue: options + } + } + } else { + options = options || {}; + } + + if (typeof o.defaultVariables === 'object') { + options = f.extend({}, o.defaultVariables, options); + } + + if (potentialKeys === undefined || potentialKeys === null || potentialKeys === '') return ''; + + if (typeof potentialKeys === 'number') { + potentialKeys = String(potentialKeys); + } + + if (typeof potentialKeys === 'string') { + potentialKeys = [potentialKeys]; + } + + var key = potentialKeys[0]; + + if (potentialKeys.length > 1) { + for (var i = 0; i < potentialKeys.length; i++) { + key = potentialKeys[i]; + if (exists(key, options)) { + break; + } + } + } + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng, options.fallbackLng) : languages + , ns = options.ns || o.ns.defaultNs + , parts; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing && typeof o.missingKeyHandler === 'function') { + if (options.lng) { + o.missingKeyHandler(lngs[0], ns, key, notFound, lngs); + } else { + o.missingKeyHandler(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessorsToApply; + if (typeof o.postProcess === 'string' && o.postProcess !== '') { + postProcessorsToApply = [o.postProcess]; + } else if (typeof o.postProcess === 'array' || typeof o.postProcess === 'object') { + postProcessorsToApply = o.postProcess; + } else { + postProcessorsToApply = []; + } + + if (typeof options.postProcess === 'string' && options.postProcess !== '') { + postProcessorsToApply = postProcessorsToApply.concat([options.postProcess]); + } else if (typeof options.postProcess === 'array' || typeof options.postProcess === 'object') { + postProcessorsToApply = postProcessorsToApply.concat(options.postProcess); + } + + if (found !== undefined && postProcessorsToApply.length) { + postProcessorsToApply.forEach(function(postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + }); + } + + // process notFound if function exists + var splitNotFound = notFound; + if (notFound.indexOf(o.nsseparator) > -1) { + parts = notFound.split(o.nsseparator); + splitNotFound = parts[1]; + } + if (splitNotFound === key && o.parseMissingKey) { + notFound = o.parseMissingKey(notFound); + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessorsToApply.length) { + var val = _getDefaultValue(key, options); + postProcessorsToApply.forEach(function(postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](val, key, options); + } + }); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options) { + options = options || {}; + + var optionWithoutCount, translated + , notFound = _getDefaultValue(key, options) + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + // CI mode + if (lngs[0].toLowerCase() === 'cimode') return notFound; + + // passed in lng + if (options.lngs) lngs = options.lngs; + if (options.lng) { + lngs = f.toLanguages(options.lng, options.fallbackLng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options, lngs[0])) { + optionWithoutCount = f.extend({ lngs: [lngs[0]]}, options); + delete optionWithoutCount.count; + optionWithoutCount._origLng = optionWithoutCount._origLng || optionWithoutCount.lng || lngs[0]; + delete optionWithoutCount.lng; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey; + if (!pluralExtensions.needsPlural(lngs[0], options.count)) { + pluralKey = ns + o.nsseparator + key; + } else { + pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(lngs[0], options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + } + + translated = translate(pluralKey, optionWithoutCount); + + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } else if (lngs.length > 1) { + // remove failed lng + var clone = lngs.slice(); + clone.shift(); + options = f.extend(options, { lngs: clone }); + options._origLng = optionWithoutCount._origLng; + delete options.lng; + // retry with fallbacks + translated = translate(ns + o.nsseparator + key, options); + if (translated != o.pluralNotFound) return translated; + } else { + optionWithoutCount.lng = optionWithoutCount._origLng; + delete optionWithoutCount._origLng; + translated = translate(ns + o.nsseparator + key, optionWithoutCount); + + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); + } + } + + if (needsIndefiniteArticle(options)) { + var optionsWithoutIndef = f.extend({}, options); + delete optionsWithoutIndef.indefinite_article; + optionsWithoutIndef.defaultValue = o.indefiniteNotFound; + // If we don't have a count, we want the indefinite, if we do have a count, and needsPlural is false + var indefiniteKey = ns + o.nsseparator + key + (((options.count && !needsPlural(options, lngs[0])) || !options.count) ? o.indefiniteSuffix : ""); + translated = translate(indefiniteKey, optionsWithoutIndef); + if (translated != o.indefiniteNotFound) { + return translated; + } + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + var valueType = Object.prototype.toString.apply(value); + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (valueType === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + if (o.objectTreeKeyHandler && typeof o.objectTreeKeyHandler == 'function') { + value = o.objectTreeKeyHandler(key, value, l, ns, options); + } else { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned an object instead of string.'; + f.log(value); + } + } else if (valueType !== '[object Number]' && valueType !== '[object Function]' && valueType !== '[object RegExp]') { + var copy = (valueType === '[object Array]') ? [] : {}; // apply child translation on a copy + f.each(value, function(m) { + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + }); + value = copy; + } + } + + if (typeof value === 'string' && value.trim() === '' && o.fallbackOnEmpty === true) + value = undefined; + + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length > 0))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found || (found==="" && o.fallbackOnEmpty === false)) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + options.isFallbackLookup = false; + } + + return found; + } + function detectLanguage() { + var detectedLng; + var whitelist = o.lngWhitelist || []; + var userLngChoices = []; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var params = query.split('&'); + for (var i=0; i 0) { + var key = params[i].substring(0,pos); + if (key == o.detectLngQS) { + userLngChoices.push(params[i].substring(pos+1)); + } + } + } + })(); + } + + // get from cookie + if (o.useCookie && typeof document !== 'undefined') { + var c = f.cookie.read(o.cookieName); + if (c) userLngChoices.push(c); + } + + // get from localStorage + if (o.detectLngFromLocalStorage && typeof window !== 'undefined' && window.localStorage) { + userLngChoices.push(f.localStorage.getItem('i18next_lng')); + } + + // get from navigator + if (typeof navigator !== 'undefined') { + if (navigator.languages) { // chrome only; not an array, so can't use .push.apply instead of iterating + for (var i=0;i -1) { + var parts = lng.split('-'); + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } + + if (whitelist.length === 0 || whitelist.indexOf(lng) > -1) { + detectedLng = lng; + break; + } + } + })(); + + //fallback + if (!detectedLng){ + detectedLng = o.fallbackLng[0]; + } + + return detectedLng; + } + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + + /* [code, name, numbers, pluralsType] */ + var _rules = [ + ["ach", "Acholi", [1,2], 1], + ["af", "Afrikaans",[1,2], 2], + ["ak", "Akan", [1,2], 1], + ["am", "Amharic", [1,2], 1], + ["an", "Aragonese",[1,2], 2], + ["ar", "Arabic", [0,1,2,3,11,100],5], + ["arn", "Mapudungun",[1,2], 1], + ["ast", "Asturian", [1,2], 2], + ["ay", "Aymará", [1], 3], + ["az", "Azerbaijani",[1,2],2], + ["be", "Belarusian",[1,2,5],4], + ["bg", "Bulgarian",[1,2], 2], + ["bn", "Bengali", [1,2], 2], + ["bo", "Tibetan", [1], 3], + ["br", "Breton", [1,2], 1], + ["bs", "Bosnian", [1,2,5],4], + ["ca", "Catalan", [1,2], 2], + ["cgg", "Chiga", [1], 3], + ["cs", "Czech", [1,2,5],6], + ["csb", "Kashubian",[1,2,5],7], + ["cy", "Welsh", [1,2,3,8],8], + ["da", "Danish", [1,2], 2], + ["de", "German", [1,2], 2], + ["dev", "Development Fallback", [1,2], 2], + ["dz", "Dzongkha", [1], 3], + ["el", "Greek", [1,2], 2], + ["en", "English", [1,2], 2], + ["eo", "Esperanto",[1,2], 2], + ["es", "Spanish", [1,2], 2], + ["es_ar","Argentinean Spanish", [1,2], 2], + ["et", "Estonian", [1,2], 2], + ["eu", "Basque", [1,2], 2], + ["fa", "Persian", [1], 3], + ["fi", "Finnish", [1,2], 2], + ["fil", "Filipino", [1,2], 1], + ["fo", "Faroese", [1,2], 2], + ["fr", "French", [1,2], 9], + ["fur", "Friulian", [1,2], 2], + ["fy", "Frisian", [1,2], 2], + ["ga", "Irish", [1,2,3,7,11],10], + ["gd", "Scottish Gaelic",[1,2,3,20],11], + ["gl", "Galician", [1,2], 2], + ["gu", "Gujarati", [1,2], 2], + ["gun", "Gun", [1,2], 1], + ["ha", "Hausa", [1,2], 2], + ["he", "Hebrew", [1,2], 2], + ["hi", "Hindi", [1,2], 2], + ["hr", "Croatian", [1,2,5],4], + ["hu", "Hungarian",[1,2], 2], + ["hy", "Armenian", [1,2], 2], + ["ia", "Interlingua",[1,2],2], + ["id", "Indonesian",[1], 3], + ["is", "Icelandic",[1,2], 12], + ["it", "Italian", [1,2], 2], + ["ja", "Japanese", [1], 3], + ["jbo", "Lojban", [1], 3], + ["jv", "Javanese", [0,1], 13], + ["ka", "Georgian", [1], 3], + ["kk", "Kazakh", [1], 3], + ["km", "Khmer", [1], 3], + ["kn", "Kannada", [1,2], 2], + ["ko", "Korean", [1], 3], + ["ku", "Kurdish", [1,2], 2], + ["kw", "Cornish", [1,2,3,4],14], + ["ky", "Kyrgyz", [1], 3], + ["lb", "Letzeburgesch",[1,2],2], + ["ln", "Lingala", [1,2], 1], + ["lo", "Lao", [1], 3], + ["lt", "Lithuanian",[1,2,10],15], + ["lv", "Latvian", [1,2,0],16], + ["mai", "Maithili", [1,2], 2], + ["mfe", "Mauritian Creole",[1,2],1], + ["mg", "Malagasy", [1,2], 1], + ["mi", "Maori", [1,2], 1], + ["mk", "Macedonian",[1,2],17], + ["ml", "Malayalam",[1,2], 2], + ["mn", "Mongolian",[1,2], 2], + ["mnk", "Mandinka", [0,1,2],18], + ["mr", "Marathi", [1,2], 2], + ["ms", "Malay", [1], 3], + ["mt", "Maltese", [1,2,11,20],19], + ["nah", "Nahuatl", [1,2], 2], + ["nap", "Neapolitan",[1,2], 2], + ["nb", "Norwegian Bokmal",[1,2],2], + ["ne", "Nepali", [1,2], 2], + ["nl", "Dutch", [1,2], 2], + ["nn", "Norwegian Nynorsk",[1,2],2], + ["no", "Norwegian",[1,2], 2], + ["nso", "Northern Sotho",[1,2],2], + ["oc", "Occitan", [1,2], 1], + ["or", "Oriya", [2,1], 2], + ["pa", "Punjabi", [1,2], 2], + ["pap", "Papiamento",[1,2], 2], + ["pl", "Polish", [1,2,5],7], + ["pms", "Piemontese",[1,2], 2], + ["ps", "Pashto", [1,2], 2], + ["pt", "Portuguese",[1,2], 2], + ["pt_br","Brazilian Portuguese",[1,2], 2], + ["rm", "Romansh", [1,2], 2], + ["ro", "Romanian", [1,2,20],20], + ["ru", "Russian", [1,2,5],4], + ["sah", "Yakut", [1], 3], + ["sco", "Scots", [1,2], 2], + ["se", "Northern Sami",[1,2], 2], + ["si", "Sinhala", [1,2], 2], + ["sk", "Slovak", [1,2,5],6], + ["sl", "Slovenian",[5,1,2,3],21], + ["so", "Somali", [1,2], 2], + ["son", "Songhay", [1,2], 2], + ["sq", "Albanian", [1,2], 2], + ["sr", "Serbian", [1,2,5],4], + ["su", "Sundanese",[1], 3], + ["sv", "Swedish", [1,2], 2], + ["sw", "Swahili", [1,2], 2], + ["ta", "Tamil", [1,2], 2], + ["te", "Telugu", [1,2], 2], + ["tg", "Tajik", [1,2], 1], + ["th", "Thai", [1], 3], + ["ti", "Tigrinya", [1,2], 1], + ["tk", "Turkmen", [1,2], 2], + ["tr", "Turkish", [1,2], 1], + ["tt", "Tatar", [1], 3], + ["ug", "Uyghur", [1], 3], + ["uk", "Ukrainian",[1,2,5],4], + ["ur", "Urdu", [1,2], 2], + ["uz", "Uzbek", [1,2], 1], + ["vi", "Vietnamese",[1], 3], + ["wa", "Walloon", [1,2], 1], + ["wo", "Wolof", [1], 3], + ["yo", "Yoruba", [1,2], 2], + ["zh", "Chinese", [1], 3] + ]; + + var _rulesPluralsTypes = { + 1: function(n) {return Number(n > 1);}, + 2: function(n) {return Number(n != 1);}, + 3: function(n) {return 0;}, + 4: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 5: function(n) {return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5);}, + 6: function(n) {return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2);}, + 7: function(n) {return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 8: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3);}, + 9: function(n) {return Number(n >= 2);}, + 10: function(n) {return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;}, + 11: function(n) {return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3);}, + 12: function(n) {return Number(n%10!=1 || n%100==11);}, + 13: function(n) {return Number(n !== 0);}, + 14: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3);}, + 15: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 16: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2);}, + 17: function(n) {return Number(n==1 || n%10==1 ? 0 : 1);}, + 18: function(n) {return Number(0 ? 0 : n==1 ? 1 : 2);}, + 19: function(n) {return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3);}, + 20: function(n) {return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2);}, + 21: function(n) {return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }; + + var pluralExtensions = { + + rules: (function () { + var l, rules = {}; + for (l=_rules.length; l-- ;) { + rules[_rules[l][0]] = { + name: _rules[l][1], + numbers: _rules[l][2], + plurals: _rulesPluralsTypes[_rules[l][3]] + } + } + return rules; + }()), + + // you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + needsPlural: function(lng, count) { + var parts = lng.split('-'); + + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[parts[f.getCountyIndexOfLng(lng)]]; + } + + if (ext && ext.numbers.length <= 1) { + return false; + } else { + return this.get(lng, count) !== 1; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i; + if (ext.noAbs) { + i = ext.plurals(c); + } else { + i = ext.plurals(Math.abs(c)); + } + + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[f.getCountyIndexOfLng(lng)], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.hasResourceBundle = hasResourceBundle; + i18n.getResourceBundle = getResourceBundle; + i18n.addResource = addResource; + i18n.addResources = addResources; + i18n.removeResourceBundle = removeResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.applyReplacement = f.applyReplacement; + i18n.options = o; + +})(typeof exports === 'undefined' ? window : exports); \ No newline at end of file diff --git a/libs/i18next/release/i18next-1.8.0.min.js b/libs/i18next/release/i18next-1.8.0.min.js new file mode 100644 index 00000000..50954bd6 --- /dev/null +++ b/libs/i18next/release/i18next-1.8.0.min.js @@ -0,0 +1,5 @@ +// i18next, v1.8.0 +// Copyright (c)2015 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +!function(a){function b(a,b){if(!b||"function"==typeof b)return a;for(var c in b)a[c]=b[c];return a}function c(a,b){for(var d in b)d in a?c(a[d],b[d]):a[d]=b[d];return a}function d(a,b,c){var d,e=0,f=a.length,g=void 0===f||"[object Array]"!==Object.prototype.toString.apply(a)||"function"==typeof a;if(c)if(g){for(d in a)if(b.apply(a[d],c)===!1)break}else for(;f>e&&b.apply(a[e++],c)!==!1;);else if(g){for(d in a)if(b.call(a[d],d,a[d])===!1)break}else for(;f>e&&b.call(a[e],e,a[e++])!==!1;);return a}function e(a){return"string"==typeof a?a.replace(/[&<>"'\/]/g,function(a){return Q[a]}):a}function f(a){var b=function(a){if(window.XMLHttpRequest)return a(null,new XMLHttpRequest);if(window.ActiveXObject)try{return a(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(b){return a(null,new ActiveXObject("Microsoft.XMLHTTP"))}return a(new Error)},c=function(a){if("string"==typeof a)return a;var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")},d=function(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;cd?b+=String.fromCharCode(d):d>127&&2048>d?(b+=String.fromCharCode(d>>6|192),b+=String.fromCharCode(63&d|128)):(b+=String.fromCharCode(d>>12|224),b+=String.fromCharCode(d>>6&63|128),b+=String.fromCharCode(63&d|128))}return b},e=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";a=d(a);var c,e,f,g,h,i,j,k="",l=0;do c=a.charCodeAt(l++),e=a.charCodeAt(l++),f=a.charCodeAt(l++),g=c>>2,h=(3&c)<<4|e>>4,i=(15&e)<<2|f>>6,j=63&f,isNaN(e)?i=j=64:isNaN(f)&&(j=64),k+=b.charAt(g)+b.charAt(h)+b.charAt(i)+b.charAt(j),c=e=f="",g=h=i=j="";while(l1&&(d+=d.indexOf("?")>-1?"&"+k:"?"+k),e.jsonp){var l=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=d,void l.appendChild(m)}}b(function(b,c){if(b)return h(b);c.open(a,d,e.async);for(var f in j)j.hasOwnProperty(f)&&c.setRequestHeader(f,j[f]);c.onreadystatechange=function(){if(4===c.readyState){var a=c.responseText||"";if(!h)return;h(c.status,{text:function(){return a},json:function(){try{return JSON.parse(a)}catch(b){return T.error("Can not parse JSON. URL: "+d),{}}}})}},c.send(i)})},h={authBasic:function(a,b){g.headers.Authorization="Basic "+e(a+":"+b)},connect:function(a,b,c){return g("CONNECT",a,b,c)},del:function(a,b,c){return g("DELETE",a,b,c)},get:function(a,b,c){return g("GET",a,b,c)},head:function(a,b,c){return g("HEAD",a,b,c)},headers:function(a){g.headers=a||{}},isAllowed:function(a,b,c){this.options(a,function(a,d){c(-1!==d.text().indexOf(b))})},options:function(a,b,c){return g("OPTIONS",a,b,c)},patch:function(a,b,c){return g("PATCH",a,b,c)},post:function(a,b,c){return g("POST",a,b,c)},put:function(a,b,c){return g("PUT",a,b,c)},trace:function(a,b,c){return g("TRACE",a,b,c)}},i=a.type?a.type.toLowerCase():"get";h[i](a.url,a,function(b,c){200===b||0===b&&c.text()?a.success(c.json(),b,null):a.error(c.text(),b,null)})}function g(a,b){"function"==typeof a&&(b=a,a={}),a=a||{},T.extend(P,a),delete P.fixLng,P.functions&&(delete P.functions,T.extend(T,a.functions)),"string"==typeof P.ns&&(P.ns={namespaces:[P.ns],defaultNs:P.ns}),"string"==typeof P.fallbackNS&&(P.fallbackNS=[P.fallbackNS]),("string"==typeof P.fallbackLng||"boolean"==typeof P.fallbackLng)&&(P.fallbackLng=[P.fallbackLng]),P.interpolationPrefixEscaped=T.regexEscape(P.interpolationPrefix),P.interpolationSuffixEscaped=T.regexEscape(P.interpolationSuffix),P.lng||(P.lng=T.detectLanguage()),M=T.toLanguages(P.lng),H=M[0],T.log("currentLng set to: "+H),P.useCookie&&T.cookie.read(P.cookieName)!==H&&T.cookie.create(P.cookieName,H,P.cookieExpirationTime,P.cookieDomain),P.detectLngFromLocalStorage&&"undefined"!=typeof document&&window.localStorage&&T.localStorage.setItem("i18next_lng",H);var c=B;a.fixLng&&(c=function(a,b){return b=b||{},b.lng=b.lng||c.lng,B(a,b)},c.lng=H),W.setCurrentLng(H),I&&P.setJqueryExt&&u();var d;if(I&&I.Deferred&&(d=I.Deferred()),!P.resStore){var e=T.toLanguages(P.lng);"string"==typeof P.preload&&(P.preload=[P.preload]);for(var f=0,g=P.preload.length;g>f;f++)for(var h=T.toLanguages(P.preload[f]),i=0,j=h.length;j>i;i++)e.indexOf(h[i])<0&&e.push(h[i]);return J.sync.load(e,P,function(a,e){K=e,N=!0,b&&b(c),d&&d.resolve(c)}),d?d.promise():void 0}return K=P.resStore,N=!0,b&&b(c),d&&d.resolve(c),d?d.promise():void 0}function h(a,b){"string"==typeof a&&(a=[a]);for(var c=0,d=a.length;d>c;c++)P.preload.indexOf(a[c])<0&&P.preload.push(a[c]);return g(b)}function i(a,b,c,d){"string"!=typeof b?(c=b,b=P.ns.defaultNs):P.ns.namespaces.indexOf(b)<0&&P.ns.namespaces.push(b),K[a]=K[a]||{},K[a][b]=K[a][b]||{},d?T.deepExtend(K[a][b],c):T.extend(K[a][b],c),P.useLocalStorage&&O._storeLocal(K)}function j(a,b){"string"!=typeof b&&(b=P.ns.defaultNs),K[a]=K[a]||{};var c=K[a][b]||{},d=!1;for(var e in c)c.hasOwnProperty(e)&&(d=!0);return d}function k(a,b){return"string"!=typeof b&&(b=P.ns.defaultNs),K[a]=K[a]||{},T.extend({},K[a][b])}function l(a,b){"string"!=typeof b&&(b=P.ns.defaultNs),K[a]=K[a]||{},K[a][b]={},P.useLocalStorage&&O._storeLocal(K)}function m(a,b,c,d){"string"!=typeof b?(resource=b,b=P.ns.defaultNs):P.ns.namespaces.indexOf(b)<0&&P.ns.namespaces.push(b),K[a]=K[a]||{},K[a][b]=K[a][b]||{};for(var e=c.split(P.keyseparator),f=0,g=K[a][b];e[f];)f==e.length-1?g[e[f]]=d:(null==g[e[f]]&&(g[e[f]]={}),g=g[e[f]]),f++;P.useLocalStorage&&O._storeLocal(K)}function n(a,b,c){"string"!=typeof b?(resource=b,b=P.ns.defaultNs):P.ns.namespaces.indexOf(b)<0&&P.ns.namespaces.push(b);for(var d in c)"string"==typeof c[d]&&m(a,b,d,c[d])}function o(a){P.ns.defaultNs=a}function p(a,b){q([a],b)}function q(a,b){var c={dynamicLoad:P.dynamicLoad,resGetPath:P.resGetPath,getAsync:P.getAsync,customLoad:P.customLoad,ns:{namespaces:a,defaultNs:""}},d=T.toLanguages(P.lng);"string"==typeof P.preload&&(P.preload=[P.preload]);for(var e=0,f=P.preload.length;f>e;e++)for(var g=T.toLanguages(P.preload[e]),h=0,i=g.length;i>h;h++)d.indexOf(g[h])<0&&d.push(g[h]);for(var j=[],k=0,l=d.length;l>k;k++){var m=!1,n=K[d[k]];if(n)for(var o=0,p=a.length;p>o;o++)n[a[o]]||(m=!0);else m=!0;m&&j.push(d[k])}j.length?J.sync._fetch(j,c,function(c,d){var e=a.length*j.length;T.each(a,function(a,c){P.ns.namespaces.indexOf(c)<0&&P.ns.namespaces.push(c),T.each(j,function(a,f){K[f]=K[f]||{},K[f][c]=d[f][c],e--,0===e&&b&&(P.useLocalStorage&&J.sync._storeLocal(K),b())})})}):b&&b()}function r(a,b,c){return"function"==typeof b?(c=b,b={}):b||(b={}),b.lng=a,g(b,c)}function s(){return H}function t(a){K={},r(H,a)}function u(){function a(a,b,c){if(0!==b.length){var d="text";if(0===b.indexOf("[")){var e=b.split("]");b=e[1],d=e[0].substr(1,e[0].length-1)}b.indexOf(";")===b.length-1&&(b=b.substr(0,b.length-2));var f;if("html"===d)f=P.defaultValueFromContent?I.extend({defaultValue:a.html()},c):c,a.html(I.t(b,f));else if("text"===d)f=P.defaultValueFromContent?I.extend({defaultValue:a.text()},c):c,a.text(I.t(b,f));else if("prepend"===d)f=P.defaultValueFromContent?I.extend({defaultValue:a.html()},c):c,a.prepend(I.t(b,f));else if("append"===d)f=P.defaultValueFromContent?I.extend({defaultValue:a.html()},c):c,a.append(I.t(b,f));else if(0===d.indexOf("data-")){var g=d.substr("data-".length);f=P.defaultValueFromContent?I.extend({defaultValue:a.data(g)},c):c;var h=I.t(b,f);a.data(g,h),a.attr(d,h)}else f=P.defaultValueFromContent?I.extend({defaultValue:a.attr(d)},c):c,a.attr(d,I.t(b,f))}}function b(b,c){var d=b.attr(P.selectorAttr);if(d||"undefined"==typeof d||d===!1||(d=b.text()||b.val()),d){var e=b,f=b.data("i18n-target");if(f&&(e=b.find(f)||b),c||P.useDataAttrOptions!==!0||(c=b.data("i18n-options")),c=c||{},d.indexOf(";")>=0){var g=d.split(";");I.each(g,function(b,d){""!==d&&a(e,d,c)})}else a(e,d,c);P.useDataAttrOptions===!0&&b.data("i18n-options",c)}}I.t=I.t||B,I.fn.i18n=function(a){return this.each(function(){b(I(this),a);var c=I(this).find("["+P.selectorAttr+"]");c.each(function(){b(I(this),a)})})}}function v(a,b,c,d){if(!a)return a;if(d=d||b,a.indexOf(d.interpolationPrefix||P.interpolationPrefix)<0)return a;var e=d.interpolationPrefix?T.regexEscape(d.interpolationPrefix):P.interpolationPrefixEscaped,f=d.interpolationSuffix?T.regexEscape(d.interpolationSuffix):P.interpolationSuffixEscaped,g="HTML"+f,h=b.replace&&"object"==typeof b.replace?b.replace:b;return T.each(h,function(b,h){var i=c?c+P.keyseparator+b:b;"object"==typeof h&&null!==h?a=v(a,h,i,d):d.escapeInterpolation||P.escapeInterpolation?(a=a.replace(new RegExp([e,i,g].join(""),"g"),T.regexReplacementEscape(h)),a=a.replace(new RegExp([e,i,f].join(""),"g"),T.regexReplacementEscape(T.escape(h)))):a=a.replace(new RegExp([e,i,f].join(""),"g"),T.regexReplacementEscape(h))}),a}function w(a,b){var c=",",d="{",e="}",f=T.extend({},b);for(delete f.postProcess;-1!=a.indexOf(P.reusePrefix)&&(L++,!(L>P.maxRecursion));){var g=a.lastIndexOf(P.reusePrefix),h=a.indexOf(P.reuseSuffix,g)+P.reuseSuffix.length,i=a.substring(g,h),j=i.replace(P.reusePrefix,"").replace(P.reuseSuffix,"");if(g>=h)return T.error("there is an missing closing in following translation value",a),"";if(-1!=j.indexOf(c)){var k=j.indexOf(c);if(-1!=j.indexOf(d,k)&&-1!=j.indexOf(e,k)){var l=j.indexOf(d,k),m=j.indexOf(e,l)+e.length;try{f=T.extend(f,JSON.parse(j.substring(l,m))),j=j.substring(0,k)}catch(n){}}}var o=E(j,f);a=a.replace(i,T.regexReplacementEscape(o))}return a}function x(a){return a.context&&("string"==typeof a.context||"number"==typeof a.context)}function y(a){return void 0!==a.count&&"string"!=typeof a.count}function z(a){return void 0!==a.indefinite_article&&"string"!=typeof a.indefinite_article&&a.indefinite_article}function A(a,b){b=b||{};var c=C(a,b),d=F(a,b);return void 0!==d||d===c}function B(a,b){return b=b||{},N?(L=0,E.apply(null,arguments)):(T.log("i18next not finished initialization. you might have called t function before loading resources finished."),b.defaultValue||"")}function C(a,b){return void 0!==b.defaultValue?b.defaultValue:a}function D(){for(var a=[],b=1;b1)for(var d=0;d-1&&(e=c.split(P.nsseparator),i=e[0],c=e[1]),void 0===g&&P.sendMissing&&"function"==typeof P.missingKeyHandler&&(b.lng?P.missingKeyHandler(h[0],i,c,f,h):P.missingKeyHandler(P.lng,i,c,f,h));var j;j="string"==typeof P.postProcess&&""!==P.postProcess?[P.postProcess]:"array"==typeof P.postProcess||"object"==typeof P.postProcess?P.postProcess:[],"string"==typeof b.postProcess&&""!==b.postProcess?j=j.concat([b.postProcess]):("array"==typeof b.postProcess||"object"==typeof b.postProcess)&&(j=j.concat(b.postProcess)),void 0!==g&&j.length&&j.forEach(function(a){X[a]&&(g=X[a](g,c,b))});var k=f;if(f.indexOf(P.nsseparator)>-1&&(e=f.split(P.nsseparator),k=e[1]),k===c&&P.parseMissingKey&&(f=P.parseMissingKey(f)),void 0===g&&(f=v(f,b),f=w(f,b),j.length)){var l=C(c,b);j.forEach(function(a){X[a]&&(g=X[a](l,c,b))})}return void 0!==g?g:f}function F(a,b){b=b||{};var c,d,e=C(a,b),f=M;if(!K)return e;if("cimode"===f[0].toLowerCase())return e;if(b.lngs&&(f=b.lngs),b.lng&&(f=T.toLanguages(b.lng,b.fallbackLng),!K[f[0]])){var g=P.getAsync;P.getAsync=!1,J.sync.load(f,P,function(a,b){T.extend(K,b),P.getAsync=g})}var h=b.ns||P.ns.defaultNs;if(a.indexOf(P.nsseparator)>-1){var i=a.split(P.nsseparator);h=i[0],a=i[1]}if(x(b)){c=T.extend({},b),delete c.context,c.defaultValue=P.contextNotFound;var j=h+P.nsseparator+a+"_"+b.context;if(d=B(j,c),d!=P.contextNotFound)return v(d,{context:b.context})}if(y(b,f[0])){c=T.extend({lngs:[f[0]]},b),delete c.count,c._origLng=c._origLng||c.lng||f[0],delete c.lng,c.defaultValue=P.pluralNotFound;var k;if(W.needsPlural(f[0],b.count)){k=h+P.nsseparator+a+P.pluralSuffix;var l=W.get(f[0],b.count);l>=0?k=k+"_"+l:1===l&&(k=h+P.nsseparator+a)}else k=h+P.nsseparator+a;if(d=B(k,c),d!=P.pluralNotFound)return v(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix});if(!(f.length>1))return c.lng=c._origLng,delete c._origLng,d=B(h+P.nsseparator+a,c),v(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix});var m=f.slice();if(m.shift(),b=T.extend(b,{lngs:m}),b._origLng=c._origLng,delete b.lng,d=B(h+P.nsseparator+a,b),d!=P.pluralNotFound)return d}if(z(b)){var n=T.extend({},b);delete n.indefinite_article,n.defaultValue=P.indefiniteNotFound;var o=h+P.nsseparator+a+(b.count&&!y(b,f[0])||!b.count?P.indefiniteSuffix:"");if(d=B(o,n),d!=P.indefiniteNotFound)return d}for(var p,q=a.split(P.keyseparator),r=0,s=f.length;s>r&&void 0===p;r++){for(var t=f[r],u=0,A=K[t]&&K[t][h];q[u];)A=A&&A[q[u]],u++;if(void 0!==A){var D=Object.prototype.toString.apply(A);if("string"==typeof A)A=v(A,b),A=w(A,b);else if("[object Array]"!==D||P.returnObjectTrees||b.returnObjectTrees){if(null===A&&P.fallbackOnNull===!0)A=void 0;else if(null!==A)if(P.returnObjectTrees||b.returnObjectTrees){if("[object Number]"!==D&&"[object Function]"!==D&&"[object RegExp]"!==D){var G="[object Array]"===D?[]:{};T.each(A,function(c){G[c]=E(h+P.nsseparator+a+P.keyseparator+c,b)}),A=G}}else P.objectTreeKeyHandler&&"function"==typeof P.objectTreeKeyHandler?A=P.objectTreeKeyHandler(a,A,t,h,b):(A="key '"+h+":"+a+" ("+t+")' returned an object instead of string.",T.log(A))}else A=A.join("\n"),A=v(A,b),A=w(A,b);"string"==typeof A&&""===A.trim()&&P.fallbackOnEmpty===!0&&(A=void 0),p=A}}if(void 0===p&&!b.isFallbackLookup&&(P.fallbackToDefaultNS===!0||P.fallbackNS&&P.fallbackNS.length>0)){if(b.isFallbackLookup=!0,P.fallbackNS.length){for(var H=0,I=P.fallbackNS.length;I>H;H++)if(p=F(P.fallbackNS[H]+P.nsseparator+a,b),p||""===p&&P.fallbackOnEmpty===!1){var L=p.indexOf(P.nsseparator)>-1?p.split(P.nsseparator)[1]:p,N=e.indexOf(P.nsseparator)>-1?e.split(P.nsseparator)[1]:e;if(L!==N)break}}else p=F(a,b);b.isFallbackLookup=!1}return p}function G(){var a,b=P.lngWhitelist||[],c=[];if("undefined"!=typeof window&&!function(){for(var a=window.location.search.substring(1),b=a.split("&"),d=0;d0){var f=b[d].substring(0,e);f==P.detectLngQS&&c.push(b[d].substring(e+1))}}}(),P.useCookie&&"undefined"!=typeof document){var d=T.cookie.read(P.cookieName);d&&c.push(d)}if(P.detectLngFromLocalStorage&&"undefined"!=typeof window&&window.localStorage&&c.push(T.localStorage.getItem("i18next_lng")),"undefined"!=typeof navigator){if(navigator.languages)for(var e=0;e-1){var f=e.split("-");e=P.lowerCaseLng?f[0].toLowerCase()+"-"+f[1].toLowerCase():f[0].toLowerCase()+"-"+f[1].toUpperCase()}if(0===b.length||b.indexOf(e)>-1){a=e;break}}}(),a||(a=P.fallbackLng[0]),a}Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>0&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=c;arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d))));for(var e=d>=0?Math.min(d,c-1):c-Math.abs(d);e>=0;e--)if(e in b&&b[e]===a)return e;return-1}),"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")});var H,I=a.jQuery||a.Zepto,J={},K={},L=0,M=[],N=!1,O={};"undefined"!=typeof module&&module.exports?module.exports=J:(I&&(I.i18n=I.i18n||J),a.i18n=a.i18n||J),O={load:function(a,b,c){b.useLocalStorage?O._loadLocal(a,b,function(d,e){for(var f=[],g=0,h=a.length;h>g;g++)e[a[g]]||f.push(a[g]);f.length>0?O._fetch(f,b,function(a,b){T.extend(e,b),O._storeLocal(b),c(null,e)}):c(null,e)}):O._fetch(a,b,function(a,b){c(null,b)})},_loadLocal:function(a,b,c){var d={},e=(new Date).getTime();if(window.localStorage){var f=a.length;T.each(a,function(a,g){var h=T.localStorage.getItem("res_"+g);h&&(h=JSON.parse(h),h.i18nStamp&&h.i18nStamp+b.localStorageExpirationTime>e&&(d[g]=h)),f--,0===f&&c(null,d)})}},_storeLocal:function(a){if(window.localStorage)for(var b in a)a[b].i18nStamp=(new Date).getTime(),T.localStorage.setItem("res_"+b,JSON.stringify(a[b]))},_fetch:function(a,b,c){var d=b.ns,e={};if(b.dynamicLoad){var f=function(a,b){c(null,b)};if("function"==typeof b.customLoad)b.customLoad(a,d.namespaces,b,f);else{var g=v(b.resGetPath,{lng:a.join("+"),ns:d.namespaces.join("+")});T.ajax({url:g,success:function(a){T.log("loaded: "+g),f(null,a)},error:function(a,b,c){T.log("failed loading: "+g),f("failed loading resource.json error: "+c)},dataType:"json",async:b.getAsync})}}else{var h,i=d.namespaces.length*a.length;T.each(d.namespaces,function(d,f){T.each(a,function(a,d){var g=function(a,b){a&&(h=h||[],h.push(a)),e[d]=e[d]||{},e[d][f]=b,i--,0===i&&c(h,e)};"function"==typeof b.customLoad?b.customLoad(d,f,b,g):O._fetchOne(d,f,b,g)})})}},_fetchOne:function(a,b,c,d){var e=v(c.resGetPath,{lng:a,ns:b});T.ajax({url:e,success:function(a){T.log("loaded: "+e),d(null,a)},error:function(a,b,c){if(b&&200==b||a&&a.status&&200==a.status)T.error("There is a typo in: "+e);else if(b&&404==b||a&&a.status&&404==a.status)T.log("Does not exist: "+e);else{var f=b?b:a&&a.status?a.status:null;T.log(f+" when loading "+e)}d(c,{})},dataType:"json",async:c.getAsync})},postMissing:function(a,b,c,d,e){var f={};f[c]=d;var g=[];if("fallback"===P.sendMissingTo&&P.fallbackLng[0]!==!1)for(var h=0;hh;h++)g.push({lng:e[h],url:v(P.resPostPath,{lng:e[h],ns:b})});for(var j=0,k=g.length;k>j;j++){var l=g[j];T.ajax({url:l.url,type:P.sendType,data:f,success:function(){T.log("posted missing key '"+c+"' to: "+l.url);for(var a=c.split("."),e=0,f=K[l.lng][b];a[e];)f=f[a[e]]=e===a.length-1?d:f[a[e]]||{},e++},error:function(){T.log("failed posting missing key '"+c+"' to: "+l.url)},dataType:"json",async:P.postAsync})}},reload:t};var P={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:["dev"],fallbackNS:[],detectLngQS:"setLng",detectLngFromLocalStorage:!1,ns:"translation",fallbackOnNull:!0,fallbackOnEmpty:!1,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",defaultVariables:!1,reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,indefiniteSuffix:"_indefinite",indefiniteNotFound:["indefinite_not_found",Math.random()].join(""),setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",cookieDomain:void 0,objectTreeKeyHandler:void 0,postProcess:void 0,parseMissingKey:void 0,missingKeyHandler:O.postMissing,shortcutFunction:"sprintf"},Q={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},R={create:function(a,b,c,d){var e;if(c){var f=new Date;f.setTime(f.getTime()+60*c*1e3),e="; expires="+f.toGMTString()}else e="";d=d?"domain="+d+";":"",document.cookie=a+"="+b+e+";"+d+"path=/"},read:function(a){for(var b=a+"=",c=document.cookie.split(";"),d=0;d-1){var c=a.split("-");b=P.lowerCaseLng?c[0].toLowerCase()+"-"+c[1].toLowerCase():c[0].toLowerCase()+"-"+c[1].toUpperCase()}else b=P.lowerCaseLng?a.toLowerCase():a;return b}var c=this.log,d=[],e=P.lngWhitelist||!1,f=function(a){!e||e.indexOf(a)>-1?d.push(a):c("rejecting non-whitelisted language: "+a)};if("string"==typeof a&&a.indexOf("-")>-1){var g=a.split("-");"unspecific"!==P.load&&f(b(a)),"current"!==P.load&&f(b(g[this.getCountyIndexOfLng(a)]))}else f(b(a));for(var h=0;h1)},2:function(a){return Number(1!=a)},3:function(){return 0},4:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},5:function(a){return Number(0===a?0:1==a?1:2==a?2:a%100>=3&&10>=a%100?3:a%100>=11?4:5)},6:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)},7:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},8:function(a){return Number(1==a?0:2==a?1:8!=a&&11!=a?2:3)},9:function(a){return Number(a>=2)},10:function(a){return Number(1==a?0:2==a?1:7>a?2:11>a?3:4)},11:function(a){return Number(1==a||11==a?0:2==a||12==a?1:a>2&&20>a?2:3)},12:function(a){return Number(a%10!=1||a%100==11)},13:function(a){return Number(0!==a)},14:function(a){return Number(1==a?0:2==a?1:3==a?2:3)},15:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&(10>a%100||a%100>=20)?1:2)},16:function(a){return Number(a%10==1&&a%100!=11?0:0!==a?1:2)},17:function(a){return Number(1==a||a%10==1?0:1)},18:function(a){return Number(1==a?1:2)},19:function(a){return Number(1==a?0:0===a||a%100>1&&11>a%100?1:a%100>10&&20>a%100?2:3)},20:function(a){return Number(1==a?0:0===a||a%100>0&&20>a%100?1:2)},21:function(a){return Number(a%100==1?1:a%100==2?2:a%100==3||a%100==4?3:0)}},W={rules:function(){var a,b={};for(a=U.length;a--;)b[U[a][0]]={name:U[a][1],numbers:U[a][2],plurals:V[U[a][3]]};return b}(),addRule:function(a,b){W.rules[a]=b},setCurrentLng:function(a){if(!W.currentRule||W.currentRule.lng!==a){var b=a.split("-");W.currentRule={lng:a,rule:W.rules[b[0]]}}},needsPlural:function(a,b){var c,d=a.split("-");return c=W.currentRule&&W.currentRule.lng===a?W.currentRule.rule:W.rules[d[T.getCountyIndexOfLng(a)]],c&&c.numbers.length<=1?!1:1!==this.get(a,b)},get:function(a,b){function c(b,c){var d;if(d=W.currentRule&&W.currentRule.lng===a?W.currentRule.rule:W.rules[b]){var e;e=d.plurals(d.noAbs?c:Math.abs(c));var f=d.numbers[e];return 2===d.numbers.length&&1===d.numbers[0]&&(2===f?f=-1:1===f&&(f=1)),f}return 1===c?"1":"-1"}var d=a.split("-");return c(d[T.getCountyIndexOfLng(a)],b)}},X={},Y=function(a,b){X[a]=b},Z=function(){function a(a){return Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}function b(a,b){for(var c=[];b>0;c[--b]=a);return c.join("")}var c=function(){return c.cache.hasOwnProperty(arguments[0])||(c.cache[arguments[0]]=c.parse(arguments[0])),c.format.call(null,c.cache[arguments[0]],arguments)};return c.format=function(c,d){var e,f,g,h,i,j,k,l=1,m=c.length,n="",o=[];for(f=0;m>f;f++)if(n=a(c[f]),"string"===n)o.push(c[f]);else if("array"===n){if(h=c[f],h[2])for(e=d[l],g=0;g=0?"+"+e:e,j=h[4]?"0"==h[4]?"0":h[4].charAt(1):" ",k=h[6]-String(e).length,i=h[6]?b(j,k):"",o.push(h[5]?e+i:i+e)}return o.join("")},c.cache={},c.parse=function(a){for(var b=a,c=[],d=[],e=0;b;){if(null!==(c=/^[^\x25]+/.exec(b)))d.push(c[0]);else if(null!==(c=/^\x25{2}/.exec(b)))d.push("%");else{if(null===(c=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(b)))throw"[sprintf] huh?";if(c[2]){e|=1;var f=[],g=c[2],h=[];if(null===(h=/^([a-z_][a-z_\d]*)/i.exec(g)))throw"[sprintf] huh?";for(f.push(h[1]);""!==(g=g.substring(h[0].length));)if(null!==(h=/^\.([a-z_][a-z_\d]*)/i.exec(g)))f.push(h[1]);else{if(null===(h=/^\[(\d+)\]/.exec(g)))throw"[sprintf] huh?";f.push(h[1])}c[2]=f}else e|=2;if(3===e)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";d.push(c)}b=b.substring(c[0].length)}return d},c}(),$=function(a,b){return b.unshift(a),Z.apply(null,b)};Y("sprintf",function(a,b,c){return c.sprintf?"[object Array]"===Object.prototype.toString.apply(c.sprintf)?$(a,c.sprintf):"object"==typeof c.sprintf?Z(a,c.sprintf):a:a}),J.init=g,J.setLng=r,J.preload=h,J.addResourceBundle=i,J.hasResourceBundle=j,J.getResourceBundle=k,J.addResource=m,J.addResources=n,J.removeResourceBundle=l,J.loadNamespace=p,J.loadNamespaces=q,J.setDefaultNamespace=o,J.t=B,J.translate=B,J.exists=A,J.detectLanguage=T.detectLanguage,J.pluralExtensions=W,J.sync=O,J.functions=T,J.lng=s,J.addPostProcessor=Y,J.applyReplacement=T.applyReplacement,J.options=P}("undefined"==typeof exports?window:exports); \ No newline at end of file diff --git a/libs/i18next/release/i18next-1.8.0.zip b/libs/i18next/release/i18next-1.8.0.zip new file mode 100644 index 00000000..fcd96611 Binary files /dev/null and b/libs/i18next/release/i18next-1.8.0.zip differ diff --git a/libs/i18next/release/i18next-1.8.1.js b/libs/i18next/release/i18next-1.8.1.js new file mode 100644 index 00000000..e0e1e6f3 --- /dev/null +++ b/libs/i18next/release/i18next-1.8.1.js @@ -0,0 +1,2175 @@ +// i18next, v1.8.1 +// Copyright (c)2015 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function(root) { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + // Add string trim for IE8. + if (typeof String.prototype.trim !== 'function') { + String.prototype.trim = function() { + return this.replace(/^\s+|\s+$/g, ''); + } + } + + var $ = root.jQuery || root.Zepto + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = [] + , initialized = false + , sync = {}; + + + + // Export the i18next object for **CommonJS**. + // If we're not in CommonJS, add `i18n` to the + // global object or to jquery. + if (typeof module !== 'undefined' && module.exports) { + module.exports = i18n; + } else { + if ($) { + $.i18n = $.i18n || i18n; + } + + root.i18n = root.i18n || i18n; + } + sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = f.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + f.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + if ((status && status == 200) || (xhr && xhr.status && xhr.status == 200)) { + // file loaded but invalid json, stop waste time ! + f.error('There is a typo in: ' + url); + } else if ((status && status == 404) || (xhr && xhr.status && xhr.status == 404)) { + f.log('Does not exist: ' + url); + } else { + var theStatus = status ? status : ((xhr && xhr.status) ? xhr.status : null); + f.log(theStatus + ' when loading ' + url); + } + + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback' && o.fallbackLng[0] !== false) { + for (var i = 0; i < o.fallbackLng.length; i++) { + urls.push({lng: o.fallbackLng[i], url: applyReplacement(o.resPostPath, { lng: o.fallbackLng[i], ns: ns })}); + } + } else if (o.sendMissingTo === 'current' || (o.sendMissingTo === 'fallback' && o.fallbackLng[0] === false) ) { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + }, + + reload: reload + }; + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: ['dev'], + fallbackNS: [], + detectLngQS: 'setLng', + detectLngFromLocalStorage: false, + ns: 'translation', + fallbackOnNull: true, + fallbackOnEmpty: false, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + defaultVariables: false, + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + indefiniteSuffix: '_indefinite', + indefiniteNotFound: ['indefinite_not_found', Math.random()].join(''), + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + cookieDomain: undefined, + + objectTreeKeyHandler: undefined, + postProcess: undefined, + parseMissingKey: undefined, + missingKeyHandler: sync.postMissing, + + shortcutFunction: 'sprintf' // or: defaultValue + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _deepExtend(target, source) { + for (var prop in source) + if (prop in target) + _deepExtend(target[prop], source[prop]); + else + target[prop] = source[prop]; + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || Object.prototype.toString.apply(object) !== '[object Array]' || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + try { + return JSON.parse(data) + } catch (e) { + f.error('Can not parse JSON. URL: ' + url); + return {}; + } + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + // file: protocol always gives status code 0, so check for data + if (status === 200 || (status === 0 && data.text())) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes,domain) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + domain = (domain)? "domain="+domain+";" : ""; + document.cookie = name+"="+value+expires+";"+domain+"path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes,domain) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + deepExtend: _deepExtend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : (typeof document !== 'undefined' ? _ajax : function() {}), + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + error: function(str) { + if (typeof console !== "undefined") console.error(str); + }, + getCountyIndexOfLng: function(lng) { + var lng_index = 0; + if (lng === 'nb-NO' || lng === 'nn-NO' || lng === 'nb-no' || lng === 'nn-no') lng_index = 1; + return lng_index; + }, + toLanguages: function(lng) { + var log = this.log; + + function applyCase(l) { + var ret = l; + + if (typeof l === 'string' && l.indexOf('-') > -1) { + var parts = l.split('-'); + + ret = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } else { + ret = o.lowerCaseLng ? l.toLowerCase() : l; + } + + return ret; + } + + var languages = []; + var whitelist = o.lngWhitelist || false; + var addLanguage = function(language){ + //reject langs not whitelisted + if(!whitelist || whitelist.indexOf(language) > -1){ + languages.push(language); + }else{ + log('rejecting non-whitelisted language: ' + language); + } + }; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + if (o.load !== 'unspecific') addLanguage(applyCase(lng)); + if (o.load !== 'current') addLanguage(applyCase(parts[this.getCountyIndexOfLng(lng)])); + } else { + addLanguage(applyCase(lng)); + } + + for (var i = 0; i < o.fallbackLng.length; i++) { + if (languages.indexOf(o.fallbackLng[i]) === -1 && o.fallbackLng[i]) languages.push(applyCase(o.fallbackLng[i])); + } + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + }, + regexReplacementEscape: function(strOrFn) { + if (typeof strOrFn === 'string') { + return strOrFn.replace(/\$/g, "$$$$"); + } else { + return strOrFn; + } + }, + localStorage: { + setItem: function(key, value) { + if (window.localStorage) { + try { + window.localStorage.setItem(key, value); + } catch (e) { + f.log('failed to set value for key "' + key + '" to localStorage.'); + } + } + }, + getItem: function(key, value) { + if (window.localStorage) { + try { + return window.localStorage.getItem(key, value); + } catch (e) { + f.log('failed to get value for key "' + key + '" from localStorage.'); + return undefined; + } + } + } + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + delete o.fixLng; /* passed in each time */ + + // override functions: .log(), .detectLanguage(), etc + if (o.functions) { + delete o.functions; + f.extend(f, options.functions); + } + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // fallback languages + if (typeof o.fallbackLng == 'string' || typeof o.fallbackLng == 'boolean') { + o.fallbackLng = [o.fallbackLng]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + if (o.useCookie && f.cookie.read(o.cookieName) !== currentLng){ //cookie is unset or invalid + f.cookie.create(o.cookieName, currentLng, o.cookieExpirationTime, o.cookieDomain); + } + if (o.detectLngFromLocalStorage && typeof document !== 'undefined' && window.localStorage) { + f.localStorage.setItem('i18next_lng', currentLng); + } + + var lngTranslate = translate; + if (options.fixLng) { + lngTranslate = function(key, options) { + options = options || {}; + options.lng = options.lng || lngTranslate.lng; + return translate(key, options); + }; + lngTranslate.lng = currentLng; + } + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + initialized = true; + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + initialized = true; + + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources, deep) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + if (deep) { + f.deepExtend(resStore[lng][ns], resources); + } else { + f.extend(resStore[lng][ns], resources); + } + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function hasResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + var res = resStore[lng][ns] || {}; + + var hasValues = false; + for(var prop in res) { + if (res.hasOwnProperty(prop)) { + hasValues = true; + } + } + + return hasValues; + } + + function getResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + return f.extend({}, resStore[lng][ns]); + } + + function removeResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = {}; + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function addResource(lng, ns, key, value) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + var keys = key.split(o.keyseparator); + var x = 0; + var node = resStore[lng][ns]; + var origRef = node; + + while (keys[x]) { + if (x == keys.length - 1) + node[keys[x]] = value; + else { + if (node[keys[x]] == null) + node[keys[x]] = {}; + + node = node[keys[x]]; + } + x++; + } + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function addResources(lng, ns, resources) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + for (var m in resources) { + if (typeof resources[m] === 'string') addResource(lng, ns, m, resources[m]); + } + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, options, cb) { + if (typeof options === 'function') { + cb = options; + options = {}; + } else if (!options) { + options = {}; + } + + options.lng = lng; + return init(options, cb); + } + + function lng() { + return currentLng; + } + + function reload(cb) { + resStore = {}; + setLng(currentLng, cb); + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else if (attr === 'prepend') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.prepend($.t(key, optionsToUse)); + } else if (attr === 'append') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.append($.t(key, optionsToUse)); + } else if (attr.indexOf("data-") === 0) { + var dataAttr = attr.substr(("data-").length); + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.data(dataAttr) }, options) : options; + var translated = $.t(key, optionsToUse); + //we change into the data cache + ele.data(dataAttr, translated); + //we change into the dom + ele.attr(attr, translated); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key && typeof key !== 'undefined' && key !== false) key = ele.text() || ele.val(); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + var hash = replacementHash.replace && typeof replacementHash.replace === 'object' ? replacementHash.replace : replacementHash; + f.each(hash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), f.regexReplacementEscape(value)); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(f.escape(value))); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(value)); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + if (index_of_end_of_closing <= index_of_opening) { + f.error('there is an missing closing in following translation value', translated); + return ''; + } + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, f.regexReplacementEscape(translated_token)); + } + return translated; + } + + function hasContext(options) { + return (options.context && (typeof options.context == 'string' || typeof options.context == 'number')); + } + + function needsPlural(options, lng) { + return (options.count !== undefined && typeof options.count != 'string'/* && pluralExtensions.needsPlural(lng, options.count)*/); + } + + function needsIndefiniteArticle(options) { + return (options.indefinite_article !== undefined && typeof options.indefinite_article != 'string' && options.indefinite_article); + } + + function exists(key, options) { + options = options || {}; + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + options = options || {}; + + if (!initialized) { + f.log('i18next not finished initialization. you might have called t function before loading resources finished.') + return options.defaultValue || ''; + }; + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _getDefaultValue(key, options) { + return (options.defaultValue !== undefined) ? options.defaultValue : key; + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(potentialKeys, options) { + if (options && typeof options !== 'object') { + if (o.shortcutFunction === 'sprintf') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else if (o.shortcutFunction === 'defaultValue') { + options = { + defaultValue: options + } + } + } else { + options = options || {}; + } + + if (typeof o.defaultVariables === 'object') { + options = f.extend({}, o.defaultVariables, options); + } + + if (potentialKeys === undefined || potentialKeys === null || potentialKeys === '') return ''; + + if (typeof potentialKeys === 'number') { + potentialKeys = String(potentialKeys); + } + + if (typeof potentialKeys === 'string') { + potentialKeys = [potentialKeys]; + } + + var key = potentialKeys[0]; + + if (potentialKeys.length > 1) { + for (var i = 0; i < potentialKeys.length; i++) { + key = potentialKeys[i]; + if (exists(key, options)) { + break; + } + } + } + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng, options.fallbackLng) : languages + , ns = options.ns || o.ns.defaultNs + , parts; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing && typeof o.missingKeyHandler === 'function') { + if (options.lng) { + o.missingKeyHandler(lngs[0], ns, key, notFound, lngs); + } else { + o.missingKeyHandler(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessorsToApply; + if (typeof o.postProcess === 'string' && o.postProcess !== '') { + postProcessorsToApply = [o.postProcess]; + } else if (typeof o.postProcess === 'array' || typeof o.postProcess === 'object') { + postProcessorsToApply = o.postProcess; + } else { + postProcessorsToApply = []; + } + + if (typeof options.postProcess === 'string' && options.postProcess !== '') { + postProcessorsToApply = postProcessorsToApply.concat([options.postProcess]); + } else if (typeof options.postProcess === 'array' || typeof options.postProcess === 'object') { + postProcessorsToApply = postProcessorsToApply.concat(options.postProcess); + } + + if (found !== undefined && postProcessorsToApply.length) { + postProcessorsToApply.forEach(function(postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + }); + } + + // process notFound if function exists + var splitNotFound = notFound; + if (notFound.indexOf(o.nsseparator) > -1) { + parts = notFound.split(o.nsseparator); + splitNotFound = parts[1]; + } + if (splitNotFound === key && o.parseMissingKey) { + notFound = o.parseMissingKey(notFound); + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessorsToApply.length) { + var val = _getDefaultValue(key, options); + postProcessorsToApply.forEach(function(postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](val, key, options); + } + }); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options) { + options = options || {}; + + var optionWithoutCount, translated + , notFound = _getDefaultValue(key, options) + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + // CI mode + if (lngs[0].toLowerCase() === 'cimode') return notFound; + + // passed in lng + if (options.lngs) lngs = options.lngs; + if (options.lng) { + lngs = f.toLanguages(options.lng, options.fallbackLng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options, lngs[0])) { + optionWithoutCount = f.extend({ lngs: [lngs[0]]}, options); + delete optionWithoutCount.count; + optionWithoutCount._origLng = optionWithoutCount._origLng || optionWithoutCount.lng || lngs[0]; + delete optionWithoutCount.lng; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey; + if (!pluralExtensions.needsPlural(lngs[0], options.count)) { + pluralKey = ns + o.nsseparator + key; + } else { + pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(lngs[0], options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + } + + translated = translate(pluralKey, optionWithoutCount); + + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } else if (lngs.length > 1) { + // remove failed lng + var clone = lngs.slice(); + clone.shift(); + options = f.extend(options, { lngs: clone }); + options._origLng = optionWithoutCount._origLng; + delete options.lng; + // retry with fallbacks + translated = translate(ns + o.nsseparator + key, options); + if (translated != o.pluralNotFound) return translated; + } else { + optionWithoutCount.lng = optionWithoutCount._origLng; + delete optionWithoutCount._origLng; + translated = translate(ns + o.nsseparator + key, optionWithoutCount); + + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); + } + } + + if (needsIndefiniteArticle(options)) { + var optionsWithoutIndef = f.extend({}, options); + delete optionsWithoutIndef.indefinite_article; + optionsWithoutIndef.defaultValue = o.indefiniteNotFound; + // If we don't have a count, we want the indefinite, if we do have a count, and needsPlural is false + var indefiniteKey = ns + o.nsseparator + key + (((options.count && !needsPlural(options, lngs[0])) || !options.count) ? o.indefiniteSuffix : ""); + translated = translate(indefiniteKey, optionsWithoutIndef); + if (translated != o.indefiniteNotFound) { + return translated; + } + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + var valueType = Object.prototype.toString.apply(value); + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (valueType === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + if (o.objectTreeKeyHandler && typeof o.objectTreeKeyHandler == 'function') { + value = o.objectTreeKeyHandler(key, value, l, ns, options); + } else { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned an object instead of string.'; + f.log(value); + } + } else if (valueType !== '[object Number]' && valueType !== '[object Function]' && valueType !== '[object RegExp]') { + var copy = (valueType === '[object Array]') ? [] : {}; // apply child translation on a copy + f.each(value, function(m) { + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + }); + value = copy; + } + } + + if (typeof value === 'string' && value.trim() === '' && o.fallbackOnEmpty === true) + value = undefined; + + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length > 0))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found || (found==="" && o.fallbackOnEmpty === false)) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + options.isFallbackLookup = false; + } + + return found; + } + function detectLanguage() { + var detectedLng; + var whitelist = o.lngWhitelist || []; + var userLngChoices = []; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var params = query.split('&'); + for (var i=0; i 0) { + var key = params[i].substring(0,pos); + if (key == o.detectLngQS) { + userLngChoices.push(params[i].substring(pos+1)); + } + } + } + })(); + } + + // get from cookie + if (o.useCookie && typeof document !== 'undefined') { + var c = f.cookie.read(o.cookieName); + if (c) userLngChoices.push(c); + } + + // get from localStorage + if (o.detectLngFromLocalStorage && typeof window !== 'undefined' && window.localStorage) { + userLngChoices.push(f.localStorage.getItem('i18next_lng')); + } + + // get from navigator + if (typeof navigator !== 'undefined') { + if (navigator.languages) { // chrome only; not an array, so can't use .push.apply instead of iterating + for (var i=0;i -1) { + var parts = lng.split('-'); + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } + + if (whitelist.length === 0 || whitelist.indexOf(lng) > -1) { + detectedLng = lng; + break; + } + } + })(); + + //fallback + if (!detectedLng){ + detectedLng = o.fallbackLng[0]; + } + + return detectedLng; + } + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + + /* [code, name, numbers, pluralsType] */ + var _rules = [ + ["ach", "Acholi", [1,2], 1], + ["af", "Afrikaans",[1,2], 2], + ["ak", "Akan", [1,2], 1], + ["am", "Amharic", [1,2], 1], + ["an", "Aragonese",[1,2], 2], + ["ar", "Arabic", [0,1,2,3,11,100],5], + ["arn", "Mapudungun",[1,2], 1], + ["ast", "Asturian", [1,2], 2], + ["ay", "Aymará", [1], 3], + ["az", "Azerbaijani",[1,2],2], + ["be", "Belarusian",[1,2,5],4], + ["bg", "Bulgarian",[1,2], 2], + ["bn", "Bengali", [1,2], 2], + ["bo", "Tibetan", [1], 3], + ["br", "Breton", [1,2], 1], + ["bs", "Bosnian", [1,2,5],4], + ["ca", "Catalan", [1,2], 2], + ["cgg", "Chiga", [1], 3], + ["cs", "Czech", [1,2,5],6], + ["csb", "Kashubian",[1,2,5],7], + ["cy", "Welsh", [1,2,3,8],8], + ["da", "Danish", [1,2], 2], + ["de", "German", [1,2], 2], + ["dev", "Development Fallback", [1,2], 2], + ["dz", "Dzongkha", [1], 3], + ["el", "Greek", [1,2], 2], + ["en", "English", [1,2], 2], + ["eo", "Esperanto",[1,2], 2], + ["es", "Spanish", [1,2], 2], + ["es_ar","Argentinean Spanish", [1,2], 2], + ["et", "Estonian", [1,2], 2], + ["eu", "Basque", [1,2], 2], + ["fa", "Persian", [1], 3], + ["fi", "Finnish", [1,2], 2], + ["fil", "Filipino", [1,2], 1], + ["fo", "Faroese", [1,2], 2], + ["fr", "French", [1,2], 9], + ["fur", "Friulian", [1,2], 2], + ["fy", "Frisian", [1,2], 2], + ["ga", "Irish", [1,2,3,7,11],10], + ["gd", "Scottish Gaelic",[1,2,3,20],11], + ["gl", "Galician", [1,2], 2], + ["gu", "Gujarati", [1,2], 2], + ["gun", "Gun", [1,2], 1], + ["ha", "Hausa", [1,2], 2], + ["he", "Hebrew", [1,2], 2], + ["hi", "Hindi", [1,2], 2], + ["hr", "Croatian", [1,2,5],4], + ["hu", "Hungarian",[1,2], 2], + ["hy", "Armenian", [1,2], 2], + ["ia", "Interlingua",[1,2],2], + ["id", "Indonesian",[1], 3], + ["is", "Icelandic",[1,2], 12], + ["it", "Italian", [1,2], 2], + ["ja", "Japanese", [1], 3], + ["jbo", "Lojban", [1], 3], + ["jv", "Javanese", [0,1], 13], + ["ka", "Georgian", [1], 3], + ["kk", "Kazakh", [1], 3], + ["km", "Khmer", [1], 3], + ["kn", "Kannada", [1,2], 2], + ["ko", "Korean", [1], 3], + ["ku", "Kurdish", [1,2], 2], + ["kw", "Cornish", [1,2,3,4],14], + ["ky", "Kyrgyz", [1], 3], + ["lb", "Letzeburgesch",[1,2],2], + ["ln", "Lingala", [1,2], 1], + ["lo", "Lao", [1], 3], + ["lt", "Lithuanian",[1,2,10],15], + ["lv", "Latvian", [1,2,0],16], + ["mai", "Maithili", [1,2], 2], + ["mfe", "Mauritian Creole",[1,2],1], + ["mg", "Malagasy", [1,2], 1], + ["mi", "Maori", [1,2], 1], + ["mk", "Macedonian",[1,2],17], + ["ml", "Malayalam",[1,2], 2], + ["mn", "Mongolian",[1,2], 2], + ["mnk", "Mandinka", [0,1,2],18], + ["mr", "Marathi", [1,2], 2], + ["ms", "Malay", [1], 3], + ["mt", "Maltese", [1,2,11,20],19], + ["nah", "Nahuatl", [1,2], 2], + ["nap", "Neapolitan",[1,2], 2], + ["nb", "Norwegian Bokmal",[1,2],2], + ["ne", "Nepali", [1,2], 2], + ["nl", "Dutch", [1,2], 2], + ["nn", "Norwegian Nynorsk",[1,2],2], + ["no", "Norwegian",[1,2], 2], + ["nso", "Northern Sotho",[1,2],2], + ["oc", "Occitan", [1,2], 1], + ["or", "Oriya", [2,1], 2], + ["pa", "Punjabi", [1,2], 2], + ["pap", "Papiamento",[1,2], 2], + ["pl", "Polish", [1,2,5],7], + ["pms", "Piemontese",[1,2], 2], + ["ps", "Pashto", [1,2], 2], + ["pt", "Portuguese",[1,2], 2], + ["pt_br","Brazilian Portuguese",[1,2], 2], + ["rm", "Romansh", [1,2], 2], + ["ro", "Romanian", [1,2,20],20], + ["ru", "Russian", [1,2,5],4], + ["sah", "Yakut", [1], 3], + ["sco", "Scots", [1,2], 2], + ["se", "Northern Sami",[1,2], 2], + ["si", "Sinhala", [1,2], 2], + ["sk", "Slovak", [1,2,5],6], + ["sl", "Slovenian",[5,1,2,3],21], + ["so", "Somali", [1,2], 2], + ["son", "Songhay", [1,2], 2], + ["sq", "Albanian", [1,2], 2], + ["sr", "Serbian", [1,2,5],4], + ["su", "Sundanese",[1], 3], + ["sv", "Swedish", [1,2], 2], + ["sw", "Swahili", [1,2], 2], + ["ta", "Tamil", [1,2], 2], + ["te", "Telugu", [1,2], 2], + ["tg", "Tajik", [1,2], 1], + ["th", "Thai", [1], 3], + ["ti", "Tigrinya", [1,2], 1], + ["tk", "Turkmen", [1,2], 2], + ["tr", "Turkish", [1,2], 1], + ["tt", "Tatar", [1], 3], + ["ug", "Uyghur", [1], 3], + ["uk", "Ukrainian",[1,2,5],4], + ["ur", "Urdu", [1,2], 2], + ["uz", "Uzbek", [1,2], 1], + ["vi", "Vietnamese",[1], 3], + ["wa", "Walloon", [1,2], 1], + ["wo", "Wolof", [1], 3], + ["yo", "Yoruba", [1,2], 2], + ["zh", "Chinese", [1], 3] + ]; + + var _rulesPluralsTypes = { + 1: function(n) {return Number(n > 1);}, + 2: function(n) {return Number(n != 1);}, + 3: function(n) {return 0;}, + 4: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 5: function(n) {return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5);}, + 6: function(n) {return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2);}, + 7: function(n) {return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 8: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3);}, + 9: function(n) {return Number(n >= 2);}, + 10: function(n) {return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;}, + 11: function(n) {return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3);}, + 12: function(n) {return Number(n%10!=1 || n%100==11);}, + 13: function(n) {return Number(n !== 0);}, + 14: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3);}, + 15: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 16: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2);}, + 17: function(n) {return Number(n==1 || n%10==1 ? 0 : 1);}, + 18: function(n) {return Number(0 ? 0 : n==1 ? 1 : 2);}, + 19: function(n) {return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3);}, + 20: function(n) {return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2);}, + 21: function(n) {return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }; + + var pluralExtensions = { + + rules: (function () { + var l, rules = {}; + for (l=_rules.length; l-- ;) { + rules[_rules[l][0]] = { + name: _rules[l][1], + numbers: _rules[l][2], + plurals: _rulesPluralsTypes[_rules[l][3]] + } + } + return rules; + }()), + + // you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + needsPlural: function(lng, count) { + var parts = lng.split('-'); + + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[parts[f.getCountyIndexOfLng(lng)]]; + } + + if (ext && ext.numbers.length <= 1) { + return false; + } else { + return this.get(lng, count) !== 1; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i; + if (ext.noAbs) { + i = ext.plurals(c); + } else { + i = ext.plurals(Math.abs(c)); + } + + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[f.getCountyIndexOfLng(lng)], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.hasResourceBundle = hasResourceBundle; + i18n.getResourceBundle = getResourceBundle; + i18n.addResource = addResource; + i18n.addResources = addResources; + i18n.removeResourceBundle = removeResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.applyReplacement = f.applyReplacement; + i18n.options = o; + +})(typeof exports === 'undefined' ? window : exports); \ No newline at end of file diff --git a/libs/i18next/release/i18next-1.8.1.min.js b/libs/i18next/release/i18next-1.8.1.min.js new file mode 100644 index 00000000..3ba215dd --- /dev/null +++ b/libs/i18next/release/i18next-1.8.1.min.js @@ -0,0 +1,5 @@ +// i18next, v1.8.1 +// Copyright (c)2015 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +!function(a){function b(a,b){if(!b||"function"==typeof b)return a;for(var c in b)a[c]=b[c];return a}function c(a,b){for(var d in b)d in a?c(a[d],b[d]):a[d]=b[d];return a}function d(a,b,c){var d,e=0,f=a.length,g=void 0===f||"[object Array]"!==Object.prototype.toString.apply(a)||"function"==typeof a;if(c)if(g){for(d in a)if(b.apply(a[d],c)===!1)break}else for(;f>e&&b.apply(a[e++],c)!==!1;);else if(g){for(d in a)if(b.call(a[d],d,a[d])===!1)break}else for(;f>e&&b.call(a[e],e,a[e++])!==!1;);return a}function e(a){return"string"==typeof a?a.replace(/[&<>"'\/]/g,function(a){return Q[a]}):a}function f(a){var b=function(a){if(window.XMLHttpRequest)return a(null,new XMLHttpRequest);if(window.ActiveXObject)try{return a(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(b){return a(null,new ActiveXObject("Microsoft.XMLHTTP"))}return a(new Error)},c=function(a){if("string"==typeof a)return a;var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")},d=function(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;cd?b+=String.fromCharCode(d):d>127&&2048>d?(b+=String.fromCharCode(d>>6|192),b+=String.fromCharCode(63&d|128)):(b+=String.fromCharCode(d>>12|224),b+=String.fromCharCode(d>>6&63|128),b+=String.fromCharCode(63&d|128))}return b},e=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";a=d(a);var c,e,f,g,h,i,j,k="",l=0;do c=a.charCodeAt(l++),e=a.charCodeAt(l++),f=a.charCodeAt(l++),g=c>>2,h=(3&c)<<4|e>>4,i=(15&e)<<2|f>>6,j=63&f,isNaN(e)?i=j=64:isNaN(f)&&(j=64),k+=b.charAt(g)+b.charAt(h)+b.charAt(i)+b.charAt(j),c=e=f="",g=h=i=j="";while(l1&&(d+=d.indexOf("?")>-1?"&"+k:"?"+k),e.jsonp){var l=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=d,void l.appendChild(m)}}b(function(b,c){if(b)return h(b);c.open(a,d,e.async);for(var f in j)j.hasOwnProperty(f)&&c.setRequestHeader(f,j[f]);c.onreadystatechange=function(){if(4===c.readyState){var a=c.responseText||"";if(!h)return;h(c.status,{text:function(){return a},json:function(){try{return JSON.parse(a)}catch(b){return T.error("Can not parse JSON. URL: "+d),{}}}})}},c.send(i)})},h={authBasic:function(a,b){g.headers.Authorization="Basic "+e(a+":"+b)},connect:function(a,b,c){return g("CONNECT",a,b,c)},del:function(a,b,c){return g("DELETE",a,b,c)},get:function(a,b,c){return g("GET",a,b,c)},head:function(a,b,c){return g("HEAD",a,b,c)},headers:function(a){g.headers=a||{}},isAllowed:function(a,b,c){this.options(a,function(a,d){c(-1!==d.text().indexOf(b))})},options:function(a,b,c){return g("OPTIONS",a,b,c)},patch:function(a,b,c){return g("PATCH",a,b,c)},post:function(a,b,c){return g("POST",a,b,c)},put:function(a,b,c){return g("PUT",a,b,c)},trace:function(a,b,c){return g("TRACE",a,b,c)}},i=a.type?a.type.toLowerCase():"get";h[i](a.url,a,function(b,c){200===b||0===b&&c.text()?a.success(c.json(),b,null):a.error(c.text(),b,null)})}function g(a,b){"function"==typeof a&&(b=a,a={}),a=a||{},T.extend(P,a),delete P.fixLng,P.functions&&(delete P.functions,T.extend(T,a.functions)),"string"==typeof P.ns&&(P.ns={namespaces:[P.ns],defaultNs:P.ns}),"string"==typeof P.fallbackNS&&(P.fallbackNS=[P.fallbackNS]),("string"==typeof P.fallbackLng||"boolean"==typeof P.fallbackLng)&&(P.fallbackLng=[P.fallbackLng]),P.interpolationPrefixEscaped=T.regexEscape(P.interpolationPrefix),P.interpolationSuffixEscaped=T.regexEscape(P.interpolationSuffix),P.lng||(P.lng=T.detectLanguage()),M=T.toLanguages(P.lng),H=M[0],T.log("currentLng set to: "+H),P.useCookie&&T.cookie.read(P.cookieName)!==H&&T.cookie.create(P.cookieName,H,P.cookieExpirationTime,P.cookieDomain),P.detectLngFromLocalStorage&&"undefined"!=typeof document&&window.localStorage&&T.localStorage.setItem("i18next_lng",H);var c=B;a.fixLng&&(c=function(a,b){return b=b||{},b.lng=b.lng||c.lng,B(a,b)},c.lng=H),W.setCurrentLng(H),I&&P.setJqueryExt&&u();var d;if(I&&I.Deferred&&(d=I.Deferred()),!P.resStore){var e=T.toLanguages(P.lng);"string"==typeof P.preload&&(P.preload=[P.preload]);for(var f=0,g=P.preload.length;g>f;f++)for(var h=T.toLanguages(P.preload[f]),i=0,j=h.length;j>i;i++)e.indexOf(h[i])<0&&e.push(h[i]);return J.sync.load(e,P,function(a,e){K=e,N=!0,b&&b(c),d&&d.resolve(c)}),d?d.promise():void 0}return K=P.resStore,N=!0,b&&b(c),d&&d.resolve(c),d?d.promise():void 0}function h(a,b){"string"==typeof a&&(a=[a]);for(var c=0,d=a.length;d>c;c++)P.preload.indexOf(a[c])<0&&P.preload.push(a[c]);return g(b)}function i(a,b,c,d){"string"!=typeof b?(c=b,b=P.ns.defaultNs):P.ns.namespaces.indexOf(b)<0&&P.ns.namespaces.push(b),K[a]=K[a]||{},K[a][b]=K[a][b]||{},d?T.deepExtend(K[a][b],c):T.extend(K[a][b],c),P.useLocalStorage&&O._storeLocal(K)}function j(a,b){"string"!=typeof b&&(b=P.ns.defaultNs),K[a]=K[a]||{};var c=K[a][b]||{},d=!1;for(var e in c)c.hasOwnProperty(e)&&(d=!0);return d}function k(a,b){return"string"!=typeof b&&(b=P.ns.defaultNs),K[a]=K[a]||{},T.extend({},K[a][b])}function l(a,b){"string"!=typeof b&&(b=P.ns.defaultNs),K[a]=K[a]||{},K[a][b]={},P.useLocalStorage&&O._storeLocal(K)}function m(a,b,c,d){"string"!=typeof b?(resource=b,b=P.ns.defaultNs):P.ns.namespaces.indexOf(b)<0&&P.ns.namespaces.push(b),K[a]=K[a]||{},K[a][b]=K[a][b]||{};for(var e=c.split(P.keyseparator),f=0,g=K[a][b];e[f];)f==e.length-1?g[e[f]]=d:(null==g[e[f]]&&(g[e[f]]={}),g=g[e[f]]),f++;P.useLocalStorage&&O._storeLocal(K)}function n(a,b,c){"string"!=typeof b?(resource=b,b=P.ns.defaultNs):P.ns.namespaces.indexOf(b)<0&&P.ns.namespaces.push(b);for(var d in c)"string"==typeof c[d]&&m(a,b,d,c[d])}function o(a){P.ns.defaultNs=a}function p(a,b){q([a],b)}function q(a,b){var c={dynamicLoad:P.dynamicLoad,resGetPath:P.resGetPath,getAsync:P.getAsync,customLoad:P.customLoad,ns:{namespaces:a,defaultNs:""}},d=T.toLanguages(P.lng);"string"==typeof P.preload&&(P.preload=[P.preload]);for(var e=0,f=P.preload.length;f>e;e++)for(var g=T.toLanguages(P.preload[e]),h=0,i=g.length;i>h;h++)d.indexOf(g[h])<0&&d.push(g[h]);for(var j=[],k=0,l=d.length;l>k;k++){var m=!1,n=K[d[k]];if(n)for(var o=0,p=a.length;p>o;o++)n[a[o]]||(m=!0);else m=!0;m&&j.push(d[k])}j.length?J.sync._fetch(j,c,function(c,d){var e=a.length*j.length;T.each(a,function(a,c){P.ns.namespaces.indexOf(c)<0&&P.ns.namespaces.push(c),T.each(j,function(a,f){K[f]=K[f]||{},K[f][c]=d[f][c],e--,0===e&&b&&(P.useLocalStorage&&J.sync._storeLocal(K),b())})})}):b&&b()}function r(a,b,c){return"function"==typeof b?(c=b,b={}):b||(b={}),b.lng=a,g(b,c)}function s(){return H}function t(a){K={},r(H,a)}function u(){function a(a,b,c){if(0!==b.length){var d="text";if(0===b.indexOf("[")){var e=b.split("]");b=e[1],d=e[0].substr(1,e[0].length-1)}b.indexOf(";")===b.length-1&&(b=b.substr(0,b.length-2));var f;if("html"===d)f=P.defaultValueFromContent?I.extend({defaultValue:a.html()},c):c,a.html(I.t(b,f));else if("text"===d)f=P.defaultValueFromContent?I.extend({defaultValue:a.text()},c):c,a.text(I.t(b,f));else if("prepend"===d)f=P.defaultValueFromContent?I.extend({defaultValue:a.html()},c):c,a.prepend(I.t(b,f));else if("append"===d)f=P.defaultValueFromContent?I.extend({defaultValue:a.html()},c):c,a.append(I.t(b,f));else if(0===d.indexOf("data-")){var g=d.substr("data-".length);f=P.defaultValueFromContent?I.extend({defaultValue:a.data(g)},c):c;var h=I.t(b,f);a.data(g,h),a.attr(d,h)}else f=P.defaultValueFromContent?I.extend({defaultValue:a.attr(d)},c):c,a.attr(d,I.t(b,f))}}function b(b,c){var d=b.attr(P.selectorAttr);if(d||"undefined"==typeof d||d===!1||(d=b.text()||b.val()),d){var e=b,f=b.data("i18n-target");if(f&&(e=b.find(f)||b),c||P.useDataAttrOptions!==!0||(c=b.data("i18n-options")),c=c||{},d.indexOf(";")>=0){var g=d.split(";");I.each(g,function(b,d){""!==d&&a(e,d,c)})}else a(e,d,c);P.useDataAttrOptions===!0&&b.data("i18n-options",c)}}I.t=I.t||B,I.fn.i18n=function(a){return this.each(function(){b(I(this),a);var c=I(this).find("["+P.selectorAttr+"]");c.each(function(){b(I(this),a)})})}}function v(a,b,c,d){if(!a)return a;if(d=d||b,a.indexOf(d.interpolationPrefix||P.interpolationPrefix)<0)return a;var e=d.interpolationPrefix?T.regexEscape(d.interpolationPrefix):P.interpolationPrefixEscaped,f=d.interpolationSuffix?T.regexEscape(d.interpolationSuffix):P.interpolationSuffixEscaped,g="HTML"+f,h=b.replace&&"object"==typeof b.replace?b.replace:b;return T.each(h,function(b,h){var i=c?c+P.keyseparator+b:b;"object"==typeof h&&null!==h?a=v(a,h,i,d):d.escapeInterpolation||P.escapeInterpolation?(a=a.replace(new RegExp([e,i,g].join(""),"g"),T.regexReplacementEscape(h)),a=a.replace(new RegExp([e,i,f].join(""),"g"),T.regexReplacementEscape(T.escape(h)))):a=a.replace(new RegExp([e,i,f].join(""),"g"),T.regexReplacementEscape(h))}),a}function w(a,b){var c=",",d="{",e="}",f=T.extend({},b);for(delete f.postProcess;-1!=a.indexOf(P.reusePrefix)&&(L++,!(L>P.maxRecursion));){var g=a.lastIndexOf(P.reusePrefix),h=a.indexOf(P.reuseSuffix,g)+P.reuseSuffix.length,i=a.substring(g,h),j=i.replace(P.reusePrefix,"").replace(P.reuseSuffix,"");if(g>=h)return T.error("there is an missing closing in following translation value",a),"";if(-1!=j.indexOf(c)){var k=j.indexOf(c);if(-1!=j.indexOf(d,k)&&-1!=j.indexOf(e,k)){var l=j.indexOf(d,k),m=j.indexOf(e,l)+e.length;try{f=T.extend(f,JSON.parse(j.substring(l,m))),j=j.substring(0,k)}catch(n){}}}var o=E(j,f);a=a.replace(i,T.regexReplacementEscape(o))}return a}function x(a){return a.context&&("string"==typeof a.context||"number"==typeof a.context)}function y(a){return void 0!==a.count&&"string"!=typeof a.count}function z(a){return void 0!==a.indefinite_article&&"string"!=typeof a.indefinite_article&&a.indefinite_article}function A(a,b){b=b||{};var c=C(a,b),d=F(a,b);return void 0!==d||d===c}function B(a,b){return b=b||{},N?(L=0,E.apply(null,arguments)):(T.log("i18next not finished initialization. you might have called t function before loading resources finished."),b.defaultValue||"")}function C(a,b){return void 0!==b.defaultValue?b.defaultValue:a}function D(){for(var a=[],b=1;b1)for(var d=0;d-1&&(e=c.split(P.nsseparator),i=e[0],c=e[1]),void 0===g&&P.sendMissing&&"function"==typeof P.missingKeyHandler&&(b.lng?P.missingKeyHandler(h[0],i,c,f,h):P.missingKeyHandler(P.lng,i,c,f,h));var j;j="string"==typeof P.postProcess&&""!==P.postProcess?[P.postProcess]:"array"==typeof P.postProcess||"object"==typeof P.postProcess?P.postProcess:[],"string"==typeof b.postProcess&&""!==b.postProcess?j=j.concat([b.postProcess]):("array"==typeof b.postProcess||"object"==typeof b.postProcess)&&(j=j.concat(b.postProcess)),void 0!==g&&j.length&&j.forEach(function(a){X[a]&&(g=X[a](g,c,b))});var k=f;if(f.indexOf(P.nsseparator)>-1&&(e=f.split(P.nsseparator),k=e[1]),k===c&&P.parseMissingKey&&(f=P.parseMissingKey(f)),void 0===g&&(f=v(f,b),f=w(f,b),j.length)){var l=C(c,b);j.forEach(function(a){X[a]&&(g=X[a](l,c,b))})}return void 0!==g?g:f}function F(a,b){b=b||{};var c,d,e=C(a,b),f=M;if(!K)return e;if("cimode"===f[0].toLowerCase())return e;if(b.lngs&&(f=b.lngs),b.lng&&(f=T.toLanguages(b.lng,b.fallbackLng),!K[f[0]])){var g=P.getAsync;P.getAsync=!1,J.sync.load(f,P,function(a,b){T.extend(K,b),P.getAsync=g})}var h=b.ns||P.ns.defaultNs;if(a.indexOf(P.nsseparator)>-1){var i=a.split(P.nsseparator);h=i[0],a=i[1]}if(x(b)){c=T.extend({},b),delete c.context,c.defaultValue=P.contextNotFound;var j=h+P.nsseparator+a+"_"+b.context;if(d=B(j,c),d!=P.contextNotFound)return v(d,{context:b.context})}if(y(b,f[0])){c=T.extend({lngs:[f[0]]},b),delete c.count,c._origLng=c._origLng||c.lng||f[0],delete c.lng,c.defaultValue=P.pluralNotFound;var k;if(W.needsPlural(f[0],b.count)){k=h+P.nsseparator+a+P.pluralSuffix;var l=W.get(f[0],b.count);l>=0?k=k+"_"+l:1===l&&(k=h+P.nsseparator+a)}else k=h+P.nsseparator+a;if(d=B(k,c),d!=P.pluralNotFound)return v(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix});if(!(f.length>1))return c.lng=c._origLng,delete c._origLng,d=B(h+P.nsseparator+a,c),v(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix});var m=f.slice();if(m.shift(),b=T.extend(b,{lngs:m}),b._origLng=c._origLng,delete b.lng,d=B(h+P.nsseparator+a,b),d!=P.pluralNotFound)return d}if(z(b)){var n=T.extend({},b);delete n.indefinite_article,n.defaultValue=P.indefiniteNotFound;var o=h+P.nsseparator+a+(b.count&&!y(b,f[0])||!b.count?P.indefiniteSuffix:"");if(d=B(o,n),d!=P.indefiniteNotFound)return d}for(var p,q=a.split(P.keyseparator),r=0,s=f.length;s>r&&void 0===p;r++){for(var t=f[r],u=0,A=K[t]&&K[t][h];q[u];)A=A&&A[q[u]],u++;if(void 0!==A){var D=Object.prototype.toString.apply(A);if("string"==typeof A)A=v(A,b),A=w(A,b);else if("[object Array]"!==D||P.returnObjectTrees||b.returnObjectTrees){if(null===A&&P.fallbackOnNull===!0)A=void 0;else if(null!==A)if(P.returnObjectTrees||b.returnObjectTrees){if("[object Number]"!==D&&"[object Function]"!==D&&"[object RegExp]"!==D){var G="[object Array]"===D?[]:{};T.each(A,function(c){G[c]=E(h+P.nsseparator+a+P.keyseparator+c,b)}),A=G}}else P.objectTreeKeyHandler&&"function"==typeof P.objectTreeKeyHandler?A=P.objectTreeKeyHandler(a,A,t,h,b):(A="key '"+h+":"+a+" ("+t+")' returned an object instead of string.",T.log(A))}else A=A.join("\n"),A=v(A,b),A=w(A,b);"string"==typeof A&&""===A.trim()&&P.fallbackOnEmpty===!0&&(A=void 0),p=A}}if(void 0===p&&!b.isFallbackLookup&&(P.fallbackToDefaultNS===!0||P.fallbackNS&&P.fallbackNS.length>0)){if(b.isFallbackLookup=!0,P.fallbackNS.length){for(var H=0,I=P.fallbackNS.length;I>H;H++)if(p=F(P.fallbackNS[H]+P.nsseparator+a,b),p||""===p&&P.fallbackOnEmpty===!1){var L=p.indexOf(P.nsseparator)>-1?p.split(P.nsseparator)[1]:p,N=e.indexOf(P.nsseparator)>-1?e.split(P.nsseparator)[1]:e;if(L!==N)break}}else p=F(a,b);b.isFallbackLookup=!1}return p}function G(){var a,b=P.lngWhitelist||[],c=[];if("undefined"!=typeof window&&!function(){for(var a=window.location.search.substring(1),b=a.split("&"),d=0;d0){var f=b[d].substring(0,e);f==P.detectLngQS&&c.push(b[d].substring(e+1))}}}(),P.useCookie&&"undefined"!=typeof document){var d=T.cookie.read(P.cookieName);d&&c.push(d)}if(P.detectLngFromLocalStorage&&"undefined"!=typeof window&&window.localStorage&&c.push(T.localStorage.getItem("i18next_lng")),"undefined"!=typeof navigator){if(navigator.languages)for(var e=0;e-1){var f=e.split("-");e=P.lowerCaseLng?f[0].toLowerCase()+"-"+f[1].toLowerCase():f[0].toLowerCase()+"-"+f[1].toUpperCase()}if(0===b.length||b.indexOf(e)>-1){a=e;break}}}(),a||(a=P.fallbackLng[0]),a}Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>0&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=c;arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d))));for(var e=d>=0?Math.min(d,c-1):c-Math.abs(d);e>=0;e--)if(e in b&&b[e]===a)return e;return-1}),"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")});var H,I=a.jQuery||a.Zepto,J={},K={},L=0,M=[],N=!1,O={};"undefined"!=typeof module&&module.exports?module.exports=J:(I&&(I.i18n=I.i18n||J),a.i18n=a.i18n||J),O={load:function(a,b,c){b.useLocalStorage?O._loadLocal(a,b,function(d,e){for(var f=[],g=0,h=a.length;h>g;g++)e[a[g]]||f.push(a[g]);f.length>0?O._fetch(f,b,function(a,b){T.extend(e,b),O._storeLocal(b),c(null,e)}):c(null,e)}):O._fetch(a,b,function(a,b){c(null,b)})},_loadLocal:function(a,b,c){var d={},e=(new Date).getTime();if(window.localStorage){var f=a.length;T.each(a,function(a,g){var h=T.localStorage.getItem("res_"+g);h&&(h=JSON.parse(h),h.i18nStamp&&h.i18nStamp+b.localStorageExpirationTime>e&&(d[g]=h)),f--,0===f&&c(null,d)})}},_storeLocal:function(a){if(window.localStorage)for(var b in a)a[b].i18nStamp=(new Date).getTime(),T.localStorage.setItem("res_"+b,JSON.stringify(a[b]))},_fetch:function(a,b,c){var d=b.ns,e={};if(b.dynamicLoad){var f=function(a,b){c(null,b)};if("function"==typeof b.customLoad)b.customLoad(a,d.namespaces,b,f);else{var g=v(b.resGetPath,{lng:a.join("+"),ns:d.namespaces.join("+")});T.ajax({url:g,success:function(a){T.log("loaded: "+g),f(null,a)},error:function(a,b,c){T.log("failed loading: "+g),f("failed loading resource.json error: "+c)},dataType:"json",async:b.getAsync})}}else{var h,i=d.namespaces.length*a.length;T.each(d.namespaces,function(d,f){T.each(a,function(a,d){var g=function(a,b){a&&(h=h||[],h.push(a)),e[d]=e[d]||{},e[d][f]=b,i--,0===i&&c(h,e)};"function"==typeof b.customLoad?b.customLoad(d,f,b,g):O._fetchOne(d,f,b,g)})})}},_fetchOne:function(a,b,c,d){var e=v(c.resGetPath,{lng:a,ns:b});T.ajax({url:e,success:function(a){T.log("loaded: "+e),d(null,a)},error:function(a,b,c){if(b&&200==b||a&&a.status&&200==a.status)T.error("There is a typo in: "+e);else if(b&&404==b||a&&a.status&&404==a.status)T.log("Does not exist: "+e);else{var f=b?b:a&&a.status?a.status:null;T.log(f+" when loading "+e)}d(c,{})},dataType:"json",async:c.getAsync})},postMissing:function(a,b,c,d,e){var f={};f[c]=d;var g=[];if("fallback"===P.sendMissingTo&&P.fallbackLng[0]!==!1)for(var h=0;hh;h++)g.push({lng:e[h],url:v(P.resPostPath,{lng:e[h],ns:b})});for(var j=0,k=g.length;k>j;j++){var l=g[j];T.ajax({url:l.url,type:P.sendType,data:f,success:function(){T.log("posted missing key '"+c+"' to: "+l.url);for(var a=c.split("."),e=0,f=K[l.lng][b];a[e];)f=f[a[e]]=e===a.length-1?d:f[a[e]]||{},e++},error:function(){T.log("failed posting missing key '"+c+"' to: "+l.url)},dataType:"json",async:P.postAsync})}},reload:t};var P={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:["dev"],fallbackNS:[],detectLngQS:"setLng",detectLngFromLocalStorage:!1,ns:"translation",fallbackOnNull:!0,fallbackOnEmpty:!1,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",defaultVariables:!1,reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,indefiniteSuffix:"_indefinite",indefiniteNotFound:["indefinite_not_found",Math.random()].join(""),setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",cookieDomain:void 0,objectTreeKeyHandler:void 0,postProcess:void 0,parseMissingKey:void 0,missingKeyHandler:O.postMissing,shortcutFunction:"sprintf"},Q={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},R={create:function(a,b,c,d){var e;if(c){var f=new Date;f.setTime(f.getTime()+60*c*1e3),e="; expires="+f.toGMTString()}else e="";d=d?"domain="+d+";":"",document.cookie=a+"="+b+e+";"+d+"path=/"},read:function(a){for(var b=a+"=",c=document.cookie.split(";"),d=0;d-1){var c=a.split("-");b=P.lowerCaseLng?c[0].toLowerCase()+"-"+c[1].toLowerCase():c[0].toLowerCase()+"-"+c[1].toUpperCase()}else b=P.lowerCaseLng?a.toLowerCase():a;return b}var c=this.log,d=[],e=P.lngWhitelist||!1,f=function(a){!e||e.indexOf(a)>-1?d.push(a):c("rejecting non-whitelisted language: "+a)};if("string"==typeof a&&a.indexOf("-")>-1){var g=a.split("-");"unspecific"!==P.load&&f(b(a)),"current"!==P.load&&f(b(g[this.getCountyIndexOfLng(a)]))}else f(b(a));for(var h=0;h1)},2:function(a){return Number(1!=a)},3:function(){return 0},4:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},5:function(a){return Number(0===a?0:1==a?1:2==a?2:a%100>=3&&10>=a%100?3:a%100>=11?4:5)},6:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)},7:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},8:function(a){return Number(1==a?0:2==a?1:8!=a&&11!=a?2:3)},9:function(a){return Number(a>=2)},10:function(a){return Number(1==a?0:2==a?1:7>a?2:11>a?3:4)},11:function(a){return Number(1==a||11==a?0:2==a||12==a?1:a>2&&20>a?2:3)},12:function(a){return Number(a%10!=1||a%100==11)},13:function(a){return Number(0!==a)},14:function(a){return Number(1==a?0:2==a?1:3==a?2:3)},15:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&(10>a%100||a%100>=20)?1:2)},16:function(a){return Number(a%10==1&&a%100!=11?0:0!==a?1:2)},17:function(a){return Number(1==a||a%10==1?0:1)},18:function(a){return Number(1==a?1:2)},19:function(a){return Number(1==a?0:0===a||a%100>1&&11>a%100?1:a%100>10&&20>a%100?2:3)},20:function(a){return Number(1==a?0:0===a||a%100>0&&20>a%100?1:2)},21:function(a){return Number(a%100==1?1:a%100==2?2:a%100==3||a%100==4?3:0)}},W={rules:function(){var a,b={};for(a=U.length;a--;)b[U[a][0]]={name:U[a][1],numbers:U[a][2],plurals:V[U[a][3]]};return b}(),addRule:function(a,b){W.rules[a]=b},setCurrentLng:function(a){if(!W.currentRule||W.currentRule.lng!==a){var b=a.split("-");W.currentRule={lng:a,rule:W.rules[b[0]]}}},needsPlural:function(a,b){var c,d=a.split("-");return c=W.currentRule&&W.currentRule.lng===a?W.currentRule.rule:W.rules[d[T.getCountyIndexOfLng(a)]],c&&c.numbers.length<=1?!1:1!==this.get(a,b)},get:function(a,b){function c(b,c){var d;if(d=W.currentRule&&W.currentRule.lng===a?W.currentRule.rule:W.rules[b]){var e;e=d.plurals(d.noAbs?c:Math.abs(c));var f=d.numbers[e];return 2===d.numbers.length&&1===d.numbers[0]&&(2===f?f=-1:1===f&&(f=1)),f}return 1===c?"1":"-1"}var d=a.split("-");return c(d[T.getCountyIndexOfLng(a)],b)}},X={},Y=function(a,b){X[a]=b},Z=function(){function a(a){return Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}function b(a,b){for(var c=[];b>0;c[--b]=a);return c.join("")}var c=function(){return c.cache.hasOwnProperty(arguments[0])||(c.cache[arguments[0]]=c.parse(arguments[0])),c.format.call(null,c.cache[arguments[0]],arguments)};return c.format=function(c,d){var e,f,g,h,i,j,k,l=1,m=c.length,n="",o=[];for(f=0;m>f;f++)if(n=a(c[f]),"string"===n)o.push(c[f]);else if("array"===n){if(h=c[f],h[2])for(e=d[l],g=0;g=0?"+"+e:e,j=h[4]?"0"==h[4]?"0":h[4].charAt(1):" ",k=h[6]-String(e).length,i=h[6]?b(j,k):"",o.push(h[5]?e+i:i+e)}return o.join("")},c.cache={},c.parse=function(a){for(var b=a,c=[],d=[],e=0;b;){if(null!==(c=/^[^\x25]+/.exec(b)))d.push(c[0]);else if(null!==(c=/^\x25{2}/.exec(b)))d.push("%");else{if(null===(c=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(b)))throw"[sprintf] huh?";if(c[2]){e|=1;var f=[],g=c[2],h=[];if(null===(h=/^([a-z_][a-z_\d]*)/i.exec(g)))throw"[sprintf] huh?";for(f.push(h[1]);""!==(g=g.substring(h[0].length));)if(null!==(h=/^\.([a-z_][a-z_\d]*)/i.exec(g)))f.push(h[1]);else{if(null===(h=/^\[(\d+)\]/.exec(g)))throw"[sprintf] huh?";f.push(h[1])}c[2]=f}else e|=2;if(3===e)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";d.push(c)}b=b.substring(c[0].length)}return d},c}(),$=function(a,b){return b.unshift(a),Z.apply(null,b)};Y("sprintf",function(a,b,c){return c.sprintf?"[object Array]"===Object.prototype.toString.apply(c.sprintf)?$(a,c.sprintf):"object"==typeof c.sprintf?Z(a,c.sprintf):a:a}),J.init=g,J.setLng=r,J.preload=h,J.addResourceBundle=i,J.hasResourceBundle=j,J.getResourceBundle=k,J.addResource=m,J.addResources=n,J.removeResourceBundle=l,J.loadNamespace=p,J.loadNamespaces=q,J.setDefaultNamespace=o,J.t=B,J.translate=B,J.exists=A,J.detectLanguage=T.detectLanguage,J.pluralExtensions=W,J.sync=O,J.functions=T,J.lng=s,J.addPostProcessor=Y,J.applyReplacement=T.applyReplacement,J.options=P}("undefined"==typeof exports?window:exports); \ No newline at end of file diff --git a/libs/i18next/release/i18next-1.8.1.zip b/libs/i18next/release/i18next-1.8.1.zip new file mode 100644 index 00000000..0c26a432 Binary files /dev/null and b/libs/i18next/release/i18next-1.8.1.zip differ diff --git a/libs/i18next/release/i18next-1.8.2.js b/libs/i18next/release/i18next-1.8.2.js new file mode 100644 index 00000000..7aab2a78 --- /dev/null +++ b/libs/i18next/release/i18next-1.8.2.js @@ -0,0 +1,2178 @@ +// i18next, v1.8.2 +// Copyright (c)2015 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function(root) { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + // Add string trim for IE8. + if (typeof String.prototype.trim !== 'function') { + String.prototype.trim = function() { + return this.replace(/^\s+|\s+$/g, ''); + } + } + + var $ = root.jQuery || root.Zepto + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = [] + , initialized = false + , sync = {}; + + + + // Export the i18next object for **CommonJS**. + // If we're not in CommonJS, add `i18n` to the + // global object or to jquery. + if (typeof module !== 'undefined' && module.exports) { + module.exports = i18n; + } else { + if ($) { + $.i18n = $.i18n || i18n; + } + + root.i18n = root.i18n || i18n; + } + sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = f.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + f.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + if ((status && status == 200) || (xhr && xhr.status && xhr.status == 200)) { + // file loaded but invalid json, stop waste time ! + f.error('There is a typo in: ' + url); + } else if ((status && status == 404) || (xhr && xhr.status && xhr.status == 404)) { + f.log('Does not exist: ' + url); + } else { + var theStatus = status ? status : ((xhr && xhr.status) ? xhr.status : null); + f.log(theStatus + ' when loading ' + url); + } + + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback' && o.fallbackLng[0] !== false) { + for (var i = 0; i < o.fallbackLng.length; i++) { + urls.push({lng: o.fallbackLng[i], url: applyReplacement(o.resPostPath, { lng: o.fallbackLng[i], ns: ns })}); + } + } else if (o.sendMissingTo === 'current' || (o.sendMissingTo === 'fallback' && o.fallbackLng[0] === false) ) { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + }, + + reload: reload + }; + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: ['dev'], + fallbackNS: [], + detectLngQS: 'setLng', + detectLngFromLocalStorage: false, + ns: { + namespaces: ['translation'], + defaultNs: 'translation' + }, + fallbackOnNull: true, + fallbackOnEmpty: false, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + defaultVariables: false, + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + indefiniteSuffix: '_indefinite', + indefiniteNotFound: ['indefinite_not_found', Math.random()].join(''), + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + cookieDomain: undefined, + + objectTreeKeyHandler: undefined, + postProcess: undefined, + parseMissingKey: undefined, + missingKeyHandler: sync.postMissing, + + shortcutFunction: 'sprintf' // or: defaultValue + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _deepExtend(target, source) { + for (var prop in source) + if (prop in target) + _deepExtend(target[prop], source[prop]); + else + target[prop] = source[prop]; + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || Object.prototype.toString.apply(object) !== '[object Array]' || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + try { + return JSON.parse(data) + } catch (e) { + f.error('Can not parse JSON. URL: ' + url); + return {}; + } + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + // file: protocol always gives status code 0, so check for data + if (status === 200 || (status === 0 && data.text())) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes,domain) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + domain = (domain)? "domain="+domain+";" : ""; + document.cookie = name+"="+value+expires+";"+domain+"path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes,domain) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + deepExtend: _deepExtend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : (typeof document !== 'undefined' ? _ajax : function() {}), + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + error: function(str) { + if (typeof console !== "undefined") console.error(str); + }, + getCountyIndexOfLng: function(lng) { + var lng_index = 0; + if (lng === 'nb-NO' || lng === 'nn-NO' || lng === 'nb-no' || lng === 'nn-no') lng_index = 1; + return lng_index; + }, + toLanguages: function(lng) { + var log = this.log; + + function applyCase(l) { + var ret = l; + + if (typeof l === 'string' && l.indexOf('-') > -1) { + var parts = l.split('-'); + + ret = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } else { + ret = o.lowerCaseLng ? l.toLowerCase() : l; + } + + return ret; + } + + var languages = []; + var whitelist = o.lngWhitelist || false; + var addLanguage = function(language){ + //reject langs not whitelisted + if(!whitelist || whitelist.indexOf(language) > -1){ + languages.push(language); + }else{ + log('rejecting non-whitelisted language: ' + language); + } + }; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + if (o.load !== 'unspecific') addLanguage(applyCase(lng)); + if (o.load !== 'current') addLanguage(applyCase(parts[this.getCountyIndexOfLng(lng)])); + } else { + addLanguage(applyCase(lng)); + } + + for (var i = 0; i < o.fallbackLng.length; i++) { + if (languages.indexOf(o.fallbackLng[i]) === -1 && o.fallbackLng[i]) languages.push(applyCase(o.fallbackLng[i])); + } + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + }, + regexReplacementEscape: function(strOrFn) { + if (typeof strOrFn === 'string') { + return strOrFn.replace(/\$/g, "$$$$"); + } else { + return strOrFn; + } + }, + localStorage: { + setItem: function(key, value) { + if (window.localStorage) { + try { + window.localStorage.setItem(key, value); + } catch (e) { + f.log('failed to set value for key "' + key + '" to localStorage.'); + } + } + }, + getItem: function(key, value) { + if (window.localStorage) { + try { + return window.localStorage.getItem(key, value); + } catch (e) { + f.log('failed to get value for key "' + key + '" from localStorage.'); + return undefined; + } + } + } + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + delete o.fixLng; /* passed in each time */ + + // override functions: .log(), .detectLanguage(), etc + if (o.functions) { + delete o.functions; + f.extend(f, options.functions); + } + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // fallback languages + if (typeof o.fallbackLng == 'string' || typeof o.fallbackLng == 'boolean') { + o.fallbackLng = [o.fallbackLng]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + if (o.useCookie && f.cookie.read(o.cookieName) !== currentLng){ //cookie is unset or invalid + f.cookie.create(o.cookieName, currentLng, o.cookieExpirationTime, o.cookieDomain); + } + if (o.detectLngFromLocalStorage && typeof document !== 'undefined' && window.localStorage) { + f.localStorage.setItem('i18next_lng', currentLng); + } + + var lngTranslate = translate; + if (options.fixLng) { + lngTranslate = function(key, options) { + options = options || {}; + options.lng = options.lng || lngTranslate.lng; + return translate(key, options); + }; + lngTranslate.lng = currentLng; + } + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + initialized = true; + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + initialized = true; + + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources, deep) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + if (deep) { + f.deepExtend(resStore[lng][ns], resources); + } else { + f.extend(resStore[lng][ns], resources); + } + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function hasResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + var res = resStore[lng][ns] || {}; + + var hasValues = false; + for(var prop in res) { + if (res.hasOwnProperty(prop)) { + hasValues = true; + } + } + + return hasValues; + } + + function getResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + return f.extend({}, resStore[lng][ns]); + } + + function removeResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = {}; + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function addResource(lng, ns, key, value) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + var keys = key.split(o.keyseparator); + var x = 0; + var node = resStore[lng][ns]; + var origRef = node; + + while (keys[x]) { + if (x == keys.length - 1) + node[keys[x]] = value; + else { + if (node[keys[x]] == null) + node[keys[x]] = {}; + + node = node[keys[x]]; + } + x++; + } + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function addResources(lng, ns, resources) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + for (var m in resources) { + if (typeof resources[m] === 'string') addResource(lng, ns, m, resources[m]); + } + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, options, cb) { + if (typeof options === 'function') { + cb = options; + options = {}; + } else if (!options) { + options = {}; + } + + options.lng = lng; + return init(options, cb); + } + + function lng() { + return currentLng; + } + + function reload(cb) { + resStore = {}; + setLng(currentLng, cb); + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else if (attr === 'prepend') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.prepend($.t(key, optionsToUse)); + } else if (attr === 'append') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.append($.t(key, optionsToUse)); + } else if (attr.indexOf("data-") === 0) { + var dataAttr = attr.substr(("data-").length); + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.data(dataAttr) }, options) : options; + var translated = $.t(key, optionsToUse); + //we change into the data cache + ele.data(dataAttr, translated); + //we change into the dom + ele.attr(attr, translated); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key && typeof key !== 'undefined' && key !== false) key = ele.text() || ele.val(); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + var hash = replacementHash.replace && typeof replacementHash.replace === 'object' ? replacementHash.replace : replacementHash; + f.each(hash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), f.regexReplacementEscape(value)); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(f.escape(value))); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(value)); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + if (index_of_end_of_closing <= index_of_opening) { + f.error('there is an missing closing in following translation value', translated); + return ''; + } + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, f.regexReplacementEscape(translated_token)); + } + return translated; + } + + function hasContext(options) { + return (options.context && (typeof options.context == 'string' || typeof options.context == 'number')); + } + + function needsPlural(options, lng) { + return (options.count !== undefined && typeof options.count != 'string'/* && pluralExtensions.needsPlural(lng, options.count)*/); + } + + function needsIndefiniteArticle(options) { + return (options.indefinite_article !== undefined && typeof options.indefinite_article != 'string' && options.indefinite_article); + } + + function exists(key, options) { + options = options || {}; + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + options = options || {}; + + if (!initialized) { + f.log('i18next not finished initialization. you might have called t function before loading resources finished.') + return options.defaultValue || ''; + }; + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _getDefaultValue(key, options) { + return (options.defaultValue !== undefined) ? options.defaultValue : key; + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(potentialKeys, options) { + if (options && typeof options !== 'object') { + if (o.shortcutFunction === 'sprintf') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else if (o.shortcutFunction === 'defaultValue') { + options = { + defaultValue: options + } + } + } else { + options = options || {}; + } + + if (typeof o.defaultVariables === 'object') { + options = f.extend({}, o.defaultVariables, options); + } + + if (potentialKeys === undefined || potentialKeys === null || potentialKeys === '') return ''; + + if (typeof potentialKeys === 'number') { + potentialKeys = String(potentialKeys); + } + + if (typeof potentialKeys === 'string') { + potentialKeys = [potentialKeys]; + } + + var key = potentialKeys[0]; + + if (potentialKeys.length > 1) { + for (var i = 0; i < potentialKeys.length; i++) { + key = potentialKeys[i]; + if (exists(key, options)) { + break; + } + } + } + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng, options.fallbackLng) : languages + , ns = options.ns || o.ns.defaultNs + , parts; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing && typeof o.missingKeyHandler === 'function') { + if (options.lng) { + o.missingKeyHandler(lngs[0], ns, key, notFound, lngs); + } else { + o.missingKeyHandler(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessorsToApply; + if (typeof o.postProcess === 'string' && o.postProcess !== '') { + postProcessorsToApply = [o.postProcess]; + } else if (typeof o.postProcess === 'array' || typeof o.postProcess === 'object') { + postProcessorsToApply = o.postProcess; + } else { + postProcessorsToApply = []; + } + + if (typeof options.postProcess === 'string' && options.postProcess !== '') { + postProcessorsToApply = postProcessorsToApply.concat([options.postProcess]); + } else if (typeof options.postProcess === 'array' || typeof options.postProcess === 'object') { + postProcessorsToApply = postProcessorsToApply.concat(options.postProcess); + } + + if (found !== undefined && postProcessorsToApply.length) { + postProcessorsToApply.forEach(function(postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + }); + } + + // process notFound if function exists + var splitNotFound = notFound; + if (notFound.indexOf(o.nsseparator) > -1) { + parts = notFound.split(o.nsseparator); + splitNotFound = parts[1]; + } + if (splitNotFound === key && o.parseMissingKey) { + notFound = o.parseMissingKey(notFound); + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessorsToApply.length) { + var val = _getDefaultValue(key, options); + postProcessorsToApply.forEach(function(postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](val, key, options); + } + }); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options) { + options = options || {}; + + var optionWithoutCount, translated + , notFound = _getDefaultValue(key, options) + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + // CI mode + if (lngs[0].toLowerCase() === 'cimode') return notFound; + + // passed in lng + if (options.lngs) lngs = options.lngs; + if (options.lng) { + lngs = f.toLanguages(options.lng, options.fallbackLng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options, lngs[0])) { + optionWithoutCount = f.extend({ lngs: [lngs[0]]}, options); + delete optionWithoutCount.count; + optionWithoutCount._origLng = optionWithoutCount._origLng || optionWithoutCount.lng || lngs[0]; + delete optionWithoutCount.lng; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey; + if (!pluralExtensions.needsPlural(lngs[0], options.count)) { + pluralKey = ns + o.nsseparator + key; + } else { + pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(lngs[0], options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + } + + translated = translate(pluralKey, optionWithoutCount); + + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } else if (lngs.length > 1) { + // remove failed lng + var clone = lngs.slice(); + clone.shift(); + options = f.extend(options, { lngs: clone }); + options._origLng = optionWithoutCount._origLng; + delete options.lng; + // retry with fallbacks + translated = translate(ns + o.nsseparator + key, options); + if (translated != o.pluralNotFound) return translated; + } else { + optionWithoutCount.lng = optionWithoutCount._origLng; + delete optionWithoutCount._origLng; + translated = translate(ns + o.nsseparator + key, optionWithoutCount); + + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); + } + } + + if (needsIndefiniteArticle(options)) { + var optionsWithoutIndef = f.extend({}, options); + delete optionsWithoutIndef.indefinite_article; + optionsWithoutIndef.defaultValue = o.indefiniteNotFound; + // If we don't have a count, we want the indefinite, if we do have a count, and needsPlural is false + var indefiniteKey = ns + o.nsseparator + key + (((options.count && !needsPlural(options, lngs[0])) || !options.count) ? o.indefiniteSuffix : ""); + translated = translate(indefiniteKey, optionsWithoutIndef); + if (translated != o.indefiniteNotFound) { + return translated; + } + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + var valueType = Object.prototype.toString.apply(value); + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (valueType === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + if (o.objectTreeKeyHandler && typeof o.objectTreeKeyHandler == 'function') { + value = o.objectTreeKeyHandler(key, value, l, ns, options); + } else { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned an object instead of string.'; + f.log(value); + } + } else if (valueType !== '[object Number]' && valueType !== '[object Function]' && valueType !== '[object RegExp]') { + var copy = (valueType === '[object Array]') ? [] : {}; // apply child translation on a copy + f.each(value, function(m) { + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + }); + value = copy; + } + } + + if (typeof value === 'string' && value.trim() === '' && o.fallbackOnEmpty === true) + value = undefined; + + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length > 0))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found || (found==="" && o.fallbackOnEmpty === false)) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + options.isFallbackLookup = false; + } + + return found; + } + function detectLanguage() { + var detectedLng; + var whitelist = o.lngWhitelist || []; + var userLngChoices = []; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var params = query.split('&'); + for (var i=0; i 0) { + var key = params[i].substring(0,pos); + if (key == o.detectLngQS) { + userLngChoices.push(params[i].substring(pos+1)); + } + } + } + })(); + } + + // get from cookie + if (o.useCookie && typeof document !== 'undefined') { + var c = f.cookie.read(o.cookieName); + if (c) userLngChoices.push(c); + } + + // get from localStorage + if (o.detectLngFromLocalStorage && typeof window !== 'undefined' && window.localStorage) { + userLngChoices.push(f.localStorage.getItem('i18next_lng')); + } + + // get from navigator + if (typeof navigator !== 'undefined') { + if (navigator.languages) { // chrome only; not an array, so can't use .push.apply instead of iterating + for (var i=0;i -1) { + var parts = lng.split('-'); + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } + + if (whitelist.length === 0 || whitelist.indexOf(lng) > -1) { + detectedLng = lng; + break; + } + } + })(); + + //fallback + if (!detectedLng){ + detectedLng = o.fallbackLng[0]; + } + + return detectedLng; + } + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + + /* [code, name, numbers, pluralsType] */ + var _rules = [ + ["ach", "Acholi", [1,2], 1], + ["af", "Afrikaans",[1,2], 2], + ["ak", "Akan", [1,2], 1], + ["am", "Amharic", [1,2], 1], + ["an", "Aragonese",[1,2], 2], + ["ar", "Arabic", [0,1,2,3,11,100],5], + ["arn", "Mapudungun",[1,2], 1], + ["ast", "Asturian", [1,2], 2], + ["ay", "Aymará", [1], 3], + ["az", "Azerbaijani",[1,2],2], + ["be", "Belarusian",[1,2,5],4], + ["bg", "Bulgarian",[1,2], 2], + ["bn", "Bengali", [1,2], 2], + ["bo", "Tibetan", [1], 3], + ["br", "Breton", [1,2], 1], + ["bs", "Bosnian", [1,2,5],4], + ["ca", "Catalan", [1,2], 2], + ["cgg", "Chiga", [1], 3], + ["cs", "Czech", [1,2,5],6], + ["csb", "Kashubian",[1,2,5],7], + ["cy", "Welsh", [1,2,3,8],8], + ["da", "Danish", [1,2], 2], + ["de", "German", [1,2], 2], + ["dev", "Development Fallback", [1,2], 2], + ["dz", "Dzongkha", [1], 3], + ["el", "Greek", [1,2], 2], + ["en", "English", [1,2], 2], + ["eo", "Esperanto",[1,2], 2], + ["es", "Spanish", [1,2], 2], + ["es_ar","Argentinean Spanish", [1,2], 2], + ["et", "Estonian", [1,2], 2], + ["eu", "Basque", [1,2], 2], + ["fa", "Persian", [1], 3], + ["fi", "Finnish", [1,2], 2], + ["fil", "Filipino", [1,2], 1], + ["fo", "Faroese", [1,2], 2], + ["fr", "French", [1,2], 9], + ["fur", "Friulian", [1,2], 2], + ["fy", "Frisian", [1,2], 2], + ["ga", "Irish", [1,2,3,7,11],10], + ["gd", "Scottish Gaelic",[1,2,3,20],11], + ["gl", "Galician", [1,2], 2], + ["gu", "Gujarati", [1,2], 2], + ["gun", "Gun", [1,2], 1], + ["ha", "Hausa", [1,2], 2], + ["he", "Hebrew", [1,2], 2], + ["hi", "Hindi", [1,2], 2], + ["hr", "Croatian", [1,2,5],4], + ["hu", "Hungarian",[1,2], 2], + ["hy", "Armenian", [1,2], 2], + ["ia", "Interlingua",[1,2],2], + ["id", "Indonesian",[1], 3], + ["is", "Icelandic",[1,2], 12], + ["it", "Italian", [1,2], 2], + ["ja", "Japanese", [1], 3], + ["jbo", "Lojban", [1], 3], + ["jv", "Javanese", [0,1], 13], + ["ka", "Georgian", [1], 3], + ["kk", "Kazakh", [1], 3], + ["km", "Khmer", [1], 3], + ["kn", "Kannada", [1,2], 2], + ["ko", "Korean", [1], 3], + ["ku", "Kurdish", [1,2], 2], + ["kw", "Cornish", [1,2,3,4],14], + ["ky", "Kyrgyz", [1], 3], + ["lb", "Letzeburgesch",[1,2],2], + ["ln", "Lingala", [1,2], 1], + ["lo", "Lao", [1], 3], + ["lt", "Lithuanian",[1,2,10],15], + ["lv", "Latvian", [1,2,0],16], + ["mai", "Maithili", [1,2], 2], + ["mfe", "Mauritian Creole",[1,2],1], + ["mg", "Malagasy", [1,2], 1], + ["mi", "Maori", [1,2], 1], + ["mk", "Macedonian",[1,2],17], + ["ml", "Malayalam",[1,2], 2], + ["mn", "Mongolian",[1,2], 2], + ["mnk", "Mandinka", [0,1,2],18], + ["mr", "Marathi", [1,2], 2], + ["ms", "Malay", [1], 3], + ["mt", "Maltese", [1,2,11,20],19], + ["nah", "Nahuatl", [1,2], 2], + ["nap", "Neapolitan",[1,2], 2], + ["nb", "Norwegian Bokmal",[1,2],2], + ["ne", "Nepali", [1,2], 2], + ["nl", "Dutch", [1,2], 2], + ["nn", "Norwegian Nynorsk",[1,2],2], + ["no", "Norwegian",[1,2], 2], + ["nso", "Northern Sotho",[1,2],2], + ["oc", "Occitan", [1,2], 1], + ["or", "Oriya", [2,1], 2], + ["pa", "Punjabi", [1,2], 2], + ["pap", "Papiamento",[1,2], 2], + ["pl", "Polish", [1,2,5],7], + ["pms", "Piemontese",[1,2], 2], + ["ps", "Pashto", [1,2], 2], + ["pt", "Portuguese",[1,2], 2], + ["pt_br","Brazilian Portuguese",[1,2], 2], + ["rm", "Romansh", [1,2], 2], + ["ro", "Romanian", [1,2,20],20], + ["ru", "Russian", [1,2,5],4], + ["sah", "Yakut", [1], 3], + ["sco", "Scots", [1,2], 2], + ["se", "Northern Sami",[1,2], 2], + ["si", "Sinhala", [1,2], 2], + ["sk", "Slovak", [1,2,5],6], + ["sl", "Slovenian",[5,1,2,3],21], + ["so", "Somali", [1,2], 2], + ["son", "Songhay", [1,2], 2], + ["sq", "Albanian", [1,2], 2], + ["sr", "Serbian", [1,2,5],4], + ["su", "Sundanese",[1], 3], + ["sv", "Swedish", [1,2], 2], + ["sw", "Swahili", [1,2], 2], + ["ta", "Tamil", [1,2], 2], + ["te", "Telugu", [1,2], 2], + ["tg", "Tajik", [1,2], 1], + ["th", "Thai", [1], 3], + ["ti", "Tigrinya", [1,2], 1], + ["tk", "Turkmen", [1,2], 2], + ["tr", "Turkish", [1,2], 1], + ["tt", "Tatar", [1], 3], + ["ug", "Uyghur", [1], 3], + ["uk", "Ukrainian",[1,2,5],4], + ["ur", "Urdu", [1,2], 2], + ["uz", "Uzbek", [1,2], 1], + ["vi", "Vietnamese",[1], 3], + ["wa", "Walloon", [1,2], 1], + ["wo", "Wolof", [1], 3], + ["yo", "Yoruba", [1,2], 2], + ["zh", "Chinese", [1], 3] + ]; + + var _rulesPluralsTypes = { + 1: function(n) {return Number(n > 1);}, + 2: function(n) {return Number(n != 1);}, + 3: function(n) {return 0;}, + 4: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 5: function(n) {return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5);}, + 6: function(n) {return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2);}, + 7: function(n) {return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 8: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3);}, + 9: function(n) {return Number(n >= 2);}, + 10: function(n) {return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;}, + 11: function(n) {return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3);}, + 12: function(n) {return Number(n%10!=1 || n%100==11);}, + 13: function(n) {return Number(n !== 0);}, + 14: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3);}, + 15: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 16: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2);}, + 17: function(n) {return Number(n==1 || n%10==1 ? 0 : 1);}, + 18: function(n) {return Number(0 ? 0 : n==1 ? 1 : 2);}, + 19: function(n) {return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3);}, + 20: function(n) {return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2);}, + 21: function(n) {return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }; + + var pluralExtensions = { + + rules: (function () { + var l, rules = {}; + for (l=_rules.length; l-- ;) { + rules[_rules[l][0]] = { + name: _rules[l][1], + numbers: _rules[l][2], + plurals: _rulesPluralsTypes[_rules[l][3]] + } + } + return rules; + }()), + + // you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + needsPlural: function(lng, count) { + var parts = lng.split('-'); + + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[parts[f.getCountyIndexOfLng(lng)]]; + } + + if (ext && ext.numbers.length <= 1) { + return false; + } else { + return this.get(lng, count) !== 1; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i; + if (ext.noAbs) { + i = ext.plurals(c); + } else { + i = ext.plurals(Math.abs(c)); + } + + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[f.getCountyIndexOfLng(lng)], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.hasResourceBundle = hasResourceBundle; + i18n.getResourceBundle = getResourceBundle; + i18n.addResource = addResource; + i18n.addResources = addResources; + i18n.removeResourceBundle = removeResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.applyReplacement = f.applyReplacement; + i18n.options = o; + +})(typeof exports === 'undefined' ? window : exports); \ No newline at end of file diff --git a/libs/i18next/release/i18next-1.8.2.min.js b/libs/i18next/release/i18next-1.8.2.min.js new file mode 100644 index 00000000..5ba7b5ba --- /dev/null +++ b/libs/i18next/release/i18next-1.8.2.min.js @@ -0,0 +1,5 @@ +// i18next, v1.8.2 +// Copyright (c)2015 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +!function(a){function b(a,b){if(!b||"function"==typeof b)return a;for(var c in b)a[c]=b[c];return a}function c(a,b){for(var d in b)d in a?c(a[d],b[d]):a[d]=b[d];return a}function d(a,b,c){var d,e=0,f=a.length,g=void 0===f||"[object Array]"!==Object.prototype.toString.apply(a)||"function"==typeof a;if(c)if(g){for(d in a)if(b.apply(a[d],c)===!1)break}else for(;f>e&&b.apply(a[e++],c)!==!1;);else if(g){for(d in a)if(b.call(a[d],d,a[d])===!1)break}else for(;f>e&&b.call(a[e],e,a[e++])!==!1;);return a}function e(a){return"string"==typeof a?a.replace(/[&<>"'\/]/g,function(a){return Q[a]}):a}function f(a){var b=function(a){if(window.XMLHttpRequest)return a(null,new XMLHttpRequest);if(window.ActiveXObject)try{return a(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(b){return a(null,new ActiveXObject("Microsoft.XMLHTTP"))}return a(new Error)},c=function(a){if("string"==typeof a)return a;var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")},d=function(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;cd?b+=String.fromCharCode(d):d>127&&2048>d?(b+=String.fromCharCode(d>>6|192),b+=String.fromCharCode(63&d|128)):(b+=String.fromCharCode(d>>12|224),b+=String.fromCharCode(d>>6&63|128),b+=String.fromCharCode(63&d|128))}return b},e=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";a=d(a);var c,e,f,g,h,i,j,k="",l=0;do c=a.charCodeAt(l++),e=a.charCodeAt(l++),f=a.charCodeAt(l++),g=c>>2,h=(3&c)<<4|e>>4,i=(15&e)<<2|f>>6,j=63&f,isNaN(e)?i=j=64:isNaN(f)&&(j=64),k+=b.charAt(g)+b.charAt(h)+b.charAt(i)+b.charAt(j),c=e=f="",g=h=i=j="";while(l1&&(d+=d.indexOf("?")>-1?"&"+k:"?"+k),e.jsonp){var l=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=d,void l.appendChild(m)}}b(function(b,c){if(b)return h(b);c.open(a,d,e.async);for(var f in j)j.hasOwnProperty(f)&&c.setRequestHeader(f,j[f]);c.onreadystatechange=function(){if(4===c.readyState){var a=c.responseText||"";if(!h)return;h(c.status,{text:function(){return a},json:function(){try{return JSON.parse(a)}catch(b){return T.error("Can not parse JSON. URL: "+d),{}}}})}},c.send(i)})},h={authBasic:function(a,b){g.headers.Authorization="Basic "+e(a+":"+b)},connect:function(a,b,c){return g("CONNECT",a,b,c)},del:function(a,b,c){return g("DELETE",a,b,c)},get:function(a,b,c){return g("GET",a,b,c)},head:function(a,b,c){return g("HEAD",a,b,c)},headers:function(a){g.headers=a||{}},isAllowed:function(a,b,c){this.options(a,function(a,d){c(-1!==d.text().indexOf(b))})},options:function(a,b,c){return g("OPTIONS",a,b,c)},patch:function(a,b,c){return g("PATCH",a,b,c)},post:function(a,b,c){return g("POST",a,b,c)},put:function(a,b,c){return g("PUT",a,b,c)},trace:function(a,b,c){return g("TRACE",a,b,c)}},i=a.type?a.type.toLowerCase():"get";h[i](a.url,a,function(b,c){200===b||0===b&&c.text()?a.success(c.json(),b,null):a.error(c.text(),b,null)})}function g(a,b){"function"==typeof a&&(b=a,a={}),a=a||{},T.extend(P,a),delete P.fixLng,P.functions&&(delete P.functions,T.extend(T,a.functions)),"string"==typeof P.ns&&(P.ns={namespaces:[P.ns],defaultNs:P.ns}),"string"==typeof P.fallbackNS&&(P.fallbackNS=[P.fallbackNS]),("string"==typeof P.fallbackLng||"boolean"==typeof P.fallbackLng)&&(P.fallbackLng=[P.fallbackLng]),P.interpolationPrefixEscaped=T.regexEscape(P.interpolationPrefix),P.interpolationSuffixEscaped=T.regexEscape(P.interpolationSuffix),P.lng||(P.lng=T.detectLanguage()),M=T.toLanguages(P.lng),H=M[0],T.log("currentLng set to: "+H),P.useCookie&&T.cookie.read(P.cookieName)!==H&&T.cookie.create(P.cookieName,H,P.cookieExpirationTime,P.cookieDomain),P.detectLngFromLocalStorage&&"undefined"!=typeof document&&window.localStorage&&T.localStorage.setItem("i18next_lng",H);var c=B;a.fixLng&&(c=function(a,b){return b=b||{},b.lng=b.lng||c.lng,B(a,b)},c.lng=H),W.setCurrentLng(H),I&&P.setJqueryExt&&u();var d;if(I&&I.Deferred&&(d=I.Deferred()),!P.resStore){var e=T.toLanguages(P.lng);"string"==typeof P.preload&&(P.preload=[P.preload]);for(var f=0,g=P.preload.length;g>f;f++)for(var h=T.toLanguages(P.preload[f]),i=0,j=h.length;j>i;i++)e.indexOf(h[i])<0&&e.push(h[i]);return J.sync.load(e,P,function(a,e){K=e,N=!0,b&&b(c),d&&d.resolve(c)}),d?d.promise():void 0}return K=P.resStore,N=!0,b&&b(c),d&&d.resolve(c),d?d.promise():void 0}function h(a,b){"string"==typeof a&&(a=[a]);for(var c=0,d=a.length;d>c;c++)P.preload.indexOf(a[c])<0&&P.preload.push(a[c]);return g(b)}function i(a,b,c,d){"string"!=typeof b?(c=b,b=P.ns.defaultNs):P.ns.namespaces.indexOf(b)<0&&P.ns.namespaces.push(b),K[a]=K[a]||{},K[a][b]=K[a][b]||{},d?T.deepExtend(K[a][b],c):T.extend(K[a][b],c),P.useLocalStorage&&O._storeLocal(K)}function j(a,b){"string"!=typeof b&&(b=P.ns.defaultNs),K[a]=K[a]||{};var c=K[a][b]||{},d=!1;for(var e in c)c.hasOwnProperty(e)&&(d=!0);return d}function k(a,b){return"string"!=typeof b&&(b=P.ns.defaultNs),K[a]=K[a]||{},T.extend({},K[a][b])}function l(a,b){"string"!=typeof b&&(b=P.ns.defaultNs),K[a]=K[a]||{},K[a][b]={},P.useLocalStorage&&O._storeLocal(K)}function m(a,b,c,d){"string"!=typeof b?(resource=b,b=P.ns.defaultNs):P.ns.namespaces.indexOf(b)<0&&P.ns.namespaces.push(b),K[a]=K[a]||{},K[a][b]=K[a][b]||{};for(var e=c.split(P.keyseparator),f=0,g=K[a][b];e[f];)f==e.length-1?g[e[f]]=d:(null==g[e[f]]&&(g[e[f]]={}),g=g[e[f]]),f++;P.useLocalStorage&&O._storeLocal(K)}function n(a,b,c){"string"!=typeof b?(resource=b,b=P.ns.defaultNs):P.ns.namespaces.indexOf(b)<0&&P.ns.namespaces.push(b);for(var d in c)"string"==typeof c[d]&&m(a,b,d,c[d])}function o(a){P.ns.defaultNs=a}function p(a,b){q([a],b)}function q(a,b){var c={dynamicLoad:P.dynamicLoad,resGetPath:P.resGetPath,getAsync:P.getAsync,customLoad:P.customLoad,ns:{namespaces:a,defaultNs:""}},d=T.toLanguages(P.lng);"string"==typeof P.preload&&(P.preload=[P.preload]);for(var e=0,f=P.preload.length;f>e;e++)for(var g=T.toLanguages(P.preload[e]),h=0,i=g.length;i>h;h++)d.indexOf(g[h])<0&&d.push(g[h]);for(var j=[],k=0,l=d.length;l>k;k++){var m=!1,n=K[d[k]];if(n)for(var o=0,p=a.length;p>o;o++)n[a[o]]||(m=!0);else m=!0;m&&j.push(d[k])}j.length?J.sync._fetch(j,c,function(c,d){var e=a.length*j.length;T.each(a,function(a,c){P.ns.namespaces.indexOf(c)<0&&P.ns.namespaces.push(c),T.each(j,function(a,f){K[f]=K[f]||{},K[f][c]=d[f][c],e--,0===e&&b&&(P.useLocalStorage&&J.sync._storeLocal(K),b())})})}):b&&b()}function r(a,b,c){return"function"==typeof b?(c=b,b={}):b||(b={}),b.lng=a,g(b,c)}function s(){return H}function t(a){K={},r(H,a)}function u(){function a(a,b,c){if(0!==b.length){var d="text";if(0===b.indexOf("[")){var e=b.split("]");b=e[1],d=e[0].substr(1,e[0].length-1)}b.indexOf(";")===b.length-1&&(b=b.substr(0,b.length-2));var f;if("html"===d)f=P.defaultValueFromContent?I.extend({defaultValue:a.html()},c):c,a.html(I.t(b,f));else if("text"===d)f=P.defaultValueFromContent?I.extend({defaultValue:a.text()},c):c,a.text(I.t(b,f));else if("prepend"===d)f=P.defaultValueFromContent?I.extend({defaultValue:a.html()},c):c,a.prepend(I.t(b,f));else if("append"===d)f=P.defaultValueFromContent?I.extend({defaultValue:a.html()},c):c,a.append(I.t(b,f));else if(0===d.indexOf("data-")){var g=d.substr("data-".length);f=P.defaultValueFromContent?I.extend({defaultValue:a.data(g)},c):c;var h=I.t(b,f);a.data(g,h),a.attr(d,h)}else f=P.defaultValueFromContent?I.extend({defaultValue:a.attr(d)},c):c,a.attr(d,I.t(b,f))}}function b(b,c){var d=b.attr(P.selectorAttr);if(d||"undefined"==typeof d||d===!1||(d=b.text()||b.val()),d){var e=b,f=b.data("i18n-target");if(f&&(e=b.find(f)||b),c||P.useDataAttrOptions!==!0||(c=b.data("i18n-options")),c=c||{},d.indexOf(";")>=0){var g=d.split(";");I.each(g,function(b,d){""!==d&&a(e,d,c)})}else a(e,d,c);P.useDataAttrOptions===!0&&b.data("i18n-options",c)}}I.t=I.t||B,I.fn.i18n=function(a){return this.each(function(){b(I(this),a);var c=I(this).find("["+P.selectorAttr+"]");c.each(function(){b(I(this),a)})})}}function v(a,b,c,d){if(!a)return a;if(d=d||b,a.indexOf(d.interpolationPrefix||P.interpolationPrefix)<0)return a;var e=d.interpolationPrefix?T.regexEscape(d.interpolationPrefix):P.interpolationPrefixEscaped,f=d.interpolationSuffix?T.regexEscape(d.interpolationSuffix):P.interpolationSuffixEscaped,g="HTML"+f,h=b.replace&&"object"==typeof b.replace?b.replace:b;return T.each(h,function(b,h){var i=c?c+P.keyseparator+b:b;"object"==typeof h&&null!==h?a=v(a,h,i,d):d.escapeInterpolation||P.escapeInterpolation?(a=a.replace(new RegExp([e,i,g].join(""),"g"),T.regexReplacementEscape(h)),a=a.replace(new RegExp([e,i,f].join(""),"g"),T.regexReplacementEscape(T.escape(h)))):a=a.replace(new RegExp([e,i,f].join(""),"g"),T.regexReplacementEscape(h))}),a}function w(a,b){var c=",",d="{",e="}",f=T.extend({},b);for(delete f.postProcess;-1!=a.indexOf(P.reusePrefix)&&(L++,!(L>P.maxRecursion));){var g=a.lastIndexOf(P.reusePrefix),h=a.indexOf(P.reuseSuffix,g)+P.reuseSuffix.length,i=a.substring(g,h),j=i.replace(P.reusePrefix,"").replace(P.reuseSuffix,"");if(g>=h)return T.error("there is an missing closing in following translation value",a),"";if(-1!=j.indexOf(c)){var k=j.indexOf(c);if(-1!=j.indexOf(d,k)&&-1!=j.indexOf(e,k)){var l=j.indexOf(d,k),m=j.indexOf(e,l)+e.length;try{f=T.extend(f,JSON.parse(j.substring(l,m))),j=j.substring(0,k)}catch(n){}}}var o=E(j,f);a=a.replace(i,T.regexReplacementEscape(o))}return a}function x(a){return a.context&&("string"==typeof a.context||"number"==typeof a.context)}function y(a){return void 0!==a.count&&"string"!=typeof a.count}function z(a){return void 0!==a.indefinite_article&&"string"!=typeof a.indefinite_article&&a.indefinite_article}function A(a,b){b=b||{};var c=C(a,b),d=F(a,b);return void 0!==d||d===c}function B(a,b){return b=b||{},N?(L=0,E.apply(null,arguments)):(T.log("i18next not finished initialization. you might have called t function before loading resources finished."),b.defaultValue||"")}function C(a,b){return void 0!==b.defaultValue?b.defaultValue:a}function D(){for(var a=[],b=1;b1)for(var d=0;d-1&&(e=c.split(P.nsseparator),i=e[0],c=e[1]),void 0===g&&P.sendMissing&&"function"==typeof P.missingKeyHandler&&(b.lng?P.missingKeyHandler(h[0],i,c,f,h):P.missingKeyHandler(P.lng,i,c,f,h));var j;j="string"==typeof P.postProcess&&""!==P.postProcess?[P.postProcess]:"array"==typeof P.postProcess||"object"==typeof P.postProcess?P.postProcess:[],"string"==typeof b.postProcess&&""!==b.postProcess?j=j.concat([b.postProcess]):("array"==typeof b.postProcess||"object"==typeof b.postProcess)&&(j=j.concat(b.postProcess)),void 0!==g&&j.length&&j.forEach(function(a){X[a]&&(g=X[a](g,c,b))});var k=f;if(f.indexOf(P.nsseparator)>-1&&(e=f.split(P.nsseparator),k=e[1]),k===c&&P.parseMissingKey&&(f=P.parseMissingKey(f)),void 0===g&&(f=v(f,b),f=w(f,b),j.length)){var l=C(c,b);j.forEach(function(a){X[a]&&(g=X[a](l,c,b))})}return void 0!==g?g:f}function F(a,b){b=b||{};var c,d,e=C(a,b),f=M;if(!K)return e;if("cimode"===f[0].toLowerCase())return e;if(b.lngs&&(f=b.lngs),b.lng&&(f=T.toLanguages(b.lng,b.fallbackLng),!K[f[0]])){var g=P.getAsync;P.getAsync=!1,J.sync.load(f,P,function(a,b){T.extend(K,b),P.getAsync=g})}var h=b.ns||P.ns.defaultNs;if(a.indexOf(P.nsseparator)>-1){var i=a.split(P.nsseparator);h=i[0],a=i[1]}if(x(b)){c=T.extend({},b),delete c.context,c.defaultValue=P.contextNotFound;var j=h+P.nsseparator+a+"_"+b.context;if(d=B(j,c),d!=P.contextNotFound)return v(d,{context:b.context})}if(y(b,f[0])){c=T.extend({lngs:[f[0]]},b),delete c.count,c._origLng=c._origLng||c.lng||f[0],delete c.lng,c.defaultValue=P.pluralNotFound;var k;if(W.needsPlural(f[0],b.count)){k=h+P.nsseparator+a+P.pluralSuffix;var l=W.get(f[0],b.count);l>=0?k=k+"_"+l:1===l&&(k=h+P.nsseparator+a)}else k=h+P.nsseparator+a;if(d=B(k,c),d!=P.pluralNotFound)return v(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix});if(!(f.length>1))return c.lng=c._origLng,delete c._origLng,d=B(h+P.nsseparator+a,c),v(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix});var m=f.slice();if(m.shift(),b=T.extend(b,{lngs:m}),b._origLng=c._origLng,delete b.lng,d=B(h+P.nsseparator+a,b),d!=P.pluralNotFound)return d}if(z(b)){var n=T.extend({},b);delete n.indefinite_article,n.defaultValue=P.indefiniteNotFound;var o=h+P.nsseparator+a+(b.count&&!y(b,f[0])||!b.count?P.indefiniteSuffix:"");if(d=B(o,n),d!=P.indefiniteNotFound)return d}for(var p,q=a.split(P.keyseparator),r=0,s=f.length;s>r&&void 0===p;r++){for(var t=f[r],u=0,A=K[t]&&K[t][h];q[u];)A=A&&A[q[u]],u++;if(void 0!==A){var D=Object.prototype.toString.apply(A);if("string"==typeof A)A=v(A,b),A=w(A,b);else if("[object Array]"!==D||P.returnObjectTrees||b.returnObjectTrees){if(null===A&&P.fallbackOnNull===!0)A=void 0;else if(null!==A)if(P.returnObjectTrees||b.returnObjectTrees){if("[object Number]"!==D&&"[object Function]"!==D&&"[object RegExp]"!==D){var G="[object Array]"===D?[]:{};T.each(A,function(c){G[c]=E(h+P.nsseparator+a+P.keyseparator+c,b)}),A=G}}else P.objectTreeKeyHandler&&"function"==typeof P.objectTreeKeyHandler?A=P.objectTreeKeyHandler(a,A,t,h,b):(A="key '"+h+":"+a+" ("+t+")' returned an object instead of string.",T.log(A))}else A=A.join("\n"),A=v(A,b),A=w(A,b);"string"==typeof A&&""===A.trim()&&P.fallbackOnEmpty===!0&&(A=void 0),p=A}}if(void 0===p&&!b.isFallbackLookup&&(P.fallbackToDefaultNS===!0||P.fallbackNS&&P.fallbackNS.length>0)){if(b.isFallbackLookup=!0,P.fallbackNS.length){for(var H=0,I=P.fallbackNS.length;I>H;H++)if(p=F(P.fallbackNS[H]+P.nsseparator+a,b),p||""===p&&P.fallbackOnEmpty===!1){var L=p.indexOf(P.nsseparator)>-1?p.split(P.nsseparator)[1]:p,N=e.indexOf(P.nsseparator)>-1?e.split(P.nsseparator)[1]:e;if(L!==N)break}}else p=F(a,b);b.isFallbackLookup=!1}return p}function G(){var a,b=P.lngWhitelist||[],c=[];if("undefined"!=typeof window&&!function(){for(var a=window.location.search.substring(1),b=a.split("&"),d=0;d0){var f=b[d].substring(0,e);f==P.detectLngQS&&c.push(b[d].substring(e+1))}}}(),P.useCookie&&"undefined"!=typeof document){var d=T.cookie.read(P.cookieName);d&&c.push(d)}if(P.detectLngFromLocalStorage&&"undefined"!=typeof window&&window.localStorage&&c.push(T.localStorage.getItem("i18next_lng")),"undefined"!=typeof navigator){if(navigator.languages)for(var e=0;e-1){var f=e.split("-");e=P.lowerCaseLng?f[0].toLowerCase()+"-"+f[1].toLowerCase():f[0].toLowerCase()+"-"+f[1].toUpperCase()}if(0===b.length||b.indexOf(e)>-1){a=e;break}}}(),a||(a=P.fallbackLng[0]),a}Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>0&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=c;arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d))));for(var e=d>=0?Math.min(d,c-1):c-Math.abs(d);e>=0;e--)if(e in b&&b[e]===a)return e;return-1}),"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")});var H,I=a.jQuery||a.Zepto,J={},K={},L=0,M=[],N=!1,O={};"undefined"!=typeof module&&module.exports?module.exports=J:(I&&(I.i18n=I.i18n||J),a.i18n=a.i18n||J),O={load:function(a,b,c){b.useLocalStorage?O._loadLocal(a,b,function(d,e){for(var f=[],g=0,h=a.length;h>g;g++)e[a[g]]||f.push(a[g]);f.length>0?O._fetch(f,b,function(a,b){T.extend(e,b),O._storeLocal(b),c(null,e)}):c(null,e)}):O._fetch(a,b,function(a,b){c(null,b)})},_loadLocal:function(a,b,c){var d={},e=(new Date).getTime();if(window.localStorage){var f=a.length;T.each(a,function(a,g){var h=T.localStorage.getItem("res_"+g);h&&(h=JSON.parse(h),h.i18nStamp&&h.i18nStamp+b.localStorageExpirationTime>e&&(d[g]=h)),f--,0===f&&c(null,d)})}},_storeLocal:function(a){if(window.localStorage)for(var b in a)a[b].i18nStamp=(new Date).getTime(),T.localStorage.setItem("res_"+b,JSON.stringify(a[b]))},_fetch:function(a,b,c){var d=b.ns,e={};if(b.dynamicLoad){var f=function(a,b){c(null,b)};if("function"==typeof b.customLoad)b.customLoad(a,d.namespaces,b,f);else{var g=v(b.resGetPath,{lng:a.join("+"),ns:d.namespaces.join("+")});T.ajax({url:g,success:function(a){T.log("loaded: "+g),f(null,a)},error:function(a,b,c){T.log("failed loading: "+g),f("failed loading resource.json error: "+c)},dataType:"json",async:b.getAsync})}}else{var h,i=d.namespaces.length*a.length;T.each(d.namespaces,function(d,f){T.each(a,function(a,d){var g=function(a,b){a&&(h=h||[],h.push(a)),e[d]=e[d]||{},e[d][f]=b,i--,0===i&&c(h,e)};"function"==typeof b.customLoad?b.customLoad(d,f,b,g):O._fetchOne(d,f,b,g)})})}},_fetchOne:function(a,b,c,d){var e=v(c.resGetPath,{lng:a,ns:b});T.ajax({url:e,success:function(a){T.log("loaded: "+e),d(null,a)},error:function(a,b,c){if(b&&200==b||a&&a.status&&200==a.status)T.error("There is a typo in: "+e);else if(b&&404==b||a&&a.status&&404==a.status)T.log("Does not exist: "+e);else{var f=b?b:a&&a.status?a.status:null;T.log(f+" when loading "+e)}d(c,{})},dataType:"json",async:c.getAsync})},postMissing:function(a,b,c,d,e){var f={};f[c]=d;var g=[];if("fallback"===P.sendMissingTo&&P.fallbackLng[0]!==!1)for(var h=0;hh;h++)g.push({lng:e[h],url:v(P.resPostPath,{lng:e[h],ns:b})});for(var j=0,k=g.length;k>j;j++){var l=g[j];T.ajax({url:l.url,type:P.sendType,data:f,success:function(){T.log("posted missing key '"+c+"' to: "+l.url);for(var a=c.split("."),e=0,f=K[l.lng][b];a[e];)f=f[a[e]]=e===a.length-1?d:f[a[e]]||{},e++},error:function(){T.log("failed posting missing key '"+c+"' to: "+l.url)},dataType:"json",async:P.postAsync})}},reload:t};var P={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:["dev"],fallbackNS:[],detectLngQS:"setLng",detectLngFromLocalStorage:!1,ns:{namespaces:["translation"],defaultNs:"translation"},fallbackOnNull:!0,fallbackOnEmpty:!1,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",defaultVariables:!1,reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,indefiniteSuffix:"_indefinite",indefiniteNotFound:["indefinite_not_found",Math.random()].join(""),setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",cookieDomain:void 0,objectTreeKeyHandler:void 0,postProcess:void 0,parseMissingKey:void 0,missingKeyHandler:O.postMissing,shortcutFunction:"sprintf"},Q={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},R={create:function(a,b,c,d){var e;if(c){var f=new Date;f.setTime(f.getTime()+60*c*1e3),e="; expires="+f.toGMTString()}else e="";d=d?"domain="+d+";":"",document.cookie=a+"="+b+e+";"+d+"path=/"},read:function(a){for(var b=a+"=",c=document.cookie.split(";"),d=0;d-1){var c=a.split("-");b=P.lowerCaseLng?c[0].toLowerCase()+"-"+c[1].toLowerCase():c[0].toLowerCase()+"-"+c[1].toUpperCase()}else b=P.lowerCaseLng?a.toLowerCase():a;return b}var c=this.log,d=[],e=P.lngWhitelist||!1,f=function(a){!e||e.indexOf(a)>-1?d.push(a):c("rejecting non-whitelisted language: "+a)};if("string"==typeof a&&a.indexOf("-")>-1){var g=a.split("-");"unspecific"!==P.load&&f(b(a)),"current"!==P.load&&f(b(g[this.getCountyIndexOfLng(a)]))}else f(b(a));for(var h=0;h1)},2:function(a){return Number(1!=a)},3:function(){return 0},4:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},5:function(a){return Number(0===a?0:1==a?1:2==a?2:a%100>=3&&10>=a%100?3:a%100>=11?4:5)},6:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)},7:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},8:function(a){return Number(1==a?0:2==a?1:8!=a&&11!=a?2:3)},9:function(a){return Number(a>=2)},10:function(a){return Number(1==a?0:2==a?1:7>a?2:11>a?3:4)},11:function(a){return Number(1==a||11==a?0:2==a||12==a?1:a>2&&20>a?2:3)},12:function(a){return Number(a%10!=1||a%100==11)},13:function(a){return Number(0!==a)},14:function(a){return Number(1==a?0:2==a?1:3==a?2:3)},15:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&(10>a%100||a%100>=20)?1:2)},16:function(a){return Number(a%10==1&&a%100!=11?0:0!==a?1:2)},17:function(a){return Number(1==a||a%10==1?0:1)},18:function(a){return Number(1==a?1:2)},19:function(a){return Number(1==a?0:0===a||a%100>1&&11>a%100?1:a%100>10&&20>a%100?2:3)},20:function(a){return Number(1==a?0:0===a||a%100>0&&20>a%100?1:2)},21:function(a){return Number(a%100==1?1:a%100==2?2:a%100==3||a%100==4?3:0)}},W={rules:function(){var a,b={};for(a=U.length;a--;)b[U[a][0]]={name:U[a][1],numbers:U[a][2],plurals:V[U[a][3]]};return b}(),addRule:function(a,b){W.rules[a]=b},setCurrentLng:function(a){if(!W.currentRule||W.currentRule.lng!==a){var b=a.split("-");W.currentRule={lng:a,rule:W.rules[b[0]]}}},needsPlural:function(a,b){var c,d=a.split("-");return c=W.currentRule&&W.currentRule.lng===a?W.currentRule.rule:W.rules[d[T.getCountyIndexOfLng(a)]],c&&c.numbers.length<=1?!1:1!==this.get(a,b)},get:function(a,b){function c(b,c){var d;if(d=W.currentRule&&W.currentRule.lng===a?W.currentRule.rule:W.rules[b]){var e;e=d.plurals(d.noAbs?c:Math.abs(c));var f=d.numbers[e];return 2===d.numbers.length&&1===d.numbers[0]&&(2===f?f=-1:1===f&&(f=1)),f}return 1===c?"1":"-1"}var d=a.split("-");return c(d[T.getCountyIndexOfLng(a)],b)}},X={},Y=function(a,b){X[a]=b},Z=function(){function a(a){return Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}function b(a,b){for(var c=[];b>0;c[--b]=a);return c.join("")}var c=function(){return c.cache.hasOwnProperty(arguments[0])||(c.cache[arguments[0]]=c.parse(arguments[0])),c.format.call(null,c.cache[arguments[0]],arguments)};return c.format=function(c,d){var e,f,g,h,i,j,k,l=1,m=c.length,n="",o=[];for(f=0;m>f;f++)if(n=a(c[f]),"string"===n)o.push(c[f]);else if("array"===n){if(h=c[f],h[2])for(e=d[l],g=0;g=0?"+"+e:e,j=h[4]?"0"==h[4]?"0":h[4].charAt(1):" ",k=h[6]-String(e).length,i=h[6]?b(j,k):"",o.push(h[5]?e+i:i+e)}return o.join("")},c.cache={},c.parse=function(a){for(var b=a,c=[],d=[],e=0;b;){if(null!==(c=/^[^\x25]+/.exec(b)))d.push(c[0]);else if(null!==(c=/^\x25{2}/.exec(b)))d.push("%");else{if(null===(c=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(b)))throw"[sprintf] huh?";if(c[2]){e|=1;var f=[],g=c[2],h=[];if(null===(h=/^([a-z_][a-z_\d]*)/i.exec(g)))throw"[sprintf] huh?";for(f.push(h[1]);""!==(g=g.substring(h[0].length));)if(null!==(h=/^\.([a-z_][a-z_\d]*)/i.exec(g)))f.push(h[1]);else{if(null===(h=/^\[(\d+)\]/.exec(g)))throw"[sprintf] huh?";f.push(h[1])}c[2]=f}else e|=2;if(3===e)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";d.push(c)}b=b.substring(c[0].length)}return d},c}(),$=function(a,b){return b.unshift(a),Z.apply(null,b)};Y("sprintf",function(a,b,c){return c.sprintf?"[object Array]"===Object.prototype.toString.apply(c.sprintf)?$(a,c.sprintf):"object"==typeof c.sprintf?Z(a,c.sprintf):a:a}),J.init=g,J.setLng=r,J.preload=h,J.addResourceBundle=i,J.hasResourceBundle=j,J.getResourceBundle=k,J.addResource=m,J.addResources=n,J.removeResourceBundle=l,J.loadNamespace=p,J.loadNamespaces=q,J.setDefaultNamespace=o,J.t=B,J.translate=B,J.exists=A,J.detectLanguage=T.detectLanguage,J.pluralExtensions=W,J.sync=O,J.functions=T,J.lng=s,J.addPostProcessor=Y,J.applyReplacement=T.applyReplacement,J.options=P}("undefined"==typeof exports?window:exports); \ No newline at end of file diff --git a/libs/i18next/release/i18next-1.8.2.zip b/libs/i18next/release/i18next-1.8.2.zip new file mode 100644 index 00000000..5e646c4e Binary files /dev/null and b/libs/i18next/release/i18next-1.8.2.zip differ diff --git a/libs/i18next/release/i18next-latest.js b/libs/i18next/release/i18next-latest.js new file mode 100644 index 00000000..7aab2a78 --- /dev/null +++ b/libs/i18next/release/i18next-latest.js @@ -0,0 +1,2178 @@ +// i18next, v1.8.2 +// Copyright (c)2015 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function(root) { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + // Add string trim for IE8. + if (typeof String.prototype.trim !== 'function') { + String.prototype.trim = function() { + return this.replace(/^\s+|\s+$/g, ''); + } + } + + var $ = root.jQuery || root.Zepto + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = [] + , initialized = false + , sync = {}; + + + + // Export the i18next object for **CommonJS**. + // If we're not in CommonJS, add `i18n` to the + // global object or to jquery. + if (typeof module !== 'undefined' && module.exports) { + module.exports = i18n; + } else { + if ($) { + $.i18n = $.i18n || i18n; + } + + root.i18n = root.i18n || i18n; + } + sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = f.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + f.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + if ((status && status == 200) || (xhr && xhr.status && xhr.status == 200)) { + // file loaded but invalid json, stop waste time ! + f.error('There is a typo in: ' + url); + } else if ((status && status == 404) || (xhr && xhr.status && xhr.status == 404)) { + f.log('Does not exist: ' + url); + } else { + var theStatus = status ? status : ((xhr && xhr.status) ? xhr.status : null); + f.log(theStatus + ' when loading ' + url); + } + + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback' && o.fallbackLng[0] !== false) { + for (var i = 0; i < o.fallbackLng.length; i++) { + urls.push({lng: o.fallbackLng[i], url: applyReplacement(o.resPostPath, { lng: o.fallbackLng[i], ns: ns })}); + } + } else if (o.sendMissingTo === 'current' || (o.sendMissingTo === 'fallback' && o.fallbackLng[0] === false) ) { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + }, + + reload: reload + }; + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: ['dev'], + fallbackNS: [], + detectLngQS: 'setLng', + detectLngFromLocalStorage: false, + ns: { + namespaces: ['translation'], + defaultNs: 'translation' + }, + fallbackOnNull: true, + fallbackOnEmpty: false, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + defaultVariables: false, + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + indefiniteSuffix: '_indefinite', + indefiniteNotFound: ['indefinite_not_found', Math.random()].join(''), + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + cookieDomain: undefined, + + objectTreeKeyHandler: undefined, + postProcess: undefined, + parseMissingKey: undefined, + missingKeyHandler: sync.postMissing, + + shortcutFunction: 'sprintf' // or: defaultValue + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _deepExtend(target, source) { + for (var prop in source) + if (prop in target) + _deepExtend(target[prop], source[prop]); + else + target[prop] = source[prop]; + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || Object.prototype.toString.apply(object) !== '[object Array]' || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + try { + return JSON.parse(data) + } catch (e) { + f.error('Can not parse JSON. URL: ' + url); + return {}; + } + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + // file: protocol always gives status code 0, so check for data + if (status === 200 || (status === 0 && data.text())) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes,domain) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + domain = (domain)? "domain="+domain+";" : ""; + document.cookie = name+"="+value+expires+";"+domain+"path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes,domain) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + deepExtend: _deepExtend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : (typeof document !== 'undefined' ? _ajax : function() {}), + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + error: function(str) { + if (typeof console !== "undefined") console.error(str); + }, + getCountyIndexOfLng: function(lng) { + var lng_index = 0; + if (lng === 'nb-NO' || lng === 'nn-NO' || lng === 'nb-no' || lng === 'nn-no') lng_index = 1; + return lng_index; + }, + toLanguages: function(lng) { + var log = this.log; + + function applyCase(l) { + var ret = l; + + if (typeof l === 'string' && l.indexOf('-') > -1) { + var parts = l.split('-'); + + ret = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } else { + ret = o.lowerCaseLng ? l.toLowerCase() : l; + } + + return ret; + } + + var languages = []; + var whitelist = o.lngWhitelist || false; + var addLanguage = function(language){ + //reject langs not whitelisted + if(!whitelist || whitelist.indexOf(language) > -1){ + languages.push(language); + }else{ + log('rejecting non-whitelisted language: ' + language); + } + }; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + if (o.load !== 'unspecific') addLanguage(applyCase(lng)); + if (o.load !== 'current') addLanguage(applyCase(parts[this.getCountyIndexOfLng(lng)])); + } else { + addLanguage(applyCase(lng)); + } + + for (var i = 0; i < o.fallbackLng.length; i++) { + if (languages.indexOf(o.fallbackLng[i]) === -1 && o.fallbackLng[i]) languages.push(applyCase(o.fallbackLng[i])); + } + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + }, + regexReplacementEscape: function(strOrFn) { + if (typeof strOrFn === 'string') { + return strOrFn.replace(/\$/g, "$$$$"); + } else { + return strOrFn; + } + }, + localStorage: { + setItem: function(key, value) { + if (window.localStorage) { + try { + window.localStorage.setItem(key, value); + } catch (e) { + f.log('failed to set value for key "' + key + '" to localStorage.'); + } + } + }, + getItem: function(key, value) { + if (window.localStorage) { + try { + return window.localStorage.getItem(key, value); + } catch (e) { + f.log('failed to get value for key "' + key + '" from localStorage.'); + return undefined; + } + } + } + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + delete o.fixLng; /* passed in each time */ + + // override functions: .log(), .detectLanguage(), etc + if (o.functions) { + delete o.functions; + f.extend(f, options.functions); + } + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // fallback languages + if (typeof o.fallbackLng == 'string' || typeof o.fallbackLng == 'boolean') { + o.fallbackLng = [o.fallbackLng]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + if (o.useCookie && f.cookie.read(o.cookieName) !== currentLng){ //cookie is unset or invalid + f.cookie.create(o.cookieName, currentLng, o.cookieExpirationTime, o.cookieDomain); + } + if (o.detectLngFromLocalStorage && typeof document !== 'undefined' && window.localStorage) { + f.localStorage.setItem('i18next_lng', currentLng); + } + + var lngTranslate = translate; + if (options.fixLng) { + lngTranslate = function(key, options) { + options = options || {}; + options.lng = options.lng || lngTranslate.lng; + return translate(key, options); + }; + lngTranslate.lng = currentLng; + } + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + initialized = true; + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + initialized = true; + + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources, deep) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + if (deep) { + f.deepExtend(resStore[lng][ns], resources); + } else { + f.extend(resStore[lng][ns], resources); + } + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function hasResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + var res = resStore[lng][ns] || {}; + + var hasValues = false; + for(var prop in res) { + if (res.hasOwnProperty(prop)) { + hasValues = true; + } + } + + return hasValues; + } + + function getResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + return f.extend({}, resStore[lng][ns]); + } + + function removeResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = {}; + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function addResource(lng, ns, key, value) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + var keys = key.split(o.keyseparator); + var x = 0; + var node = resStore[lng][ns]; + var origRef = node; + + while (keys[x]) { + if (x == keys.length - 1) + node[keys[x]] = value; + else { + if (node[keys[x]] == null) + node[keys[x]] = {}; + + node = node[keys[x]]; + } + x++; + } + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function addResources(lng, ns, resources) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + for (var m in resources) { + if (typeof resources[m] === 'string') addResource(lng, ns, m, resources[m]); + } + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, options, cb) { + if (typeof options === 'function') { + cb = options; + options = {}; + } else if (!options) { + options = {}; + } + + options.lng = lng; + return init(options, cb); + } + + function lng() { + return currentLng; + } + + function reload(cb) { + resStore = {}; + setLng(currentLng, cb); + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else if (attr === 'prepend') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.prepend($.t(key, optionsToUse)); + } else if (attr === 'append') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.append($.t(key, optionsToUse)); + } else if (attr.indexOf("data-") === 0) { + var dataAttr = attr.substr(("data-").length); + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.data(dataAttr) }, options) : options; + var translated = $.t(key, optionsToUse); + //we change into the data cache + ele.data(dataAttr, translated); + //we change into the dom + ele.attr(attr, translated); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key && typeof key !== 'undefined' && key !== false) key = ele.text() || ele.val(); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + var hash = replacementHash.replace && typeof replacementHash.replace === 'object' ? replacementHash.replace : replacementHash; + f.each(hash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), f.regexReplacementEscape(value)); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(f.escape(value))); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(value)); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + if (index_of_end_of_closing <= index_of_opening) { + f.error('there is an missing closing in following translation value', translated); + return ''; + } + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, f.regexReplacementEscape(translated_token)); + } + return translated; + } + + function hasContext(options) { + return (options.context && (typeof options.context == 'string' || typeof options.context == 'number')); + } + + function needsPlural(options, lng) { + return (options.count !== undefined && typeof options.count != 'string'/* && pluralExtensions.needsPlural(lng, options.count)*/); + } + + function needsIndefiniteArticle(options) { + return (options.indefinite_article !== undefined && typeof options.indefinite_article != 'string' && options.indefinite_article); + } + + function exists(key, options) { + options = options || {}; + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + options = options || {}; + + if (!initialized) { + f.log('i18next not finished initialization. you might have called t function before loading resources finished.') + return options.defaultValue || ''; + }; + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _getDefaultValue(key, options) { + return (options.defaultValue !== undefined) ? options.defaultValue : key; + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(potentialKeys, options) { + if (options && typeof options !== 'object') { + if (o.shortcutFunction === 'sprintf') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else if (o.shortcutFunction === 'defaultValue') { + options = { + defaultValue: options + } + } + } else { + options = options || {}; + } + + if (typeof o.defaultVariables === 'object') { + options = f.extend({}, o.defaultVariables, options); + } + + if (potentialKeys === undefined || potentialKeys === null || potentialKeys === '') return ''; + + if (typeof potentialKeys === 'number') { + potentialKeys = String(potentialKeys); + } + + if (typeof potentialKeys === 'string') { + potentialKeys = [potentialKeys]; + } + + var key = potentialKeys[0]; + + if (potentialKeys.length > 1) { + for (var i = 0; i < potentialKeys.length; i++) { + key = potentialKeys[i]; + if (exists(key, options)) { + break; + } + } + } + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng, options.fallbackLng) : languages + , ns = options.ns || o.ns.defaultNs + , parts; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing && typeof o.missingKeyHandler === 'function') { + if (options.lng) { + o.missingKeyHandler(lngs[0], ns, key, notFound, lngs); + } else { + o.missingKeyHandler(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessorsToApply; + if (typeof o.postProcess === 'string' && o.postProcess !== '') { + postProcessorsToApply = [o.postProcess]; + } else if (typeof o.postProcess === 'array' || typeof o.postProcess === 'object') { + postProcessorsToApply = o.postProcess; + } else { + postProcessorsToApply = []; + } + + if (typeof options.postProcess === 'string' && options.postProcess !== '') { + postProcessorsToApply = postProcessorsToApply.concat([options.postProcess]); + } else if (typeof options.postProcess === 'array' || typeof options.postProcess === 'object') { + postProcessorsToApply = postProcessorsToApply.concat(options.postProcess); + } + + if (found !== undefined && postProcessorsToApply.length) { + postProcessorsToApply.forEach(function(postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + }); + } + + // process notFound if function exists + var splitNotFound = notFound; + if (notFound.indexOf(o.nsseparator) > -1) { + parts = notFound.split(o.nsseparator); + splitNotFound = parts[1]; + } + if (splitNotFound === key && o.parseMissingKey) { + notFound = o.parseMissingKey(notFound); + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessorsToApply.length) { + var val = _getDefaultValue(key, options); + postProcessorsToApply.forEach(function(postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](val, key, options); + } + }); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options) { + options = options || {}; + + var optionWithoutCount, translated + , notFound = _getDefaultValue(key, options) + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + // CI mode + if (lngs[0].toLowerCase() === 'cimode') return notFound; + + // passed in lng + if (options.lngs) lngs = options.lngs; + if (options.lng) { + lngs = f.toLanguages(options.lng, options.fallbackLng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options, lngs[0])) { + optionWithoutCount = f.extend({ lngs: [lngs[0]]}, options); + delete optionWithoutCount.count; + optionWithoutCount._origLng = optionWithoutCount._origLng || optionWithoutCount.lng || lngs[0]; + delete optionWithoutCount.lng; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey; + if (!pluralExtensions.needsPlural(lngs[0], options.count)) { + pluralKey = ns + o.nsseparator + key; + } else { + pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(lngs[0], options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + } + + translated = translate(pluralKey, optionWithoutCount); + + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } else if (lngs.length > 1) { + // remove failed lng + var clone = lngs.slice(); + clone.shift(); + options = f.extend(options, { lngs: clone }); + options._origLng = optionWithoutCount._origLng; + delete options.lng; + // retry with fallbacks + translated = translate(ns + o.nsseparator + key, options); + if (translated != o.pluralNotFound) return translated; + } else { + optionWithoutCount.lng = optionWithoutCount._origLng; + delete optionWithoutCount._origLng; + translated = translate(ns + o.nsseparator + key, optionWithoutCount); + + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); + } + } + + if (needsIndefiniteArticle(options)) { + var optionsWithoutIndef = f.extend({}, options); + delete optionsWithoutIndef.indefinite_article; + optionsWithoutIndef.defaultValue = o.indefiniteNotFound; + // If we don't have a count, we want the indefinite, if we do have a count, and needsPlural is false + var indefiniteKey = ns + o.nsseparator + key + (((options.count && !needsPlural(options, lngs[0])) || !options.count) ? o.indefiniteSuffix : ""); + translated = translate(indefiniteKey, optionsWithoutIndef); + if (translated != o.indefiniteNotFound) { + return translated; + } + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + var valueType = Object.prototype.toString.apply(value); + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (valueType === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + if (o.objectTreeKeyHandler && typeof o.objectTreeKeyHandler == 'function') { + value = o.objectTreeKeyHandler(key, value, l, ns, options); + } else { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned an object instead of string.'; + f.log(value); + } + } else if (valueType !== '[object Number]' && valueType !== '[object Function]' && valueType !== '[object RegExp]') { + var copy = (valueType === '[object Array]') ? [] : {}; // apply child translation on a copy + f.each(value, function(m) { + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + }); + value = copy; + } + } + + if (typeof value === 'string' && value.trim() === '' && o.fallbackOnEmpty === true) + value = undefined; + + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length > 0))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found || (found==="" && o.fallbackOnEmpty === false)) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + options.isFallbackLookup = false; + } + + return found; + } + function detectLanguage() { + var detectedLng; + var whitelist = o.lngWhitelist || []; + var userLngChoices = []; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var params = query.split('&'); + for (var i=0; i 0) { + var key = params[i].substring(0,pos); + if (key == o.detectLngQS) { + userLngChoices.push(params[i].substring(pos+1)); + } + } + } + })(); + } + + // get from cookie + if (o.useCookie && typeof document !== 'undefined') { + var c = f.cookie.read(o.cookieName); + if (c) userLngChoices.push(c); + } + + // get from localStorage + if (o.detectLngFromLocalStorage && typeof window !== 'undefined' && window.localStorage) { + userLngChoices.push(f.localStorage.getItem('i18next_lng')); + } + + // get from navigator + if (typeof navigator !== 'undefined') { + if (navigator.languages) { // chrome only; not an array, so can't use .push.apply instead of iterating + for (var i=0;i -1) { + var parts = lng.split('-'); + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } + + if (whitelist.length === 0 || whitelist.indexOf(lng) > -1) { + detectedLng = lng; + break; + } + } + })(); + + //fallback + if (!detectedLng){ + detectedLng = o.fallbackLng[0]; + } + + return detectedLng; + } + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + + /* [code, name, numbers, pluralsType] */ + var _rules = [ + ["ach", "Acholi", [1,2], 1], + ["af", "Afrikaans",[1,2], 2], + ["ak", "Akan", [1,2], 1], + ["am", "Amharic", [1,2], 1], + ["an", "Aragonese",[1,2], 2], + ["ar", "Arabic", [0,1,2,3,11,100],5], + ["arn", "Mapudungun",[1,2], 1], + ["ast", "Asturian", [1,2], 2], + ["ay", "Aymará", [1], 3], + ["az", "Azerbaijani",[1,2],2], + ["be", "Belarusian",[1,2,5],4], + ["bg", "Bulgarian",[1,2], 2], + ["bn", "Bengali", [1,2], 2], + ["bo", "Tibetan", [1], 3], + ["br", "Breton", [1,2], 1], + ["bs", "Bosnian", [1,2,5],4], + ["ca", "Catalan", [1,2], 2], + ["cgg", "Chiga", [1], 3], + ["cs", "Czech", [1,2,5],6], + ["csb", "Kashubian",[1,2,5],7], + ["cy", "Welsh", [1,2,3,8],8], + ["da", "Danish", [1,2], 2], + ["de", "German", [1,2], 2], + ["dev", "Development Fallback", [1,2], 2], + ["dz", "Dzongkha", [1], 3], + ["el", "Greek", [1,2], 2], + ["en", "English", [1,2], 2], + ["eo", "Esperanto",[1,2], 2], + ["es", "Spanish", [1,2], 2], + ["es_ar","Argentinean Spanish", [1,2], 2], + ["et", "Estonian", [1,2], 2], + ["eu", "Basque", [1,2], 2], + ["fa", "Persian", [1], 3], + ["fi", "Finnish", [1,2], 2], + ["fil", "Filipino", [1,2], 1], + ["fo", "Faroese", [1,2], 2], + ["fr", "French", [1,2], 9], + ["fur", "Friulian", [1,2], 2], + ["fy", "Frisian", [1,2], 2], + ["ga", "Irish", [1,2,3,7,11],10], + ["gd", "Scottish Gaelic",[1,2,3,20],11], + ["gl", "Galician", [1,2], 2], + ["gu", "Gujarati", [1,2], 2], + ["gun", "Gun", [1,2], 1], + ["ha", "Hausa", [1,2], 2], + ["he", "Hebrew", [1,2], 2], + ["hi", "Hindi", [1,2], 2], + ["hr", "Croatian", [1,2,5],4], + ["hu", "Hungarian",[1,2], 2], + ["hy", "Armenian", [1,2], 2], + ["ia", "Interlingua",[1,2],2], + ["id", "Indonesian",[1], 3], + ["is", "Icelandic",[1,2], 12], + ["it", "Italian", [1,2], 2], + ["ja", "Japanese", [1], 3], + ["jbo", "Lojban", [1], 3], + ["jv", "Javanese", [0,1], 13], + ["ka", "Georgian", [1], 3], + ["kk", "Kazakh", [1], 3], + ["km", "Khmer", [1], 3], + ["kn", "Kannada", [1,2], 2], + ["ko", "Korean", [1], 3], + ["ku", "Kurdish", [1,2], 2], + ["kw", "Cornish", [1,2,3,4],14], + ["ky", "Kyrgyz", [1], 3], + ["lb", "Letzeburgesch",[1,2],2], + ["ln", "Lingala", [1,2], 1], + ["lo", "Lao", [1], 3], + ["lt", "Lithuanian",[1,2,10],15], + ["lv", "Latvian", [1,2,0],16], + ["mai", "Maithili", [1,2], 2], + ["mfe", "Mauritian Creole",[1,2],1], + ["mg", "Malagasy", [1,2], 1], + ["mi", "Maori", [1,2], 1], + ["mk", "Macedonian",[1,2],17], + ["ml", "Malayalam",[1,2], 2], + ["mn", "Mongolian",[1,2], 2], + ["mnk", "Mandinka", [0,1,2],18], + ["mr", "Marathi", [1,2], 2], + ["ms", "Malay", [1], 3], + ["mt", "Maltese", [1,2,11,20],19], + ["nah", "Nahuatl", [1,2], 2], + ["nap", "Neapolitan",[1,2], 2], + ["nb", "Norwegian Bokmal",[1,2],2], + ["ne", "Nepali", [1,2], 2], + ["nl", "Dutch", [1,2], 2], + ["nn", "Norwegian Nynorsk",[1,2],2], + ["no", "Norwegian",[1,2], 2], + ["nso", "Northern Sotho",[1,2],2], + ["oc", "Occitan", [1,2], 1], + ["or", "Oriya", [2,1], 2], + ["pa", "Punjabi", [1,2], 2], + ["pap", "Papiamento",[1,2], 2], + ["pl", "Polish", [1,2,5],7], + ["pms", "Piemontese",[1,2], 2], + ["ps", "Pashto", [1,2], 2], + ["pt", "Portuguese",[1,2], 2], + ["pt_br","Brazilian Portuguese",[1,2], 2], + ["rm", "Romansh", [1,2], 2], + ["ro", "Romanian", [1,2,20],20], + ["ru", "Russian", [1,2,5],4], + ["sah", "Yakut", [1], 3], + ["sco", "Scots", [1,2], 2], + ["se", "Northern Sami",[1,2], 2], + ["si", "Sinhala", [1,2], 2], + ["sk", "Slovak", [1,2,5],6], + ["sl", "Slovenian",[5,1,2,3],21], + ["so", "Somali", [1,2], 2], + ["son", "Songhay", [1,2], 2], + ["sq", "Albanian", [1,2], 2], + ["sr", "Serbian", [1,2,5],4], + ["su", "Sundanese",[1], 3], + ["sv", "Swedish", [1,2], 2], + ["sw", "Swahili", [1,2], 2], + ["ta", "Tamil", [1,2], 2], + ["te", "Telugu", [1,2], 2], + ["tg", "Tajik", [1,2], 1], + ["th", "Thai", [1], 3], + ["ti", "Tigrinya", [1,2], 1], + ["tk", "Turkmen", [1,2], 2], + ["tr", "Turkish", [1,2], 1], + ["tt", "Tatar", [1], 3], + ["ug", "Uyghur", [1], 3], + ["uk", "Ukrainian",[1,2,5],4], + ["ur", "Urdu", [1,2], 2], + ["uz", "Uzbek", [1,2], 1], + ["vi", "Vietnamese",[1], 3], + ["wa", "Walloon", [1,2], 1], + ["wo", "Wolof", [1], 3], + ["yo", "Yoruba", [1,2], 2], + ["zh", "Chinese", [1], 3] + ]; + + var _rulesPluralsTypes = { + 1: function(n) {return Number(n > 1);}, + 2: function(n) {return Number(n != 1);}, + 3: function(n) {return 0;}, + 4: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 5: function(n) {return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5);}, + 6: function(n) {return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2);}, + 7: function(n) {return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 8: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3);}, + 9: function(n) {return Number(n >= 2);}, + 10: function(n) {return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;}, + 11: function(n) {return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3);}, + 12: function(n) {return Number(n%10!=1 || n%100==11);}, + 13: function(n) {return Number(n !== 0);}, + 14: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3);}, + 15: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 16: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2);}, + 17: function(n) {return Number(n==1 || n%10==1 ? 0 : 1);}, + 18: function(n) {return Number(0 ? 0 : n==1 ? 1 : 2);}, + 19: function(n) {return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3);}, + 20: function(n) {return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2);}, + 21: function(n) {return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }; + + var pluralExtensions = { + + rules: (function () { + var l, rules = {}; + for (l=_rules.length; l-- ;) { + rules[_rules[l][0]] = { + name: _rules[l][1], + numbers: _rules[l][2], + plurals: _rulesPluralsTypes[_rules[l][3]] + } + } + return rules; + }()), + + // you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + needsPlural: function(lng, count) { + var parts = lng.split('-'); + + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[parts[f.getCountyIndexOfLng(lng)]]; + } + + if (ext && ext.numbers.length <= 1) { + return false; + } else { + return this.get(lng, count) !== 1; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i; + if (ext.noAbs) { + i = ext.plurals(c); + } else { + i = ext.plurals(Math.abs(c)); + } + + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[f.getCountyIndexOfLng(lng)], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.hasResourceBundle = hasResourceBundle; + i18n.getResourceBundle = getResourceBundle; + i18n.addResource = addResource; + i18n.addResources = addResources; + i18n.removeResourceBundle = removeResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.applyReplacement = f.applyReplacement; + i18n.options = o; + +})(typeof exports === 'undefined' ? window : exports); \ No newline at end of file diff --git a/libs/i18next/release/i18next-latest.min.js b/libs/i18next/release/i18next-latest.min.js new file mode 100644 index 00000000..5ba7b5ba --- /dev/null +++ b/libs/i18next/release/i18next-latest.min.js @@ -0,0 +1,5 @@ +// i18next, v1.8.2 +// Copyright (c)2015 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +!function(a){function b(a,b){if(!b||"function"==typeof b)return a;for(var c in b)a[c]=b[c];return a}function c(a,b){for(var d in b)d in a?c(a[d],b[d]):a[d]=b[d];return a}function d(a,b,c){var d,e=0,f=a.length,g=void 0===f||"[object Array]"!==Object.prototype.toString.apply(a)||"function"==typeof a;if(c)if(g){for(d in a)if(b.apply(a[d],c)===!1)break}else for(;f>e&&b.apply(a[e++],c)!==!1;);else if(g){for(d in a)if(b.call(a[d],d,a[d])===!1)break}else for(;f>e&&b.call(a[e],e,a[e++])!==!1;);return a}function e(a){return"string"==typeof a?a.replace(/[&<>"'\/]/g,function(a){return Q[a]}):a}function f(a){var b=function(a){if(window.XMLHttpRequest)return a(null,new XMLHttpRequest);if(window.ActiveXObject)try{return a(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(b){return a(null,new ActiveXObject("Microsoft.XMLHTTP"))}return a(new Error)},c=function(a){if("string"==typeof a)return a;var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")},d=function(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;cd?b+=String.fromCharCode(d):d>127&&2048>d?(b+=String.fromCharCode(d>>6|192),b+=String.fromCharCode(63&d|128)):(b+=String.fromCharCode(d>>12|224),b+=String.fromCharCode(d>>6&63|128),b+=String.fromCharCode(63&d|128))}return b},e=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";a=d(a);var c,e,f,g,h,i,j,k="",l=0;do c=a.charCodeAt(l++),e=a.charCodeAt(l++),f=a.charCodeAt(l++),g=c>>2,h=(3&c)<<4|e>>4,i=(15&e)<<2|f>>6,j=63&f,isNaN(e)?i=j=64:isNaN(f)&&(j=64),k+=b.charAt(g)+b.charAt(h)+b.charAt(i)+b.charAt(j),c=e=f="",g=h=i=j="";while(l1&&(d+=d.indexOf("?")>-1?"&"+k:"?"+k),e.jsonp){var l=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=d,void l.appendChild(m)}}b(function(b,c){if(b)return h(b);c.open(a,d,e.async);for(var f in j)j.hasOwnProperty(f)&&c.setRequestHeader(f,j[f]);c.onreadystatechange=function(){if(4===c.readyState){var a=c.responseText||"";if(!h)return;h(c.status,{text:function(){return a},json:function(){try{return JSON.parse(a)}catch(b){return T.error("Can not parse JSON. URL: "+d),{}}}})}},c.send(i)})},h={authBasic:function(a,b){g.headers.Authorization="Basic "+e(a+":"+b)},connect:function(a,b,c){return g("CONNECT",a,b,c)},del:function(a,b,c){return g("DELETE",a,b,c)},get:function(a,b,c){return g("GET",a,b,c)},head:function(a,b,c){return g("HEAD",a,b,c)},headers:function(a){g.headers=a||{}},isAllowed:function(a,b,c){this.options(a,function(a,d){c(-1!==d.text().indexOf(b))})},options:function(a,b,c){return g("OPTIONS",a,b,c)},patch:function(a,b,c){return g("PATCH",a,b,c)},post:function(a,b,c){return g("POST",a,b,c)},put:function(a,b,c){return g("PUT",a,b,c)},trace:function(a,b,c){return g("TRACE",a,b,c)}},i=a.type?a.type.toLowerCase():"get";h[i](a.url,a,function(b,c){200===b||0===b&&c.text()?a.success(c.json(),b,null):a.error(c.text(),b,null)})}function g(a,b){"function"==typeof a&&(b=a,a={}),a=a||{},T.extend(P,a),delete P.fixLng,P.functions&&(delete P.functions,T.extend(T,a.functions)),"string"==typeof P.ns&&(P.ns={namespaces:[P.ns],defaultNs:P.ns}),"string"==typeof P.fallbackNS&&(P.fallbackNS=[P.fallbackNS]),("string"==typeof P.fallbackLng||"boolean"==typeof P.fallbackLng)&&(P.fallbackLng=[P.fallbackLng]),P.interpolationPrefixEscaped=T.regexEscape(P.interpolationPrefix),P.interpolationSuffixEscaped=T.regexEscape(P.interpolationSuffix),P.lng||(P.lng=T.detectLanguage()),M=T.toLanguages(P.lng),H=M[0],T.log("currentLng set to: "+H),P.useCookie&&T.cookie.read(P.cookieName)!==H&&T.cookie.create(P.cookieName,H,P.cookieExpirationTime,P.cookieDomain),P.detectLngFromLocalStorage&&"undefined"!=typeof document&&window.localStorage&&T.localStorage.setItem("i18next_lng",H);var c=B;a.fixLng&&(c=function(a,b){return b=b||{},b.lng=b.lng||c.lng,B(a,b)},c.lng=H),W.setCurrentLng(H),I&&P.setJqueryExt&&u();var d;if(I&&I.Deferred&&(d=I.Deferred()),!P.resStore){var e=T.toLanguages(P.lng);"string"==typeof P.preload&&(P.preload=[P.preload]);for(var f=0,g=P.preload.length;g>f;f++)for(var h=T.toLanguages(P.preload[f]),i=0,j=h.length;j>i;i++)e.indexOf(h[i])<0&&e.push(h[i]);return J.sync.load(e,P,function(a,e){K=e,N=!0,b&&b(c),d&&d.resolve(c)}),d?d.promise():void 0}return K=P.resStore,N=!0,b&&b(c),d&&d.resolve(c),d?d.promise():void 0}function h(a,b){"string"==typeof a&&(a=[a]);for(var c=0,d=a.length;d>c;c++)P.preload.indexOf(a[c])<0&&P.preload.push(a[c]);return g(b)}function i(a,b,c,d){"string"!=typeof b?(c=b,b=P.ns.defaultNs):P.ns.namespaces.indexOf(b)<0&&P.ns.namespaces.push(b),K[a]=K[a]||{},K[a][b]=K[a][b]||{},d?T.deepExtend(K[a][b],c):T.extend(K[a][b],c),P.useLocalStorage&&O._storeLocal(K)}function j(a,b){"string"!=typeof b&&(b=P.ns.defaultNs),K[a]=K[a]||{};var c=K[a][b]||{},d=!1;for(var e in c)c.hasOwnProperty(e)&&(d=!0);return d}function k(a,b){return"string"!=typeof b&&(b=P.ns.defaultNs),K[a]=K[a]||{},T.extend({},K[a][b])}function l(a,b){"string"!=typeof b&&(b=P.ns.defaultNs),K[a]=K[a]||{},K[a][b]={},P.useLocalStorage&&O._storeLocal(K)}function m(a,b,c,d){"string"!=typeof b?(resource=b,b=P.ns.defaultNs):P.ns.namespaces.indexOf(b)<0&&P.ns.namespaces.push(b),K[a]=K[a]||{},K[a][b]=K[a][b]||{};for(var e=c.split(P.keyseparator),f=0,g=K[a][b];e[f];)f==e.length-1?g[e[f]]=d:(null==g[e[f]]&&(g[e[f]]={}),g=g[e[f]]),f++;P.useLocalStorage&&O._storeLocal(K)}function n(a,b,c){"string"!=typeof b?(resource=b,b=P.ns.defaultNs):P.ns.namespaces.indexOf(b)<0&&P.ns.namespaces.push(b);for(var d in c)"string"==typeof c[d]&&m(a,b,d,c[d])}function o(a){P.ns.defaultNs=a}function p(a,b){q([a],b)}function q(a,b){var c={dynamicLoad:P.dynamicLoad,resGetPath:P.resGetPath,getAsync:P.getAsync,customLoad:P.customLoad,ns:{namespaces:a,defaultNs:""}},d=T.toLanguages(P.lng);"string"==typeof P.preload&&(P.preload=[P.preload]);for(var e=0,f=P.preload.length;f>e;e++)for(var g=T.toLanguages(P.preload[e]),h=0,i=g.length;i>h;h++)d.indexOf(g[h])<0&&d.push(g[h]);for(var j=[],k=0,l=d.length;l>k;k++){var m=!1,n=K[d[k]];if(n)for(var o=0,p=a.length;p>o;o++)n[a[o]]||(m=!0);else m=!0;m&&j.push(d[k])}j.length?J.sync._fetch(j,c,function(c,d){var e=a.length*j.length;T.each(a,function(a,c){P.ns.namespaces.indexOf(c)<0&&P.ns.namespaces.push(c),T.each(j,function(a,f){K[f]=K[f]||{},K[f][c]=d[f][c],e--,0===e&&b&&(P.useLocalStorage&&J.sync._storeLocal(K),b())})})}):b&&b()}function r(a,b,c){return"function"==typeof b?(c=b,b={}):b||(b={}),b.lng=a,g(b,c)}function s(){return H}function t(a){K={},r(H,a)}function u(){function a(a,b,c){if(0!==b.length){var d="text";if(0===b.indexOf("[")){var e=b.split("]");b=e[1],d=e[0].substr(1,e[0].length-1)}b.indexOf(";")===b.length-1&&(b=b.substr(0,b.length-2));var f;if("html"===d)f=P.defaultValueFromContent?I.extend({defaultValue:a.html()},c):c,a.html(I.t(b,f));else if("text"===d)f=P.defaultValueFromContent?I.extend({defaultValue:a.text()},c):c,a.text(I.t(b,f));else if("prepend"===d)f=P.defaultValueFromContent?I.extend({defaultValue:a.html()},c):c,a.prepend(I.t(b,f));else if("append"===d)f=P.defaultValueFromContent?I.extend({defaultValue:a.html()},c):c,a.append(I.t(b,f));else if(0===d.indexOf("data-")){var g=d.substr("data-".length);f=P.defaultValueFromContent?I.extend({defaultValue:a.data(g)},c):c;var h=I.t(b,f);a.data(g,h),a.attr(d,h)}else f=P.defaultValueFromContent?I.extend({defaultValue:a.attr(d)},c):c,a.attr(d,I.t(b,f))}}function b(b,c){var d=b.attr(P.selectorAttr);if(d||"undefined"==typeof d||d===!1||(d=b.text()||b.val()),d){var e=b,f=b.data("i18n-target");if(f&&(e=b.find(f)||b),c||P.useDataAttrOptions!==!0||(c=b.data("i18n-options")),c=c||{},d.indexOf(";")>=0){var g=d.split(";");I.each(g,function(b,d){""!==d&&a(e,d,c)})}else a(e,d,c);P.useDataAttrOptions===!0&&b.data("i18n-options",c)}}I.t=I.t||B,I.fn.i18n=function(a){return this.each(function(){b(I(this),a);var c=I(this).find("["+P.selectorAttr+"]");c.each(function(){b(I(this),a)})})}}function v(a,b,c,d){if(!a)return a;if(d=d||b,a.indexOf(d.interpolationPrefix||P.interpolationPrefix)<0)return a;var e=d.interpolationPrefix?T.regexEscape(d.interpolationPrefix):P.interpolationPrefixEscaped,f=d.interpolationSuffix?T.regexEscape(d.interpolationSuffix):P.interpolationSuffixEscaped,g="HTML"+f,h=b.replace&&"object"==typeof b.replace?b.replace:b;return T.each(h,function(b,h){var i=c?c+P.keyseparator+b:b;"object"==typeof h&&null!==h?a=v(a,h,i,d):d.escapeInterpolation||P.escapeInterpolation?(a=a.replace(new RegExp([e,i,g].join(""),"g"),T.regexReplacementEscape(h)),a=a.replace(new RegExp([e,i,f].join(""),"g"),T.regexReplacementEscape(T.escape(h)))):a=a.replace(new RegExp([e,i,f].join(""),"g"),T.regexReplacementEscape(h))}),a}function w(a,b){var c=",",d="{",e="}",f=T.extend({},b);for(delete f.postProcess;-1!=a.indexOf(P.reusePrefix)&&(L++,!(L>P.maxRecursion));){var g=a.lastIndexOf(P.reusePrefix),h=a.indexOf(P.reuseSuffix,g)+P.reuseSuffix.length,i=a.substring(g,h),j=i.replace(P.reusePrefix,"").replace(P.reuseSuffix,"");if(g>=h)return T.error("there is an missing closing in following translation value",a),"";if(-1!=j.indexOf(c)){var k=j.indexOf(c);if(-1!=j.indexOf(d,k)&&-1!=j.indexOf(e,k)){var l=j.indexOf(d,k),m=j.indexOf(e,l)+e.length;try{f=T.extend(f,JSON.parse(j.substring(l,m))),j=j.substring(0,k)}catch(n){}}}var o=E(j,f);a=a.replace(i,T.regexReplacementEscape(o))}return a}function x(a){return a.context&&("string"==typeof a.context||"number"==typeof a.context)}function y(a){return void 0!==a.count&&"string"!=typeof a.count}function z(a){return void 0!==a.indefinite_article&&"string"!=typeof a.indefinite_article&&a.indefinite_article}function A(a,b){b=b||{};var c=C(a,b),d=F(a,b);return void 0!==d||d===c}function B(a,b){return b=b||{},N?(L=0,E.apply(null,arguments)):(T.log("i18next not finished initialization. you might have called t function before loading resources finished."),b.defaultValue||"")}function C(a,b){return void 0!==b.defaultValue?b.defaultValue:a}function D(){for(var a=[],b=1;b1)for(var d=0;d-1&&(e=c.split(P.nsseparator),i=e[0],c=e[1]),void 0===g&&P.sendMissing&&"function"==typeof P.missingKeyHandler&&(b.lng?P.missingKeyHandler(h[0],i,c,f,h):P.missingKeyHandler(P.lng,i,c,f,h));var j;j="string"==typeof P.postProcess&&""!==P.postProcess?[P.postProcess]:"array"==typeof P.postProcess||"object"==typeof P.postProcess?P.postProcess:[],"string"==typeof b.postProcess&&""!==b.postProcess?j=j.concat([b.postProcess]):("array"==typeof b.postProcess||"object"==typeof b.postProcess)&&(j=j.concat(b.postProcess)),void 0!==g&&j.length&&j.forEach(function(a){X[a]&&(g=X[a](g,c,b))});var k=f;if(f.indexOf(P.nsseparator)>-1&&(e=f.split(P.nsseparator),k=e[1]),k===c&&P.parseMissingKey&&(f=P.parseMissingKey(f)),void 0===g&&(f=v(f,b),f=w(f,b),j.length)){var l=C(c,b);j.forEach(function(a){X[a]&&(g=X[a](l,c,b))})}return void 0!==g?g:f}function F(a,b){b=b||{};var c,d,e=C(a,b),f=M;if(!K)return e;if("cimode"===f[0].toLowerCase())return e;if(b.lngs&&(f=b.lngs),b.lng&&(f=T.toLanguages(b.lng,b.fallbackLng),!K[f[0]])){var g=P.getAsync;P.getAsync=!1,J.sync.load(f,P,function(a,b){T.extend(K,b),P.getAsync=g})}var h=b.ns||P.ns.defaultNs;if(a.indexOf(P.nsseparator)>-1){var i=a.split(P.nsseparator);h=i[0],a=i[1]}if(x(b)){c=T.extend({},b),delete c.context,c.defaultValue=P.contextNotFound;var j=h+P.nsseparator+a+"_"+b.context;if(d=B(j,c),d!=P.contextNotFound)return v(d,{context:b.context})}if(y(b,f[0])){c=T.extend({lngs:[f[0]]},b),delete c.count,c._origLng=c._origLng||c.lng||f[0],delete c.lng,c.defaultValue=P.pluralNotFound;var k;if(W.needsPlural(f[0],b.count)){k=h+P.nsseparator+a+P.pluralSuffix;var l=W.get(f[0],b.count);l>=0?k=k+"_"+l:1===l&&(k=h+P.nsseparator+a)}else k=h+P.nsseparator+a;if(d=B(k,c),d!=P.pluralNotFound)return v(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix});if(!(f.length>1))return c.lng=c._origLng,delete c._origLng,d=B(h+P.nsseparator+a,c),v(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix});var m=f.slice();if(m.shift(),b=T.extend(b,{lngs:m}),b._origLng=c._origLng,delete b.lng,d=B(h+P.nsseparator+a,b),d!=P.pluralNotFound)return d}if(z(b)){var n=T.extend({},b);delete n.indefinite_article,n.defaultValue=P.indefiniteNotFound;var o=h+P.nsseparator+a+(b.count&&!y(b,f[0])||!b.count?P.indefiniteSuffix:"");if(d=B(o,n),d!=P.indefiniteNotFound)return d}for(var p,q=a.split(P.keyseparator),r=0,s=f.length;s>r&&void 0===p;r++){for(var t=f[r],u=0,A=K[t]&&K[t][h];q[u];)A=A&&A[q[u]],u++;if(void 0!==A){var D=Object.prototype.toString.apply(A);if("string"==typeof A)A=v(A,b),A=w(A,b);else if("[object Array]"!==D||P.returnObjectTrees||b.returnObjectTrees){if(null===A&&P.fallbackOnNull===!0)A=void 0;else if(null!==A)if(P.returnObjectTrees||b.returnObjectTrees){if("[object Number]"!==D&&"[object Function]"!==D&&"[object RegExp]"!==D){var G="[object Array]"===D?[]:{};T.each(A,function(c){G[c]=E(h+P.nsseparator+a+P.keyseparator+c,b)}),A=G}}else P.objectTreeKeyHandler&&"function"==typeof P.objectTreeKeyHandler?A=P.objectTreeKeyHandler(a,A,t,h,b):(A="key '"+h+":"+a+" ("+t+")' returned an object instead of string.",T.log(A))}else A=A.join("\n"),A=v(A,b),A=w(A,b);"string"==typeof A&&""===A.trim()&&P.fallbackOnEmpty===!0&&(A=void 0),p=A}}if(void 0===p&&!b.isFallbackLookup&&(P.fallbackToDefaultNS===!0||P.fallbackNS&&P.fallbackNS.length>0)){if(b.isFallbackLookup=!0,P.fallbackNS.length){for(var H=0,I=P.fallbackNS.length;I>H;H++)if(p=F(P.fallbackNS[H]+P.nsseparator+a,b),p||""===p&&P.fallbackOnEmpty===!1){var L=p.indexOf(P.nsseparator)>-1?p.split(P.nsseparator)[1]:p,N=e.indexOf(P.nsseparator)>-1?e.split(P.nsseparator)[1]:e;if(L!==N)break}}else p=F(a,b);b.isFallbackLookup=!1}return p}function G(){var a,b=P.lngWhitelist||[],c=[];if("undefined"!=typeof window&&!function(){for(var a=window.location.search.substring(1),b=a.split("&"),d=0;d0){var f=b[d].substring(0,e);f==P.detectLngQS&&c.push(b[d].substring(e+1))}}}(),P.useCookie&&"undefined"!=typeof document){var d=T.cookie.read(P.cookieName);d&&c.push(d)}if(P.detectLngFromLocalStorage&&"undefined"!=typeof window&&window.localStorage&&c.push(T.localStorage.getItem("i18next_lng")),"undefined"!=typeof navigator){if(navigator.languages)for(var e=0;e-1){var f=e.split("-");e=P.lowerCaseLng?f[0].toLowerCase()+"-"+f[1].toLowerCase():f[0].toLowerCase()+"-"+f[1].toUpperCase()}if(0===b.length||b.indexOf(e)>-1){a=e;break}}}(),a||(a=P.fallbackLng[0]),a}Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>0&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=c;arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d))));for(var e=d>=0?Math.min(d,c-1):c-Math.abs(d);e>=0;e--)if(e in b&&b[e]===a)return e;return-1}),"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")});var H,I=a.jQuery||a.Zepto,J={},K={},L=0,M=[],N=!1,O={};"undefined"!=typeof module&&module.exports?module.exports=J:(I&&(I.i18n=I.i18n||J),a.i18n=a.i18n||J),O={load:function(a,b,c){b.useLocalStorage?O._loadLocal(a,b,function(d,e){for(var f=[],g=0,h=a.length;h>g;g++)e[a[g]]||f.push(a[g]);f.length>0?O._fetch(f,b,function(a,b){T.extend(e,b),O._storeLocal(b),c(null,e)}):c(null,e)}):O._fetch(a,b,function(a,b){c(null,b)})},_loadLocal:function(a,b,c){var d={},e=(new Date).getTime();if(window.localStorage){var f=a.length;T.each(a,function(a,g){var h=T.localStorage.getItem("res_"+g);h&&(h=JSON.parse(h),h.i18nStamp&&h.i18nStamp+b.localStorageExpirationTime>e&&(d[g]=h)),f--,0===f&&c(null,d)})}},_storeLocal:function(a){if(window.localStorage)for(var b in a)a[b].i18nStamp=(new Date).getTime(),T.localStorage.setItem("res_"+b,JSON.stringify(a[b]))},_fetch:function(a,b,c){var d=b.ns,e={};if(b.dynamicLoad){var f=function(a,b){c(null,b)};if("function"==typeof b.customLoad)b.customLoad(a,d.namespaces,b,f);else{var g=v(b.resGetPath,{lng:a.join("+"),ns:d.namespaces.join("+")});T.ajax({url:g,success:function(a){T.log("loaded: "+g),f(null,a)},error:function(a,b,c){T.log("failed loading: "+g),f("failed loading resource.json error: "+c)},dataType:"json",async:b.getAsync})}}else{var h,i=d.namespaces.length*a.length;T.each(d.namespaces,function(d,f){T.each(a,function(a,d){var g=function(a,b){a&&(h=h||[],h.push(a)),e[d]=e[d]||{},e[d][f]=b,i--,0===i&&c(h,e)};"function"==typeof b.customLoad?b.customLoad(d,f,b,g):O._fetchOne(d,f,b,g)})})}},_fetchOne:function(a,b,c,d){var e=v(c.resGetPath,{lng:a,ns:b});T.ajax({url:e,success:function(a){T.log("loaded: "+e),d(null,a)},error:function(a,b,c){if(b&&200==b||a&&a.status&&200==a.status)T.error("There is a typo in: "+e);else if(b&&404==b||a&&a.status&&404==a.status)T.log("Does not exist: "+e);else{var f=b?b:a&&a.status?a.status:null;T.log(f+" when loading "+e)}d(c,{})},dataType:"json",async:c.getAsync})},postMissing:function(a,b,c,d,e){var f={};f[c]=d;var g=[];if("fallback"===P.sendMissingTo&&P.fallbackLng[0]!==!1)for(var h=0;hh;h++)g.push({lng:e[h],url:v(P.resPostPath,{lng:e[h],ns:b})});for(var j=0,k=g.length;k>j;j++){var l=g[j];T.ajax({url:l.url,type:P.sendType,data:f,success:function(){T.log("posted missing key '"+c+"' to: "+l.url);for(var a=c.split("."),e=0,f=K[l.lng][b];a[e];)f=f[a[e]]=e===a.length-1?d:f[a[e]]||{},e++},error:function(){T.log("failed posting missing key '"+c+"' to: "+l.url)},dataType:"json",async:P.postAsync})}},reload:t};var P={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:["dev"],fallbackNS:[],detectLngQS:"setLng",detectLngFromLocalStorage:!1,ns:{namespaces:["translation"],defaultNs:"translation"},fallbackOnNull:!0,fallbackOnEmpty:!1,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",defaultVariables:!1,reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,indefiniteSuffix:"_indefinite",indefiniteNotFound:["indefinite_not_found",Math.random()].join(""),setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",cookieDomain:void 0,objectTreeKeyHandler:void 0,postProcess:void 0,parseMissingKey:void 0,missingKeyHandler:O.postMissing,shortcutFunction:"sprintf"},Q={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},R={create:function(a,b,c,d){var e;if(c){var f=new Date;f.setTime(f.getTime()+60*c*1e3),e="; expires="+f.toGMTString()}else e="";d=d?"domain="+d+";":"",document.cookie=a+"="+b+e+";"+d+"path=/"},read:function(a){for(var b=a+"=",c=document.cookie.split(";"),d=0;d-1){var c=a.split("-");b=P.lowerCaseLng?c[0].toLowerCase()+"-"+c[1].toLowerCase():c[0].toLowerCase()+"-"+c[1].toUpperCase()}else b=P.lowerCaseLng?a.toLowerCase():a;return b}var c=this.log,d=[],e=P.lngWhitelist||!1,f=function(a){!e||e.indexOf(a)>-1?d.push(a):c("rejecting non-whitelisted language: "+a)};if("string"==typeof a&&a.indexOf("-")>-1){var g=a.split("-");"unspecific"!==P.load&&f(b(a)),"current"!==P.load&&f(b(g[this.getCountyIndexOfLng(a)]))}else f(b(a));for(var h=0;h1)},2:function(a){return Number(1!=a)},3:function(){return 0},4:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},5:function(a){return Number(0===a?0:1==a?1:2==a?2:a%100>=3&&10>=a%100?3:a%100>=11?4:5)},6:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)},7:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},8:function(a){return Number(1==a?0:2==a?1:8!=a&&11!=a?2:3)},9:function(a){return Number(a>=2)},10:function(a){return Number(1==a?0:2==a?1:7>a?2:11>a?3:4)},11:function(a){return Number(1==a||11==a?0:2==a||12==a?1:a>2&&20>a?2:3)},12:function(a){return Number(a%10!=1||a%100==11)},13:function(a){return Number(0!==a)},14:function(a){return Number(1==a?0:2==a?1:3==a?2:3)},15:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&(10>a%100||a%100>=20)?1:2)},16:function(a){return Number(a%10==1&&a%100!=11?0:0!==a?1:2)},17:function(a){return Number(1==a||a%10==1?0:1)},18:function(a){return Number(1==a?1:2)},19:function(a){return Number(1==a?0:0===a||a%100>1&&11>a%100?1:a%100>10&&20>a%100?2:3)},20:function(a){return Number(1==a?0:0===a||a%100>0&&20>a%100?1:2)},21:function(a){return Number(a%100==1?1:a%100==2?2:a%100==3||a%100==4?3:0)}},W={rules:function(){var a,b={};for(a=U.length;a--;)b[U[a][0]]={name:U[a][1],numbers:U[a][2],plurals:V[U[a][3]]};return b}(),addRule:function(a,b){W.rules[a]=b},setCurrentLng:function(a){if(!W.currentRule||W.currentRule.lng!==a){var b=a.split("-");W.currentRule={lng:a,rule:W.rules[b[0]]}}},needsPlural:function(a,b){var c,d=a.split("-");return c=W.currentRule&&W.currentRule.lng===a?W.currentRule.rule:W.rules[d[T.getCountyIndexOfLng(a)]],c&&c.numbers.length<=1?!1:1!==this.get(a,b)},get:function(a,b){function c(b,c){var d;if(d=W.currentRule&&W.currentRule.lng===a?W.currentRule.rule:W.rules[b]){var e;e=d.plurals(d.noAbs?c:Math.abs(c));var f=d.numbers[e];return 2===d.numbers.length&&1===d.numbers[0]&&(2===f?f=-1:1===f&&(f=1)),f}return 1===c?"1":"-1"}var d=a.split("-");return c(d[T.getCountyIndexOfLng(a)],b)}},X={},Y=function(a,b){X[a]=b},Z=function(){function a(a){return Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}function b(a,b){for(var c=[];b>0;c[--b]=a);return c.join("")}var c=function(){return c.cache.hasOwnProperty(arguments[0])||(c.cache[arguments[0]]=c.parse(arguments[0])),c.format.call(null,c.cache[arguments[0]],arguments)};return c.format=function(c,d){var e,f,g,h,i,j,k,l=1,m=c.length,n="",o=[];for(f=0;m>f;f++)if(n=a(c[f]),"string"===n)o.push(c[f]);else if("array"===n){if(h=c[f],h[2])for(e=d[l],g=0;g=0?"+"+e:e,j=h[4]?"0"==h[4]?"0":h[4].charAt(1):" ",k=h[6]-String(e).length,i=h[6]?b(j,k):"",o.push(h[5]?e+i:i+e)}return o.join("")},c.cache={},c.parse=function(a){for(var b=a,c=[],d=[],e=0;b;){if(null!==(c=/^[^\x25]+/.exec(b)))d.push(c[0]);else if(null!==(c=/^\x25{2}/.exec(b)))d.push("%");else{if(null===(c=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(b)))throw"[sprintf] huh?";if(c[2]){e|=1;var f=[],g=c[2],h=[];if(null===(h=/^([a-z_][a-z_\d]*)/i.exec(g)))throw"[sprintf] huh?";for(f.push(h[1]);""!==(g=g.substring(h[0].length));)if(null!==(h=/^\.([a-z_][a-z_\d]*)/i.exec(g)))f.push(h[1]);else{if(null===(h=/^\[(\d+)\]/.exec(g)))throw"[sprintf] huh?";f.push(h[1])}c[2]=f}else e|=2;if(3===e)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";d.push(c)}b=b.substring(c[0].length)}return d},c}(),$=function(a,b){return b.unshift(a),Z.apply(null,b)};Y("sprintf",function(a,b,c){return c.sprintf?"[object Array]"===Object.prototype.toString.apply(c.sprintf)?$(a,c.sprintf):"object"==typeof c.sprintf?Z(a,c.sprintf):a:a}),J.init=g,J.setLng=r,J.preload=h,J.addResourceBundle=i,J.hasResourceBundle=j,J.getResourceBundle=k,J.addResource=m,J.addResources=n,J.removeResourceBundle=l,J.loadNamespace=p,J.loadNamespaces=q,J.setDefaultNamespace=o,J.t=B,J.translate=B,J.exists=A,J.detectLanguage=T.detectLanguage,J.pluralExtensions=W,J.sync=O,J.functions=T,J.lng=s,J.addPostProcessor=Y,J.applyReplacement=T.applyReplacement,J.options=P}("undefined"==typeof exports?window:exports); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd-1.5.10.js b/libs/i18next/release/i18next.amd-1.5.10.js new file mode 100644 index 00000000..a448f8eb --- /dev/null +++ b/libs/i18next/release/i18next.amd-1.5.10.js @@ -0,0 +1,2366 @@ +// i18next, v1.5.10 +// Copyright (c)2012 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function (root, factory) { + if (typeof exports === 'object') { + + module.exports = factory(); + + } else if (typeof define === 'function' && define.amd) { + + define([], factory); + + } +}(this, function () { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + var $ = undefined + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = []; + + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: 'dev', + detectLngQS: 'setLng', + ns: 'translation', + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + + postProcess: undefined + }; + + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = '?' + queryString.join('&'); + url += queryString !== '?' ? queryString : ''; + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + return JSON.parse(data); + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, {async: options.async}, function (status, data) { + if (status === 200) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + document.cookie = name+"="+value+expires+"; path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : _ajax, + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + toLanguages: function(lng) { + var languages = []; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + + if (o.load !== 'unspecific') languages.push(lng); + if (o.load !== 'current') languages.push(parts[0]); + } else { + languages.push(lng); + } + + if (languages.indexOf(o.fallbackLng) === -1 && o.fallbackLng) languages.push(o.fallbackLng); + + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + if (o.lng) { + // set cookie with lng set (as detectLanguage will set cookie on need) + if (o.useCookie) f.cookie.create(o.cookieName, o.lng, o.cookieExpirationTime); + } else { + o.lng = o.fallbackLng; + if (o.useCookie) f.cookie.remove(o.cookieName); + } + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + if (cb) cb(translate); + if (deferred) deferred.resolve(); + return deferred; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + + if (cb) cb(translate); + if (deferred) deferred.resolve(); + }); + + return deferred; + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, cb) { + return init({lng: lng}, cb); + } + + function lng() { + return currentLng; + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } + else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key) return; + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') <= key.length-1) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + parse(ele, k, options); + }); + + } else { + parse(ele, k, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + + function applyReplacement(str, replacementHash, nestedKey) { + if (str.indexOf(o.interpolationPrefix) < 0) return str; + + f.each(replacementHash, function(key, value) { + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nestedKey ? nestedKey + '.' + key : key); + } else { + str = str.replace(new RegExp([o.interpolationPrefixEscaped, nestedKey ? nestedKey + '.' + key : key, o.interpolationSuffixEscaped].join(''), 'g'), value); + } + }); + return str; + } + + function applyReuse(translated, options){ + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.indexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_sans_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + var translated_token = _translate(token_sans_symbols, opts); + translated = translated.replace(token, translated_token); + } + return translated; + } + + function hasContext(options) { + return (options.context && typeof options.context == 'string'); + } + + function needsPlural(options) { + return (options.count !== undefined && typeof options.count != 'string' && options.count !== 1); + } + + function translate(key, options){ + replacementCounter = 0; + return _translate(key, options); + } + + function _translate(key, options){ + options = options || {}; + + if (!resStore) { return notfound; } // no resStore to translate from + + var optionWithoutCount, translated + , notfound = options.defaultValue || key + , lngs = languages; + + if (options.lng) { + lngs = f.toLanguages(options.lng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + ':' + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.count; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey = ns + ':' + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(currentLng, options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + ':' + key; // singular + } + + translated = translate(pluralKey, optionWithoutCount); + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { count: options.count }); // apply replacement for count only + } // else continue translation with original/singular key + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (Object.prototype.toString.apply(value) === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned a object instead of string.'; + f.log(value); + } else { + for (var m in value) { + // apply translation on childs + value[m] = _translate(ns + ':' + key + '.' + m, options); + } + } + } + found = value; + } + } + + if (found === undefined && o.sendMissing) { + if (options.lng) { + sync.postMissing(options.lng, ns, key, notfound, lngs); + } else { + sync.postMissing(o.lng, ns, key, notfound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found !== undefined && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + if (found === undefined) { + notfound = applyReplacement(notfound, options); + notfound = applyReuse(notfound, options); + } + + return (found !== undefined) ? found : notfound; + } + + function detectLanguage() { + var detectedLng; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var parms = query.split('&'); + for (var i=0; i 0) { + var key = parms[i].substring(0,pos); + var val = parms[i].substring(pos+1); + qsParm[key] = val; + } + } + })(); + if (qsParm[o.detectLngQS]) { + detectedLng = qsParm[o.detectLngQS]; + } + } + + // get from cookie + if (!detectedLng && typeof document !== 'undefined' && o.useCookie ) { + var c = f.cookie.read(o.cookieName); + if (c) detectedLng = c; + } + + // get from navigator + if (!detectedLng && typeof navigator !== 'undefined') { + detectedLng = (navigator.language) ? navigator.language : navigator.userLanguage; + } + + return detectedLng; + } + var sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + window.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + cb(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + cb('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback') { + urls.push({lng: o.fallbackLng, url: applyReplacement(o.resPostPath, { lng: o.fallbackLng, ns: ns })}); + } else if (o.sendMissingTo === 'current') { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + resStore[item.lng][ns][key] = defaultValue; + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + } + }; + + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + var pluralExtensions = { + + rules: { + "ach": { + "name": "Acholi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "af": { + "name": "Afrikaans", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ak": { + "name": "Akan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "am": { + "name": "Amharic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "an": { + "name": "Aragonese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ar": { + "name": "Arabic", + "numbers": [ + 0, + 1, + 2, + 3, + 11, + 100 + ], + "plurals": function(n) { return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5); } + }, + "arn": { + "name": "Mapudungun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ast": { + "name": "Asturian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ay": { + "name": "Aymar\u00e1", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "az": { + "name": "Azerbaijani", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "be": { + "name": "Belarusian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "bg": { + "name": "Bulgarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bn": { + "name": "Bengali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bo": { + "name": "Tibetan", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "br": { + "name": "Breton", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "bs": { + "name": "Bosnian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ca": { + "name": "Catalan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "cgg": { + "name": "Chiga", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "cs": { + "name": "Czech", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "csb": { + "name": "Kashubian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "cy": { + "name": "Welsh", + "numbers": [ + 1, + 2, + 3, + 8 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3); } + }, + "da": { + "name": "Danish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "de": { + "name": "German", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "dz": { + "name": "Dzongkha", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "el": { + "name": "Greek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "en": { + "name": "English", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eo": { + "name": "Esperanto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es": { + "name": "Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es_ar": { + "name": "Argentinean Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "et": { + "name": "Estonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eu": { + "name": "Basque", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fa": { + "name": "Persian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "fi": { + "name": "Finnish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fil": { + "name": "Filipino", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fo": { + "name": "Faroese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fr": { + "name": "French", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fur": { + "name": "Friulian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fy": { + "name": "Frisian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ga": { + "name": "Irish", + "numbers": [ + 1, + 2, + 3, + 7, + 11 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;} + }, + "gd": { + "name": "Scottish Gaelic", + "numbers": [ + 1, + 2, + 3, + 20 + ], + "plurals": function(n) { return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3); } + }, + "gl": { + "name": "Galician", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gu": { + "name": "Gujarati", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gun": { + "name": "Gun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ha": { + "name": "Hausa", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "he": { + "name": "Hebrew", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hi": { + "name": "Hindi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hr": { + "name": "Croatian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "hu": { + "name": "Hungarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hy": { + "name": "Armenian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ia": { + "name": "Interlingua", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "id": { + "name": "Indonesian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "is": { + "name": "Icelandic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n%10!=1 || n%100==11); } + }, + "it": { + "name": "Italian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ja": { + "name": "Japanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jbo": { + "name": "Lojban", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jv": { + "name": "Javanese", + "numbers": [ + 0, + 1 + ], + "plurals": function(n) { return Number(n !== 0); } + }, + "ka": { + "name": "Georgian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kk": { + "name": "Kazakh", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "km": { + "name": "Khmer", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kn": { + "name": "Kannada", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ko": { + "name": "Korean", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ku": { + "name": "Kurdish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "kw": { + "name": "Cornish", + "numbers": [ + 1, + 2, + 3, + 4 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3); } + }, + "ky": { + "name": "Kyrgyz", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lb": { + "name": "Letzeburgesch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ln": { + "name": "Lingala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "lo": { + "name": "Lao", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lt": { + "name": "Lithuanian", + "numbers": [ + 1, + 2, + 10 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "lv": { + "name": "Latvian", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2); } + }, + "mai": { + "name": "Maithili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mfe": { + "name": "Mauritian Creole", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mg": { + "name": "Malagasy", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mi": { + "name": "Maori", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mk": { + "name": "Macedonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 || n%10==1 ? 0 : 1); } + }, + "ml": { + "name": "Malayalam", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mn": { + "name": "Mongolian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mnk": { + "name": "Mandinka", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(0 ? 0 : n==1 ? 1 : 2); } + }, + "mr": { + "name": "Marathi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ms": { + "name": "Malay", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "mt": { + "name": "Maltese", + "numbers": [ + 1, + 2, + 11, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3); } + }, + "nah": { + "name": "Nahuatl", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nap": { + "name": "Neapolitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nb": { + "name": "Norwegian Bokmal", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ne": { + "name": "Nepali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nl": { + "name": "Dutch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nn": { + "name": "Norwegian Nynorsk", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "no": { + "name": "Norwegian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nso": { + "name": "Northern Sotho", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "oc": { + "name": "Occitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "or": { + "name": "Oriya", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pa": { + "name": "Punjabi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pap": { + "name": "Papiamento", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pl": { + "name": "Polish", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "pms": { + "name": "Piemontese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ps": { + "name": "Pashto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt": { + "name": "Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt_br": { + "name": "Brazilian Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "rm": { + "name": "Romansh", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ro": { + "name": "Romanian", + "numbers": [ + 1, + 2, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2); } + }, + "ru": { + "name": "Russian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "sah": { + "name": "Yakut", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sco": { + "name": "Scots", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "se": { + "name": "Northern Sami", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "si": { + "name": "Sinhala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sk": { + "name": "Slovak", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "sl": { + "name": "Slovenian", + "numbers": [ + 5, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }, + "so": { + "name": "Somali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "son": { + "name": "Songhay", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sq": { + "name": "Albanian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sr": { + "name": "Serbian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "su": { + "name": "Sundanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sv": { + "name": "Swedish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sw": { + "name": "Swahili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ta": { + "name": "Tamil", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "te": { + "name": "Telugu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tg": { + "name": "Tajik", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "th": { + "name": "Thai", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ti": { + "name": "Tigrinya", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tk": { + "name": "Turkmen", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tr": { + "name": "Turkish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tt": { + "name": "Tatar", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ug": { + "name": "Uyghur", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "uk": { + "name": "Ukrainian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ur": { + "name": "Urdu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "uz": { + "name": "Uzbek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "vi": { + "name": "Vietnamese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "wa": { + "name": "Walloon", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "wo": { + "name": "Wolof", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "yo": { + "name": "Yoruba", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "zh": { + "name": "Chinese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + } + }, + + // for demonstration only sl and ar is added but you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i = ext.plurals(c); + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[0], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + + return i18n; + +})); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd-1.5.10.zip b/libs/i18next/release/i18next.amd-1.5.10.zip new file mode 100644 index 00000000..932d144f Binary files /dev/null and b/libs/i18next/release/i18next.amd-1.5.10.zip differ diff --git a/libs/i18next/release/i18next.amd-1.5.6.js b/libs/i18next/release/i18next.amd-1.5.6.js new file mode 100644 index 00000000..047ba0b8 --- /dev/null +++ b/libs/i18next/release/i18next.amd-1.5.6.js @@ -0,0 +1,2270 @@ +// i18next, v1.5.6 +// Copyright (c)2012 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function (root, factory) { + if (typeof exports === 'object') { + + module.exports = factory(); + + } else if (typeof define === 'function' && define.amd) { + + define([], factory); + + } +}(this, function () { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + var $ = undefinded + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = []; + + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: 'dev', + ns: 'translation', + nsseparator: ':', + keyseparator: '.', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + + setJqueryExt: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + + postProcess: undefined + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = '?' + queryString.join('&'); + url += queryString !== '?' ? queryString : ''; + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + return JSON.parse(data); + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.sendType ? options.sendType.toLowerCase() : 'get'; + + http[methode](options.url, {async: options.async}, function (status, data) { + if (status === 200) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + document.cookie = name+"="+value+expires+"; path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : _ajax, + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + log: function(str) { + if (o.debug) console.log(str); + }, + toLanguages: function(lng) { + var languages = []; + if (lng.indexOf('-') === 2 && lng.length === 5) { + var parts = lng.split('-'); + + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + + if (o.load !== 'unspecific') languages.push(lng); + if (o.load !== 'current') languages.push(lng.substr(0, 2)); + } else { + languages.push(lng); + } + + if (languages.indexOf(o.fallbackLng) === -1 && o.fallbackLng) languages.push(o.fallbackLng); + + return languages; + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + if (!o.lng) o.lng = f.detectLanguage(); + if (o.lng) { + // set cookie with lng set (as detectLanguage will set cookie on need) + f.cookie.create('i18next', o.lng, o.cookieExpirationTime); + } else { + o.lng = o.fallbackLng; + f.cookie.remove('i18next'); + } + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + if (cb) cb(translate); + if (deferred) deferred.resolve(); + return deferred; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + + if (cb) cb(translate); + if (deferred) deferred.resolve(); + }); + + return deferred; + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function setLng(lng, cb) { + return init({lng: lng}, cb); + } + + function lng() { + return currentLng; + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = $.extend({ defaultValue: ele.html() }, options); + ele.html($.t(key, optionsToUse)); + } + else if (attr === 'text') { + optionsToUse = $.extend({ defaultValue: ele.text() }, options); + ele.text($.t(key, optionsToUse)); + } else { + optionsToUse = $.extend({ defaultValue: ele.attr(attr) }, options); + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr('data-i18n'); + if (!key) return; + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') <= key.length-1) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + parse(ele, k, options); + }); + + } else { + parse(ele, k, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[data-i18n]'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey) { + if (str.indexOf(o.interpolationPrefix) < 0) return str; + + f.each(replacementHash, function(key, value) { + if (typeof value === 'object') { + str = applyReplacement(str, value, key); + } else { + str = str.replace(new RegExp([o.interpolationPrefix, nestedKey ? nestedKey + '.' + key : key, o.interpolationSuffix].join(''), 'g'), value); + } + }); + return str; + } + + function applyReuse(translated, options){ + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.indexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_sans_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + var translated_token = _translate(token_sans_symbols, opts); + translated = translated.replace(token, translated_token); + } + return translated; + } + + function hasContext(options) { + return (options.context && typeof options.context == 'string'); + } + + function needsPlural(options) { + return (options.count !== undefined && typeof options.count != 'string' && options.count !== 1); + } + + function translate(key, options){ + replacementCounter = 0; + return _translate(key, options); + } + + function _translate(key, options){ + options = options || {}; + + var optionsSansCount, translated + , notfound = options.defaultValue || key + , lngs = languages; + + if (options.lng) { + lngs = f.toLanguages(options.lng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + if (!resStore) { return notfound; } // no resStore to translate from + + var ns = o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionsSansCount = f.extend({}, options); + delete optionsSansCount.context; + optionsSansCount.defaultValue = o.contextNotFound; + + var contextKey = ns + ':' + key + '_' + options.context; + + translated = translate(contextKey, optionsSansCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options)) { + optionsSansCount = f.extend({}, options); + delete optionsSansCount.count; + optionsSansCount.defaultValue = o.pluralNotFound; + + var pluralKey = ns + ':' + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(currentLng, options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + ':' + key; // singular + } + + translated = translate(pluralKey, optionsSansCount); + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { count: options.count }); // apply replacement for count only + } // else continue translation with original/singular key + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value) { + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (Object.prototype.toString.apply(value) === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned a object instead of string.'; + f.log(value); + } else { + for (var m in value) { + // apply translation on childs + value[m] = _translate(key + '.' + m, options); + } + } + } + found = value; + } + } + + if (!found && o.sendMissing) { + if (options.lng) { + sync.postMissing(options.lng, ns, key, notfound, lngs); + } else { + sync.postMissing(o.lng, ns, key, notfound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + if (!found) { + notfound = applyReplacement(notfound, options); + notfound = applyReuse(notfound, options); + } + + return (found) ? found : notfound; + } + function detectLanguage() { + var detectedLng; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var parms = query.split('&'); + for (var i=0; i 0) { + var key = parms[i].substring(0,pos); + var val = parms[i].substring(pos+1); + qsParm[key] = val; + } + } + })(); + if (qsParm.setLng) { + detectedLng = qsParm.setLng; + } + } + + // get from cookie + if (!detectedLng && typeof document !== 'undefined') { + var c = f.cookie.read('i18next'); + if (c) detectedLng = c; + } + + // get from navigator + if (!detectedLng && typeof navigator !== 'undefined') { + detectedLng = (navigator.language) ? navigator.language : navigator.userLanguage; + } + + return detectedLng; + } + var sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched){ + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + window.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + sync._fetchOne(lngValue, nsValue, options, function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }); + }); + }); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + cb(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + cb('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback') { + urls.push({lng: o.fallbackLng, url: applyReplacement(o.resPostPath, { lng: o.fallbackLng, ns: ns })}); + } else if (o.sendMissingTo === 'current') { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + resStore[item.lng][ns][key] = defaultValue; + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + } + }; + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + var pluralExtensions = { + + rules: { + "ach": { + "name": "Acholi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "af": { + "name": "Afrikaans", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ak": { + "name": "Akan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "am": { + "name": "Amharic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "an": { + "name": "Aragonese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ar": { + "name": "Arabic", + "numbers": [ + 0, + 1, + 2, + 3, + 11, + 100 + ], + "plurals": function(n) { return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5); } + }, + "arn": { + "name": "Mapudungun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ast": { + "name": "Asturian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ay": { + "name": "Aymar\u00e1", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "az": { + "name": "Azerbaijani", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "be": { + "name": "Belarusian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "bg": { + "name": "Bulgarian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bn": { + "name": "Bengali", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bo": { + "name": "Tibetan", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "br": { + "name": "Breton", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "bs": { + "name": "Bosnian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ca": { + "name": "Catalan", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "cgg": { + "name": "Chiga", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "cs": { + "name": "Czech", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "csb": { + "name": "Kashubian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "cy": { + "name": "Welsh", + "numbers": [ + 3, + 1, + 2, + 8 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3); } + }, + "da": { + "name": "Danish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "de": { + "name": "German", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "dz": { + "name": "Dzongkha", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "el": { + "name": "Greek", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "en": { + "name": "English", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eo": { + "name": "Esperanto", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es": { + "name": "Spanish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es_ar": { + "name": "Argentinean Spanish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "et": { + "name": "Estonian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eu": { + "name": "Basque", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fa": { + "name": "Persian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "fi": { + "name": "Finnish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fil": { + "name": "Filipino", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fo": { + "name": "Faroese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fr": { + "name": "French", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fur": { + "name": "Friulian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fy": { + "name": "Frisian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ga": { + "name": "Irish", + "numbers": [ + 3, + 1, + 2, + 7, + 11 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;} + }, + "gd": { + "name": "Scottish Gaelic", + "numbers": [ + 20, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3); } + }, + "gl": { + "name": "Galician", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gu": { + "name": "Gujarati", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gun": { + "name": "Gun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ha": { + "name": "Hausa", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "he": { + "name": "Hebrew", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hi": { + "name": "Hindi", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hr": { + "name": "Croatian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "hu": { + "name": "Hungarian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hy": { + "name": "Armenian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ia": { + "name": "Interlingua", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "id": { + "name": "Indonesian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "is": { + "name": "Icelandic", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n%10!=1 || n%100==11); } + }, + "it": { + "name": "Italian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ja": { + "name": "Japanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jbo": { + "name": "Lojban", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jv": { + "name": "Javanese", + "numbers": [ + 0, + 1 + ], + "plurals": function(n) { return Number(n !== 0); } + }, + "ka": { + "name": "Georgian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kk": { + "name": "Kazakh", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "km": { + "name": "Khmer", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kn": { + "name": "Kannada", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ko": { + "name": "Korean", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ku": { + "name": "Kurdish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "kw": { + "name": "Cornish", + "numbers": [ + 4, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3); } + }, + "ky": { + "name": "Kyrgyz", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lb": { + "name": "Letzeburgesch", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ln": { + "name": "Lingala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "lo": { + "name": "Lao", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lt": { + "name": "Lithuanian", + "numbers": [ + 10, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "lv": { + "name": "Latvian", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2); } + }, + "mai": { + "name": "Maithili", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mfe": { + "name": "Mauritian Creole", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mg": { + "name": "Malagasy", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mi": { + "name": "Maori", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mk": { + "name": "Macedonian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n==1 || n%10==1 ? 0 : 1); } + }, + "ml": { + "name": "Malayalam", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mn": { + "name": "Mongolian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mnk": { + "name": "Mandinka", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(0 ? 0 : n==1 ? 1 : 2); } + }, + "mr": { + "name": "Marathi", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ms": { + "name": "Malay", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "mt": { + "name": "Maltese", + "numbers": [ + 2, + 1, + 11, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3); } + }, + "nah": { + "name": "Nahuatl", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nap": { + "name": "Neapolitan", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nb": { + "name": "Norwegian Bokmal", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ne": { + "name": "Nepali", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nl": { + "name": "Dutch", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nn": { + "name": "Norwegian Nynorsk", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "no": { + "name": "Norwegian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nso": { + "name": "Northern Sotho", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "oc": { + "name": "Occitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "or": { + "name": "Oriya", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pa": { + "name": "Punjabi", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pap": { + "name": "Papiamento", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pl": { + "name": "Polish", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "pms": { + "name": "Piemontese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ps": { + "name": "Pashto", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt": { + "name": "Portuguese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt_br": { + "name": "Brazilian Portuguese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "rm": { + "name": "Romansh", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ro": { + "name": "Romanian", + "numbers": [ + 2, + 1, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2); } + }, + "ru": { + "name": "Russian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "sah": { + "name": "Yakut", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sco": { + "name": "Scots", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "se": { + "name": "Northern Sami", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "si": { + "name": "Sinhala", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sk": { + "name": "Slovak", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "sl": { + "name": "Slovenian", + "numbers": [ + 5, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }, + "so": { + "name": "Somali", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "son": { + "name": "Songhay", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sq": { + "name": "Albanian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sr": { + "name": "Serbian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "su": { + "name": "Sundanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sv": { + "name": "Swedish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sw": { + "name": "Swahili", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ta": { + "name": "Tamil", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "te": { + "name": "Telugu", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tg": { + "name": "Tajik", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "th": { + "name": "Thai", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ti": { + "name": "Tigrinya", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tk": { + "name": "Turkmen", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tr": { + "name": "Turkish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tt": { + "name": "Tatar", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ug": { + "name": "Uyghur", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "uk": { + "name": "Ukrainian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ur": { + "name": "Urdu", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "uz": { + "name": "Uzbek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "vi": { + "name": "Vietnamese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "wa": { + "name": "Walloon", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "wo": { + "name": "Wolof", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "yo": { + "name": "Yoruba", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "zh": { + "name": "Chinese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + } + }, + + // for demonstration only sl and ar is added but you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i = ext.plurals(c); + var number = ext.numbers[i]; + if (ext.numbers.length === 2) { + if (number === 2) { + number = 1; + } else if (number === 1) { + number = -1; + } + } //console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[0], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.t = translate; + i18n.translate = translate; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + + return i18n; + +})); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd-1.5.6.zip b/libs/i18next/release/i18next.amd-1.5.6.zip new file mode 100644 index 00000000..2933eea7 Binary files /dev/null and b/libs/i18next/release/i18next.amd-1.5.6.zip differ diff --git a/libs/i18next/release/i18next.amd-1.5.7.js b/libs/i18next/release/i18next.amd-1.5.7.js new file mode 100644 index 00000000..a0ff8072 --- /dev/null +++ b/libs/i18next/release/i18next.amd-1.5.7.js @@ -0,0 +1,2272 @@ +// i18next, v1.5.7 +// Copyright (c)2012 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function (root, factory) { + if (typeof exports === 'object') { + + module.exports = factory(); + + } else if (typeof define === 'function' && define.amd) { + + define([], factory); + + } +}(this, function () { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + var $ = undefined + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = []; + + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: 'dev', + detectLngQS: 'setLng', + ns: 'translation', + nsseparator: ':', + keyseparator: '.', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + + setJqueryExt: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + + postProcess: undefined + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = '?' + queryString.join('&'); + url += queryString !== '?' ? queryString : ''; + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + return JSON.parse(data); + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.sendType ? options.sendType.toLowerCase() : 'get'; + + http[methode](options.url, {async: options.async}, function (status, data) { + if (status === 200) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + document.cookie = name+"="+value+expires+"; path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : _ajax, + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + log: function(str) { + if (o.debug) console.log(str); + }, + toLanguages: function(lng) { + var languages = []; + if (lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + + if (o.load !== 'unspecific') languages.push(lng); + if (o.load !== 'current') languages.push(parts[0]); + } else { + languages.push(lng); + } + + if (languages.indexOf(o.fallbackLng) === -1 && o.fallbackLng) languages.push(o.fallbackLng); + + return languages; + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + if (!o.lng) o.lng = f.detectLanguage(); + if (o.lng) { + // set cookie with lng set (as detectLanguage will set cookie on need) + f.cookie.create('i18next', o.lng, o.cookieExpirationTime); + } else { + o.lng = o.fallbackLng; + f.cookie.remove('i18next'); + } + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + if (cb) cb(translate); + if (deferred) deferred.resolve(); + return deferred; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + + if (cb) cb(translate); + if (deferred) deferred.resolve(); + }); + + return deferred; + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function setLng(lng, cb) { + return init({lng: lng}, cb); + } + + function lng() { + return currentLng; + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = $.extend({ defaultValue: ele.html() }, options); + ele.html($.t(key, optionsToUse)); + } + else if (attr === 'text') { + optionsToUse = $.extend({ defaultValue: ele.text() }, options); + ele.text($.t(key, optionsToUse)); + } else { + optionsToUse = $.extend({ defaultValue: ele.attr(attr) }, options); + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr('data-i18n'); + if (!key) return; + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') <= key.length-1) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + parse(ele, k, options); + }); + + } else { + parse(ele, k, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[data-i18n]'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey) { + if (str.indexOf(o.interpolationPrefix) < 0) return str; + + f.each(replacementHash, function(key, value) { + if (typeof value === 'object') { + str = applyReplacement(str, value, nestedKey ? nestedKey + '.' + key : key); + } else { + str = str.replace(new RegExp([o.interpolationPrefix, nestedKey ? nestedKey + '.' + key : key, o.interpolationSuffix].join(''), 'g'), value); + } + }); + return str; + } + + function applyReuse(translated, options){ + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.indexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_sans_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + var translated_token = _translate(token_sans_symbols, opts); + translated = translated.replace(token, translated_token); + } + return translated; + } + + function hasContext(options) { + return (options.context && typeof options.context == 'string'); + } + + function needsPlural(options) { + return (options.count !== undefined && typeof options.count != 'string' && options.count !== 1); + } + + function translate(key, options){ + replacementCounter = 0; + return _translate(key, options); + } + + function _translate(key, options){ + options = options || {}; + + var optionsSansCount, translated + , notfound = options.defaultValue || key + , lngs = languages; + + if (options.lng) { + lngs = f.toLanguages(options.lng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + if (!resStore) { return notfound; } // no resStore to translate from + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionsSansCount = f.extend({}, options); + delete optionsSansCount.context; + optionsSansCount.defaultValue = o.contextNotFound; + + var contextKey = ns + ':' + key + '_' + options.context; + + translated = translate(contextKey, optionsSansCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options)) { + optionsSansCount = f.extend({}, options); + delete optionsSansCount.count; + optionsSansCount.defaultValue = o.pluralNotFound; + + var pluralKey = ns + ':' + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(currentLng, options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + ':' + key; // singular + } + + translated = translate(pluralKey, optionsSansCount); + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { count: options.count }); // apply replacement for count only + } // else continue translation with original/singular key + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value) { + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (Object.prototype.toString.apply(value) === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned a object instead of string.'; + f.log(value); + } else { + for (var m in value) { + // apply translation on childs + value[m] = _translate(key + '.' + m, options); + } + } + } + found = value; + } + } + + if (!found && o.sendMissing) { + if (options.lng) { + sync.postMissing(options.lng, ns, key, notfound, lngs); + } else { + sync.postMissing(o.lng, ns, key, notfound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + if (!found) { + notfound = applyReplacement(notfound, options); + notfound = applyReuse(notfound, options); + } + + return (found) ? found : notfound; + } + + function detectLanguage() { + var detectedLng; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var parms = query.split('&'); + for (var i=0; i 0) { + var key = parms[i].substring(0,pos); + var val = parms[i].substring(pos+1); + qsParm[key] = val; + } + } + })(); + if (qsParm[o.detectLngQS]) { + detectedLng = qsParm[o.detectLngQS]; + } + } + + // get from cookie + if (!detectedLng && typeof document !== 'undefined') { + var c = f.cookie.read('i18next'); + if (c) detectedLng = c; + } + + // get from navigator + if (!detectedLng && typeof navigator !== 'undefined') { + detectedLng = (navigator.language) ? navigator.language : navigator.userLanguage; + } + + return detectedLng; + } + var sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched){ + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + window.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + sync._fetchOne(lngValue, nsValue, options, function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }); + }); + }); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + cb(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + cb('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback') { + urls.push({lng: o.fallbackLng, url: applyReplacement(o.resPostPath, { lng: o.fallbackLng, ns: ns })}); + } else if (o.sendMissingTo === 'current') { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + resStore[item.lng][ns][key] = defaultValue; + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + } + }; + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + var pluralExtensions = { + + rules: { + "ach": { + "name": "Acholi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "af": { + "name": "Afrikaans", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ak": { + "name": "Akan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "am": { + "name": "Amharic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "an": { + "name": "Aragonese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ar": { + "name": "Arabic", + "numbers": [ + 0, + 1, + 2, + 3, + 11, + 100 + ], + "plurals": function(n) { return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5); } + }, + "arn": { + "name": "Mapudungun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ast": { + "name": "Asturian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ay": { + "name": "Aymar\u00e1", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "az": { + "name": "Azerbaijani", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "be": { + "name": "Belarusian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "bg": { + "name": "Bulgarian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bn": { + "name": "Bengali", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bo": { + "name": "Tibetan", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "br": { + "name": "Breton", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "bs": { + "name": "Bosnian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ca": { + "name": "Catalan", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "cgg": { + "name": "Chiga", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "cs": { + "name": "Czech", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "csb": { + "name": "Kashubian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "cy": { + "name": "Welsh", + "numbers": [ + 3, + 1, + 2, + 8 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3); } + }, + "da": { + "name": "Danish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "de": { + "name": "German", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "dz": { + "name": "Dzongkha", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "el": { + "name": "Greek", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "en": { + "name": "English", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eo": { + "name": "Esperanto", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es": { + "name": "Spanish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es_ar": { + "name": "Argentinean Spanish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "et": { + "name": "Estonian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eu": { + "name": "Basque", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fa": { + "name": "Persian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "fi": { + "name": "Finnish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fil": { + "name": "Filipino", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fo": { + "name": "Faroese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fr": { + "name": "French", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fur": { + "name": "Friulian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fy": { + "name": "Frisian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ga": { + "name": "Irish", + "numbers": [ + 3, + 1, + 2, + 7, + 11 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;} + }, + "gd": { + "name": "Scottish Gaelic", + "numbers": [ + 20, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3); } + }, + "gl": { + "name": "Galician", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gu": { + "name": "Gujarati", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gun": { + "name": "Gun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ha": { + "name": "Hausa", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "he": { + "name": "Hebrew", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hi": { + "name": "Hindi", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hr": { + "name": "Croatian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "hu": { + "name": "Hungarian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hy": { + "name": "Armenian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ia": { + "name": "Interlingua", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "id": { + "name": "Indonesian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "is": { + "name": "Icelandic", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n%10!=1 || n%100==11); } + }, + "it": { + "name": "Italian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ja": { + "name": "Japanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jbo": { + "name": "Lojban", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jv": { + "name": "Javanese", + "numbers": [ + 0, + 1 + ], + "plurals": function(n) { return Number(n !== 0); } + }, + "ka": { + "name": "Georgian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kk": { + "name": "Kazakh", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "km": { + "name": "Khmer", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kn": { + "name": "Kannada", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ko": { + "name": "Korean", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ku": { + "name": "Kurdish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "kw": { + "name": "Cornish", + "numbers": [ + 4, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3); } + }, + "ky": { + "name": "Kyrgyz", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lb": { + "name": "Letzeburgesch", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ln": { + "name": "Lingala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "lo": { + "name": "Lao", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lt": { + "name": "Lithuanian", + "numbers": [ + 10, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "lv": { + "name": "Latvian", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2); } + }, + "mai": { + "name": "Maithili", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mfe": { + "name": "Mauritian Creole", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mg": { + "name": "Malagasy", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mi": { + "name": "Maori", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mk": { + "name": "Macedonian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n==1 || n%10==1 ? 0 : 1); } + }, + "ml": { + "name": "Malayalam", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mn": { + "name": "Mongolian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mnk": { + "name": "Mandinka", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(0 ? 0 : n==1 ? 1 : 2); } + }, + "mr": { + "name": "Marathi", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ms": { + "name": "Malay", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "mt": { + "name": "Maltese", + "numbers": [ + 2, + 1, + 11, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3); } + }, + "nah": { + "name": "Nahuatl", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nap": { + "name": "Neapolitan", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nb": { + "name": "Norwegian Bokmal", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ne": { + "name": "Nepali", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nl": { + "name": "Dutch", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nn": { + "name": "Norwegian Nynorsk", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "no": { + "name": "Norwegian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nso": { + "name": "Northern Sotho", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "oc": { + "name": "Occitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "or": { + "name": "Oriya", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pa": { + "name": "Punjabi", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pap": { + "name": "Papiamento", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pl": { + "name": "Polish", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "pms": { + "name": "Piemontese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ps": { + "name": "Pashto", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt": { + "name": "Portuguese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt_br": { + "name": "Brazilian Portuguese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "rm": { + "name": "Romansh", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ro": { + "name": "Romanian", + "numbers": [ + 2, + 1, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2); } + }, + "ru": { + "name": "Russian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "sah": { + "name": "Yakut", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sco": { + "name": "Scots", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "se": { + "name": "Northern Sami", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "si": { + "name": "Sinhala", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sk": { + "name": "Slovak", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "sl": { + "name": "Slovenian", + "numbers": [ + 5, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }, + "so": { + "name": "Somali", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "son": { + "name": "Songhay", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sq": { + "name": "Albanian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sr": { + "name": "Serbian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "su": { + "name": "Sundanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sv": { + "name": "Swedish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sw": { + "name": "Swahili", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ta": { + "name": "Tamil", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "te": { + "name": "Telugu", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tg": { + "name": "Tajik", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "th": { + "name": "Thai", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ti": { + "name": "Tigrinya", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tk": { + "name": "Turkmen", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tr": { + "name": "Turkish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tt": { + "name": "Tatar", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ug": { + "name": "Uyghur", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "uk": { + "name": "Ukrainian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ur": { + "name": "Urdu", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "uz": { + "name": "Uzbek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "vi": { + "name": "Vietnamese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "wa": { + "name": "Walloon", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "wo": { + "name": "Wolof", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "yo": { + "name": "Yoruba", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "zh": { + "name": "Chinese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + } + }, + + // for demonstration only sl and ar is added but you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i = ext.plurals(c); + var number = ext.numbers[i]; + if (ext.numbers.length === 2) { + if (number === 2) { + number = 1; + } else if (number === 1) { + number = -1; + } + } //console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[0], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.t = translate; + i18n.translate = translate; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + + return i18n; + +})); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd-1.5.7.zip b/libs/i18next/release/i18next.amd-1.5.7.zip new file mode 100644 index 00000000..30955ea2 Binary files /dev/null and b/libs/i18next/release/i18next.amd-1.5.7.zip differ diff --git a/libs/i18next/release/i18next.amd-1.5.8.js b/libs/i18next/release/i18next.amd-1.5.8.js new file mode 100644 index 00000000..cdda4acf --- /dev/null +++ b/libs/i18next/release/i18next.amd-1.5.8.js @@ -0,0 +1,2284 @@ +// i18next, v1.5.8 +// Copyright (c)2012 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function (root, factory) { + if (typeof exports === 'object') { + + module.exports = factory(); + + } else if (typeof define === 'function' && define.amd) { + + define([], factory); + + } +}(this, function () { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + var $ = undefined + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = []; + + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: 'dev', + detectLngQS: 'setLng', + ns: 'translation', + nsseparator: ':', + keyseparator: '.', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + + setJqueryExt: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + + postProcess: undefined + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = '?' + queryString.join('&'); + url += queryString !== '?' ? queryString : ''; + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + return JSON.parse(data); + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, {async: options.async}, function (status, data) { + if (status === 200) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + document.cookie = name+"="+value+expires+"; path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : _ajax, + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + log: function(str) { + if (o.debug) console.log(str); + }, + toLanguages: function(lng) { + var languages = []; + if (lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + + if (o.load !== 'unspecific') languages.push(lng); + if (o.load !== 'current') languages.push(parts[0]); + } else { + languages.push(lng); + } + + if (languages.indexOf(o.fallbackLng) === -1 && o.fallbackLng) languages.push(o.fallbackLng); + + return languages; + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + if (!o.lng) o.lng = f.detectLanguage(); + if (o.lng) { + // set cookie with lng set (as detectLanguage will set cookie on need) + if (o.useCookie) f.cookie.create('i18next', o.lng, o.cookieExpirationTime); + } else { + o.lng = o.fallbackLng; + if (o.useCookie) f.cookie.remove('i18next'); + } + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + if (cb) cb(translate); + if (deferred) deferred.resolve(); + return deferred; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + + if (cb) cb(translate); + if (deferred) deferred.resolve(); + }); + + return deferred; + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function setLng(lng, cb) { + return init({lng: lng}, cb); + } + + function lng() { + return currentLng; + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = $.extend({ defaultValue: ele.html() }, options); + ele.html($.t(key, optionsToUse)); + } + else if (attr === 'text') { + optionsToUse = $.extend({ defaultValue: ele.text() }, options); + ele.text($.t(key, optionsToUse)); + } else { + optionsToUse = $.extend({ defaultValue: ele.attr(attr) }, options); + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr('data-i18n'); + if (!key) return; + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') <= key.length-1) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + parse(ele, k, options); + }); + + } else { + parse(ele, k, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[data-i18n]'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey) { + if (str.indexOf(o.interpolationPrefix) < 0) return str; + + f.each(replacementHash, function(key, value) { + if (typeof value === 'object') { + str = applyReplacement(str, value, nestedKey ? nestedKey + '.' + key : key); + } else { + str = str.replace(new RegExp([o.interpolationPrefix, nestedKey ? nestedKey + '.' + key : key, o.interpolationSuffix].join(''), 'g'), value); + } + }); + return str; + } + + function applyReuse(translated, options){ + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.indexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_sans_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + var translated_token = _translate(token_sans_symbols, opts); + translated = translated.replace(token, translated_token); + } + return translated; + } + + function hasContext(options) { + return (options.context && typeof options.context == 'string'); + } + + function needsPlural(options) { + return (options.count !== undefined && typeof options.count != 'string' && options.count !== 1); + } + + function translate(key, options){ + replacementCounter = 0; + return _translate(key, options); + } + + function _translate(key, options){ + options = options || {}; + + var optionWithoutCount, translated + , notfound = options.defaultValue || key + , lngs = languages; + + if (options.lng) { + lngs = f.toLanguages(options.lng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + if (!resStore) { return notfound; } // no resStore to translate from + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + ':' + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.count; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey = ns + ':' + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(currentLng, options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + ':' + key; // singular + } + + translated = translate(pluralKey, optionWithoutCount); + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { count: options.count }); // apply replacement for count only + } // else continue translation with original/singular key + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (Object.prototype.toString.apply(value) === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned a object instead of string.'; + f.log(value); + } else { + for (var m in value) { + // apply translation on childs + value[m] = _translate(ns + ':' + key + '.' + m, options); + } + } + } + found = value; + } + } + + if (found === undefined && o.sendMissing) { + if (options.lng) { + sync.postMissing(options.lng, ns, key, notfound, lngs); + } else { + sync.postMissing(o.lng, ns, key, notfound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found !== undefined && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + if (found === undefined) { + notfound = applyReplacement(notfound, options); + notfound = applyReuse(notfound, options); + } + + return (found !== undefined) ? found : notfound; + } + + function detectLanguage() { + var detectedLng; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var parms = query.split('&'); + for (var i=0; i 0) { + var key = parms[i].substring(0,pos); + var val = parms[i].substring(pos+1); + qsParm[key] = val; + } + } + })(); + if (qsParm[o.detectLngQS]) { + detectedLng = qsParm[o.detectLngQS]; + } + } + + // get from cookie + if (!detectedLng && typeof document !== 'undefined' && o.useCookie ) { + var c = f.cookie.read('i18next'); + if (c) detectedLng = c; + } + + // get from navigator + if (!detectedLng && typeof navigator !== 'undefined') { + detectedLng = (navigator.language) ? navigator.language : navigator.userLanguage; + } + + return detectedLng; + } + var sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched){ + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + window.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + sync._fetchOne(lngValue, nsValue, options, function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }); + }); + }); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + cb(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + cb('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback') { + urls.push({lng: o.fallbackLng, url: applyReplacement(o.resPostPath, { lng: o.fallbackLng, ns: ns })}); + } else if (o.sendMissingTo === 'current') { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + resStore[item.lng][ns][key] = defaultValue; + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + } + }; + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + var pluralExtensions = { + + rules: { + "ach": { + "name": "Acholi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "af": { + "name": "Afrikaans", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ak": { + "name": "Akan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "am": { + "name": "Amharic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "an": { + "name": "Aragonese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ar": { + "name": "Arabic", + "numbers": [ + 0, + 1, + 2, + 3, + 11, + 100 + ], + "plurals": function(n) { return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5); } + }, + "arn": { + "name": "Mapudungun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ast": { + "name": "Asturian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ay": { + "name": "Aymar\u00e1", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "az": { + "name": "Azerbaijani", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "be": { + "name": "Belarusian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "bg": { + "name": "Bulgarian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bn": { + "name": "Bengali", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bo": { + "name": "Tibetan", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "br": { + "name": "Breton", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "bs": { + "name": "Bosnian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ca": { + "name": "Catalan", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "cgg": { + "name": "Chiga", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "cs": { + "name": "Czech", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "csb": { + "name": "Kashubian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "cy": { + "name": "Welsh", + "numbers": [ + 3, + 1, + 2, + 8 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3); } + }, + "da": { + "name": "Danish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "de": { + "name": "German", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "dz": { + "name": "Dzongkha", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "el": { + "name": "Greek", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "en": { + "name": "English", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eo": { + "name": "Esperanto", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es": { + "name": "Spanish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es_ar": { + "name": "Argentinean Spanish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "et": { + "name": "Estonian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eu": { + "name": "Basque", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fa": { + "name": "Persian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "fi": { + "name": "Finnish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fil": { + "name": "Filipino", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fo": { + "name": "Faroese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fr": { + "name": "French", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fur": { + "name": "Friulian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fy": { + "name": "Frisian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ga": { + "name": "Irish", + "numbers": [ + 3, + 1, + 2, + 7, + 11 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;} + }, + "gd": { + "name": "Scottish Gaelic", + "numbers": [ + 20, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3); } + }, + "gl": { + "name": "Galician", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gu": { + "name": "Gujarati", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gun": { + "name": "Gun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ha": { + "name": "Hausa", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "he": { + "name": "Hebrew", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hi": { + "name": "Hindi", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hr": { + "name": "Croatian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "hu": { + "name": "Hungarian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hy": { + "name": "Armenian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ia": { + "name": "Interlingua", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "id": { + "name": "Indonesian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "is": { + "name": "Icelandic", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n%10!=1 || n%100==11); } + }, + "it": { + "name": "Italian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ja": { + "name": "Japanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jbo": { + "name": "Lojban", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jv": { + "name": "Javanese", + "numbers": [ + 0, + 1 + ], + "plurals": function(n) { return Number(n !== 0); } + }, + "ka": { + "name": "Georgian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kk": { + "name": "Kazakh", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "km": { + "name": "Khmer", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kn": { + "name": "Kannada", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ko": { + "name": "Korean", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ku": { + "name": "Kurdish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "kw": { + "name": "Cornish", + "numbers": [ + 4, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3); } + }, + "ky": { + "name": "Kyrgyz", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lb": { + "name": "Letzeburgesch", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ln": { + "name": "Lingala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "lo": { + "name": "Lao", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lt": { + "name": "Lithuanian", + "numbers": [ + 10, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "lv": { + "name": "Latvian", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2); } + }, + "mai": { + "name": "Maithili", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mfe": { + "name": "Mauritian Creole", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mg": { + "name": "Malagasy", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mi": { + "name": "Maori", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mk": { + "name": "Macedonian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n==1 || n%10==1 ? 0 : 1); } + }, + "ml": { + "name": "Malayalam", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mn": { + "name": "Mongolian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mnk": { + "name": "Mandinka", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(0 ? 0 : n==1 ? 1 : 2); } + }, + "mr": { + "name": "Marathi", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ms": { + "name": "Malay", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "mt": { + "name": "Maltese", + "numbers": [ + 2, + 1, + 11, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3); } + }, + "nah": { + "name": "Nahuatl", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nap": { + "name": "Neapolitan", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nb": { + "name": "Norwegian Bokmal", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ne": { + "name": "Nepali", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nl": { + "name": "Dutch", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nn": { + "name": "Norwegian Nynorsk", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "no": { + "name": "Norwegian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nso": { + "name": "Northern Sotho", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "oc": { + "name": "Occitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "or": { + "name": "Oriya", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pa": { + "name": "Punjabi", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pap": { + "name": "Papiamento", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pl": { + "name": "Polish", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "pms": { + "name": "Piemontese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ps": { + "name": "Pashto", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt": { + "name": "Portuguese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt_br": { + "name": "Brazilian Portuguese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "rm": { + "name": "Romansh", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ro": { + "name": "Romanian", + "numbers": [ + 2, + 1, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2); } + }, + "ru": { + "name": "Russian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "sah": { + "name": "Yakut", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sco": { + "name": "Scots", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "se": { + "name": "Northern Sami", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "si": { + "name": "Sinhala", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sk": { + "name": "Slovak", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "sl": { + "name": "Slovenian", + "numbers": [ + 5, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }, + "so": { + "name": "Somali", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "son": { + "name": "Songhay", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sq": { + "name": "Albanian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sr": { + "name": "Serbian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "su": { + "name": "Sundanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sv": { + "name": "Swedish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sw": { + "name": "Swahili", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ta": { + "name": "Tamil", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "te": { + "name": "Telugu", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tg": { + "name": "Tajik", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "th": { + "name": "Thai", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ti": { + "name": "Tigrinya", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tk": { + "name": "Turkmen", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tr": { + "name": "Turkish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tt": { + "name": "Tatar", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ug": { + "name": "Uyghur", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "uk": { + "name": "Ukrainian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ur": { + "name": "Urdu", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "uz": { + "name": "Uzbek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "vi": { + "name": "Vietnamese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "wa": { + "name": "Walloon", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "wo": { + "name": "Wolof", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "yo": { + "name": "Yoruba", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "zh": { + "name": "Chinese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + } + }, + + // for demonstration only sl and ar is added but you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i = ext.plurals(c); + var number = ext.numbers[i]; + if (ext.numbers.length === 2) { + // germanic like en + if (ext.numbers[0] === 2) { + if (number === 2) { + number = 1; // singular + } else if (number === 1) { + number = -1; // regular plural + } + } + // romanic like fr + else if (ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + } + } //console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[0], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.t = translate; + i18n.translate = translate; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + + return i18n; + +})); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd-1.5.8.zip b/libs/i18next/release/i18next.amd-1.5.8.zip new file mode 100644 index 00000000..e8ff5f5a Binary files /dev/null and b/libs/i18next/release/i18next.amd-1.5.8.zip differ diff --git a/libs/i18next/release/i18next.amd-1.5.9.js b/libs/i18next/release/i18next.amd-1.5.9.js new file mode 100644 index 00000000..f2a6dabc --- /dev/null +++ b/libs/i18next/release/i18next.amd-1.5.9.js @@ -0,0 +1,2359 @@ +// i18next, v1.5.9 +// Copyright (c)2012 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function (root, factory) { + if (typeof exports === 'object') { + + module.exports = factory(); + + } else if (typeof define === 'function' && define.amd) { + + define([], factory); + + } +}(this, function () { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + var $ = undefined + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = []; + + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: 'dev', + detectLngQS: 'setLng', + ns: 'translation', + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + + postProcess: undefined + }; + + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = '?' + queryString.join('&'); + url += queryString !== '?' ? queryString : ''; + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + return JSON.parse(data); + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, {async: options.async}, function (status, data) { + if (status === 200) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + document.cookie = name+"="+value+expires+"; path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : _ajax, + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + toLanguages: function(lng) { + var languages = []; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + + if (o.load !== 'unspecific') languages.push(lng); + if (o.load !== 'current') languages.push(parts[0]); + } else { + languages.push(lng); + } + + if (languages.indexOf(o.fallbackLng) === -1 && o.fallbackLng) languages.push(o.fallbackLng); + + return languages; + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + if (!o.lng) o.lng = f.detectLanguage(); + if (o.lng) { + // set cookie with lng set (as detectLanguage will set cookie on need) + if (o.useCookie) f.cookie.create(o.cookieName, o.lng, o.cookieExpirationTime); + } else { + o.lng = o.fallbackLng; + if (o.useCookie) f.cookie.remove(o.cookieName); + } + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + if (cb) cb(translate); + if (deferred) deferred.resolve(); + return deferred; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + + if (cb) cb(translate); + if (deferred) deferred.resolve(); + }); + + return deferred; + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, cb) { + return init({lng: lng}, cb); + } + + function lng() { + return currentLng; + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } + else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key) return; + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') <= key.length-1) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + parse(ele, k, options); + }); + + } else { + parse(ele, k, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + + function applyReplacement(str, replacementHash, nestedKey) { + if (str.indexOf(o.interpolationPrefix) < 0) return str; + + f.each(replacementHash, function(key, value) { + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nestedKey ? nestedKey + '.' + key : key); + } else { + str = str.replace(new RegExp([o.interpolationPrefix, nestedKey ? nestedKey + '.' + key : key, o.interpolationSuffix].join(''), 'g'), value); + } + }); + return str; + } + + function applyReuse(translated, options){ + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.indexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_sans_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + var translated_token = _translate(token_sans_symbols, opts); + translated = translated.replace(token, translated_token); + } + return translated; + } + + function hasContext(options) { + return (options.context && typeof options.context == 'string'); + } + + function needsPlural(options) { + return (options.count !== undefined && typeof options.count != 'string' && options.count !== 1); + } + + function translate(key, options){ + replacementCounter = 0; + return _translate(key, options); + } + + function _translate(key, options){ + options = options || {}; + + if (!resStore) { return notfound; } // no resStore to translate from + + var optionWithoutCount, translated + , notfound = options.defaultValue || key + , lngs = languages; + + if (options.lng) { + lngs = f.toLanguages(options.lng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + ':' + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.count; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey = ns + ':' + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(currentLng, options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + ':' + key; // singular + } + + translated = translate(pluralKey, optionWithoutCount); + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { count: options.count }); // apply replacement for count only + } // else continue translation with original/singular key + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (Object.prototype.toString.apply(value) === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned a object instead of string.'; + f.log(value); + } else { + for (var m in value) { + // apply translation on childs + value[m] = _translate(ns + ':' + key + '.' + m, options); + } + } + } + found = value; + } + } + + if (found === undefined && o.sendMissing) { + if (options.lng) { + sync.postMissing(options.lng, ns, key, notfound, lngs); + } else { + sync.postMissing(o.lng, ns, key, notfound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found !== undefined && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + if (found === undefined) { + notfound = applyReplacement(notfound, options); + notfound = applyReuse(notfound, options); + } + + return (found !== undefined) ? found : notfound; + } + + function detectLanguage() { + var detectedLng; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var parms = query.split('&'); + for (var i=0; i 0) { + var key = parms[i].substring(0,pos); + var val = parms[i].substring(pos+1); + qsParm[key] = val; + } + } + })(); + if (qsParm[o.detectLngQS]) { + detectedLng = qsParm[o.detectLngQS]; + } + } + + // get from cookie + if (!detectedLng && typeof document !== 'undefined' && o.useCookie ) { + var c = f.cookie.read(o.cookieName); + if (c) detectedLng = c; + } + + // get from navigator + if (!detectedLng && typeof navigator !== 'undefined') { + detectedLng = (navigator.language) ? navigator.language : navigator.userLanguage; + } + + return detectedLng; + } + var sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + window.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + sync._fetchOne(lngValue, nsValue, options, function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }); + }); + }); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + cb(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + cb('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback') { + urls.push({lng: o.fallbackLng, url: applyReplacement(o.resPostPath, { lng: o.fallbackLng, ns: ns })}); + } else if (o.sendMissingTo === 'current') { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + resStore[item.lng][ns][key] = defaultValue; + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + } + }; + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + var pluralExtensions = { + + rules: { + "ach": { + "name": "Acholi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "af": { + "name": "Afrikaans", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ak": { + "name": "Akan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "am": { + "name": "Amharic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "an": { + "name": "Aragonese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ar": { + "name": "Arabic", + "numbers": [ + 0, + 1, + 2, + 3, + 11, + 100 + ], + "plurals": function(n) { return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5); } + }, + "arn": { + "name": "Mapudungun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ast": { + "name": "Asturian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ay": { + "name": "Aymar\u00e1", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "az": { + "name": "Azerbaijani", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "be": { + "name": "Belarusian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "bg": { + "name": "Bulgarian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bn": { + "name": "Bengali", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bo": { + "name": "Tibetan", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "br": { + "name": "Breton", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "bs": { + "name": "Bosnian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ca": { + "name": "Catalan", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "cgg": { + "name": "Chiga", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "cs": { + "name": "Czech", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "csb": { + "name": "Kashubian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "cy": { + "name": "Welsh", + "numbers": [ + 3, + 1, + 2, + 8 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3); } + }, + "da": { + "name": "Danish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "de": { + "name": "German", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "dz": { + "name": "Dzongkha", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "el": { + "name": "Greek", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "en": { + "name": "English", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eo": { + "name": "Esperanto", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es": { + "name": "Spanish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es_ar": { + "name": "Argentinean Spanish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "et": { + "name": "Estonian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eu": { + "name": "Basque", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fa": { + "name": "Persian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "fi": { + "name": "Finnish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fil": { + "name": "Filipino", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fo": { + "name": "Faroese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fr": { + "name": "French", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fur": { + "name": "Friulian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fy": { + "name": "Frisian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ga": { + "name": "Irish", + "numbers": [ + 3, + 1, + 2, + 7, + 11 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;} + }, + "gd": { + "name": "Scottish Gaelic", + "numbers": [ + 20, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3); } + }, + "gl": { + "name": "Galician", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gu": { + "name": "Gujarati", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gun": { + "name": "Gun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ha": { + "name": "Hausa", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "he": { + "name": "Hebrew", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hi": { + "name": "Hindi", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hr": { + "name": "Croatian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "hu": { + "name": "Hungarian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hy": { + "name": "Armenian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ia": { + "name": "Interlingua", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "id": { + "name": "Indonesian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "is": { + "name": "Icelandic", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n%10!=1 || n%100==11); } + }, + "it": { + "name": "Italian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ja": { + "name": "Japanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jbo": { + "name": "Lojban", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jv": { + "name": "Javanese", + "numbers": [ + 0, + 1 + ], + "plurals": function(n) { return Number(n !== 0); } + }, + "ka": { + "name": "Georgian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kk": { + "name": "Kazakh", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "km": { + "name": "Khmer", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kn": { + "name": "Kannada", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ko": { + "name": "Korean", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ku": { + "name": "Kurdish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "kw": { + "name": "Cornish", + "numbers": [ + 4, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3); } + }, + "ky": { + "name": "Kyrgyz", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lb": { + "name": "Letzeburgesch", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ln": { + "name": "Lingala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "lo": { + "name": "Lao", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lt": { + "name": "Lithuanian", + "numbers": [ + 10, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "lv": { + "name": "Latvian", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2); } + }, + "mai": { + "name": "Maithili", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mfe": { + "name": "Mauritian Creole", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mg": { + "name": "Malagasy", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mi": { + "name": "Maori", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mk": { + "name": "Macedonian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n==1 || n%10==1 ? 0 : 1); } + }, + "ml": { + "name": "Malayalam", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mn": { + "name": "Mongolian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mnk": { + "name": "Mandinka", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(0 ? 0 : n==1 ? 1 : 2); } + }, + "mr": { + "name": "Marathi", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ms": { + "name": "Malay", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "mt": { + "name": "Maltese", + "numbers": [ + 2, + 1, + 11, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3); } + }, + "nah": { + "name": "Nahuatl", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nap": { + "name": "Neapolitan", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nb": { + "name": "Norwegian Bokmal", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ne": { + "name": "Nepali", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nl": { + "name": "Dutch", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nn": { + "name": "Norwegian Nynorsk", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "no": { + "name": "Norwegian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nso": { + "name": "Northern Sotho", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "oc": { + "name": "Occitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "or": { + "name": "Oriya", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pa": { + "name": "Punjabi", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pap": { + "name": "Papiamento", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pl": { + "name": "Polish", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "pms": { + "name": "Piemontese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ps": { + "name": "Pashto", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt": { + "name": "Portuguese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt_br": { + "name": "Brazilian Portuguese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "rm": { + "name": "Romansh", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ro": { + "name": "Romanian", + "numbers": [ + 2, + 1, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2); } + }, + "ru": { + "name": "Russian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "sah": { + "name": "Yakut", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sco": { + "name": "Scots", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "se": { + "name": "Northern Sami", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "si": { + "name": "Sinhala", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sk": { + "name": "Slovak", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "sl": { + "name": "Slovenian", + "numbers": [ + 5, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }, + "so": { + "name": "Somali", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "son": { + "name": "Songhay", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sq": { + "name": "Albanian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sr": { + "name": "Serbian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "su": { + "name": "Sundanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sv": { + "name": "Swedish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sw": { + "name": "Swahili", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ta": { + "name": "Tamil", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "te": { + "name": "Telugu", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tg": { + "name": "Tajik", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "th": { + "name": "Thai", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ti": { + "name": "Tigrinya", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tk": { + "name": "Turkmen", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tr": { + "name": "Turkish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tt": { + "name": "Tatar", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ug": { + "name": "Uyghur", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "uk": { + "name": "Ukrainian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ur": { + "name": "Urdu", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "uz": { + "name": "Uzbek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "vi": { + "name": "Vietnamese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "wa": { + "name": "Walloon", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "wo": { + "name": "Wolof", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "yo": { + "name": "Yoruba", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "zh": { + "name": "Chinese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + } + }, + + // for demonstration only sl and ar is added but you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i = ext.plurals(c); + var number = ext.numbers[i]; + if (ext.numbers.length === 2) { + // germanic like en + if (ext.numbers[0] === 2) { + if (number === 2) { + number = 1; // singular + } else if (number === 1) { + number = -1; // regular plural + } + } + // romanic like fr + else if (ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + } + } //console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[0], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + + return i18n; + +})); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd-1.5.9.zip b/libs/i18next/release/i18next.amd-1.5.9.zip new file mode 100644 index 00000000..1e61276f Binary files /dev/null and b/libs/i18next/release/i18next.amd-1.5.9.zip differ diff --git a/libs/i18next/release/i18next.amd-1.6.0.js b/libs/i18next/release/i18next.amd-1.6.0.js new file mode 100644 index 00000000..4fbe0abf --- /dev/null +++ b/libs/i18next/release/i18next.amd-1.6.0.js @@ -0,0 +1,2434 @@ +// i18next, v1.6.0 +// Copyright (c)2013 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function (root, factory) { + if (typeof exports === 'object') { + + module.exports = factory(); + + } else if (typeof define === 'function' && define.amd) { + + define([], factory); + + } +}(this, function () { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + var $ = undefined + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = []; + + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: 'dev', + detectLngQS: 'setLng', + ns: 'translation', + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + + postProcess: undefined + }; + + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + return JSON.parse(data); + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + if (status === 200) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + document.cookie = name+"="+value+expires+"; path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : _ajax, + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + toLanguages: function(lng) { + var languages = []; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + + if (o.load !== 'unspecific') languages.push(lng); + if (o.load !== 'current') languages.push(parts[0]); + } else { + languages.push(lng); + } + + if (languages.indexOf(o.fallbackLng) === -1 && o.fallbackLng) languages.push(o.fallbackLng); + + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + if (o.lng) { + // set cookie with lng set (as detectLanguage will set cookie on need) + if (o.useCookie) f.cookie.create(o.cookieName, o.lng, o.cookieExpirationTime); + } else { + o.lng = o.fallbackLng; + if (o.useCookie) f.cookie.remove(o.cookieName); + } + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + if (cb) cb(translate); + if (deferred) deferred.resolve(); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + + if (cb) cb(translate); + if (deferred) deferred.resolve(); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + f.extend(resStore[lng][ns], resources); + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, cb) { + return init({lng: lng}, cb); + } + + function lng() { + return currentLng; + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } + else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') <= key.length-1) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + parse(target, k, options); + }); + + } else { + parse(target, k, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + + function applyReplacement(str, replacementHash, nestedKey, options) { + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped; + + f.each(replacementHash, function(key, value) { + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nestedKey ? nestedKey + o.keyseparator + key : key, options); + } else { + str = str.replace(new RegExp([prefix, nestedKey ? nestedKey + o.keyseparator + key : key, suffix].join(''), 'g'), value); + } + }); + return str; + } + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.indexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, translated_token); + } + return translated; + } + + function hasContext(options) { + return (options.context && typeof options.context == 'string'); + } + + function needsPlural(options) { + return (options.count !== undefined && typeof options.count != 'string' && options.count !== 1); + } + + function translate(key, options){ + replacementCounter = 0; + return _translate(key, options); + } + + function _translate(key, options){ + options = options || {}; + + if (!resStore) { return notfound; } // no resStore to translate from + + var optionWithoutCount, translated + , notfound = options.defaultValue || key + , lngs = languages; + + if (options.lng) { + lngs = f.toLanguages(options.lng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.count; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(currentLng, options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + + translated = translate(pluralKey, optionWithoutCount); + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { count: options.count }); // apply replacement for count only + } // else continue translation with original/singular key + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (Object.prototype.toString.apply(value) === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned a object instead of string.'; + f.log(value); + } else { + var copy = {}; // apply child translation on a copy + for (var m in value) { + // apply translation on childs + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + } + value = copy; + } + } + found = value; + } + } + + if (found === undefined && o.fallbackToDefaultNS) { + found = _translate(key, options); + } + + if (found === undefined && o.sendMissing) { + if (options.lng) { + sync.postMissing(lngs[0], ns, key, notfound, lngs); + } else { + sync.postMissing(o.lng, ns, key, notfound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found !== undefined && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + if (found === undefined) { + notfound = applyReplacement(notfound, options); + notfound = applyReuse(notfound, options); + } + + return (found !== undefined) ? found : notfound; + } + + function detectLanguage() { + var detectedLng; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var parms = query.split('&'); + for (var i=0; i 0) { + var key = parms[i].substring(0,pos); + var val = parms[i].substring(pos+1); + qsParm[key] = val; + } + } + })(); + if (qsParm[o.detectLngQS]) { + detectedLng = qsParm[o.detectLngQS]; + } + } + + // get from cookie + if (!detectedLng && typeof document !== 'undefined' && o.useCookie ) { + var c = f.cookie.read(o.cookieName); + if (c) detectedLng = c; + } + + // get from navigator + if (!detectedLng && typeof navigator !== 'undefined') { + detectedLng = (navigator.language) ? navigator.language : navigator.userLanguage; + } + + return detectedLng; + } + var sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + window.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + cb(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + cb('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback') { + urls.push({lng: o.fallbackLng, url: applyReplacement(o.resPostPath, { lng: o.fallbackLng, ns: ns })}); + } else if (o.sendMissingTo === 'current') { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + } + }; + + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + var pluralExtensions = { + + rules: { + "ach": { + "name": "Acholi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "af": { + "name": "Afrikaans", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ak": { + "name": "Akan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "am": { + "name": "Amharic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "an": { + "name": "Aragonese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ar": { + "name": "Arabic", + "numbers": [ + 0, + 1, + 2, + 3, + 11, + 100 + ], + "plurals": function(n) { return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5); } + }, + "arn": { + "name": "Mapudungun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ast": { + "name": "Asturian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ay": { + "name": "Aymar\u00e1", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "az": { + "name": "Azerbaijani", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "be": { + "name": "Belarusian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "bg": { + "name": "Bulgarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bn": { + "name": "Bengali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bo": { + "name": "Tibetan", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "br": { + "name": "Breton", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "bs": { + "name": "Bosnian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ca": { + "name": "Catalan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "cgg": { + "name": "Chiga", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "cs": { + "name": "Czech", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "csb": { + "name": "Kashubian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "cy": { + "name": "Welsh", + "numbers": [ + 1, + 2, + 3, + 8 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3); } + }, + "da": { + "name": "Danish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "de": { + "name": "German", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "dz": { + "name": "Dzongkha", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "el": { + "name": "Greek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "en": { + "name": "English", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eo": { + "name": "Esperanto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es": { + "name": "Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es_ar": { + "name": "Argentinean Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "et": { + "name": "Estonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eu": { + "name": "Basque", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fa": { + "name": "Persian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "fi": { + "name": "Finnish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fil": { + "name": "Filipino", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fo": { + "name": "Faroese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fr": { + "name": "French", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fur": { + "name": "Friulian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fy": { + "name": "Frisian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ga": { + "name": "Irish", + "numbers": [ + 1, + 2, + 3, + 7, + 11 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;} + }, + "gd": { + "name": "Scottish Gaelic", + "numbers": [ + 1, + 2, + 3, + 20 + ], + "plurals": function(n) { return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3); } + }, + "gl": { + "name": "Galician", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gu": { + "name": "Gujarati", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gun": { + "name": "Gun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ha": { + "name": "Hausa", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "he": { + "name": "Hebrew", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hi": { + "name": "Hindi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hr": { + "name": "Croatian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "hu": { + "name": "Hungarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hy": { + "name": "Armenian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ia": { + "name": "Interlingua", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "id": { + "name": "Indonesian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "is": { + "name": "Icelandic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n%10!=1 || n%100==11); } + }, + "it": { + "name": "Italian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ja": { + "name": "Japanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jbo": { + "name": "Lojban", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jv": { + "name": "Javanese", + "numbers": [ + 0, + 1 + ], + "plurals": function(n) { return Number(n !== 0); } + }, + "ka": { + "name": "Georgian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kk": { + "name": "Kazakh", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "km": { + "name": "Khmer", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kn": { + "name": "Kannada", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ko": { + "name": "Korean", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ku": { + "name": "Kurdish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "kw": { + "name": "Cornish", + "numbers": [ + 1, + 2, + 3, + 4 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3); } + }, + "ky": { + "name": "Kyrgyz", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lb": { + "name": "Letzeburgesch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ln": { + "name": "Lingala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "lo": { + "name": "Lao", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lt": { + "name": "Lithuanian", + "numbers": [ + 1, + 2, + 10 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "lv": { + "name": "Latvian", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2); } + }, + "mai": { + "name": "Maithili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mfe": { + "name": "Mauritian Creole", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mg": { + "name": "Malagasy", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mi": { + "name": "Maori", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mk": { + "name": "Macedonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 || n%10==1 ? 0 : 1); } + }, + "ml": { + "name": "Malayalam", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mn": { + "name": "Mongolian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mnk": { + "name": "Mandinka", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(0 ? 0 : n==1 ? 1 : 2); } + }, + "mr": { + "name": "Marathi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ms": { + "name": "Malay", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "mt": { + "name": "Maltese", + "numbers": [ + 1, + 2, + 11, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3); } + }, + "nah": { + "name": "Nahuatl", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nap": { + "name": "Neapolitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nb": { + "name": "Norwegian Bokmal", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ne": { + "name": "Nepali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nl": { + "name": "Dutch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nn": { + "name": "Norwegian Nynorsk", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "no": { + "name": "Norwegian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nso": { + "name": "Northern Sotho", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "oc": { + "name": "Occitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "or": { + "name": "Oriya", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pa": { + "name": "Punjabi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pap": { + "name": "Papiamento", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pl": { + "name": "Polish", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "pms": { + "name": "Piemontese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ps": { + "name": "Pashto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt": { + "name": "Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt_br": { + "name": "Brazilian Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "rm": { + "name": "Romansh", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ro": { + "name": "Romanian", + "numbers": [ + 1, + 2, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2); } + }, + "ru": { + "name": "Russian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "sah": { + "name": "Yakut", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sco": { + "name": "Scots", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "se": { + "name": "Northern Sami", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "si": { + "name": "Sinhala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sk": { + "name": "Slovak", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "sl": { + "name": "Slovenian", + "numbers": [ + 5, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }, + "so": { + "name": "Somali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "son": { + "name": "Songhay", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sq": { + "name": "Albanian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sr": { + "name": "Serbian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "su": { + "name": "Sundanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sv": { + "name": "Swedish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sw": { + "name": "Swahili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ta": { + "name": "Tamil", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "te": { + "name": "Telugu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tg": { + "name": "Tajik", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "th": { + "name": "Thai", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ti": { + "name": "Tigrinya", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tk": { + "name": "Turkmen", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tr": { + "name": "Turkish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tt": { + "name": "Tatar", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ug": { + "name": "Uyghur", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "uk": { + "name": "Ukrainian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ur": { + "name": "Urdu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "uz": { + "name": "Uzbek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "vi": { + "name": "Vietnamese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "wa": { + "name": "Walloon", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "wo": { + "name": "Wolof", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "yo": { + "name": "Yoruba", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "zh": { + "name": "Chinese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + } + }, + + // for demonstration only sl and ar is added but you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i = ext.plurals(c); + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[0], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + + return i18n; + +})); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd-1.6.0.zip b/libs/i18next/release/i18next.amd-1.6.0.zip new file mode 100644 index 00000000..822b7d48 Binary files /dev/null and b/libs/i18next/release/i18next.amd-1.6.0.zip differ diff --git a/libs/i18next/release/i18next.amd-1.6.1.js b/libs/i18next/release/i18next.amd-1.6.1.js new file mode 100644 index 00000000..558cdcde --- /dev/null +++ b/libs/i18next/release/i18next.amd-1.6.1.js @@ -0,0 +1,2591 @@ +// i18next, v1.6.1 +// Copyright (c)2013 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function (root, factory) { + if (typeof exports === 'object') { + + module.exports = factory(); + + } else if (typeof define === 'function' && define.amd) { + + define([], factory); + + } +}(this, function () { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + var $ = undefined + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = []; + + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: 'dev', + fallbackNS: [], + detectLngQS: 'setLng', + ns: 'translation', + fallbackOnNull: true, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + + postProcess: undefined + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + return JSON.parse(data); + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + if (status === 200) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + document.cookie = name+"="+value+expires+"; path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : _ajax, + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + toLanguages: function(lng) { + var languages = []; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + + if (o.load !== 'unspecific') languages.push(lng); + if (o.load !== 'current') languages.push(parts[0]); + } else { + languages.push(lng); + } + + if (languages.indexOf(o.fallbackLng) === -1 && o.fallbackLng) languages.push(o.fallbackLng); + + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + if (o.lng) { + // set cookie with lng set (as detectLanguage will set cookie on need) + if (o.useCookie) f.cookie.create(o.cookieName, o.lng, o.cookieExpirationTime); + } else { + o.lng = o.fallbackLng; + if (o.useCookie) f.cookie.remove(o.cookieName); + } + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + if (cb) cb(translate); + if (deferred) deferred.resolve(); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + + if (cb) cb(translate); + if (deferred) deferred.resolve(); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + f.extend(resStore[lng][ns], resources); + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, cb) { + return init({lng: lng}, cb); + } + + function lng() { + return currentLng; + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } + else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + f.each(replacementHash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), value); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.escape(value)); + }else{ + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), value); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, translated_token); + } + return translated; + } + + function hasContext(options) { + return (options.context && typeof options.context == 'string'); + } + + function needsPlural(options) { + return (options.count !== undefined && typeof options.count != 'string' && options.count !== 1); + } + + function exists(key, options) { + options = options || {}; + + var notFound = options.defaultValue || key + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(key, options) { + + if (typeof options == 'string') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else { + options = options || {}; + } + + var notFound = options.defaultValue || key + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng) : languages + , ns = options.ns || o.ns.defaultNs; + + if (found === undefined && o.sendMissing) { + if (options.lng) { + sync.postMissing(lngs[0], ns, key, notfound, lngs); + } else { + sync.postMissing(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found !== undefined && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessor && postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options){ + options = options || {}; + + if (!resStore) { return notfound; } // no resStore to translate from + + var optionWithoutCount, translated + , notFound = options.defaultValue || key + , lngs = languages; + + if (options.lng) { + lngs = f.toLanguages(options.lng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.count; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(currentLng, options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + + translated = translate(pluralKey, optionWithoutCount); + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } // else continue translation with original/singular key + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (Object.prototype.toString.apply(value) === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned a object instead of string.'; + f.log(value); + } else { + var copy = {}; // apply child translation on a copy + for (var m in value) { + // apply translation on childs + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + } + value = copy; + } + } + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _translate(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _translate(key, options); // fallback to default NS + } + } + + return found; + } + function detectLanguage() { + var detectedLng; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var parms = query.split('&'); + for (var i=0; i 0) { + var key = parms[i].substring(0,pos); + var val = parms[i].substring(pos+1); + qsParm[key] = val; + } + } + })(); + if (qsParm[o.detectLngQS]) { + detectedLng = qsParm[o.detectLngQS]; + } + } + + // get from cookie + if (!detectedLng && typeof document !== 'undefined' && o.useCookie ) { + var c = f.cookie.read(o.cookieName); + if (c) detectedLng = c; + } + + // get from navigator + if (!detectedLng && typeof navigator !== 'undefined') { + detectedLng = (navigator.language) ? navigator.language : navigator.userLanguage; + } + + return detectedLng; + } + var sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + window.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback') { + urls.push({lng: o.fallbackLng, url: applyReplacement(o.resPostPath, { lng: o.fallbackLng, ns: ns })}); + } else if (o.sendMissingTo === 'current') { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + } + }; + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + var pluralExtensions = { + + rules: { + "ach": { + "name": "Acholi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "af": { + "name": "Afrikaans", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ak": { + "name": "Akan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "am": { + "name": "Amharic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "an": { + "name": "Aragonese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ar": { + "name": "Arabic", + "numbers": [ + 0, + 1, + 2, + 3, + 11, + 100 + ], + "plurals": function(n) { return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5); } + }, + "arn": { + "name": "Mapudungun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ast": { + "name": "Asturian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ay": { + "name": "Aymar\u00e1", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "az": { + "name": "Azerbaijani", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "be": { + "name": "Belarusian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "bg": { + "name": "Bulgarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bn": { + "name": "Bengali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bo": { + "name": "Tibetan", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "br": { + "name": "Breton", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "bs": { + "name": "Bosnian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ca": { + "name": "Catalan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "cgg": { + "name": "Chiga", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "cs": { + "name": "Czech", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "csb": { + "name": "Kashubian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "cy": { + "name": "Welsh", + "numbers": [ + 1, + 2, + 3, + 8 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3); } + }, + "da": { + "name": "Danish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "de": { + "name": "German", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "dz": { + "name": "Dzongkha", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "el": { + "name": "Greek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "en": { + "name": "English", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eo": { + "name": "Esperanto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es": { + "name": "Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es_ar": { + "name": "Argentinean Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "et": { + "name": "Estonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eu": { + "name": "Basque", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fa": { + "name": "Persian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "fi": { + "name": "Finnish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fil": { + "name": "Filipino", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fo": { + "name": "Faroese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fr": { + "name": "French", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fur": { + "name": "Friulian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fy": { + "name": "Frisian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ga": { + "name": "Irish", + "numbers": [ + 1, + 2, + 3, + 7, + 11 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;} + }, + "gd": { + "name": "Scottish Gaelic", + "numbers": [ + 1, + 2, + 3, + 20 + ], + "plurals": function(n) { return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3); } + }, + "gl": { + "name": "Galician", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gu": { + "name": "Gujarati", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gun": { + "name": "Gun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ha": { + "name": "Hausa", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "he": { + "name": "Hebrew", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hi": { + "name": "Hindi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hr": { + "name": "Croatian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "hu": { + "name": "Hungarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hy": { + "name": "Armenian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ia": { + "name": "Interlingua", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "id": { + "name": "Indonesian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "is": { + "name": "Icelandic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n%10!=1 || n%100==11); } + }, + "it": { + "name": "Italian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ja": { + "name": "Japanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jbo": { + "name": "Lojban", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jv": { + "name": "Javanese", + "numbers": [ + 0, + 1 + ], + "plurals": function(n) { return Number(n !== 0); } + }, + "ka": { + "name": "Georgian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kk": { + "name": "Kazakh", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "km": { + "name": "Khmer", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kn": { + "name": "Kannada", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ko": { + "name": "Korean", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ku": { + "name": "Kurdish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "kw": { + "name": "Cornish", + "numbers": [ + 1, + 2, + 3, + 4 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3); } + }, + "ky": { + "name": "Kyrgyz", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lb": { + "name": "Letzeburgesch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ln": { + "name": "Lingala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "lo": { + "name": "Lao", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lt": { + "name": "Lithuanian", + "numbers": [ + 1, + 2, + 10 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "lv": { + "name": "Latvian", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2); } + }, + "mai": { + "name": "Maithili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mfe": { + "name": "Mauritian Creole", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mg": { + "name": "Malagasy", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mi": { + "name": "Maori", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mk": { + "name": "Macedonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 || n%10==1 ? 0 : 1); } + }, + "ml": { + "name": "Malayalam", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mn": { + "name": "Mongolian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mnk": { + "name": "Mandinka", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(0 ? 0 : n==1 ? 1 : 2); } + }, + "mr": { + "name": "Marathi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ms": { + "name": "Malay", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "mt": { + "name": "Maltese", + "numbers": [ + 1, + 2, + 11, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3); } + }, + "nah": { + "name": "Nahuatl", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nap": { + "name": "Neapolitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nb": { + "name": "Norwegian Bokmal", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ne": { + "name": "Nepali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nl": { + "name": "Dutch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nn": { + "name": "Norwegian Nynorsk", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "no": { + "name": "Norwegian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nso": { + "name": "Northern Sotho", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "oc": { + "name": "Occitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "or": { + "name": "Oriya", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pa": { + "name": "Punjabi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pap": { + "name": "Papiamento", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pl": { + "name": "Polish", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "pms": { + "name": "Piemontese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ps": { + "name": "Pashto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt": { + "name": "Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt_br": { + "name": "Brazilian Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "rm": { + "name": "Romansh", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ro": { + "name": "Romanian", + "numbers": [ + 1, + 2, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2); } + }, + "ru": { + "name": "Russian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "sah": { + "name": "Yakut", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sco": { + "name": "Scots", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "se": { + "name": "Northern Sami", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "si": { + "name": "Sinhala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sk": { + "name": "Slovak", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "sl": { + "name": "Slovenian", + "numbers": [ + 5, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }, + "so": { + "name": "Somali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "son": { + "name": "Songhay", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sq": { + "name": "Albanian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sr": { + "name": "Serbian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "su": { + "name": "Sundanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sv": { + "name": "Swedish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sw": { + "name": "Swahili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ta": { + "name": "Tamil", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "te": { + "name": "Telugu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tg": { + "name": "Tajik", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "th": { + "name": "Thai", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ti": { + "name": "Tigrinya", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tk": { + "name": "Turkmen", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tr": { + "name": "Turkish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tt": { + "name": "Tatar", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ug": { + "name": "Uyghur", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "uk": { + "name": "Ukrainian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ur": { + "name": "Urdu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "uz": { + "name": "Uzbek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "vi": { + "name": "Vietnamese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "wa": { + "name": "Walloon", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "wo": { + "name": "Wolof", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "yo": { + "name": "Yoruba", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "zh": { + "name": "Chinese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + } + }, + + // for demonstration only sl and ar is added but you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i = ext.plurals(c); + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[0], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + + return i18n; + +})); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd-1.6.1.min.js b/libs/i18next/release/i18next.amd-1.6.1.min.js new file mode 100644 index 00000000..101f6821 --- /dev/null +++ b/libs/i18next/release/i18next.amd-1.6.1.min.js @@ -0,0 +1,5 @@ +// i18next, v1.6.1 +// Copyright (c)2013 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function(n,e){"object"==typeof exports?module.exports=e():"function"==typeof define&&define.amd&&define([],e)})(this,function(){function n(n,e){if(!e||"function"==typeof e)return n;for(var r in e)n[r]=e[r];return n}function e(n,e,r){var t,u=0,a=n.length,o=void 0===a||"function"==typeof n;if(r)if(o){for(t in n)if(e.apply(n[t],r)===!1)break}else for(;a>u&&e.apply(n[u++],r)!==!1;);else if(o){for(t in n)if(e.call(n[t],t,n[t])===!1)break}else for(;a>u&&e.call(n[u],u,n[u++])!==!1;);return n}function r(n){return"string"==typeof n?n.replace(/[&<>"'\/]/g,function(n){return A[n]}):n}function t(n){var e=function(n){if(window.XMLHttpRequest)return n(null,new XMLHttpRequest);if(window.ActiveXObject)try{return n(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(e){return n(null,new ActiveXObject("Microsoft.XMLHTTP"))}return n(Error())},r=function(n){if("string"==typeof n)return n;var e=[];for(var r in n)n.hasOwnProperty(r)&&e.push(encodeURIComponent(r)+"="+encodeURIComponent(n[r]));return e.join("&")},t=function(n){n=n.replace(/\r\n/g,"\n");for(var e="",r=0;n.length>r;r++){var t=n.charCodeAt(r);128>t?e+=String.fromCharCode(t):t>127&&2048>t?(e+=String.fromCharCode(192|t>>6),e+=String.fromCharCode(128|63&t)):(e+=String.fromCharCode(224|t>>12),e+=String.fromCharCode(128|63&t>>6),e+=String.fromCharCode(128|63&t))}return e},u=function(n){var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";n=t(n);var r,u,a,o,s,i,l,c="",f=0;do r=n.charCodeAt(f++),u=n.charCodeAt(f++),a=n.charCodeAt(f++),o=r>>2,s=(3&r)<<4|u>>4,i=(15&u)<<2|a>>6,l=63&a,isNaN(u)?i=l=64:isNaN(a)&&(l=64),c+=e.charAt(o)+e.charAt(s)+e.charAt(i)+e.charAt(l),r=u=a="",o=s=i=l="";while(n.length>f);return c},a=function(){for(var n=arguments[0],e=1;arguments.length>e;e++){var r=arguments[e];for(var t in r)r.hasOwnProperty(t)&&(n[t]=r[t])}return n},o=function(n,t,u,s){"function"==typeof u&&(s=u,u={}),u.cache=u.cache||!1,u.data=u.data||{},u.headers=u.headers||{},u.jsonp=u.jsonp||!1,u.async=void 0===u.async?!0:u.async;var i,l=a({accept:"*/*","content-type":"application/x-www-form-urlencoded;charset=UTF-8"},o.headers,u.headers);if(i="application/json"===l["content-type"]?JSON.stringify(u.data):r(u.data),"GET"===n){var c=[];if(i&&(c.push(i),i=null),u.cache||c.push("_="+(new Date).getTime()),u.jsonp&&(c.push("callback="+u.jsonp),c.push("jsonp="+u.jsonp)),c=c.join("&"),c.length>1&&(t+=t.indexOf("?")>-1?"&"+c:"?"+c),u.jsonp){var f=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=t,f.appendChild(m),void 0}}e(function(e,r){if(e)return s(e);r.open(n,t,u.async);for(var a in l)l.hasOwnProperty(a)&&r.setRequestHeader(a,l[a]);r.onreadystatechange=function(){if(4===r.readyState){var n=r.responseText||"";if(!s)return;s(r.status,{text:function(){return n},json:function(){return JSON.parse(n)}})}},r.send(i)})},s={authBasic:function(n,e){o.headers.Authorization="Basic "+u(n+":"+e)},connect:function(n,e,r){return o("CONNECT",n,e,r)},del:function(n,e,r){return o("DELETE",n,e,r)},get:function(n,e,r){return o("GET",n,e,r)},head:function(n,e,r){return o("HEAD",n,e,r)},headers:function(n){o.headers=n||{}},isAllowed:function(n,e,r){this.options(n,function(n,t){r(-1!==t.text().indexOf(e))})},options:function(n,e,r){return o("OPTIONS",n,e,r)},patch:function(n,e,r){return o("PATCH",n,e,r)},post:function(n,e,r){return o("POST",n,e,r)},put:function(n,e,r){return o("PUT",n,e,r)},trace:function(n,e,r){return o("TRACE",n,e,r)}},i=n.type?n.type.toLowerCase():"get";s[i](n.url,n,function(e,r){200===e?n.success(r.json(),e,null):n.error(r.text(),e,null)})}function u(n,e){"function"==typeof n&&(e=n,n={}),n=n||{},M.extend(P,n),"string"==typeof P.ns&&(P.ns={namespaces:[P.ns],defaultNs:P.ns}),"string"==typeof P.fallbackNS&&(P.fallbackNS=[P.fallbackNS]),P.interpolationPrefixEscaped=M.regexEscape(P.interpolationPrefix),P.interpolationSuffixEscaped=M.regexEscape(P.interpolationSuffix),P.lng||(P.lng=M.detectLanguage()),P.lng?P.useCookie&&M.cookie.create(P.cookieName,P.lng,P.cookieExpirationTime):(P.lng=P.fallbackLng,P.useCookie&&M.cookie.remove(P.cookieName)),T=M.toLanguages(P.lng),S=T[0],M.log("currentLng set to: "+S),F.setCurrentLng(S),O&&P.setJqueryExt&&m();var r;if(O&&O.Deferred&&(r=O.Deferred()),!P.resStore){var t=M.toLanguages(P.lng);"string"==typeof P.preload&&(P.preload=[P.preload]);for(var u=0,a=P.preload.length;a>u;u++)for(var o=M.toLanguages(P.preload[u]),s=0,i=o.length;i>s;s++)0>t.indexOf(o[s])&&t.push(o[s]);return L.sync.load(t,P,function(n,t){w=t,e&&e(N),r&&r.resolve()}),r?r.promise():void 0}return w=P.resStore,e&&e(N),r&&r.resolve(),r?r.promise():void 0}function a(n,e){"string"==typeof n&&(n=[n]);for(var r=0,t=n.length;t>r;r++)0>P.preload.indexOf(n[r])&&P.preload.push(n[r]);return u(e)}function o(n,e,r){"string"!=typeof e?(r=e,e=P.ns.defaultNs):0>P.ns.namespaces.indexOf(e)&&P.ns.namespaces.push(e),w[n]=w[n]||{},w[n][e]=w[n][e]||{},M.extend(w[n][e],r)}function s(n){P.ns.defaultNs=n}function i(n,e){l([n],e)}function l(n,e){var r={dynamicLoad:P.dynamicLoad,resGetPath:P.resGetPath,getAsync:P.getAsync,customLoad:P.customLoad,ns:{namespaces:n,defaultNs:""}},t=M.toLanguages(P.lng);"string"==typeof P.preload&&(P.preload=[P.preload]);for(var u=0,a=P.preload.length;a>u;u++)for(var o=M.toLanguages(P.preload[u]),s=0,i=o.length;i>s;s++)0>t.indexOf(o[s])&&t.push(o[s]);for(var l=[],c=0,f=t.length;f>c;c++){var m=!1,p=w[t[c]];if(p)for(var b=0,g=n.length;g>b;b++)p[n[b]]||(m=!0);else m=!0;m&&l.push(t[c])}l.length?L.sync._fetch(l,r,function(r,t){var u=n.length*l.length;M.each(n,function(n,r){0>P.ns.namespaces.indexOf(r)&&P.ns.namespaces.push(r),M.each(l,function(n,a){w[a]=w[a]||{},w[a][r]=t[a][r],u--,0===u&&e&&(P.useLocalStorage&&L.sync._storeLocal(w),e())})})}):e&&e()}function c(n,e){return u({lng:n},e)}function f(){return S}function m(){function n(n,e,r){if(0!==e.length){var t="text";if(0===e.indexOf("[")){var u=e.split("]");e=u[1],t=u[0].substr(1,u[0].length-1)}e.indexOf(";")===e.length-1&&(e=e.substr(0,e.length-2));var a;"html"===t?(a=P.defaultValueFromContent?O.extend({defaultValue:n.html()},r):r,n.html(O.t(e,a))):"text"===t?(a=P.defaultValueFromContent?O.extend({defaultValue:n.text()},r):r,n.text(O.t(e,a))):(a=P.defaultValueFromContent?O.extend({defaultValue:n.attr(t)},r):r,n.attr(t,O.t(e,a)))}}function e(e,r){var t=e.attr(P.selectorAttr);if(t){var u=e,a=e.data("i18n-target");if(a&&(u=e.find(a)||e),r||P.useDataAttrOptions!==!0||(r=e.data("i18n-options")),r=r||{},t.indexOf(";")>=0){var o=t.split(";");O.each(o,function(e,t){""!==t&&n(u,t,r)})}else n(u,t,r);P.useDataAttrOptions===!0&&e.data("i18n-options",r)}}O.t=O.t||N,O.fn.i18n=function(n){return this.each(function(){e(O(this),n);var r=O(this).find("["+P.selectorAttr+"]");r.each(function(){e(O(this),n)})})}}function p(n,e,r,t){if(!n)return n;if(t=t||e,0>n.indexOf(t.interpolationPrefix||P.interpolationPrefix))return n;var u=t.interpolationPrefix?M.regexEscape(t.interpolationPrefix):P.interpolationPrefixEscaped,a=t.interpolationSuffix?M.regexEscape(t.interpolationSuffix):P.interpolationSuffixEscaped,o="HTML"+a;return M.each(e,function(e,s){var i=r?r+P.keyseparator+e:e;"object"==typeof s&&null!==s?n=p(n,s,i,t):t.escapeInterpolation||P.escapeInterpolation?(n=n.replace(RegExp([u,i,o].join(""),"g"),s),n=n.replace(RegExp([u,i,a].join(""),"g"),M.escape(s))):n=n.replace(RegExp([u,i,a].join(""),"g"),s)}),n}function b(n,e){var r=",",t="{",u="}",a=M.extend({},e);for(delete a.postProcess;-1!=n.indexOf(P.reusePrefix)&&(j++,!(j>P.maxRecursion));){var o=n.lastIndexOf(P.reusePrefix),s=n.indexOf(P.reuseSuffix,o)+P.reuseSuffix.length,i=n.substring(o,s),l=i.replace(P.reusePrefix,"").replace(P.reuseSuffix,"");if(-1!=l.indexOf(r)){var c=l.indexOf(r);if(-1!=l.indexOf(t,c)&&-1!=l.indexOf(u,c)){var f=l.indexOf(t,c),m=l.indexOf(u,f)+u.length;try{a=M.extend(a,JSON.parse(l.substring(f,m))),l=l.substring(0,c)}catch(p){}}}var b=x(l,a);n=n.replace(i,b)}return n}function g(n){return n.context&&"string"==typeof n.context}function d(n){return void 0!==n.count&&"string"!=typeof n.count&&1!==n.count}function h(n,e){e=e||{};var r=e.defaultValue||n,t=y(n,e);return void 0!==t||t===r}function N(){return j=0,x.apply(null,arguments)}function v(){for(var n=[],e=1;arguments.length>e;e++)n.push(arguments[e]);return{postProcess:"sprintf",sprintf:n}}function x(n,e){e="string"==typeof e?v.apply(null,arguments):e||{};var r=e.defaultValue||n,t=y(n,e),u=e.lng?M.toLanguages(e.lng):T,a=e.ns||P.ns.defaultNs;void 0===t&&P.sendMissing&&(e.lng?E.postMissing(u[0],a,n,notfound,u):E.postMissing(P.lng,a,n,r,u));var o=e.postProcess||P.postProcess;return void 0!==t&&o&&R[o]&&(t=R[o](t,n,e)),void 0===t&&(r=p(r,e),r=b(r,e),o&&R[o]&&(t=R[o](t,n,e))),void 0!==t?t:r}function y(n,e){if(e=e||{},!w)return notfound;var r,t,u=e.defaultValue||n,a=T;if(e.lng&&(a=M.toLanguages(e.lng),!w[a[0]])){var o=P.getAsync;P.getAsync=!1,L.sync.load(a,P,function(n,e){M.extend(w,e),P.getAsync=o})}var s=e.ns||P.ns.defaultNs;if(n.indexOf(P.nsseparator)>-1){var i=n.split(P.nsseparator);s=i[0],n=i[1]}if(g(e)){r=M.extend({},e),delete r.context,r.defaultValue=P.contextNotFound;var l=s+P.nsseparator+n+"_"+e.context;if(t=N(l,r),t!=P.contextNotFound)return p(t,{context:e.context})}if(d(e)){r=M.extend({},e),delete r.count,r.defaultValue=P.pluralNotFound;var c=s+P.nsseparator+n+P.pluralSuffix,f=F.get(S,e.count);if(f>=0?c=c+"_"+f:1===f&&(c=s+P.nsseparator+n),t=N(c,r),t!=P.pluralNotFound)return p(t,{count:e.count,interpolationPrefix:e.interpolationPrefix,interpolationSuffix:e.interpolationSuffix})}for(var m,h=n.split(P.keyseparator),v=0,y=a.length;y>v&&void 0===m;v++){for(var k=a[v],O=0,j=w[k]&&w[k][s];h[O];)j=j&&j[h[O]],O++;if(void 0!==j){if("string"==typeof j)j=p(j,e),j=b(j,e);else if("[object Array]"!==Object.prototype.toString.apply(j)||P.returnObjectTrees||e.returnObjectTrees){if(null===j&&P.fallbackOnNull===!0)j=void 0;else if(null!==j)if(P.returnObjectTrees||e.returnObjectTrees){var A={};for(var C in j)A[C]=x(s+P.nsseparator+n+P.keyseparator+C,e);j=A}else j="key '"+s+":"+n+" ("+k+")' "+"returned a object instead of string.",M.log(j)}else j=j.join("\n"),j=p(j,e),j=b(j,e);m=j}}if(void 0===m&&!e.isFallbackLookup&&(P.fallbackToDefaultNS===!0||P.fallbackNS&&P.fallbackNS.length))if(e.isFallbackLookup=!0,P.fallbackNS.length){for(var _=0,E=P.fallbackNS.length;E>_;_++)if(m=x(P.fallbackNS[_]+P.nsseparator+n,e)){var R=m.indexOf(P.nsseparator)>-1?m.split(P.nsseparator)[1]:m,z=u.indexOf(P.nsseparator)>-1?u.split(P.nsseparator)[1]:u;if(R!==z)break}}else m=x(n,e);return m}function k(){var n,e=[];if("undefined"!=typeof window&&(function(){for(var n=window.location.search.substring(1),r=n.split("&"),t=0;r.length>t;t++){var u=r[t].indexOf("=");if(u>0){var a=r[t].substring(0,u),o=r[t].substring(u+1);e[a]=o}}}(),e[P.detectLngQS]&&(n=e[P.detectLngQS])),!n&&"undefined"!=typeof document&&P.useCookie){var r=M.cookie.read(P.cookieName);r&&(n=r)}return n||"undefined"==typeof navigator||(n=navigator.language?navigator.language:navigator.userLanguage),n}Array.prototype.indexOf||(Array.prototype.indexOf=function(n){"use strict";if(null==this)throw new TypeError;var e=Object(this),r=e.length>>>0;if(0===r)return-1;var t=0;if(arguments.length>0&&(t=Number(arguments[1]),t!=t?t=0:0!=t&&1/0!=t&&t!=-1/0&&(t=(t>0||-1)*Math.floor(Math.abs(t)))),t>=r)return-1;for(var u=t>=0?t:Math.max(r-Math.abs(t),0);r>u;u++)if(u in e&&e[u]===n)return u;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(n){"use strict";if(null==this)throw new TypeError;var e=Object(this),r=e.length>>>0;if(0===r)return-1;var t=r;arguments.length>1&&(t=Number(arguments[1]),t!=t?t=0:0!=t&&t!=1/0&&t!=-(1/0)&&(t=(t>0||-1)*Math.floor(Math.abs(t))));for(var u=t>=0?Math.min(t,r-1):r-Math.abs(t);u>=0;u--)if(u in e&&e[u]===n)return u;return-1});var S,O=void 0,L={},w={},j=0,T=[],P={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:"dev",fallbackNS:[],detectLngQS:"setLng",ns:"translation",fallbackOnNull:!0,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",postProcess:void 0},A={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},C={create:function(n,e,r){var t;if(r){var u=new Date;u.setTime(u.getTime()+1e3*60*r),t="; expires="+u.toGMTString()}else t="";document.cookie=n+"="+e+t+"; path=/"},read:function(n){for(var e=n+"=",r=document.cookie.split(";"),t=0;r.length>t;t++){for(var u=r[t];" "==u.charAt(0);)u=u.substring(1,u.length);if(0===u.indexOf(e))return u.substring(e.length,u.length)}return null},remove:function(n){this.create(n,"",-1)}},_={create:function(){},read:function(){return null},remove:function(){}},M={extend:O?O.extend:n,each:O?O.each:e,ajax:O?O.ajax:t,cookie:"undefined"!=typeof document?C:_,detectLanguage:k,escape:r,log:function(n){P.debug&&"undefined"!=typeof console&&console.log(n)},toLanguages:function(n){var e=[];if("string"==typeof n&&n.indexOf("-")>-1){var r=n.split("-");n=P.lowerCaseLng?r[0].toLowerCase()+"-"+r[1].toLowerCase():r[0].toLowerCase()+"-"+r[1].toUpperCase(),"unspecific"!==P.load&&e.push(n),"current"!==P.load&&e.push(r[0])}else e.push(n);return-1===e.indexOf(P.fallbackLng)&&P.fallbackLng&&e.push(P.fallbackLng),e},regexEscape:function(n){return n.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}};M.applyReplacement=p;var E={load:function(n,e,r){e.useLocalStorage?E._loadLocal(n,e,function(t,u){for(var a=[],o=0,s=n.length;s>o;o++)u[n[o]]||a.push(n[o]);a.length>0?E._fetch(a,e,function(n,e){M.extend(u,e),E._storeLocal(e),r(null,u)}):r(null,u)}):E._fetch(n,e,function(n,e){r(null,e)})},_loadLocal:function(n,e,r){var t={},u=(new Date).getTime();if(window.localStorage){var a=n.length;M.each(n,function(n,o){var s=window.localStorage.getItem("res_"+o);s&&(s=JSON.parse(s),s.i18nStamp&&s.i18nStamp+e.localStorageExpirationTime>u&&(t[o]=s)),a--,0===a&&r(null,t)})}},_storeLocal:function(n){if(window.localStorage)for(var e in n)n[e].i18nStamp=(new Date).getTime(),window.localStorage.setItem("res_"+e,JSON.stringify(n[e]))},_fetch:function(n,e,r){var t=e.ns,u={};if(e.dynamicLoad){var a=function(n,e){r(null,e)};if("function"==typeof e.customLoad)e.customLoad(n,t.namespaces,e,a);else{var o=p(e.resGetPath,{lng:n.join("+"),ns:t.namespaces.join("+")});M.ajax({url:o,success:function(n){M.log("loaded: "+o),a(null,n)},error:function(n,e,r){M.log("failed loading: "+o),a("failed loading resource.json error: "+r)},dataType:"json",async:e.getAsync})}}else{var s,i=t.namespaces.length*n.length;M.each(t.namespaces,function(t,a){M.each(n,function(n,t){var o=function(n,e){n&&(s=s||[],s.push(n)),u[t]=u[t]||{},u[t][a]=e,i--,0===i&&r(s,u)};"function"==typeof e.customLoad?e.customLoad(t,a,e,o):E._fetchOne(t,a,e,o)})})}},_fetchOne:function(n,e,r,t){var u=p(r.resGetPath,{lng:n,ns:e});M.ajax({url:u,success:function(n){M.log("loaded: "+u),t(null,n)},error:function(n,e,r){M.log("failed loading: "+u),t(r,{})},dataType:"json",async:r.getAsync})},postMissing:function(n,e,r,t,u){var a={};a[r]=t;var o=[];if("fallback"===P.sendMissingTo)o.push({lng:P.fallbackLng,url:p(P.resPostPath,{lng:P.fallbackLng,ns:e})});else if("current"===P.sendMissingTo)o.push({lng:n,url:p(P.resPostPath,{lng:n,ns:e})});else if("all"===P.sendMissingTo)for(var s=0,i=u.length;i>s;s++)o.push({lng:u[s],url:p(P.resPostPath,{lng:u[s],ns:e})});for(var l=0,c=o.length;c>l;l++){var f=o[l];M.ajax({url:f.url,type:P.sendType,data:a,success:function(){M.log("posted missing key '"+r+"' to: "+f.url);for(var n=r.split("."),u=0,a=w[f.lng][e];n[u];)a=a[n[u]]=u===n.length-1?t:a[n[u]]||{},u++},error:function(){M.log("failed posting missing key '"+r+"' to: "+f.url)},dataType:"json",async:P.postAsync})}}},F={rules:{ach:{name:"Acholi",numbers:[1,2],plurals:function(n){return Number(n>1)}},af:{name:"Afrikaans",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ak:{name:"Akan",numbers:[1,2],plurals:function(n){return Number(n>1)}},am:{name:"Amharic",numbers:[1,2],plurals:function(n){return Number(n>1)}},an:{name:"Aragonese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ar:{name:"Arabic",numbers:[0,1,2,3,11,100],plurals:function(n){return Number(0===n?0:1==n?1:2==n?2:n%100>=3&&10>=n%100?3:n%100>=11?4:5)}},arn:{name:"Mapudungun",numbers:[1,2],plurals:function(n){return Number(n>1)}},ast:{name:"Asturian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ay:{name:"Aymará",numbers:[1],plurals:function(){return 0}},az:{name:"Azerbaijani",numbers:[1,2],plurals:function(n){return Number(1!=n)}},be:{name:"Belarusian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},bg:{name:"Bulgarian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},bn:{name:"Bengali",numbers:[1,2],plurals:function(n){return Number(1!=n)}},bo:{name:"Tibetan",numbers:[1],plurals:function(){return 0}},br:{name:"Breton",numbers:[1,2],plurals:function(n){return Number(n>1)}},bs:{name:"Bosnian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},ca:{name:"Catalan",numbers:[1,2],plurals:function(n){return Number(1!=n)}},cgg:{name:"Chiga",numbers:[1],plurals:function(){return 0}},cs:{name:"Czech",numbers:[1,2,5],plurals:function(n){return Number(1==n?0:n>=2&&4>=n?1:2)}},csb:{name:"Kashubian",numbers:[1,2,5],plurals:function(n){return Number(1==n?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},cy:{name:"Welsh",numbers:[1,2,3,8],plurals:function(n){return Number(1==n?0:2==n?1:8!=n&&11!=n?2:3)}},da:{name:"Danish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},de:{name:"German",numbers:[1,2],plurals:function(n){return Number(1!=n)}},dz:{name:"Dzongkha",numbers:[1],plurals:function(){return 0}},el:{name:"Greek",numbers:[1,2],plurals:function(n){return Number(1!=n)}},en:{name:"English",numbers:[1,2],plurals:function(n){return Number(1!=n)}},eo:{name:"Esperanto",numbers:[1,2],plurals:function(n){return Number(1!=n)}},es:{name:"Spanish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},es_ar:{name:"Argentinean Spanish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},et:{name:"Estonian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},eu:{name:"Basque",numbers:[1,2],plurals:function(n){return Number(1!=n)}},fa:{name:"Persian",numbers:[1],plurals:function(){return 0}},fi:{name:"Finnish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},fil:{name:"Filipino",numbers:[1,2],plurals:function(n){return Number(n>1)}},fo:{name:"Faroese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},fr:{name:"French",numbers:[1,2],plurals:function(n){return Number(n>1)}},fur:{name:"Friulian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},fy:{name:"Frisian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ga:{name:"Irish",numbers:[1,2,3,7,11],plurals:function(n){return Number(1==n?0:2==n?1:7>n?2:11>n?3:4)}},gd:{name:"Scottish Gaelic",numbers:[1,2,3,20],plurals:function(n){return Number(1==n||11==n?0:2==n||12==n?1:n>2&&20>n?2:3)}},gl:{name:"Galician",numbers:[1,2],plurals:function(n){return Number(1!=n)}},gu:{name:"Gujarati",numbers:[1,2],plurals:function(n){return Number(1!=n)}},gun:{name:"Gun",numbers:[1,2],plurals:function(n){return Number(n>1)}},ha:{name:"Hausa",numbers:[1,2],plurals:function(n){return Number(1!=n)}},he:{name:"Hebrew",numbers:[1,2],plurals:function(n){return Number(1!=n)}},hi:{name:"Hindi",numbers:[1,2],plurals:function(n){return Number(1!=n)}},hr:{name:"Croatian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},hu:{name:"Hungarian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},hy:{name:"Armenian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ia:{name:"Interlingua",numbers:[1,2],plurals:function(n){return Number(1!=n)}},id:{name:"Indonesian",numbers:[1],plurals:function(){return 0}},is:{name:"Icelandic",numbers:[1,2],plurals:function(n){return Number(1!=n%10||11==n%100)}},it:{name:"Italian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ja:{name:"Japanese",numbers:[1],plurals:function(){return 0}},jbo:{name:"Lojban",numbers:[1],plurals:function(){return 0}},jv:{name:"Javanese",numbers:[0,1],plurals:function(n){return Number(0!==n)}},ka:{name:"Georgian",numbers:[1],plurals:function(){return 0}},kk:{name:"Kazakh",numbers:[1],plurals:function(){return 0}},km:{name:"Khmer",numbers:[1],plurals:function(){return 0}},kn:{name:"Kannada",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ko:{name:"Korean",numbers:[1],plurals:function(){return 0}},ku:{name:"Kurdish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},kw:{name:"Cornish",numbers:[1,2,3,4],plurals:function(n){return Number(1==n?0:2==n?1:3==n?2:3)}},ky:{name:"Kyrgyz",numbers:[1],plurals:function(){return 0}},lb:{name:"Letzeburgesch",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ln:{name:"Lingala",numbers:[1,2],plurals:function(n){return Number(n>1)}},lo:{name:"Lao",numbers:[1],plurals:function(){return 0}},lt:{name:"Lithuanian",numbers:[1,2,10],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&(10>n%100||n%100>=20)?1:2)}},lv:{name:"Latvian",numbers:[0,1,2],plurals:function(n){return Number(1==n%10&&11!=n%100?0:0!==n?1:2)}},mai:{name:"Maithili",numbers:[1,2],plurals:function(n){return Number(1!=n)}},mfe:{name:"Mauritian Creole",numbers:[1,2],plurals:function(n){return Number(n>1)}},mg:{name:"Malagasy",numbers:[1,2],plurals:function(n){return Number(n>1)}},mi:{name:"Maori",numbers:[1,2],plurals:function(n){return Number(n>1)}},mk:{name:"Macedonian",numbers:[1,2],plurals:function(n){return Number(1==n||1==n%10?0:1)}},ml:{name:"Malayalam",numbers:[1,2],plurals:function(n){return Number(1!=n)}},mn:{name:"Mongolian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},mnk:{name:"Mandinka",numbers:[0,1,2],plurals:function(n){return Number(1==n?1:2)}},mr:{name:"Marathi",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ms:{name:"Malay",numbers:[1],plurals:function(){return 0}},mt:{name:"Maltese",numbers:[1,2,11,20],plurals:function(n){return Number(1==n?0:0===n||n%100>1&&11>n%100?1:n%100>10&&20>n%100?2:3)}},nah:{name:"Nahuatl",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nap:{name:"Neapolitan",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nb:{name:"Norwegian Bokmal",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ne:{name:"Nepali",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nl:{name:"Dutch",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nn:{name:"Norwegian Nynorsk",numbers:[1,2],plurals:function(n){return Number(1!=n)}},no:{name:"Norwegian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nso:{name:"Northern Sotho",numbers:[1,2],plurals:function(n){return Number(1!=n)}},oc:{name:"Occitan",numbers:[1,2],plurals:function(n){return Number(n>1)}},or:{name:"Oriya",numbers:[2,1],plurals:function(n){return Number(1!=n)}},pa:{name:"Punjabi",numbers:[1,2],plurals:function(n){return Number(1!=n)}},pap:{name:"Papiamento",numbers:[1,2],plurals:function(n){return Number(1!=n)}},pl:{name:"Polish",numbers:[1,2,5],plurals:function(n){return Number(1==n?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},pms:{name:"Piemontese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ps:{name:"Pashto",numbers:[1,2],plurals:function(n){return Number(1!=n)}},pt:{name:"Portuguese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},pt_br:{name:"Brazilian Portuguese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},rm:{name:"Romansh",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ro:{name:"Romanian",numbers:[1,2,20],plurals:function(n){return Number(1==n?0:0===n||n%100>0&&20>n%100?1:2)}},ru:{name:"Russian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},sah:{name:"Yakut",numbers:[1],plurals:function(){return 0}},sco:{name:"Scots",numbers:[1,2],plurals:function(n){return Number(1!=n)}},se:{name:"Northern Sami",numbers:[1,2],plurals:function(n){return Number(1!=n)}},si:{name:"Sinhala",numbers:[1,2],plurals:function(n){return Number(1!=n)}},sk:{name:"Slovak",numbers:[1,2,5],plurals:function(n){return Number(1==n?0:n>=2&&4>=n?1:2)}},sl:{name:"Slovenian",numbers:[5,1,2,3],plurals:function(n){return Number(1==n%100?1:2==n%100?2:3==n%100||4==n%100?3:0)}},so:{name:"Somali",numbers:[1,2],plurals:function(n){return Number(1!=n)}},son:{name:"Songhay",numbers:[1,2],plurals:function(n){return Number(1!=n)}},sq:{name:"Albanian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},sr:{name:"Serbian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},su:{name:"Sundanese",numbers:[1],plurals:function(){return 0}},sv:{name:"Swedish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},sw:{name:"Swahili",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ta:{name:"Tamil",numbers:[1,2],plurals:function(n){return Number(1!=n)}},te:{name:"Telugu",numbers:[1,2],plurals:function(n){return Number(1!=n)}},tg:{name:"Tajik",numbers:[1,2],plurals:function(n){return Number(n>1)}},th:{name:"Thai",numbers:[1],plurals:function(){return 0}},ti:{name:"Tigrinya",numbers:[1,2],plurals:function(n){return Number(n>1)}},tk:{name:"Turkmen",numbers:[1,2],plurals:function(n){return Number(1!=n)}},tr:{name:"Turkish",numbers:[1,2],plurals:function(n){return Number(n>1)}},tt:{name:"Tatar",numbers:[1],plurals:function(){return 0}},ug:{name:"Uyghur",numbers:[1],plurals:function(){return 0}},uk:{name:"Ukrainian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},ur:{name:"Urdu",numbers:[1,2],plurals:function(n){return Number(1!=n)}},uz:{name:"Uzbek",numbers:[1,2],plurals:function(n){return Number(n>1)}},vi:{name:"Vietnamese",numbers:[1],plurals:function(){return 0}},wa:{name:"Walloon",numbers:[1,2],plurals:function(n){return Number(n>1)}},wo:{name:"Wolof",numbers:[1],plurals:function(){return 0}},yo:{name:"Yoruba",numbers:[1,2],plurals:function(n){return Number(1!=n)}},zh:{name:"Chinese",numbers:[1],plurals:function(){return 0}}},addRule:function(n,e){F.rules[n]=e},setCurrentLng:function(n){if(!F.currentRule||F.currentRule.lng!==n){var e=n.split("-");F.currentRule={lng:n,rule:F.rules[e[0]]}}},get:function(n,e){function r(e,r){var t;if(t=F.currentRule&&F.currentRule.lng===n?F.currentRule.rule:F.rules[e]){var u=t.plurals(r),a=t.numbers[u];return 2===t.numbers.length&&1===t.numbers[0]&&(2===a?a=-1:1===a&&(a=1)),a}return 1===r?"1":"-1"}var t=n.split("-");return r(t[0],e)}},R={},z=function(n,e){R[n]=e},D=function(){function n(n){return Object.prototype.toString.call(n).slice(8,-1).toLowerCase()}function e(n,e){for(var r=[];e>0;r[--e]=n);return r.join("")}var r=function(){return r.cache.hasOwnProperty(arguments[0])||(r.cache[arguments[0]]=r.parse(arguments[0])),r.format.call(null,r.cache[arguments[0]],arguments)};return r.format=function(r,t){var u,a,o,s,i,l,c,f=1,m=r.length,p="",b=[];for(a=0;m>a;a++)if(p=n(r[a]),"string"===p)b.push(r[a]);else if("array"===p){if(s=r[a],s[2])for(u=t[f],o=0;s[2].length>o;o++){if(!u.hasOwnProperty(s[2][o]))throw D('[sprintf] property "%s" does not exist',s[2][o]);u=u[s[2][o]]}else u=s[1]?t[s[1]]:t[f++];if(/[^s]/.test(s[8])&&"number"!=n(u))throw D("[sprintf] expecting number but found %s",n(u));switch(s[8]){case"b":u=u.toString(2);break;case"c":u=String.fromCharCode(u);break;case"d":u=parseInt(u,10);break;case"e":u=s[7]?u.toExponential(s[7]):u.toExponential();break;case"f":u=s[7]?parseFloat(u).toFixed(s[7]):parseFloat(u);break;case"o":u=u.toString(8);break;case"s":u=(u+="")&&s[7]?u.substring(0,s[7]):u;break;case"u":u=Math.abs(u);break;case"x":u=u.toString(16);break;case"X":u=u.toString(16).toUpperCase()}u=/[def]/.test(s[8])&&s[3]&&u>=0?"+"+u:u,l=s[4]?"0"==s[4]?"0":s[4].charAt(1):" ",c=s[6]-(u+"").length,i=s[6]?e(l,c):"",b.push(s[5]?u+i:i+u)}return b.join("")},r.cache={},r.parse=function(n){for(var e=n,r=[],t=[],u=0;e;){if(null!==(r=/^[^\x25]+/.exec(e)))t.push(r[0]);else if(null!==(r=/^\x25{2}/.exec(e)))t.push("%");else{if(null===(r=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(e)))throw"[sprintf] huh?";if(r[2]){u|=1;var a=[],o=r[2],s=[];if(null===(s=/^([a-z_][a-z_\d]*)/i.exec(o)))throw"[sprintf] huh?";for(a.push(s[1]);""!==(o=o.substring(s[0].length));)if(null!==(s=/^\.([a-z_][a-z_\d]*)/i.exec(o)))a.push(s[1]);else{if(null===(s=/^\[(\d+)\]/.exec(o)))throw"[sprintf] huh?";a.push(s[1])}r[2]=a}else u|=2;if(3===u)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";t.push(r)}e=e.substring(r[0].length)}return t},r}(),I=function(n,e){return e.unshift(n),D.apply(null,e)};return z("sprintf",function(n,e,r){return r.sprintf?"[object Array]"===Object.prototype.toString.apply(r.sprintf)?I(n,r.sprintf):"object"==typeof r.sprintf?D(n,r.sprintf):n:n}),L.init=u,L.setLng=c,L.preload=a,L.addResourceBundle=o,L.loadNamespace=i,L.loadNamespaces=l,L.setDefaultNamespace=s,L.t=N,L.translate=N,L.exists=h,L.detectLanguage=M.detectLanguage,L.pluralExtensions=F,L.sync=E,L.functions=M,L.lng=f,L.addPostProcessor=z,L.options=P,L}); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd-1.6.1.zip b/libs/i18next/release/i18next.amd-1.6.1.zip new file mode 100644 index 00000000..013ca605 Binary files /dev/null and b/libs/i18next/release/i18next.amd-1.6.1.zip differ diff --git a/libs/i18next/release/i18next.amd-1.6.2.js b/libs/i18next/release/i18next.amd-1.6.2.js new file mode 100644 index 00000000..8d8e3524 --- /dev/null +++ b/libs/i18next/release/i18next.amd-1.6.2.js @@ -0,0 +1,2598 @@ +// i18next, v1.6.2 +// Copyright (c)2013 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function (root, factory) { + if (typeof exports === 'object') { + + module.exports = factory(); + + } else if (typeof define === 'function' && define.amd) { + + define([], factory); + + } +}(this, function () { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + var $ = undefined + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = []; + + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: 'dev', + fallbackNS: [], + detectLngQS: 'setLng', + ns: 'translation', + fallbackOnNull: true, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + + postProcess: undefined + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + return JSON.parse(data); + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + if (status === 200) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + document.cookie = name+"="+value+expires+"; path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : _ajax, + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + toLanguages: function(lng) { + var languages = []; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + + if (o.load !== 'unspecific') languages.push(lng); + if (o.load !== 'current') languages.push(parts[0]); + } else { + languages.push(lng); + } + + if (languages.indexOf(o.fallbackLng) === -1 && o.fallbackLng) languages.push(o.fallbackLng); + + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + if (o.lng) { + // set cookie with lng set (as detectLanguage will set cookie on need) + if (o.useCookie) f.cookie.create(o.cookieName, o.lng, o.cookieExpirationTime); + } else { + o.lng = o.fallbackLng; + if (o.useCookie) f.cookie.remove(o.cookieName); + } + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + if (cb) cb(translate); + if (deferred) deferred.resolve(); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + + if (cb) cb(translate); + if (deferred) deferred.resolve(); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + f.extend(resStore[lng][ns], resources); + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, cb) { + return init({lng: lng}, cb); + } + + function lng() { + return currentLng; + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } + else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + f.each(replacementHash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), value); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.escape(value)); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), value); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, translated_token); + } + return translated; + } + + function hasContext(options) { + return (options.context && typeof options.context == 'string'); + } + + function needsPlural(options) { + return (options.count !== undefined && typeof options.count != 'string' && options.count !== 1); + } + + function exists(key, options) { + options = options || {}; + + var notFound = options.defaultValue || key + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(key, options) { + + if (typeof options == 'string') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else { + options = options || {}; + } + + var notFound = options.defaultValue || key + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng) : languages + , ns = options.ns || o.ns.defaultNs; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing) { + if (options.lng) { + sync.postMissing(lngs[0], ns, key, notFound, lngs); + } else { + sync.postMissing(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found !== undefined && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessor && postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options){ + options = options || {}; + + var optionWithoutCount, translated + , notFound = options.defaultValue || key + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + if (options.lng) { + lngs = f.toLanguages(options.lng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.count; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(currentLng, options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + + translated = translate(pluralKey, optionWithoutCount); + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } // else continue translation with original/singular key + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (Object.prototype.toString.apply(value) === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned a object instead of string.'; + f.log(value); + } else { + var copy = {}; // apply child translation on a copy + for (var m in value) { + // apply translation on childs + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + } + value = copy; + } + } + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + } + + return found; + } + function detectLanguage() { + var detectedLng; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var parms = query.split('&'); + for (var i=0; i 0) { + var key = parms[i].substring(0,pos); + var val = parms[i].substring(pos+1); + qsParm[key] = val; + } + } + })(); + if (qsParm[o.detectLngQS]) { + detectedLng = qsParm[o.detectLngQS]; + } + } + + // get from cookie + if (!detectedLng && typeof document !== 'undefined' && o.useCookie ) { + var c = f.cookie.read(o.cookieName); + if (c) detectedLng = c; + } + + // get from navigator + if (!detectedLng && typeof navigator !== 'undefined') { + detectedLng = (navigator.language) ? navigator.language : navigator.userLanguage; + } + + return detectedLng; + } + var sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + window.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback') { + urls.push({lng: o.fallbackLng, url: applyReplacement(o.resPostPath, { lng: o.fallbackLng, ns: ns })}); + } else if (o.sendMissingTo === 'current') { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + } + }; + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + var pluralExtensions = { + + rules: { + "ach": { + "name": "Acholi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "af": { + "name": "Afrikaans", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ak": { + "name": "Akan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "am": { + "name": "Amharic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "an": { + "name": "Aragonese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ar": { + "name": "Arabic", + "numbers": [ + 0, + 1, + 2, + 3, + 11, + 100 + ], + "plurals": function(n) { return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5); } + }, + "arn": { + "name": "Mapudungun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ast": { + "name": "Asturian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ay": { + "name": "Aymar\u00e1", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "az": { + "name": "Azerbaijani", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "be": { + "name": "Belarusian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "bg": { + "name": "Bulgarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bn": { + "name": "Bengali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bo": { + "name": "Tibetan", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "br": { + "name": "Breton", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "bs": { + "name": "Bosnian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ca": { + "name": "Catalan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "cgg": { + "name": "Chiga", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "cs": { + "name": "Czech", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "csb": { + "name": "Kashubian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "cy": { + "name": "Welsh", + "numbers": [ + 1, + 2, + 3, + 8 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3); } + }, + "da": { + "name": "Danish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "de": { + "name": "German", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "dz": { + "name": "Dzongkha", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "el": { + "name": "Greek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "en": { + "name": "English", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eo": { + "name": "Esperanto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es": { + "name": "Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es_ar": { + "name": "Argentinean Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "et": { + "name": "Estonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eu": { + "name": "Basque", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fa": { + "name": "Persian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "fi": { + "name": "Finnish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fil": { + "name": "Filipino", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fo": { + "name": "Faroese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fr": { + "name": "French", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fur": { + "name": "Friulian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fy": { + "name": "Frisian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ga": { + "name": "Irish", + "numbers": [ + 1, + 2, + 3, + 7, + 11 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;} + }, + "gd": { + "name": "Scottish Gaelic", + "numbers": [ + 1, + 2, + 3, + 20 + ], + "plurals": function(n) { return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3); } + }, + "gl": { + "name": "Galician", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gu": { + "name": "Gujarati", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gun": { + "name": "Gun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ha": { + "name": "Hausa", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "he": { + "name": "Hebrew", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hi": { + "name": "Hindi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hr": { + "name": "Croatian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "hu": { + "name": "Hungarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hy": { + "name": "Armenian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ia": { + "name": "Interlingua", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "id": { + "name": "Indonesian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "is": { + "name": "Icelandic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n%10!=1 || n%100==11); } + }, + "it": { + "name": "Italian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ja": { + "name": "Japanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jbo": { + "name": "Lojban", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jv": { + "name": "Javanese", + "numbers": [ + 0, + 1 + ], + "plurals": function(n) { return Number(n !== 0); } + }, + "ka": { + "name": "Georgian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kk": { + "name": "Kazakh", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "km": { + "name": "Khmer", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kn": { + "name": "Kannada", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ko": { + "name": "Korean", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ku": { + "name": "Kurdish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "kw": { + "name": "Cornish", + "numbers": [ + 1, + 2, + 3, + 4 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3); } + }, + "ky": { + "name": "Kyrgyz", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lb": { + "name": "Letzeburgesch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ln": { + "name": "Lingala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "lo": { + "name": "Lao", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lt": { + "name": "Lithuanian", + "numbers": [ + 1, + 2, + 10 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "lv": { + "name": "Latvian", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2); } + }, + "mai": { + "name": "Maithili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mfe": { + "name": "Mauritian Creole", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mg": { + "name": "Malagasy", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mi": { + "name": "Maori", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mk": { + "name": "Macedonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 || n%10==1 ? 0 : 1); } + }, + "ml": { + "name": "Malayalam", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mn": { + "name": "Mongolian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mnk": { + "name": "Mandinka", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(0 ? 0 : n==1 ? 1 : 2); } + }, + "mr": { + "name": "Marathi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ms": { + "name": "Malay", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "mt": { + "name": "Maltese", + "numbers": [ + 1, + 2, + 11, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3); } + }, + "nah": { + "name": "Nahuatl", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nap": { + "name": "Neapolitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nb": { + "name": "Norwegian Bokmal", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ne": { + "name": "Nepali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nl": { + "name": "Dutch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nn": { + "name": "Norwegian Nynorsk", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "no": { + "name": "Norwegian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nso": { + "name": "Northern Sotho", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "oc": { + "name": "Occitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "or": { + "name": "Oriya", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pa": { + "name": "Punjabi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pap": { + "name": "Papiamento", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pl": { + "name": "Polish", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "pms": { + "name": "Piemontese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ps": { + "name": "Pashto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt": { + "name": "Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt_br": { + "name": "Brazilian Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "rm": { + "name": "Romansh", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ro": { + "name": "Romanian", + "numbers": [ + 1, + 2, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2); } + }, + "ru": { + "name": "Russian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "sah": { + "name": "Yakut", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sco": { + "name": "Scots", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "se": { + "name": "Northern Sami", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "si": { + "name": "Sinhala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sk": { + "name": "Slovak", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "sl": { + "name": "Slovenian", + "numbers": [ + 5, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }, + "so": { + "name": "Somali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "son": { + "name": "Songhay", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sq": { + "name": "Albanian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sr": { + "name": "Serbian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "su": { + "name": "Sundanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sv": { + "name": "Swedish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sw": { + "name": "Swahili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ta": { + "name": "Tamil", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "te": { + "name": "Telugu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tg": { + "name": "Tajik", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "th": { + "name": "Thai", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ti": { + "name": "Tigrinya", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tk": { + "name": "Turkmen", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tr": { + "name": "Turkish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tt": { + "name": "Tatar", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ug": { + "name": "Uyghur", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "uk": { + "name": "Ukrainian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ur": { + "name": "Urdu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "uz": { + "name": "Uzbek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "vi": { + "name": "Vietnamese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "wa": { + "name": "Walloon", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "wo": { + "name": "Wolof", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "yo": { + "name": "Yoruba", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "zh": { + "name": "Chinese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + } + }, + + // for demonstration only sl and ar is added but you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i = ext.plurals(c); + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[0], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + + return i18n; + +})); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd-1.6.2.min.js b/libs/i18next/release/i18next.amd-1.6.2.min.js new file mode 100644 index 00000000..69d1ed2a --- /dev/null +++ b/libs/i18next/release/i18next.amd-1.6.2.min.js @@ -0,0 +1,5 @@ +// i18next, v1.6.2 +// Copyright (c)2013 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function(n,e){"object"==typeof exports?module.exports=e():"function"==typeof define&&define.amd&&define([],e)})(this,function(){function n(n,e){if(!e||"function"==typeof e)return n;for(var r in e)n[r]=e[r];return n}function e(n,e,r){var t,u=0,a=n.length,s=void 0===a||"function"==typeof n;if(r)if(s){for(t in n)if(e.apply(n[t],r)===!1)break}else for(;a>u&&e.apply(n[u++],r)!==!1;);else if(s){for(t in n)if(e.call(n[t],t,n[t])===!1)break}else for(;a>u&&e.call(n[u],u,n[u++])!==!1;);return n}function r(n){return"string"==typeof n?n.replace(/[&<>"'\/]/g,function(n){return A[n]}):n}function t(n){var e=function(n){if(window.XMLHttpRequest)return n(null,new XMLHttpRequest);if(window.ActiveXObject)try{return n(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(e){return n(null,new ActiveXObject("Microsoft.XMLHTTP"))}return n(Error())},r=function(n){if("string"==typeof n)return n;var e=[];for(var r in n)n.hasOwnProperty(r)&&e.push(encodeURIComponent(r)+"="+encodeURIComponent(n[r]));return e.join("&")},t=function(n){n=n.replace(/\r\n/g,"\n");for(var e="",r=0;n.length>r;r++){var t=n.charCodeAt(r);128>t?e+=String.fromCharCode(t):t>127&&2048>t?(e+=String.fromCharCode(192|t>>6),e+=String.fromCharCode(128|63&t)):(e+=String.fromCharCode(224|t>>12),e+=String.fromCharCode(128|63&t>>6),e+=String.fromCharCode(128|63&t))}return e},u=function(n){var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";n=t(n);var r,u,a,s,o,i,l,c="",f=0;do r=n.charCodeAt(f++),u=n.charCodeAt(f++),a=n.charCodeAt(f++),s=r>>2,o=(3&r)<<4|u>>4,i=(15&u)<<2|a>>6,l=63&a,isNaN(u)?i=l=64:isNaN(a)&&(l=64),c+=e.charAt(s)+e.charAt(o)+e.charAt(i)+e.charAt(l),r=u=a="",s=o=i=l="";while(n.length>f);return c},a=function(){for(var n=arguments[0],e=1;arguments.length>e;e++){var r=arguments[e];for(var t in r)r.hasOwnProperty(t)&&(n[t]=r[t])}return n},s=function(n,t,u,o){"function"==typeof u&&(o=u,u={}),u.cache=u.cache||!1,u.data=u.data||{},u.headers=u.headers||{},u.jsonp=u.jsonp||!1,u.async=void 0===u.async?!0:u.async;var i,l=a({accept:"*/*","content-type":"application/x-www-form-urlencoded;charset=UTF-8"},s.headers,u.headers);if(i="application/json"===l["content-type"]?JSON.stringify(u.data):r(u.data),"GET"===n){var c=[];if(i&&(c.push(i),i=null),u.cache||c.push("_="+(new Date).getTime()),u.jsonp&&(c.push("callback="+u.jsonp),c.push("jsonp="+u.jsonp)),c=c.join("&"),c.length>1&&(t+=t.indexOf("?")>-1?"&"+c:"?"+c),u.jsonp){var f=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=t,f.appendChild(m),void 0}}e(function(e,r){if(e)return o(e);r.open(n,t,u.async);for(var a in l)l.hasOwnProperty(a)&&r.setRequestHeader(a,l[a]);r.onreadystatechange=function(){if(4===r.readyState){var n=r.responseText||"";if(!o)return;o(r.status,{text:function(){return n},json:function(){return JSON.parse(n)}})}},r.send(i)})},o={authBasic:function(n,e){s.headers.Authorization="Basic "+u(n+":"+e)},connect:function(n,e,r){return s("CONNECT",n,e,r)},del:function(n,e,r){return s("DELETE",n,e,r)},get:function(n,e,r){return s("GET",n,e,r)},head:function(n,e,r){return s("HEAD",n,e,r)},headers:function(n){s.headers=n||{}},isAllowed:function(n,e,r){this.options(n,function(n,t){r(-1!==t.text().indexOf(e))})},options:function(n,e,r){return s("OPTIONS",n,e,r)},patch:function(n,e,r){return s("PATCH",n,e,r)},post:function(n,e,r){return s("POST",n,e,r)},put:function(n,e,r){return s("PUT",n,e,r)},trace:function(n,e,r){return s("TRACE",n,e,r)}},i=n.type?n.type.toLowerCase():"get";o[i](n.url,n,function(e,r){200===e?n.success(r.json(),e,null):n.error(r.text(),e,null)})}function u(n,e){"function"==typeof n&&(e=n,n={}),n=n||{},M.extend(P,n),"string"==typeof P.ns&&(P.ns={namespaces:[P.ns],defaultNs:P.ns}),"string"==typeof P.fallbackNS&&(P.fallbackNS=[P.fallbackNS]),P.interpolationPrefixEscaped=M.regexEscape(P.interpolationPrefix),P.interpolationSuffixEscaped=M.regexEscape(P.interpolationSuffix),P.lng||(P.lng=M.detectLanguage()),P.lng?P.useCookie&&M.cookie.create(P.cookieName,P.lng,P.cookieExpirationTime):(P.lng=P.fallbackLng,P.useCookie&&M.cookie.remove(P.cookieName)),T=M.toLanguages(P.lng),S=T[0],M.log("currentLng set to: "+S),F.setCurrentLng(S),O&&P.setJqueryExt&&m();var r;if(O&&O.Deferred&&(r=O.Deferred()),!P.resStore){var t=M.toLanguages(P.lng);"string"==typeof P.preload&&(P.preload=[P.preload]);for(var u=0,a=P.preload.length;a>u;u++)for(var s=M.toLanguages(P.preload[u]),o=0,i=s.length;i>o;o++)0>t.indexOf(s[o])&&t.push(s[o]);return L.sync.load(t,P,function(n,t){w=t,e&&e(N),r&&r.resolve()}),r?r.promise():void 0}return w=P.resStore,e&&e(N),r&&r.resolve(),r?r.promise():void 0}function a(n,e){"string"==typeof n&&(n=[n]);for(var r=0,t=n.length;t>r;r++)0>P.preload.indexOf(n[r])&&P.preload.push(n[r]);return u(e)}function s(n,e,r){"string"!=typeof e?(r=e,e=P.ns.defaultNs):0>P.ns.namespaces.indexOf(e)&&P.ns.namespaces.push(e),w[n]=w[n]||{},w[n][e]=w[n][e]||{},M.extend(w[n][e],r)}function o(n){P.ns.defaultNs=n}function i(n,e){l([n],e)}function l(n,e){var r={dynamicLoad:P.dynamicLoad,resGetPath:P.resGetPath,getAsync:P.getAsync,customLoad:P.customLoad,ns:{namespaces:n,defaultNs:""}},t=M.toLanguages(P.lng);"string"==typeof P.preload&&(P.preload=[P.preload]);for(var u=0,a=P.preload.length;a>u;u++)for(var s=M.toLanguages(P.preload[u]),o=0,i=s.length;i>o;o++)0>t.indexOf(s[o])&&t.push(s[o]);for(var l=[],c=0,f=t.length;f>c;c++){var m=!1,p=w[t[c]];if(p)for(var b=0,g=n.length;g>b;b++)p[n[b]]||(m=!0);else m=!0;m&&l.push(t[c])}l.length?L.sync._fetch(l,r,function(r,t){var u=n.length*l.length;M.each(n,function(n,r){0>P.ns.namespaces.indexOf(r)&&P.ns.namespaces.push(r),M.each(l,function(n,a){w[a]=w[a]||{},w[a][r]=t[a][r],u--,0===u&&e&&(P.useLocalStorage&&L.sync._storeLocal(w),e())})})}):e&&e()}function c(n,e){return u({lng:n},e)}function f(){return S}function m(){function n(n,e,r){if(0!==e.length){var t="text";if(0===e.indexOf("[")){var u=e.split("]");e=u[1],t=u[0].substr(1,u[0].length-1)}e.indexOf(";")===e.length-1&&(e=e.substr(0,e.length-2));var a;"html"===t?(a=P.defaultValueFromContent?O.extend({defaultValue:n.html()},r):r,n.html(O.t(e,a))):"text"===t?(a=P.defaultValueFromContent?O.extend({defaultValue:n.text()},r):r,n.text(O.t(e,a))):(a=P.defaultValueFromContent?O.extend({defaultValue:n.attr(t)},r):r,n.attr(t,O.t(e,a)))}}function e(e,r){var t=e.attr(P.selectorAttr);if(t){var u=e,a=e.data("i18n-target");if(a&&(u=e.find(a)||e),r||P.useDataAttrOptions!==!0||(r=e.data("i18n-options")),r=r||{},t.indexOf(";")>=0){var s=t.split(";");O.each(s,function(e,t){""!==t&&n(u,t,r)})}else n(u,t,r);P.useDataAttrOptions===!0&&e.data("i18n-options",r)}}O.t=O.t||N,O.fn.i18n=function(n){return this.each(function(){e(O(this),n);var r=O(this).find("["+P.selectorAttr+"]");r.each(function(){e(O(this),n)})})}}function p(n,e,r,t){if(!n)return n;if(t=t||e,0>n.indexOf(t.interpolationPrefix||P.interpolationPrefix))return n;var u=t.interpolationPrefix?M.regexEscape(t.interpolationPrefix):P.interpolationPrefixEscaped,a=t.interpolationSuffix?M.regexEscape(t.interpolationSuffix):P.interpolationSuffixEscaped,s="HTML"+a;return M.each(e,function(e,o){var i=r?r+P.keyseparator+e:e;"object"==typeof o&&null!==o?n=p(n,o,i,t):t.escapeInterpolation||P.escapeInterpolation?(n=n.replace(RegExp([u,i,s].join(""),"g"),o),n=n.replace(RegExp([u,i,a].join(""),"g"),M.escape(o))):n=n.replace(RegExp([u,i,a].join(""),"g"),o)}),n}function b(n,e){var r=",",t="{",u="}",a=M.extend({},e);for(delete a.postProcess;-1!=n.indexOf(P.reusePrefix)&&(j++,!(j>P.maxRecursion));){var s=n.lastIndexOf(P.reusePrefix),o=n.indexOf(P.reuseSuffix,s)+P.reuseSuffix.length,i=n.substring(s,o),l=i.replace(P.reusePrefix,"").replace(P.reuseSuffix,"");if(-1!=l.indexOf(r)){var c=l.indexOf(r);if(-1!=l.indexOf(t,c)&&-1!=l.indexOf(u,c)){var f=l.indexOf(t,c),m=l.indexOf(u,f)+u.length;try{a=M.extend(a,JSON.parse(l.substring(f,m))),l=l.substring(0,c)}catch(p){}}}var b=x(l,a);n=n.replace(i,b)}return n}function g(n){return n.context&&"string"==typeof n.context}function d(n){return void 0!==n.count&&"string"!=typeof n.count&&1!==n.count}function h(n,e){e=e||{};var r=e.defaultValue||n,t=y(n,e);return void 0!==t||t===r}function N(){return j=0,x.apply(null,arguments)}function v(){for(var n=[],e=1;arguments.length>e;e++)n.push(arguments[e]);return{postProcess:"sprintf",sprintf:n}}function x(n,e){e="string"==typeof e?v.apply(null,arguments):e||{};var r=e.defaultValue||n,t=y(n,e),u=e.lng?M.toLanguages(e.lng):T,a=e.ns||P.ns.defaultNs;if(n.indexOf(P.nsseparator)>-1){var s=n.split(P.nsseparator);a=s[0],n=s[1]}void 0===t&&P.sendMissing&&(e.lng?E.postMissing(u[0],a,n,r,u):E.postMissing(P.lng,a,n,r,u));var o=e.postProcess||P.postProcess;return void 0!==t&&o&&R[o]&&(t=R[o](t,n,e)),void 0===t&&(r=p(r,e),r=b(r,e),o&&R[o]&&(t=R[o](t,n,e))),void 0!==t?t:r}function y(n,e){e=e||{};var r,t,u=e.defaultValue||n,a=T;if(!w)return u;if(e.lng&&(a=M.toLanguages(e.lng),!w[a[0]])){var s=P.getAsync;P.getAsync=!1,L.sync.load(a,P,function(n,e){M.extend(w,e),P.getAsync=s})}var o=e.ns||P.ns.defaultNs;if(n.indexOf(P.nsseparator)>-1){var i=n.split(P.nsseparator);o=i[0],n=i[1]}if(g(e)){r=M.extend({},e),delete r.context,r.defaultValue=P.contextNotFound;var l=o+P.nsseparator+n+"_"+e.context;if(t=N(l,r),t!=P.contextNotFound)return p(t,{context:e.context})}if(d(e)){r=M.extend({},e),delete r.count,r.defaultValue=P.pluralNotFound;var c=o+P.nsseparator+n+P.pluralSuffix,f=F.get(S,e.count);if(f>=0?c=c+"_"+f:1===f&&(c=o+P.nsseparator+n),t=N(c,r),t!=P.pluralNotFound)return p(t,{count:e.count,interpolationPrefix:e.interpolationPrefix,interpolationSuffix:e.interpolationSuffix})}for(var m,h=n.split(P.keyseparator),v=0,k=a.length;k>v&&void 0===m;v++){for(var O=a[v],j=0,A=w[O]&&w[O][o];h[j];)A=A&&A[h[j]],j++;if(void 0!==A){if("string"==typeof A)A=p(A,e),A=b(A,e);else if("[object Array]"!==Object.prototype.toString.apply(A)||P.returnObjectTrees||e.returnObjectTrees){if(null===A&&P.fallbackOnNull===!0)A=void 0;else if(null!==A)if(P.returnObjectTrees||e.returnObjectTrees){var C={};for(var _ in A)C[_]=x(o+P.nsseparator+n+P.keyseparator+_,e);A=C}else A="key '"+o+":"+n+" ("+O+")' "+"returned a object instead of string.",M.log(A)}else A=A.join("\n"),A=p(A,e),A=b(A,e);m=A}}if(void 0===m&&!e.isFallbackLookup&&(P.fallbackToDefaultNS===!0||P.fallbackNS&&P.fallbackNS.length))if(e.isFallbackLookup=!0,P.fallbackNS.length){for(var E=0,R=P.fallbackNS.length;R>E;E++)if(m=y(P.fallbackNS[E]+P.nsseparator+n,e)){var z=m.indexOf(P.nsseparator)>-1?m.split(P.nsseparator)[1]:m,D=u.indexOf(P.nsseparator)>-1?u.split(P.nsseparator)[1]:u;if(z!==D)break}}else m=y(n,e);return m}function k(){var n,e=[];if("undefined"!=typeof window&&(function(){for(var n=window.location.search.substring(1),r=n.split("&"),t=0;r.length>t;t++){var u=r[t].indexOf("=");if(u>0){var a=r[t].substring(0,u),s=r[t].substring(u+1);e[a]=s}}}(),e[P.detectLngQS]&&(n=e[P.detectLngQS])),!n&&"undefined"!=typeof document&&P.useCookie){var r=M.cookie.read(P.cookieName);r&&(n=r)}return n||"undefined"==typeof navigator||(n=navigator.language?navigator.language:navigator.userLanguage),n}Array.prototype.indexOf||(Array.prototype.indexOf=function(n){"use strict";if(null==this)throw new TypeError;var e=Object(this),r=e.length>>>0;if(0===r)return-1;var t=0;if(arguments.length>0&&(t=Number(arguments[1]),t!=t?t=0:0!=t&&1/0!=t&&t!=-1/0&&(t=(t>0||-1)*Math.floor(Math.abs(t)))),t>=r)return-1;for(var u=t>=0?t:Math.max(r-Math.abs(t),0);r>u;u++)if(u in e&&e[u]===n)return u;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(n){"use strict";if(null==this)throw new TypeError;var e=Object(this),r=e.length>>>0;if(0===r)return-1;var t=r;arguments.length>1&&(t=Number(arguments[1]),t!=t?t=0:0!=t&&t!=1/0&&t!=-(1/0)&&(t=(t>0||-1)*Math.floor(Math.abs(t))));for(var u=t>=0?Math.min(t,r-1):r-Math.abs(t);u>=0;u--)if(u in e&&e[u]===n)return u;return-1});var S,O=void 0,L={},w={},j=0,T=[],P={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:"dev",fallbackNS:[],detectLngQS:"setLng",ns:"translation",fallbackOnNull:!0,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",postProcess:void 0},A={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},C={create:function(n,e,r){var t;if(r){var u=new Date;u.setTime(u.getTime()+1e3*60*r),t="; expires="+u.toGMTString()}else t="";document.cookie=n+"="+e+t+"; path=/"},read:function(n){for(var e=n+"=",r=document.cookie.split(";"),t=0;r.length>t;t++){for(var u=r[t];" "==u.charAt(0);)u=u.substring(1,u.length);if(0===u.indexOf(e))return u.substring(e.length,u.length)}return null},remove:function(n){this.create(n,"",-1)}},_={create:function(){},read:function(){return null},remove:function(){}},M={extend:O?O.extend:n,each:O?O.each:e,ajax:O?O.ajax:t,cookie:"undefined"!=typeof document?C:_,detectLanguage:k,escape:r,log:function(n){P.debug&&"undefined"!=typeof console&&console.log(n)},toLanguages:function(n){var e=[];if("string"==typeof n&&n.indexOf("-")>-1){var r=n.split("-");n=P.lowerCaseLng?r[0].toLowerCase()+"-"+r[1].toLowerCase():r[0].toLowerCase()+"-"+r[1].toUpperCase(),"unspecific"!==P.load&&e.push(n),"current"!==P.load&&e.push(r[0])}else e.push(n);return-1===e.indexOf(P.fallbackLng)&&P.fallbackLng&&e.push(P.fallbackLng),e},regexEscape:function(n){return n.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}};M.applyReplacement=p;var E={load:function(n,e,r){e.useLocalStorage?E._loadLocal(n,e,function(t,u){for(var a=[],s=0,o=n.length;o>s;s++)u[n[s]]||a.push(n[s]);a.length>0?E._fetch(a,e,function(n,e){M.extend(u,e),E._storeLocal(e),r(null,u)}):r(null,u)}):E._fetch(n,e,function(n,e){r(null,e)})},_loadLocal:function(n,e,r){var t={},u=(new Date).getTime();if(window.localStorage){var a=n.length;M.each(n,function(n,s){var o=window.localStorage.getItem("res_"+s);o&&(o=JSON.parse(o),o.i18nStamp&&o.i18nStamp+e.localStorageExpirationTime>u&&(t[s]=o)),a--,0===a&&r(null,t)})}},_storeLocal:function(n){if(window.localStorage)for(var e in n)n[e].i18nStamp=(new Date).getTime(),window.localStorage.setItem("res_"+e,JSON.stringify(n[e]))},_fetch:function(n,e,r){var t=e.ns,u={};if(e.dynamicLoad){var a=function(n,e){r(null,e)};if("function"==typeof e.customLoad)e.customLoad(n,t.namespaces,e,a);else{var s=p(e.resGetPath,{lng:n.join("+"),ns:t.namespaces.join("+")});M.ajax({url:s,success:function(n){M.log("loaded: "+s),a(null,n)},error:function(n,e,r){M.log("failed loading: "+s),a("failed loading resource.json error: "+r)},dataType:"json",async:e.getAsync})}}else{var o,i=t.namespaces.length*n.length;M.each(t.namespaces,function(t,a){M.each(n,function(n,t){var s=function(n,e){n&&(o=o||[],o.push(n)),u[t]=u[t]||{},u[t][a]=e,i--,0===i&&r(o,u)};"function"==typeof e.customLoad?e.customLoad(t,a,e,s):E._fetchOne(t,a,e,s)})})}},_fetchOne:function(n,e,r,t){var u=p(r.resGetPath,{lng:n,ns:e});M.ajax({url:u,success:function(n){M.log("loaded: "+u),t(null,n)},error:function(n,e,r){M.log("failed loading: "+u),t(r,{})},dataType:"json",async:r.getAsync})},postMissing:function(n,e,r,t,u){var a={};a[r]=t;var s=[];if("fallback"===P.sendMissingTo)s.push({lng:P.fallbackLng,url:p(P.resPostPath,{lng:P.fallbackLng,ns:e})});else if("current"===P.sendMissingTo)s.push({lng:n,url:p(P.resPostPath,{lng:n,ns:e})});else if("all"===P.sendMissingTo)for(var o=0,i=u.length;i>o;o++)s.push({lng:u[o],url:p(P.resPostPath,{lng:u[o],ns:e})});for(var l=0,c=s.length;c>l;l++){var f=s[l];M.ajax({url:f.url,type:P.sendType,data:a,success:function(){M.log("posted missing key '"+r+"' to: "+f.url);for(var n=r.split("."),u=0,a=w[f.lng][e];n[u];)a=a[n[u]]=u===n.length-1?t:a[n[u]]||{},u++},error:function(){M.log("failed posting missing key '"+r+"' to: "+f.url)},dataType:"json",async:P.postAsync})}}},F={rules:{ach:{name:"Acholi",numbers:[1,2],plurals:function(n){return Number(n>1)}},af:{name:"Afrikaans",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ak:{name:"Akan",numbers:[1,2],plurals:function(n){return Number(n>1)}},am:{name:"Amharic",numbers:[1,2],plurals:function(n){return Number(n>1)}},an:{name:"Aragonese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ar:{name:"Arabic",numbers:[0,1,2,3,11,100],plurals:function(n){return Number(0===n?0:1==n?1:2==n?2:n%100>=3&&10>=n%100?3:n%100>=11?4:5)}},arn:{name:"Mapudungun",numbers:[1,2],plurals:function(n){return Number(n>1)}},ast:{name:"Asturian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ay:{name:"Aymará",numbers:[1],plurals:function(){return 0}},az:{name:"Azerbaijani",numbers:[1,2],plurals:function(n){return Number(1!=n)}},be:{name:"Belarusian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},bg:{name:"Bulgarian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},bn:{name:"Bengali",numbers:[1,2],plurals:function(n){return Number(1!=n)}},bo:{name:"Tibetan",numbers:[1],plurals:function(){return 0}},br:{name:"Breton",numbers:[1,2],plurals:function(n){return Number(n>1)}},bs:{name:"Bosnian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},ca:{name:"Catalan",numbers:[1,2],plurals:function(n){return Number(1!=n)}},cgg:{name:"Chiga",numbers:[1],plurals:function(){return 0}},cs:{name:"Czech",numbers:[1,2,5],plurals:function(n){return Number(1==n?0:n>=2&&4>=n?1:2)}},csb:{name:"Kashubian",numbers:[1,2,5],plurals:function(n){return Number(1==n?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},cy:{name:"Welsh",numbers:[1,2,3,8],plurals:function(n){return Number(1==n?0:2==n?1:8!=n&&11!=n?2:3)}},da:{name:"Danish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},de:{name:"German",numbers:[1,2],plurals:function(n){return Number(1!=n)}},dz:{name:"Dzongkha",numbers:[1],plurals:function(){return 0}},el:{name:"Greek",numbers:[1,2],plurals:function(n){return Number(1!=n)}},en:{name:"English",numbers:[1,2],plurals:function(n){return Number(1!=n)}},eo:{name:"Esperanto",numbers:[1,2],plurals:function(n){return Number(1!=n)}},es:{name:"Spanish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},es_ar:{name:"Argentinean Spanish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},et:{name:"Estonian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},eu:{name:"Basque",numbers:[1,2],plurals:function(n){return Number(1!=n)}},fa:{name:"Persian",numbers:[1],plurals:function(){return 0}},fi:{name:"Finnish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},fil:{name:"Filipino",numbers:[1,2],plurals:function(n){return Number(n>1)}},fo:{name:"Faroese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},fr:{name:"French",numbers:[1,2],plurals:function(n){return Number(n>1)}},fur:{name:"Friulian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},fy:{name:"Frisian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ga:{name:"Irish",numbers:[1,2,3,7,11],plurals:function(n){return Number(1==n?0:2==n?1:7>n?2:11>n?3:4)}},gd:{name:"Scottish Gaelic",numbers:[1,2,3,20],plurals:function(n){return Number(1==n||11==n?0:2==n||12==n?1:n>2&&20>n?2:3)}},gl:{name:"Galician",numbers:[1,2],plurals:function(n){return Number(1!=n)}},gu:{name:"Gujarati",numbers:[1,2],plurals:function(n){return Number(1!=n)}},gun:{name:"Gun",numbers:[1,2],plurals:function(n){return Number(n>1)}},ha:{name:"Hausa",numbers:[1,2],plurals:function(n){return Number(1!=n)}},he:{name:"Hebrew",numbers:[1,2],plurals:function(n){return Number(1!=n)}},hi:{name:"Hindi",numbers:[1,2],plurals:function(n){return Number(1!=n)}},hr:{name:"Croatian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},hu:{name:"Hungarian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},hy:{name:"Armenian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ia:{name:"Interlingua",numbers:[1,2],plurals:function(n){return Number(1!=n)}},id:{name:"Indonesian",numbers:[1],plurals:function(){return 0}},is:{name:"Icelandic",numbers:[1,2],plurals:function(n){return Number(1!=n%10||11==n%100)}},it:{name:"Italian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ja:{name:"Japanese",numbers:[1],plurals:function(){return 0}},jbo:{name:"Lojban",numbers:[1],plurals:function(){return 0}},jv:{name:"Javanese",numbers:[0,1],plurals:function(n){return Number(0!==n)}},ka:{name:"Georgian",numbers:[1],plurals:function(){return 0}},kk:{name:"Kazakh",numbers:[1],plurals:function(){return 0}},km:{name:"Khmer",numbers:[1],plurals:function(){return 0}},kn:{name:"Kannada",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ko:{name:"Korean",numbers:[1],plurals:function(){return 0}},ku:{name:"Kurdish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},kw:{name:"Cornish",numbers:[1,2,3,4],plurals:function(n){return Number(1==n?0:2==n?1:3==n?2:3)}},ky:{name:"Kyrgyz",numbers:[1],plurals:function(){return 0}},lb:{name:"Letzeburgesch",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ln:{name:"Lingala",numbers:[1,2],plurals:function(n){return Number(n>1)}},lo:{name:"Lao",numbers:[1],plurals:function(){return 0}},lt:{name:"Lithuanian",numbers:[1,2,10],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&(10>n%100||n%100>=20)?1:2)}},lv:{name:"Latvian",numbers:[0,1,2],plurals:function(n){return Number(1==n%10&&11!=n%100?0:0!==n?1:2)}},mai:{name:"Maithili",numbers:[1,2],plurals:function(n){return Number(1!=n)}},mfe:{name:"Mauritian Creole",numbers:[1,2],plurals:function(n){return Number(n>1)}},mg:{name:"Malagasy",numbers:[1,2],plurals:function(n){return Number(n>1)}},mi:{name:"Maori",numbers:[1,2],plurals:function(n){return Number(n>1)}},mk:{name:"Macedonian",numbers:[1,2],plurals:function(n){return Number(1==n||1==n%10?0:1)}},ml:{name:"Malayalam",numbers:[1,2],plurals:function(n){return Number(1!=n)}},mn:{name:"Mongolian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},mnk:{name:"Mandinka",numbers:[0,1,2],plurals:function(n){return Number(1==n?1:2)}},mr:{name:"Marathi",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ms:{name:"Malay",numbers:[1],plurals:function(){return 0}},mt:{name:"Maltese",numbers:[1,2,11,20],plurals:function(n){return Number(1==n?0:0===n||n%100>1&&11>n%100?1:n%100>10&&20>n%100?2:3)}},nah:{name:"Nahuatl",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nap:{name:"Neapolitan",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nb:{name:"Norwegian Bokmal",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ne:{name:"Nepali",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nl:{name:"Dutch",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nn:{name:"Norwegian Nynorsk",numbers:[1,2],plurals:function(n){return Number(1!=n)}},no:{name:"Norwegian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nso:{name:"Northern Sotho",numbers:[1,2],plurals:function(n){return Number(1!=n)}},oc:{name:"Occitan",numbers:[1,2],plurals:function(n){return Number(n>1)}},or:{name:"Oriya",numbers:[2,1],plurals:function(n){return Number(1!=n)}},pa:{name:"Punjabi",numbers:[1,2],plurals:function(n){return Number(1!=n)}},pap:{name:"Papiamento",numbers:[1,2],plurals:function(n){return Number(1!=n)}},pl:{name:"Polish",numbers:[1,2,5],plurals:function(n){return Number(1==n?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},pms:{name:"Piemontese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ps:{name:"Pashto",numbers:[1,2],plurals:function(n){return Number(1!=n)}},pt:{name:"Portuguese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},pt_br:{name:"Brazilian Portuguese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},rm:{name:"Romansh",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ro:{name:"Romanian",numbers:[1,2,20],plurals:function(n){return Number(1==n?0:0===n||n%100>0&&20>n%100?1:2)}},ru:{name:"Russian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},sah:{name:"Yakut",numbers:[1],plurals:function(){return 0}},sco:{name:"Scots",numbers:[1,2],plurals:function(n){return Number(1!=n)}},se:{name:"Northern Sami",numbers:[1,2],plurals:function(n){return Number(1!=n)}},si:{name:"Sinhala",numbers:[1,2],plurals:function(n){return Number(1!=n)}},sk:{name:"Slovak",numbers:[1,2,5],plurals:function(n){return Number(1==n?0:n>=2&&4>=n?1:2)}},sl:{name:"Slovenian",numbers:[5,1,2,3],plurals:function(n){return Number(1==n%100?1:2==n%100?2:3==n%100||4==n%100?3:0)}},so:{name:"Somali",numbers:[1,2],plurals:function(n){return Number(1!=n)}},son:{name:"Songhay",numbers:[1,2],plurals:function(n){return Number(1!=n)}},sq:{name:"Albanian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},sr:{name:"Serbian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},su:{name:"Sundanese",numbers:[1],plurals:function(){return 0}},sv:{name:"Swedish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},sw:{name:"Swahili",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ta:{name:"Tamil",numbers:[1,2],plurals:function(n){return Number(1!=n)}},te:{name:"Telugu",numbers:[1,2],plurals:function(n){return Number(1!=n)}},tg:{name:"Tajik",numbers:[1,2],plurals:function(n){return Number(n>1)}},th:{name:"Thai",numbers:[1],plurals:function(){return 0}},ti:{name:"Tigrinya",numbers:[1,2],plurals:function(n){return Number(n>1)}},tk:{name:"Turkmen",numbers:[1,2],plurals:function(n){return Number(1!=n)}},tr:{name:"Turkish",numbers:[1,2],plurals:function(n){return Number(n>1)}},tt:{name:"Tatar",numbers:[1],plurals:function(){return 0}},ug:{name:"Uyghur",numbers:[1],plurals:function(){return 0}},uk:{name:"Ukrainian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},ur:{name:"Urdu",numbers:[1,2],plurals:function(n){return Number(1!=n)}},uz:{name:"Uzbek",numbers:[1,2],plurals:function(n){return Number(n>1)}},vi:{name:"Vietnamese",numbers:[1],plurals:function(){return 0}},wa:{name:"Walloon",numbers:[1,2],plurals:function(n){return Number(n>1)}},wo:{name:"Wolof",numbers:[1],plurals:function(){return 0}},yo:{name:"Yoruba",numbers:[1,2],plurals:function(n){return Number(1!=n)}},zh:{name:"Chinese",numbers:[1],plurals:function(){return 0}}},addRule:function(n,e){F.rules[n]=e},setCurrentLng:function(n){if(!F.currentRule||F.currentRule.lng!==n){var e=n.split("-");F.currentRule={lng:n,rule:F.rules[e[0]]}}},get:function(n,e){function r(e,r){var t;if(t=F.currentRule&&F.currentRule.lng===n?F.currentRule.rule:F.rules[e]){var u=t.plurals(r),a=t.numbers[u];return 2===t.numbers.length&&1===t.numbers[0]&&(2===a?a=-1:1===a&&(a=1)),a}return 1===r?"1":"-1"}var t=n.split("-");return r(t[0],e)}},R={},z=function(n,e){R[n]=e},D=function(){function n(n){return Object.prototype.toString.call(n).slice(8,-1).toLowerCase()}function e(n,e){for(var r=[];e>0;r[--e]=n);return r.join("")}var r=function(){return r.cache.hasOwnProperty(arguments[0])||(r.cache[arguments[0]]=r.parse(arguments[0])),r.format.call(null,r.cache[arguments[0]],arguments)};return r.format=function(r,t){var u,a,s,o,i,l,c,f=1,m=r.length,p="",b=[];for(a=0;m>a;a++)if(p=n(r[a]),"string"===p)b.push(r[a]);else if("array"===p){if(o=r[a],o[2])for(u=t[f],s=0;o[2].length>s;s++){if(!u.hasOwnProperty(o[2][s]))throw D('[sprintf] property "%s" does not exist',o[2][s]);u=u[o[2][s]]}else u=o[1]?t[o[1]]:t[f++];if(/[^s]/.test(o[8])&&"number"!=n(u))throw D("[sprintf] expecting number but found %s",n(u));switch(o[8]){case"b":u=u.toString(2);break;case"c":u=String.fromCharCode(u);break;case"d":u=parseInt(u,10);break;case"e":u=o[7]?u.toExponential(o[7]):u.toExponential();break;case"f":u=o[7]?parseFloat(u).toFixed(o[7]):parseFloat(u);break;case"o":u=u.toString(8);break;case"s":u=(u+="")&&o[7]?u.substring(0,o[7]):u;break;case"u":u=Math.abs(u);break;case"x":u=u.toString(16);break;case"X":u=u.toString(16).toUpperCase()}u=/[def]/.test(o[8])&&o[3]&&u>=0?"+"+u:u,l=o[4]?"0"==o[4]?"0":o[4].charAt(1):" ",c=o[6]-(u+"").length,i=o[6]?e(l,c):"",b.push(o[5]?u+i:i+u)}return b.join("")},r.cache={},r.parse=function(n){for(var e=n,r=[],t=[],u=0;e;){if(null!==(r=/^[^\x25]+/.exec(e)))t.push(r[0]);else if(null!==(r=/^\x25{2}/.exec(e)))t.push("%");else{if(null===(r=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(e)))throw"[sprintf] huh?";if(r[2]){u|=1;var a=[],s=r[2],o=[];if(null===(o=/^([a-z_][a-z_\d]*)/i.exec(s)))throw"[sprintf] huh?";for(a.push(o[1]);""!==(s=s.substring(o[0].length));)if(null!==(o=/^\.([a-z_][a-z_\d]*)/i.exec(s)))a.push(o[1]);else{if(null===(o=/^\[(\d+)\]/.exec(s)))throw"[sprintf] huh?";a.push(o[1])}r[2]=a}else u|=2;if(3===u)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";t.push(r)}e=e.substring(r[0].length)}return t},r}(),I=function(n,e){return e.unshift(n),D.apply(null,e)};return z("sprintf",function(n,e,r){return r.sprintf?"[object Array]"===Object.prototype.toString.apply(r.sprintf)?I(n,r.sprintf):"object"==typeof r.sprintf?D(n,r.sprintf):n:n}),L.init=u,L.setLng=c,L.preload=a,L.addResourceBundle=s,L.loadNamespace=i,L.loadNamespaces=l,L.setDefaultNamespace=o,L.t=N,L.translate=N,L.exists=h,L.detectLanguage=M.detectLanguage,L.pluralExtensions=F,L.sync=E,L.functions=M,L.lng=f,L.addPostProcessor=z,L.options=P,L}); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd-1.6.2.zip b/libs/i18next/release/i18next.amd-1.6.2.zip new file mode 100644 index 00000000..284306fd Binary files /dev/null and b/libs/i18next/release/i18next.amd-1.6.2.zip differ diff --git a/libs/i18next/release/i18next.amd-1.6.3.js b/libs/i18next/release/i18next.amd-1.6.3.js new file mode 100644 index 00000000..7a28e787 --- /dev/null +++ b/libs/i18next/release/i18next.amd-1.6.3.js @@ -0,0 +1,2611 @@ +// i18next, v1.6.3 +// Copyright (c)2013 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function (root, factory) { + if (typeof exports === 'object') { + + module.exports = factory(); + + } else if (typeof define === 'function' && define.amd) { + + define([], factory); + + } +}(this, function () { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + var $ = undefined + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = []; + + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: 'dev', + fallbackNS: [], + detectLngQS: 'setLng', + ns: 'translation', + fallbackOnNull: true, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + + postProcess: undefined, + parseMissingKey: undefined + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + return JSON.parse(data); + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + if (status === 200) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + document.cookie = name+"="+value+expires+"; path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : _ajax, + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + toLanguages: function(lng) { + var languages = []; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + + if (o.load !== 'unspecific') languages.push(lng); + if (o.load !== 'current') languages.push(parts[0]); + } else { + languages.push(lng); + } + + if (languages.indexOf(o.fallbackLng) === -1 && o.fallbackLng) languages.push(o.fallbackLng); + + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + if (o.lng) { + // set cookie with lng set (as detectLanguage will set cookie on need) + if (o.useCookie) f.cookie.create(o.cookieName, o.lng, o.cookieExpirationTime); + } else { + o.lng = o.fallbackLng; + if (o.useCookie) f.cookie.remove(o.cookieName); + } + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + if (cb) cb(translate); + if (deferred) deferred.resolve(); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + + if (cb) cb(translate); + if (deferred) deferred.resolve(); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + f.extend(resStore[lng][ns], resources); + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, cb) { + return init({lng: lng}, cb); + } + + function lng() { + return currentLng; + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } + else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + f.each(replacementHash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), value); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.escape(value)); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), value); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, translated_token); + } + return translated; + } + + function hasContext(options) { + return (options.context && typeof options.context == 'string'); + } + + function needsPlural(options) { + return (options.count !== undefined && typeof options.count != 'string' && options.count !== 1); + } + + function exists(key, options) { + options = options || {}; + + var notFound = options.defaultValue || key + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(key, options) { + + if (typeof options == 'string') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else { + options = options || {}; + } + + var notFound = options.defaultValue || key + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng) : languages + , ns = options.ns || o.ns.defaultNs + , parts; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing) { + if (options.lng) { + sync.postMissing(lngs[0], ns, key, notFound, lngs); + } else { + sync.postMissing(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found !== undefined && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + // process notFound if function exists + var splitNotFound = notFound; + if (notFound.indexOf(o.nsseparator) > -1) { + parts = notFound.split(o.nsseparator); + splitNotFound = parts[1]; + } + if (splitNotFound === key && o.parseMissingKey) { + notFound = o.parseMissingKey(notFound); + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessor && postProcessors[postProcessor]) { + var val = options.defaultValue || key; + found = postProcessors[postProcessor](val, key, options); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options){ + options = options || {}; + + var optionWithoutCount, translated + , notFound = options.defaultValue || key + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + if (options.lng) { + lngs = f.toLanguages(options.lng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.count; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(lngs[0], options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + + translated = translate(pluralKey, optionWithoutCount); + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } // else continue translation with original/singular key + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (Object.prototype.toString.apply(value) === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned a object instead of string.'; + f.log(value); + } else { + var copy = {}; // apply child translation on a copy + for (var m in value) { + // apply translation on childs + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + } + value = copy; + } + } + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length > 0))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + } + + return found; + } + function detectLanguage() { + var detectedLng; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var parms = query.split('&'); + for (var i=0; i 0) { + var key = parms[i].substring(0,pos); + var val = parms[i].substring(pos+1); + qsParm[key] = val; + } + } + })(); + if (qsParm[o.detectLngQS]) { + detectedLng = qsParm[o.detectLngQS]; + } + } + + // get from cookie + if (!detectedLng && typeof document !== 'undefined' && o.useCookie ) { + var c = f.cookie.read(o.cookieName); + if (c) detectedLng = c; + } + + // get from navigator + if (!detectedLng && typeof navigator !== 'undefined') { + detectedLng = (navigator.language) ? navigator.language : navigator.userLanguage; + } + + return detectedLng; + } + var sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + window.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback' && o.fallbackLng !== false) { + urls.push({lng: o.fallbackLng, url: applyReplacement(o.resPostPath, { lng: o.fallbackLng, ns: ns })}); + } else if (o.sendMissingTo === 'current' || (o.sendMissingTo === 'fallback' && o.fallbackLng === false) ) { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + } + }; + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + var pluralExtensions = { + + rules: { + "ach": { + "name": "Acholi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "af": { + "name": "Afrikaans", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ak": { + "name": "Akan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "am": { + "name": "Amharic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "an": { + "name": "Aragonese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ar": { + "name": "Arabic", + "numbers": [ + 0, + 1, + 2, + 3, + 11, + 100 + ], + "plurals": function(n) { return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5); } + }, + "arn": { + "name": "Mapudungun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ast": { + "name": "Asturian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ay": { + "name": "Aymar\u00e1", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "az": { + "name": "Azerbaijani", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "be": { + "name": "Belarusian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "bg": { + "name": "Bulgarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bn": { + "name": "Bengali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bo": { + "name": "Tibetan", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "br": { + "name": "Breton", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "bs": { + "name": "Bosnian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ca": { + "name": "Catalan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "cgg": { + "name": "Chiga", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "cs": { + "name": "Czech", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "csb": { + "name": "Kashubian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "cy": { + "name": "Welsh", + "numbers": [ + 1, + 2, + 3, + 8 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3); } + }, + "da": { + "name": "Danish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "de": { + "name": "German", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "dz": { + "name": "Dzongkha", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "el": { + "name": "Greek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "en": { + "name": "English", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eo": { + "name": "Esperanto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es": { + "name": "Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es_ar": { + "name": "Argentinean Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "et": { + "name": "Estonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eu": { + "name": "Basque", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fa": { + "name": "Persian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "fi": { + "name": "Finnish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fil": { + "name": "Filipino", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fo": { + "name": "Faroese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fr": { + "name": "French", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fur": { + "name": "Friulian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fy": { + "name": "Frisian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ga": { + "name": "Irish", + "numbers": [ + 1, + 2, + 3, + 7, + 11 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;} + }, + "gd": { + "name": "Scottish Gaelic", + "numbers": [ + 1, + 2, + 3, + 20 + ], + "plurals": function(n) { return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3); } + }, + "gl": { + "name": "Galician", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gu": { + "name": "Gujarati", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gun": { + "name": "Gun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ha": { + "name": "Hausa", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "he": { + "name": "Hebrew", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hi": { + "name": "Hindi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hr": { + "name": "Croatian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "hu": { + "name": "Hungarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hy": { + "name": "Armenian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ia": { + "name": "Interlingua", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "id": { + "name": "Indonesian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "is": { + "name": "Icelandic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n%10!=1 || n%100==11); } + }, + "it": { + "name": "Italian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ja": { + "name": "Japanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jbo": { + "name": "Lojban", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jv": { + "name": "Javanese", + "numbers": [ + 0, + 1 + ], + "plurals": function(n) { return Number(n !== 0); } + }, + "ka": { + "name": "Georgian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kk": { + "name": "Kazakh", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "km": { + "name": "Khmer", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kn": { + "name": "Kannada", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ko": { + "name": "Korean", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ku": { + "name": "Kurdish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "kw": { + "name": "Cornish", + "numbers": [ + 1, + 2, + 3, + 4 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3); } + }, + "ky": { + "name": "Kyrgyz", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lb": { + "name": "Letzeburgesch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ln": { + "name": "Lingala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "lo": { + "name": "Lao", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lt": { + "name": "Lithuanian", + "numbers": [ + 1, + 2, + 10 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "lv": { + "name": "Latvian", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2); } + }, + "mai": { + "name": "Maithili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mfe": { + "name": "Mauritian Creole", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mg": { + "name": "Malagasy", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mi": { + "name": "Maori", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mk": { + "name": "Macedonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 || n%10==1 ? 0 : 1); } + }, + "ml": { + "name": "Malayalam", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mn": { + "name": "Mongolian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mnk": { + "name": "Mandinka", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(0 ? 0 : n==1 ? 1 : 2); } + }, + "mr": { + "name": "Marathi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ms": { + "name": "Malay", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "mt": { + "name": "Maltese", + "numbers": [ + 1, + 2, + 11, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3); } + }, + "nah": { + "name": "Nahuatl", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nap": { + "name": "Neapolitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nb": { + "name": "Norwegian Bokmal", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ne": { + "name": "Nepali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nl": { + "name": "Dutch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nn": { + "name": "Norwegian Nynorsk", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "no": { + "name": "Norwegian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nso": { + "name": "Northern Sotho", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "oc": { + "name": "Occitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "or": { + "name": "Oriya", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pa": { + "name": "Punjabi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pap": { + "name": "Papiamento", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pl": { + "name": "Polish", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "pms": { + "name": "Piemontese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ps": { + "name": "Pashto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt": { + "name": "Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt_br": { + "name": "Brazilian Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "rm": { + "name": "Romansh", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ro": { + "name": "Romanian", + "numbers": [ + 1, + 2, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2); } + }, + "ru": { + "name": "Russian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "sah": { + "name": "Yakut", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sco": { + "name": "Scots", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "se": { + "name": "Northern Sami", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "si": { + "name": "Sinhala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sk": { + "name": "Slovak", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "sl": { + "name": "Slovenian", + "numbers": [ + 5, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }, + "so": { + "name": "Somali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "son": { + "name": "Songhay", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sq": { + "name": "Albanian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sr": { + "name": "Serbian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "su": { + "name": "Sundanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sv": { + "name": "Swedish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sw": { + "name": "Swahili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ta": { + "name": "Tamil", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "te": { + "name": "Telugu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tg": { + "name": "Tajik", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "th": { + "name": "Thai", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ti": { + "name": "Tigrinya", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tk": { + "name": "Turkmen", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tr": { + "name": "Turkish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tt": { + "name": "Tatar", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ug": { + "name": "Uyghur", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "uk": { + "name": "Ukrainian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ur": { + "name": "Urdu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "uz": { + "name": "Uzbek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "vi": { + "name": "Vietnamese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "wa": { + "name": "Walloon", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "wo": { + "name": "Wolof", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "yo": { + "name": "Yoruba", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "zh": { + "name": "Chinese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + } + }, + + // for demonstration only sl and ar is added but you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i = ext.plurals(c); + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[0], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + + return i18n; + +})); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd-1.6.3.min.js b/libs/i18next/release/i18next.amd-1.6.3.min.js new file mode 100644 index 00000000..5b9a84e5 --- /dev/null +++ b/libs/i18next/release/i18next.amd-1.6.3.min.js @@ -0,0 +1,5 @@ +// i18next, v1.6.3 +// Copyright (c)2013 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function(n,e){"object"==typeof exports?module.exports=e():"function"==typeof define&&define.amd&&define([],e)})(this,function(){function n(n,e){if(!e||"function"==typeof e)return n;for(var r in e)n[r]=e[r];return n}function e(n,e,r){var t,u=0,a=n.length,s=void 0===a||"function"==typeof n;if(r)if(s){for(t in n)if(e.apply(n[t],r)===!1)break}else for(;a>u&&e.apply(n[u++],r)!==!1;);else if(s){for(t in n)if(e.call(n[t],t,n[t])===!1)break}else for(;a>u&&e.call(n[u],u,n[u++])!==!1;);return n}function r(n){return"string"==typeof n?n.replace(/[&<>"'\/]/g,function(n){return A[n]}):n}function t(n){var e=function(n){if(window.XMLHttpRequest)return n(null,new XMLHttpRequest);if(window.ActiveXObject)try{return n(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(e){return n(null,new ActiveXObject("Microsoft.XMLHTTP"))}return n(Error())},r=function(n){if("string"==typeof n)return n;var e=[];for(var r in n)n.hasOwnProperty(r)&&e.push(encodeURIComponent(r)+"="+encodeURIComponent(n[r]));return e.join("&")},t=function(n){n=n.replace(/\r\n/g,"\n");for(var e="",r=0;n.length>r;r++){var t=n.charCodeAt(r);128>t?e+=String.fromCharCode(t):t>127&&2048>t?(e+=String.fromCharCode(192|t>>6),e+=String.fromCharCode(128|63&t)):(e+=String.fromCharCode(224|t>>12),e+=String.fromCharCode(128|63&t>>6),e+=String.fromCharCode(128|63&t))}return e},u=function(n){var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";n=t(n);var r,u,a,s,o,i,l,c="",f=0;do r=n.charCodeAt(f++),u=n.charCodeAt(f++),a=n.charCodeAt(f++),s=r>>2,o=(3&r)<<4|u>>4,i=(15&u)<<2|a>>6,l=63&a,isNaN(u)?i=l=64:isNaN(a)&&(l=64),c+=e.charAt(s)+e.charAt(o)+e.charAt(i)+e.charAt(l),r=u=a="",s=o=i=l="";while(n.length>f);return c},a=function(){for(var n=arguments[0],e=1;arguments.length>e;e++){var r=arguments[e];for(var t in r)r.hasOwnProperty(t)&&(n[t]=r[t])}return n},s=function(n,t,u,o){"function"==typeof u&&(o=u,u={}),u.cache=u.cache||!1,u.data=u.data||{},u.headers=u.headers||{},u.jsonp=u.jsonp||!1,u.async=void 0===u.async?!0:u.async;var i,l=a({accept:"*/*","content-type":"application/x-www-form-urlencoded;charset=UTF-8"},s.headers,u.headers);if(i="application/json"===l["content-type"]?JSON.stringify(u.data):r(u.data),"GET"===n){var c=[];if(i&&(c.push(i),i=null),u.cache||c.push("_="+(new Date).getTime()),u.jsonp&&(c.push("callback="+u.jsonp),c.push("jsonp="+u.jsonp)),c=c.join("&"),c.length>1&&(t+=t.indexOf("?")>-1?"&"+c:"?"+c),u.jsonp){var f=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=t,f.appendChild(m),void 0}}e(function(e,r){if(e)return o(e);r.open(n,t,u.async);for(var a in l)l.hasOwnProperty(a)&&r.setRequestHeader(a,l[a]);r.onreadystatechange=function(){if(4===r.readyState){var n=r.responseText||"";if(!o)return;o(r.status,{text:function(){return n},json:function(){return JSON.parse(n)}})}},r.send(i)})},o={authBasic:function(n,e){s.headers.Authorization="Basic "+u(n+":"+e)},connect:function(n,e,r){return s("CONNECT",n,e,r)},del:function(n,e,r){return s("DELETE",n,e,r)},get:function(n,e,r){return s("GET",n,e,r)},head:function(n,e,r){return s("HEAD",n,e,r)},headers:function(n){s.headers=n||{}},isAllowed:function(n,e,r){this.options(n,function(n,t){r(-1!==t.text().indexOf(e))})},options:function(n,e,r){return s("OPTIONS",n,e,r)},patch:function(n,e,r){return s("PATCH",n,e,r)},post:function(n,e,r){return s("POST",n,e,r)},put:function(n,e,r){return s("PUT",n,e,r)},trace:function(n,e,r){return s("TRACE",n,e,r)}},i=n.type?n.type.toLowerCase():"get";o[i](n.url,n,function(e,r){200===e?n.success(r.json(),e,null):n.error(r.text(),e,null)})}function u(n,e){"function"==typeof n&&(e=n,n={}),n=n||{},M.extend(P,n),"string"==typeof P.ns&&(P.ns={namespaces:[P.ns],defaultNs:P.ns}),"string"==typeof P.fallbackNS&&(P.fallbackNS=[P.fallbackNS]),P.interpolationPrefixEscaped=M.regexEscape(P.interpolationPrefix),P.interpolationSuffixEscaped=M.regexEscape(P.interpolationSuffix),P.lng||(P.lng=M.detectLanguage()),P.lng?P.useCookie&&M.cookie.create(P.cookieName,P.lng,P.cookieExpirationTime):(P.lng=P.fallbackLng,P.useCookie&&M.cookie.remove(P.cookieName)),T=M.toLanguages(P.lng),S=T[0],M.log("currentLng set to: "+S),F.setCurrentLng(S),O&&P.setJqueryExt&&m();var r;if(O&&O.Deferred&&(r=O.Deferred()),!P.resStore){var t=M.toLanguages(P.lng);"string"==typeof P.preload&&(P.preload=[P.preload]);for(var u=0,a=P.preload.length;a>u;u++)for(var s=M.toLanguages(P.preload[u]),o=0,i=s.length;i>o;o++)0>t.indexOf(s[o])&&t.push(s[o]);return L.sync.load(t,P,function(n,t){w=t,e&&e(N),r&&r.resolve()}),r?r.promise():void 0}return w=P.resStore,e&&e(N),r&&r.resolve(),r?r.promise():void 0}function a(n,e){"string"==typeof n&&(n=[n]);for(var r=0,t=n.length;t>r;r++)0>P.preload.indexOf(n[r])&&P.preload.push(n[r]);return u(e)}function s(n,e,r){"string"!=typeof e?(r=e,e=P.ns.defaultNs):0>P.ns.namespaces.indexOf(e)&&P.ns.namespaces.push(e),w[n]=w[n]||{},w[n][e]=w[n][e]||{},M.extend(w[n][e],r)}function o(n){P.ns.defaultNs=n}function i(n,e){l([n],e)}function l(n,e){var r={dynamicLoad:P.dynamicLoad,resGetPath:P.resGetPath,getAsync:P.getAsync,customLoad:P.customLoad,ns:{namespaces:n,defaultNs:""}},t=M.toLanguages(P.lng);"string"==typeof P.preload&&(P.preload=[P.preload]);for(var u=0,a=P.preload.length;a>u;u++)for(var s=M.toLanguages(P.preload[u]),o=0,i=s.length;i>o;o++)0>t.indexOf(s[o])&&t.push(s[o]);for(var l=[],c=0,f=t.length;f>c;c++){var m=!1,p=w[t[c]];if(p)for(var b=0,g=n.length;g>b;b++)p[n[b]]||(m=!0);else m=!0;m&&l.push(t[c])}l.length?L.sync._fetch(l,r,function(r,t){var u=n.length*l.length;M.each(n,function(n,r){0>P.ns.namespaces.indexOf(r)&&P.ns.namespaces.push(r),M.each(l,function(n,a){w[a]=w[a]||{},w[a][r]=t[a][r],u--,0===u&&e&&(P.useLocalStorage&&L.sync._storeLocal(w),e())})})}):e&&e()}function c(n,e){return u({lng:n},e)}function f(){return S}function m(){function n(n,e,r){if(0!==e.length){var t="text";if(0===e.indexOf("[")){var u=e.split("]");e=u[1],t=u[0].substr(1,u[0].length-1)}e.indexOf(";")===e.length-1&&(e=e.substr(0,e.length-2));var a;"html"===t?(a=P.defaultValueFromContent?O.extend({defaultValue:n.html()},r):r,n.html(O.t(e,a))):"text"===t?(a=P.defaultValueFromContent?O.extend({defaultValue:n.text()},r):r,n.text(O.t(e,a))):(a=P.defaultValueFromContent?O.extend({defaultValue:n.attr(t)},r):r,n.attr(t,O.t(e,a)))}}function e(e,r){var t=e.attr(P.selectorAttr);if(t){var u=e,a=e.data("i18n-target");if(a&&(u=e.find(a)||e),r||P.useDataAttrOptions!==!0||(r=e.data("i18n-options")),r=r||{},t.indexOf(";")>=0){var s=t.split(";");O.each(s,function(e,t){""!==t&&n(u,t,r)})}else n(u,t,r);P.useDataAttrOptions===!0&&e.data("i18n-options",r)}}O.t=O.t||N,O.fn.i18n=function(n){return this.each(function(){e(O(this),n);var r=O(this).find("["+P.selectorAttr+"]");r.each(function(){e(O(this),n)})})}}function p(n,e,r,t){if(!n)return n;if(t=t||e,0>n.indexOf(t.interpolationPrefix||P.interpolationPrefix))return n;var u=t.interpolationPrefix?M.regexEscape(t.interpolationPrefix):P.interpolationPrefixEscaped,a=t.interpolationSuffix?M.regexEscape(t.interpolationSuffix):P.interpolationSuffixEscaped,s="HTML"+a;return M.each(e,function(e,o){var i=r?r+P.keyseparator+e:e;"object"==typeof o&&null!==o?n=p(n,o,i,t):t.escapeInterpolation||P.escapeInterpolation?(n=n.replace(RegExp([u,i,s].join(""),"g"),o),n=n.replace(RegExp([u,i,a].join(""),"g"),M.escape(o))):n=n.replace(RegExp([u,i,a].join(""),"g"),o)}),n}function b(n,e){var r=",",t="{",u="}",a=M.extend({},e);for(delete a.postProcess;-1!=n.indexOf(P.reusePrefix)&&(j++,!(j>P.maxRecursion));){var s=n.lastIndexOf(P.reusePrefix),o=n.indexOf(P.reuseSuffix,s)+P.reuseSuffix.length,i=n.substring(s,o),l=i.replace(P.reusePrefix,"").replace(P.reuseSuffix,"");if(-1!=l.indexOf(r)){var c=l.indexOf(r);if(-1!=l.indexOf(t,c)&&-1!=l.indexOf(u,c)){var f=l.indexOf(t,c),m=l.indexOf(u,f)+u.length;try{a=M.extend(a,JSON.parse(l.substring(f,m))),l=l.substring(0,c)}catch(p){}}}var b=x(l,a);n=n.replace(i,b)}return n}function g(n){return n.context&&"string"==typeof n.context}function d(n){return void 0!==n.count&&"string"!=typeof n.count&&1!==n.count}function h(n,e){e=e||{};var r=e.defaultValue||n,t=y(n,e);return void 0!==t||t===r}function N(){return j=0,x.apply(null,arguments)}function v(){for(var n=[],e=1;arguments.length>e;e++)n.push(arguments[e]);return{postProcess:"sprintf",sprintf:n}}function x(n,e){e="string"==typeof e?v.apply(null,arguments):e||{};var r,t=e.defaultValue||n,u=y(n,e),a=e.lng?M.toLanguages(e.lng):T,s=e.ns||P.ns.defaultNs;n.indexOf(P.nsseparator)>-1&&(r=n.split(P.nsseparator),s=r[0],n=r[1]),void 0===u&&P.sendMissing&&(e.lng?E.postMissing(a[0],s,n,t,a):E.postMissing(P.lng,s,n,t,a));var o=e.postProcess||P.postProcess;void 0!==u&&o&&R[o]&&(u=R[o](u,n,e));var i=t;if(t.indexOf(P.nsseparator)>-1&&(r=t.split(P.nsseparator),i=r[1]),i===n&&P.parseMissingKey&&(t=P.parseMissingKey(t)),void 0===u&&(t=p(t,e),t=b(t,e),o&&R[o])){var l=e.defaultValue||n;u=R[o](l,n,e)}return void 0!==u?u:t}function y(n,e){e=e||{};var r,t,u=e.defaultValue||n,a=T;if(!w)return u;if(e.lng&&(a=M.toLanguages(e.lng),!w[a[0]])){var s=P.getAsync;P.getAsync=!1,L.sync.load(a,P,function(n,e){M.extend(w,e),P.getAsync=s})}var o=e.ns||P.ns.defaultNs;if(n.indexOf(P.nsseparator)>-1){var i=n.split(P.nsseparator);o=i[0],n=i[1]}if(g(e)){r=M.extend({},e),delete r.context,r.defaultValue=P.contextNotFound;var l=o+P.nsseparator+n+"_"+e.context;if(t=N(l,r),t!=P.contextNotFound)return p(t,{context:e.context})}if(d(e)){r=M.extend({},e),delete r.count,r.defaultValue=P.pluralNotFound;var c=o+P.nsseparator+n+P.pluralSuffix,f=F.get(a[0],e.count);if(f>=0?c=c+"_"+f:1===f&&(c=o+P.nsseparator+n),t=N(c,r),t!=P.pluralNotFound)return p(t,{count:e.count,interpolationPrefix:e.interpolationPrefix,interpolationSuffix:e.interpolationSuffix})}for(var m,h=n.split(P.keyseparator),v=0,k=a.length;k>v&&void 0===m;v++){for(var S=a[v],O=0,j=w[S]&&w[S][o];h[O];)j=j&&j[h[O]],O++;if(void 0!==j){if("string"==typeof j)j=p(j,e),j=b(j,e);else if("[object Array]"!==Object.prototype.toString.apply(j)||P.returnObjectTrees||e.returnObjectTrees){if(null===j&&P.fallbackOnNull===!0)j=void 0;else if(null!==j)if(P.returnObjectTrees||e.returnObjectTrees){var A={};for(var C in j)A[C]=x(o+P.nsseparator+n+P.keyseparator+C,e);j=A}else j="key '"+o+":"+n+" ("+S+")' "+"returned a object instead of string.",M.log(j)}else j=j.join("\n"),j=p(j,e),j=b(j,e);m=j}}if(void 0===m&&!e.isFallbackLookup&&(P.fallbackToDefaultNS===!0||P.fallbackNS&&P.fallbackNS.length>0))if(e.isFallbackLookup=!0,P.fallbackNS.length){for(var _=0,E=P.fallbackNS.length;E>_;_++)if(m=y(P.fallbackNS[_]+P.nsseparator+n,e)){var R=m.indexOf(P.nsseparator)>-1?m.split(P.nsseparator)[1]:m,z=u.indexOf(P.nsseparator)>-1?u.split(P.nsseparator)[1]:u;if(R!==z)break}}else m=y(n,e);return m}function k(){var n,e=[];if("undefined"!=typeof window&&(function(){for(var n=window.location.search.substring(1),r=n.split("&"),t=0;r.length>t;t++){var u=r[t].indexOf("=");if(u>0){var a=r[t].substring(0,u),s=r[t].substring(u+1);e[a]=s}}}(),e[P.detectLngQS]&&(n=e[P.detectLngQS])),!n&&"undefined"!=typeof document&&P.useCookie){var r=M.cookie.read(P.cookieName);r&&(n=r)}return n||"undefined"==typeof navigator||(n=navigator.language?navigator.language:navigator.userLanguage),n}Array.prototype.indexOf||(Array.prototype.indexOf=function(n){"use strict";if(null==this)throw new TypeError;var e=Object(this),r=e.length>>>0;if(0===r)return-1;var t=0;if(arguments.length>0&&(t=Number(arguments[1]),t!=t?t=0:0!=t&&1/0!=t&&t!=-1/0&&(t=(t>0||-1)*Math.floor(Math.abs(t)))),t>=r)return-1;for(var u=t>=0?t:Math.max(r-Math.abs(t),0);r>u;u++)if(u in e&&e[u]===n)return u;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(n){"use strict";if(null==this)throw new TypeError;var e=Object(this),r=e.length>>>0;if(0===r)return-1;var t=r;arguments.length>1&&(t=Number(arguments[1]),t!=t?t=0:0!=t&&t!=1/0&&t!=-(1/0)&&(t=(t>0||-1)*Math.floor(Math.abs(t))));for(var u=t>=0?Math.min(t,r-1):r-Math.abs(t);u>=0;u--)if(u in e&&e[u]===n)return u;return-1});var S,O=void 0,L={},w={},j=0,T=[],P={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:"dev",fallbackNS:[],detectLngQS:"setLng",ns:"translation",fallbackOnNull:!0,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",postProcess:void 0,parseMissingKey:void 0},A={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},C={create:function(n,e,r){var t;if(r){var u=new Date;u.setTime(u.getTime()+1e3*60*r),t="; expires="+u.toGMTString()}else t="";document.cookie=n+"="+e+t+"; path=/"},read:function(n){for(var e=n+"=",r=document.cookie.split(";"),t=0;r.length>t;t++){for(var u=r[t];" "==u.charAt(0);)u=u.substring(1,u.length);if(0===u.indexOf(e))return u.substring(e.length,u.length)}return null},remove:function(n){this.create(n,"",-1)}},_={create:function(){},read:function(){return null},remove:function(){}},M={extend:O?O.extend:n,each:O?O.each:e,ajax:O?O.ajax:t,cookie:"undefined"!=typeof document?C:_,detectLanguage:k,escape:r,log:function(n){P.debug&&"undefined"!=typeof console&&console.log(n)},toLanguages:function(n){var e=[];if("string"==typeof n&&n.indexOf("-")>-1){var r=n.split("-");n=P.lowerCaseLng?r[0].toLowerCase()+"-"+r[1].toLowerCase():r[0].toLowerCase()+"-"+r[1].toUpperCase(),"unspecific"!==P.load&&e.push(n),"current"!==P.load&&e.push(r[0])}else e.push(n);return-1===e.indexOf(P.fallbackLng)&&P.fallbackLng&&e.push(P.fallbackLng),e},regexEscape:function(n){return n.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}};M.applyReplacement=p;var E={load:function(n,e,r){e.useLocalStorage?E._loadLocal(n,e,function(t,u){for(var a=[],s=0,o=n.length;o>s;s++)u[n[s]]||a.push(n[s]);a.length>0?E._fetch(a,e,function(n,e){M.extend(u,e),E._storeLocal(e),r(null,u)}):r(null,u)}):E._fetch(n,e,function(n,e){r(null,e)})},_loadLocal:function(n,e,r){var t={},u=(new Date).getTime();if(window.localStorage){var a=n.length;M.each(n,function(n,s){var o=window.localStorage.getItem("res_"+s);o&&(o=JSON.parse(o),o.i18nStamp&&o.i18nStamp+e.localStorageExpirationTime>u&&(t[s]=o)),a--,0===a&&r(null,t)})}},_storeLocal:function(n){if(window.localStorage)for(var e in n)n[e].i18nStamp=(new Date).getTime(),window.localStorage.setItem("res_"+e,JSON.stringify(n[e]))},_fetch:function(n,e,r){var t=e.ns,u={};if(e.dynamicLoad){var a=function(n,e){r(null,e)};if("function"==typeof e.customLoad)e.customLoad(n,t.namespaces,e,a);else{var s=p(e.resGetPath,{lng:n.join("+"),ns:t.namespaces.join("+")});M.ajax({url:s,success:function(n){M.log("loaded: "+s),a(null,n)},error:function(n,e,r){M.log("failed loading: "+s),a("failed loading resource.json error: "+r)},dataType:"json",async:e.getAsync})}}else{var o,i=t.namespaces.length*n.length;M.each(t.namespaces,function(t,a){M.each(n,function(n,t){var s=function(n,e){n&&(o=o||[],o.push(n)),u[t]=u[t]||{},u[t][a]=e,i--,0===i&&r(o,u)};"function"==typeof e.customLoad?e.customLoad(t,a,e,s):E._fetchOne(t,a,e,s)})})}},_fetchOne:function(n,e,r,t){var u=p(r.resGetPath,{lng:n,ns:e});M.ajax({url:u,success:function(n){M.log("loaded: "+u),t(null,n)},error:function(n,e,r){M.log("failed loading: "+u),t(r,{})},dataType:"json",async:r.getAsync})},postMissing:function(n,e,r,t,u){var a={};a[r]=t;var s=[];if("fallback"===P.sendMissingTo&&P.fallbackLng!==!1)s.push({lng:P.fallbackLng,url:p(P.resPostPath,{lng:P.fallbackLng,ns:e})});else if("current"===P.sendMissingTo||"fallback"===P.sendMissingTo&&P.fallbackLng===!1)s.push({lng:n,url:p(P.resPostPath,{lng:n,ns:e})});else if("all"===P.sendMissingTo)for(var o=0,i=u.length;i>o;o++)s.push({lng:u[o],url:p(P.resPostPath,{lng:u[o],ns:e})});for(var l=0,c=s.length;c>l;l++){var f=s[l];M.ajax({url:f.url,type:P.sendType,data:a,success:function(){M.log("posted missing key '"+r+"' to: "+f.url);for(var n=r.split("."),u=0,a=w[f.lng][e];n[u];)a=a[n[u]]=u===n.length-1?t:a[n[u]]||{},u++},error:function(){M.log("failed posting missing key '"+r+"' to: "+f.url)},dataType:"json",async:P.postAsync})}}},F={rules:{ach:{name:"Acholi",numbers:[1,2],plurals:function(n){return Number(n>1)}},af:{name:"Afrikaans",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ak:{name:"Akan",numbers:[1,2],plurals:function(n){return Number(n>1)}},am:{name:"Amharic",numbers:[1,2],plurals:function(n){return Number(n>1)}},an:{name:"Aragonese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ar:{name:"Arabic",numbers:[0,1,2,3,11,100],plurals:function(n){return Number(0===n?0:1==n?1:2==n?2:n%100>=3&&10>=n%100?3:n%100>=11?4:5)}},arn:{name:"Mapudungun",numbers:[1,2],plurals:function(n){return Number(n>1)}},ast:{name:"Asturian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ay:{name:"Aymará",numbers:[1],plurals:function(){return 0}},az:{name:"Azerbaijani",numbers:[1,2],plurals:function(n){return Number(1!=n)}},be:{name:"Belarusian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},bg:{name:"Bulgarian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},bn:{name:"Bengali",numbers:[1,2],plurals:function(n){return Number(1!=n)}},bo:{name:"Tibetan",numbers:[1],plurals:function(){return 0}},br:{name:"Breton",numbers:[1,2],plurals:function(n){return Number(n>1)}},bs:{name:"Bosnian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},ca:{name:"Catalan",numbers:[1,2],plurals:function(n){return Number(1!=n)}},cgg:{name:"Chiga",numbers:[1],plurals:function(){return 0}},cs:{name:"Czech",numbers:[1,2,5],plurals:function(n){return Number(1==n?0:n>=2&&4>=n?1:2)}},csb:{name:"Kashubian",numbers:[1,2,5],plurals:function(n){return Number(1==n?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},cy:{name:"Welsh",numbers:[1,2,3,8],plurals:function(n){return Number(1==n?0:2==n?1:8!=n&&11!=n?2:3)}},da:{name:"Danish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},de:{name:"German",numbers:[1,2],plurals:function(n){return Number(1!=n)}},dz:{name:"Dzongkha",numbers:[1],plurals:function(){return 0}},el:{name:"Greek",numbers:[1,2],plurals:function(n){return Number(1!=n)}},en:{name:"English",numbers:[1,2],plurals:function(n){return Number(1!=n)}},eo:{name:"Esperanto",numbers:[1,2],plurals:function(n){return Number(1!=n)}},es:{name:"Spanish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},es_ar:{name:"Argentinean Spanish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},et:{name:"Estonian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},eu:{name:"Basque",numbers:[1,2],plurals:function(n){return Number(1!=n)}},fa:{name:"Persian",numbers:[1],plurals:function(){return 0}},fi:{name:"Finnish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},fil:{name:"Filipino",numbers:[1,2],plurals:function(n){return Number(n>1)}},fo:{name:"Faroese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},fr:{name:"French",numbers:[1,2],plurals:function(n){return Number(n>1)}},fur:{name:"Friulian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},fy:{name:"Frisian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ga:{name:"Irish",numbers:[1,2,3,7,11],plurals:function(n){return Number(1==n?0:2==n?1:7>n?2:11>n?3:4)}},gd:{name:"Scottish Gaelic",numbers:[1,2,3,20],plurals:function(n){return Number(1==n||11==n?0:2==n||12==n?1:n>2&&20>n?2:3)}},gl:{name:"Galician",numbers:[1,2],plurals:function(n){return Number(1!=n)}},gu:{name:"Gujarati",numbers:[1,2],plurals:function(n){return Number(1!=n)}},gun:{name:"Gun",numbers:[1,2],plurals:function(n){return Number(n>1)}},ha:{name:"Hausa",numbers:[1,2],plurals:function(n){return Number(1!=n)}},he:{name:"Hebrew",numbers:[1,2],plurals:function(n){return Number(1!=n)}},hi:{name:"Hindi",numbers:[1,2],plurals:function(n){return Number(1!=n)}},hr:{name:"Croatian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},hu:{name:"Hungarian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},hy:{name:"Armenian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ia:{name:"Interlingua",numbers:[1,2],plurals:function(n){return Number(1!=n)}},id:{name:"Indonesian",numbers:[1],plurals:function(){return 0}},is:{name:"Icelandic",numbers:[1,2],plurals:function(n){return Number(1!=n%10||11==n%100)}},it:{name:"Italian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ja:{name:"Japanese",numbers:[1],plurals:function(){return 0}},jbo:{name:"Lojban",numbers:[1],plurals:function(){return 0}},jv:{name:"Javanese",numbers:[0,1],plurals:function(n){return Number(0!==n)}},ka:{name:"Georgian",numbers:[1],plurals:function(){return 0}},kk:{name:"Kazakh",numbers:[1],plurals:function(){return 0}},km:{name:"Khmer",numbers:[1],plurals:function(){return 0}},kn:{name:"Kannada",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ko:{name:"Korean",numbers:[1],plurals:function(){return 0}},ku:{name:"Kurdish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},kw:{name:"Cornish",numbers:[1,2,3,4],plurals:function(n){return Number(1==n?0:2==n?1:3==n?2:3)}},ky:{name:"Kyrgyz",numbers:[1],plurals:function(){return 0}},lb:{name:"Letzeburgesch",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ln:{name:"Lingala",numbers:[1,2],plurals:function(n){return Number(n>1)}},lo:{name:"Lao",numbers:[1],plurals:function(){return 0}},lt:{name:"Lithuanian",numbers:[1,2,10],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&(10>n%100||n%100>=20)?1:2)}},lv:{name:"Latvian",numbers:[0,1,2],plurals:function(n){return Number(1==n%10&&11!=n%100?0:0!==n?1:2)}},mai:{name:"Maithili",numbers:[1,2],plurals:function(n){return Number(1!=n)}},mfe:{name:"Mauritian Creole",numbers:[1,2],plurals:function(n){return Number(n>1)}},mg:{name:"Malagasy",numbers:[1,2],plurals:function(n){return Number(n>1)}},mi:{name:"Maori",numbers:[1,2],plurals:function(n){return Number(n>1)}},mk:{name:"Macedonian",numbers:[1,2],plurals:function(n){return Number(1==n||1==n%10?0:1)}},ml:{name:"Malayalam",numbers:[1,2],plurals:function(n){return Number(1!=n)}},mn:{name:"Mongolian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},mnk:{name:"Mandinka",numbers:[0,1,2],plurals:function(n){return Number(1==n?1:2)}},mr:{name:"Marathi",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ms:{name:"Malay",numbers:[1],plurals:function(){return 0}},mt:{name:"Maltese",numbers:[1,2,11,20],plurals:function(n){return Number(1==n?0:0===n||n%100>1&&11>n%100?1:n%100>10&&20>n%100?2:3)}},nah:{name:"Nahuatl",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nap:{name:"Neapolitan",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nb:{name:"Norwegian Bokmal",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ne:{name:"Nepali",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nl:{name:"Dutch",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nn:{name:"Norwegian Nynorsk",numbers:[1,2],plurals:function(n){return Number(1!=n)}},no:{name:"Norwegian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nso:{name:"Northern Sotho",numbers:[1,2],plurals:function(n){return Number(1!=n)}},oc:{name:"Occitan",numbers:[1,2],plurals:function(n){return Number(n>1)}},or:{name:"Oriya",numbers:[2,1],plurals:function(n){return Number(1!=n)}},pa:{name:"Punjabi",numbers:[1,2],plurals:function(n){return Number(1!=n)}},pap:{name:"Papiamento",numbers:[1,2],plurals:function(n){return Number(1!=n)}},pl:{name:"Polish",numbers:[1,2,5],plurals:function(n){return Number(1==n?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},pms:{name:"Piemontese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ps:{name:"Pashto",numbers:[1,2],plurals:function(n){return Number(1!=n)}},pt:{name:"Portuguese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},pt_br:{name:"Brazilian Portuguese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},rm:{name:"Romansh",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ro:{name:"Romanian",numbers:[1,2,20],plurals:function(n){return Number(1==n?0:0===n||n%100>0&&20>n%100?1:2)}},ru:{name:"Russian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},sah:{name:"Yakut",numbers:[1],plurals:function(){return 0}},sco:{name:"Scots",numbers:[1,2],plurals:function(n){return Number(1!=n)}},se:{name:"Northern Sami",numbers:[1,2],plurals:function(n){return Number(1!=n)}},si:{name:"Sinhala",numbers:[1,2],plurals:function(n){return Number(1!=n)}},sk:{name:"Slovak",numbers:[1,2,5],plurals:function(n){return Number(1==n?0:n>=2&&4>=n?1:2)}},sl:{name:"Slovenian",numbers:[5,1,2,3],plurals:function(n){return Number(1==n%100?1:2==n%100?2:3==n%100||4==n%100?3:0)}},so:{name:"Somali",numbers:[1,2],plurals:function(n){return Number(1!=n)}},son:{name:"Songhay",numbers:[1,2],plurals:function(n){return Number(1!=n)}},sq:{name:"Albanian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},sr:{name:"Serbian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},su:{name:"Sundanese",numbers:[1],plurals:function(){return 0}},sv:{name:"Swedish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},sw:{name:"Swahili",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ta:{name:"Tamil",numbers:[1,2],plurals:function(n){return Number(1!=n)}},te:{name:"Telugu",numbers:[1,2],plurals:function(n){return Number(1!=n)}},tg:{name:"Tajik",numbers:[1,2],plurals:function(n){return Number(n>1)}},th:{name:"Thai",numbers:[1],plurals:function(){return 0}},ti:{name:"Tigrinya",numbers:[1,2],plurals:function(n){return Number(n>1)}},tk:{name:"Turkmen",numbers:[1,2],plurals:function(n){return Number(1!=n)}},tr:{name:"Turkish",numbers:[1,2],plurals:function(n){return Number(n>1)}},tt:{name:"Tatar",numbers:[1],plurals:function(){return 0}},ug:{name:"Uyghur",numbers:[1],plurals:function(){return 0}},uk:{name:"Ukrainian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},ur:{name:"Urdu",numbers:[1,2],plurals:function(n){return Number(1!=n)}},uz:{name:"Uzbek",numbers:[1,2],plurals:function(n){return Number(n>1)}},vi:{name:"Vietnamese",numbers:[1],plurals:function(){return 0}},wa:{name:"Walloon",numbers:[1,2],plurals:function(n){return Number(n>1)}},wo:{name:"Wolof",numbers:[1],plurals:function(){return 0}},yo:{name:"Yoruba",numbers:[1,2],plurals:function(n){return Number(1!=n)}},zh:{name:"Chinese",numbers:[1],plurals:function(){return 0}}},addRule:function(n,e){F.rules[n]=e},setCurrentLng:function(n){if(!F.currentRule||F.currentRule.lng!==n){var e=n.split("-");F.currentRule={lng:n,rule:F.rules[e[0]]}}},get:function(n,e){function r(e,r){var t;if(t=F.currentRule&&F.currentRule.lng===n?F.currentRule.rule:F.rules[e]){var u=t.plurals(r),a=t.numbers[u];return 2===t.numbers.length&&1===t.numbers[0]&&(2===a?a=-1:1===a&&(a=1)),a}return 1===r?"1":"-1"}var t=n.split("-");return r(t[0],e)}},R={},z=function(n,e){R[n]=e},D=function(){function n(n){return Object.prototype.toString.call(n).slice(8,-1).toLowerCase()}function e(n,e){for(var r=[];e>0;r[--e]=n);return r.join("")}var r=function(){return r.cache.hasOwnProperty(arguments[0])||(r.cache[arguments[0]]=r.parse(arguments[0])),r.format.call(null,r.cache[arguments[0]],arguments)};return r.format=function(r,t){var u,a,s,o,i,l,c,f=1,m=r.length,p="",b=[];for(a=0;m>a;a++)if(p=n(r[a]),"string"===p)b.push(r[a]);else if("array"===p){if(o=r[a],o[2])for(u=t[f],s=0;o[2].length>s;s++){if(!u.hasOwnProperty(o[2][s]))throw D('[sprintf] property "%s" does not exist',o[2][s]);u=u[o[2][s]]}else u=o[1]?t[o[1]]:t[f++];if(/[^s]/.test(o[8])&&"number"!=n(u))throw D("[sprintf] expecting number but found %s",n(u));switch(o[8]){case"b":u=u.toString(2);break;case"c":u=String.fromCharCode(u);break;case"d":u=parseInt(u,10);break;case"e":u=o[7]?u.toExponential(o[7]):u.toExponential();break;case"f":u=o[7]?parseFloat(u).toFixed(o[7]):parseFloat(u);break;case"o":u=u.toString(8);break;case"s":u=(u+="")&&o[7]?u.substring(0,o[7]):u;break;case"u":u=Math.abs(u);break;case"x":u=u.toString(16);break;case"X":u=u.toString(16).toUpperCase()}u=/[def]/.test(o[8])&&o[3]&&u>=0?"+"+u:u,l=o[4]?"0"==o[4]?"0":o[4].charAt(1):" ",c=o[6]-(u+"").length,i=o[6]?e(l,c):"",b.push(o[5]?u+i:i+u)}return b.join("")},r.cache={},r.parse=function(n){for(var e=n,r=[],t=[],u=0;e;){if(null!==(r=/^[^\x25]+/.exec(e)))t.push(r[0]);else if(null!==(r=/^\x25{2}/.exec(e)))t.push("%");else{if(null===(r=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(e)))throw"[sprintf] huh?";if(r[2]){u|=1;var a=[],s=r[2],o=[];if(null===(o=/^([a-z_][a-z_\d]*)/i.exec(s)))throw"[sprintf] huh?";for(a.push(o[1]);""!==(s=s.substring(o[0].length));)if(null!==(o=/^\.([a-z_][a-z_\d]*)/i.exec(s)))a.push(o[1]);else{if(null===(o=/^\[(\d+)\]/.exec(s)))throw"[sprintf] huh?";a.push(o[1])}r[2]=a}else u|=2;if(3===u)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";t.push(r)}e=e.substring(r[0].length)}return t},r}(),I=function(n,e){return e.unshift(n),D.apply(null,e)};return z("sprintf",function(n,e,r){return r.sprintf?"[object Array]"===Object.prototype.toString.apply(r.sprintf)?I(n,r.sprintf):"object"==typeof r.sprintf?D(n,r.sprintf):n:n}),L.init=u,L.setLng=c,L.preload=a,L.addResourceBundle=s,L.loadNamespace=i,L.loadNamespaces=l,L.setDefaultNamespace=o,L.t=N,L.translate=N,L.exists=h,L.detectLanguage=M.detectLanguage,L.pluralExtensions=F,L.sync=E,L.functions=M,L.lng=f,L.addPostProcessor=z,L.options=P,L}); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd-1.6.3.zip b/libs/i18next/release/i18next.amd-1.6.3.zip new file mode 100644 index 00000000..73713c58 Binary files /dev/null and b/libs/i18next/release/i18next.amd-1.6.3.zip differ diff --git a/libs/i18next/release/i18next.amd-1.7.0.js b/libs/i18next/release/i18next.amd-1.7.0.js new file mode 100644 index 00000000..e9786544 --- /dev/null +++ b/libs/i18next/release/i18next.amd-1.7.0.js @@ -0,0 +1,2659 @@ +// i18next, v1.7.0 +// Copyright (c)2013 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function (root, factory) { + if (typeof exports === 'object') { + + module.exports = factory(); + + } else if (typeof define === 'function' && define.amd) { + + define([], factory); + + } +}(this, function () { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + var $ = undefined + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = []; + + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: 'dev', + fallbackNS: [], + detectLngQS: 'setLng', + ns: 'translation', + fallbackOnNull: true, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + cookieDomain: undefined, + + postProcess: undefined, + parseMissingKey: undefined, + + shortcutFunction: 'sprintf' // or: defaultValue + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + return JSON.parse(data); + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + if (status === 200) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes,domain) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + domain = (domain)? "domain="+domain+";" : ""; + document.cookie = name+"="+value+expires+";"+domain+"path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes,domain) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : _ajax, + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + toLanguages: function(lng) { + var languages = []; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + + if (o.load !== 'unspecific') languages.push(lng); + if (o.load !== 'current') languages.push(parts[0]); + } else { + languages.push(lng); + } + + if (languages.indexOf(o.fallbackLng) === -1 && o.fallbackLng) languages.push(o.fallbackLng); + + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + delete o.fixLng; /* passed in each time */ + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + if (o.lng) { + // set cookie with lng set (as detectLanguage will set cookie on need) + if (o.useCookie) f.cookie.create(o.cookieName, o.lng, o.cookieExpirationTime, o.cookieDomain); + } else { + o.lng = o.fallbackLng; + if (o.useCookie) f.cookie.remove(o.cookieName); + } + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + var lngTranslate = translate; + if (options.fixLng) { + lngTranslate = function(key, options) { + options = options || {}; + options.lng = options.lng || lngTranslate.lng; + return translate(key, options); + }; + lngTranslate.lng = currentLng; + } + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + initialized = true; + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + initialized = true; + + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + f.extend(resStore[lng][ns], resources); + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, options, cb) { + if (typeof options === 'function') { + cb = options; + options = {}; + } + options.lng = lng; + return init(options, cb); + } + + function lng() { + return currentLng; + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } + else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key && typeof key !== 'undefined' && key !== false) key = ele.text() || ele.val(); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + f.each(replacementHash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), value); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.escape(value)); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), value); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, translated_token); + } + return translated; + } + + function hasContext(options) { + return (options.context && typeof options.context == 'string'); + } + + function needsPlural(options) { + return (options.count !== undefined && typeof options.count != 'string' && options.count !== 1); + } + + function exists(key, options) { + options = options || {}; + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + if (!initialized) { + f.log('i18next not finished initialization. you might have called t function before loading resources finished.') + return options.defaultValue || ''; + }; + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _getDefaultValue(key, options) { + return (options.defaultValue !== undefined) ? options.defaultValue : key; + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(potentialKeys, options) { + if (typeof options == 'string') { + if (o.shortcutFunction === 'sprintf') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else if (o.shortcutFunction === 'defaultValue') { + options = { + defaultValue: options + } + } + } else { + options = options || {}; + } + + if (typeof potentialKeys == 'string') { + potentialKeys = [potentialKeys]; + } + + var key = null; + + for (var i = 0; i < potentialKeys.length; i++) { + key = potentialKeys[i]; + if (exists(key)) { + break; + } + } + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng) : languages + , ns = options.ns || o.ns.defaultNs + , parts; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing) { + if (options.lng) { + sync.postMissing(lngs[0], ns, key, notFound, lngs); + } else { + sync.postMissing(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found !== undefined && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + // process notFound if function exists + var splitNotFound = notFound; + if (notFound.indexOf(o.nsseparator) > -1) { + parts = notFound.split(o.nsseparator); + splitNotFound = parts[1]; + } + if (splitNotFound === key && o.parseMissingKey) { + notFound = o.parseMissingKey(notFound); + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessor && postProcessors[postProcessor]) { + var val = _getDefaultValue(key, options); + found = postProcessors[postProcessor](val, key, options); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options){ + options = options || {}; + + var optionWithoutCount, translated + , notFound = _getDefaultValue(key, options) + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + if (options.lng) { + lngs = f.toLanguages(options.lng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.count; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(lngs[0], options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + + translated = translate(pluralKey, optionWithoutCount); + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } // else continue translation with original/singular key + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (Object.prototype.toString.apply(value) === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned a object instead of string.'; + f.log(value); + } else if (typeof value !== 'number') { + var copy = {}; // apply child translation on a copy + f.each(value, function(m) { + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + }); + value = copy; + } + } + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length > 0))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + } + + return found; + } + function detectLanguage() { + var detectedLng; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var parms = query.split('&'); + for (var i=0; i 0) { + var key = parms[i].substring(0,pos); + var val = parms[i].substring(pos+1); + qsParm[key] = val; + } + } + })(); + if (qsParm[o.detectLngQS]) { + detectedLng = qsParm[o.detectLngQS]; + } + } + + // get from cookie + if (!detectedLng && typeof document !== 'undefined' && o.useCookie ) { + var c = f.cookie.read(o.cookieName); + if (c) detectedLng = c; + } + + // get from navigator + if (!detectedLng && typeof navigator !== 'undefined') { + detectedLng = (navigator.language) ? navigator.language : navigator.userLanguage; + } + + return detectedLng; + } + var sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + window.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback' && o.fallbackLng !== false) { + urls.push({lng: o.fallbackLng, url: applyReplacement(o.resPostPath, { lng: o.fallbackLng, ns: ns })}); + } else if (o.sendMissingTo === 'current' || (o.sendMissingTo === 'fallback' && o.fallbackLng === false) ) { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + } + }; + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + var pluralExtensions = { + + rules: { + "ach": { + "name": "Acholi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "af": { + "name": "Afrikaans", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ak": { + "name": "Akan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "am": { + "name": "Amharic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "an": { + "name": "Aragonese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ar": { + "name": "Arabic", + "numbers": [ + 0, + 1, + 2, + 3, + 11, + 100 + ], + "plurals": function(n) { return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5); } + }, + "arn": { + "name": "Mapudungun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ast": { + "name": "Asturian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ay": { + "name": "Aymar\u00e1", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "az": { + "name": "Azerbaijani", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "be": { + "name": "Belarusian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "bg": { + "name": "Bulgarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bn": { + "name": "Bengali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bo": { + "name": "Tibetan", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "br": { + "name": "Breton", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "bs": { + "name": "Bosnian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ca": { + "name": "Catalan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "cgg": { + "name": "Chiga", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "cs": { + "name": "Czech", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "csb": { + "name": "Kashubian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "cy": { + "name": "Welsh", + "numbers": [ + 1, + 2, + 3, + 8 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3); } + }, + "da": { + "name": "Danish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "de": { + "name": "German", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "dz": { + "name": "Dzongkha", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "el": { + "name": "Greek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "en": { + "name": "English", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eo": { + "name": "Esperanto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es": { + "name": "Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es_ar": { + "name": "Argentinean Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "et": { + "name": "Estonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eu": { + "name": "Basque", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fa": { + "name": "Persian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "fi": { + "name": "Finnish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fil": { + "name": "Filipino", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fo": { + "name": "Faroese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fr": { + "name": "French", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fur": { + "name": "Friulian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fy": { + "name": "Frisian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ga": { + "name": "Irish", + "numbers": [ + 1, + 2, + 3, + 7, + 11 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;} + }, + "gd": { + "name": "Scottish Gaelic", + "numbers": [ + 1, + 2, + 3, + 20 + ], + "plurals": function(n) { return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3); } + }, + "gl": { + "name": "Galician", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gu": { + "name": "Gujarati", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gun": { + "name": "Gun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ha": { + "name": "Hausa", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "he": { + "name": "Hebrew", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hi": { + "name": "Hindi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hr": { + "name": "Croatian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "hu": { + "name": "Hungarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hy": { + "name": "Armenian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ia": { + "name": "Interlingua", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "id": { + "name": "Indonesian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "is": { + "name": "Icelandic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n%10!=1 || n%100==11); } + }, + "it": { + "name": "Italian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ja": { + "name": "Japanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jbo": { + "name": "Lojban", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jv": { + "name": "Javanese", + "numbers": [ + 0, + 1 + ], + "plurals": function(n) { return Number(n !== 0); } + }, + "ka": { + "name": "Georgian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kk": { + "name": "Kazakh", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "km": { + "name": "Khmer", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kn": { + "name": "Kannada", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ko": { + "name": "Korean", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ku": { + "name": "Kurdish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "kw": { + "name": "Cornish", + "numbers": [ + 1, + 2, + 3, + 4 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3); } + }, + "ky": { + "name": "Kyrgyz", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lb": { + "name": "Letzeburgesch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ln": { + "name": "Lingala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "lo": { + "name": "Lao", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lt": { + "name": "Lithuanian", + "numbers": [ + 1, + 2, + 10 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "lv": { + "name": "Latvian", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2); } + }, + "mai": { + "name": "Maithili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mfe": { + "name": "Mauritian Creole", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mg": { + "name": "Malagasy", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mi": { + "name": "Maori", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mk": { + "name": "Macedonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 || n%10==1 ? 0 : 1); } + }, + "ml": { + "name": "Malayalam", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mn": { + "name": "Mongolian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mnk": { + "name": "Mandinka", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(0 ? 0 : n==1 ? 1 : 2); } + }, + "mr": { + "name": "Marathi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ms": { + "name": "Malay", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "mt": { + "name": "Maltese", + "numbers": [ + 1, + 2, + 11, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3); } + }, + "nah": { + "name": "Nahuatl", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nap": { + "name": "Neapolitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nb": { + "name": "Norwegian Bokmal", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ne": { + "name": "Nepali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nl": { + "name": "Dutch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nn": { + "name": "Norwegian Nynorsk", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "no": { + "name": "Norwegian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nso": { + "name": "Northern Sotho", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "oc": { + "name": "Occitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "or": { + "name": "Oriya", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pa": { + "name": "Punjabi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pap": { + "name": "Papiamento", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pl": { + "name": "Polish", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "pms": { + "name": "Piemontese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ps": { + "name": "Pashto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt": { + "name": "Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt_br": { + "name": "Brazilian Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "rm": { + "name": "Romansh", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ro": { + "name": "Romanian", + "numbers": [ + 1, + 2, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2); } + }, + "ru": { + "name": "Russian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "sah": { + "name": "Yakut", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sco": { + "name": "Scots", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "se": { + "name": "Northern Sami", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "si": { + "name": "Sinhala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sk": { + "name": "Slovak", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "sl": { + "name": "Slovenian", + "numbers": [ + 5, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }, + "so": { + "name": "Somali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "son": { + "name": "Songhay", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sq": { + "name": "Albanian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sr": { + "name": "Serbian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "su": { + "name": "Sundanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sv": { + "name": "Swedish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sw": { + "name": "Swahili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ta": { + "name": "Tamil", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "te": { + "name": "Telugu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tg": { + "name": "Tajik", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "th": { + "name": "Thai", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ti": { + "name": "Tigrinya", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tk": { + "name": "Turkmen", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tr": { + "name": "Turkish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tt": { + "name": "Tatar", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ug": { + "name": "Uyghur", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "uk": { + "name": "Ukrainian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ur": { + "name": "Urdu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "uz": { + "name": "Uzbek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "vi": { + "name": "Vietnamese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "wa": { + "name": "Walloon", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "wo": { + "name": "Wolof", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "yo": { + "name": "Yoruba", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "zh": { + "name": "Chinese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + } + }, + + // for demonstration only sl and ar is added but you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i = ext.plurals(c); + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[0], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + + return i18n; + +})); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd-1.7.0.min.js b/libs/i18next/release/i18next.amd-1.7.0.min.js new file mode 100644 index 00000000..0b5b56e7 --- /dev/null +++ b/libs/i18next/release/i18next.amd-1.7.0.min.js @@ -0,0 +1,5 @@ +// i18next, v1.7.0 +// Copyright (c)2013 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +!function(a,b){"object"==typeof exports?module.exports=b():"function"==typeof define&&define.amd&&define([],b)}(this,function(){function a(a,b){if(!b||"function"==typeof b)return a;for(var c in b)a[c]=b[c];return a}function b(a,b,c){var d,e=0,f=a.length,g=void 0===f||"function"==typeof a;if(c)if(g){for(d in a)if(b.apply(a[d],c)===!1)break}else for(;f>e&&b.apply(a[e++],c)!==!1;);else if(g){for(d in a)if(b.call(a[d],d,a[d])===!1)break}else for(;f>e&&b.call(a[e],e,a[e++])!==!1;);return a}function c(a){return"string"==typeof a?a.replace(/[&<>"'\/]/g,function(a){return F[a]}):a}function d(a){var b=function(a){if(window.XMLHttpRequest)return a(null,new XMLHttpRequest);if(window.ActiveXObject)try{return a(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(b){return a(null,new ActiveXObject("Microsoft.XMLHTTP"))}return a(new Error)},c=function(a){if("string"==typeof a)return a;var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")},d=function(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;cd?b+=String.fromCharCode(d):d>127&&2048>d?(b+=String.fromCharCode(192|d>>6),b+=String.fromCharCode(128|63&d)):(b+=String.fromCharCode(224|d>>12),b+=String.fromCharCode(128|63&d>>6),b+=String.fromCharCode(128|63&d))}return b},e=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";a=d(a);var c,e,f,g,h,i,j,k="",l=0;do c=a.charCodeAt(l++),e=a.charCodeAt(l++),f=a.charCodeAt(l++),g=c>>2,h=(3&c)<<4|e>>4,i=(15&e)<<2|f>>6,j=63&f,isNaN(e)?i=j=64:isNaN(f)&&(j=64),k+=b.charAt(g)+b.charAt(h)+b.charAt(i)+b.charAt(j),c=e=f="",g=h=i=j="";while(l1&&(d+=d.indexOf("?")>-1?"&"+k:"?"+k),e.jsonp){var l=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=d,l.appendChild(m),void 0}}b(function(b,c){if(b)return h(b);c.open(a,d,e.async);for(var f in j)j.hasOwnProperty(f)&&c.setRequestHeader(f,j[f]);c.onreadystatechange=function(){if(4===c.readyState){var a=c.responseText||"";if(!h)return;h(c.status,{text:function(){return a},json:function(){return JSON.parse(a)}})}},c.send(i)})},h={authBasic:function(a,b){g.headers.Authorization="Basic "+e(a+":"+b)},connect:function(a,b,c){return g("CONNECT",a,b,c)},del:function(a,b,c){return g("DELETE",a,b,c)},get:function(a,b,c){return g("GET",a,b,c)},head:function(a,b,c){return g("HEAD",a,b,c)},headers:function(a){g.headers=a||{}},isAllowed:function(a,b,c){this.options(a,function(a,d){c(-1!==d.text().indexOf(b))})},options:function(a,b,c){return g("OPTIONS",a,b,c)},patch:function(a,b,c){return g("PATCH",a,b,c)},post:function(a,b,c){return g("POST",a,b,c)},put:function(a,b,c){return g("PUT",a,b,c)},trace:function(a,b,c){return g("TRACE",a,b,c)}},i=a.type?a.type.toLowerCase():"get";h[i](a.url,a,function(b,c){200===b?a.success(c.json(),b,null):a.error(c.text(),b,null)})}function e(a,b){"function"==typeof a&&(b=a,a={}),a=a||{},I.extend(E,a),delete E.fixLng,"string"==typeof E.ns&&(E.ns={namespaces:[E.ns],defaultNs:E.ns}),"string"==typeof E.fallbackNS&&(E.fallbackNS=[E.fallbackNS]),E.interpolationPrefixEscaped=I.regexEscape(E.interpolationPrefix),E.interpolationSuffixEscaped=I.regexEscape(E.interpolationSuffix),E.lng||(E.lng=I.detectLanguage()),E.lng?E.useCookie&&I.cookie.create(E.cookieName,E.lng,E.cookieExpirationTime,E.cookieDomain):(E.lng=E.fallbackLng,E.useCookie&&I.cookie.remove(E.cookieName)),D=I.toLanguages(E.lng),y=D[0],I.log("currentLng set to: "+y);var c=s;a.fixLng&&(c=function(a,b){return b=b||{},b.lng=b.lng||c.lng,s(a,b)},c.lng=y),K.setCurrentLng(y),z&&E.setJqueryExt&&m();var d;if(z&&z.Deferred&&(d=z.Deferred()),!E.resStore){var e=I.toLanguages(E.lng);"string"==typeof E.preload&&(E.preload=[E.preload]);for(var f=0,g=E.preload.length;g>f;f++)for(var h=I.toLanguages(E.preload[f]),i=0,j=h.length;j>i;i++)e.indexOf(h[i])<0&&e.push(h[i]);return A.sync.load(e,E,function(a,e){B=e,initialized=!0,b&&b(c),d&&d.resolve(c)}),d?d.promise():void 0}return B=E.resStore,initialized=!0,b&&b(c),d&&d.resolve(c),d?d.promise():void 0}function f(a,b){"string"==typeof a&&(a=[a]);for(var c=0,d=a.length;d>c;c++)E.preload.indexOf(a[c])<0&&E.preload.push(a[c]);return e(b)}function g(a,b,c){"string"!=typeof b?(c=b,b=E.ns.defaultNs):E.ns.namespaces.indexOf(b)<0&&E.ns.namespaces.push(b),B[a]=B[a]||{},B[a][b]=B[a][b]||{},I.extend(B[a][b],c)}function h(a){E.ns.defaultNs=a}function i(a,b){j([a],b)}function j(a,b){var c={dynamicLoad:E.dynamicLoad,resGetPath:E.resGetPath,getAsync:E.getAsync,customLoad:E.customLoad,ns:{namespaces:a,defaultNs:""}},d=I.toLanguages(E.lng);"string"==typeof E.preload&&(E.preload=[E.preload]);for(var e=0,f=E.preload.length;f>e;e++)for(var g=I.toLanguages(E.preload[e]),h=0,i=g.length;i>h;h++)d.indexOf(g[h])<0&&d.push(g[h]);for(var j=[],k=0,l=d.length;l>k;k++){var m=!1,n=B[d[k]];if(n)for(var o=0,p=a.length;p>o;o++)n[a[o]]||(m=!0);else m=!0;m&&j.push(d[k])}j.length?A.sync._fetch(j,c,function(c,d){var e=a.length*j.length;I.each(a,function(a,c){E.ns.namespaces.indexOf(c)<0&&E.ns.namespaces.push(c),I.each(j,function(a,f){B[f]=B[f]||{},B[f][c]=d[f][c],e--,0===e&&b&&(E.useLocalStorage&&A.sync._storeLocal(B),b())})})}):b&&b()}function k(a,b,c){return"function"==typeof b&&(c=b,b={}),b.lng=a,e(b,c)}function l(){return y}function m(){function a(a,b,c){if(0!==b.length){var d="text";if(0===b.indexOf("[")){var e=b.split("]");b=e[1],d=e[0].substr(1,e[0].length-1)}b.indexOf(";")===b.length-1&&(b=b.substr(0,b.length-2));var f;"html"===d?(f=E.defaultValueFromContent?z.extend({defaultValue:a.html()},c):c,a.html(z.t(b,f))):"text"===d?(f=E.defaultValueFromContent?z.extend({defaultValue:a.text()},c):c,a.text(z.t(b,f))):(f=E.defaultValueFromContent?z.extend({defaultValue:a.attr(d)},c):c,a.attr(d,z.t(b,f)))}}function b(b,c){var d=b.attr(E.selectorAttr);if(d||"undefined"==typeof d||d===!1||(d=b.text()||b.val()),d){var e=b,f=b.data("i18n-target");if(f&&(e=b.find(f)||b),c||E.useDataAttrOptions!==!0||(c=b.data("i18n-options")),c=c||{},d.indexOf(";")>=0){var g=d.split(";");z.each(g,function(b,d){""!==d&&a(e,d,c)})}else a(e,d,c);E.useDataAttrOptions===!0&&b.data("i18n-options",c)}}z.t=z.t||s,z.fn.i18n=function(a){return this.each(function(){b(z(this),a);var c=z(this).find("["+E.selectorAttr+"]");c.each(function(){b(z(this),a)})})}}function n(a,b,c,d){if(!a)return a;if(d=d||b,a.indexOf(d.interpolationPrefix||E.interpolationPrefix)<0)return a;var e=d.interpolationPrefix?I.regexEscape(d.interpolationPrefix):E.interpolationPrefixEscaped,f=d.interpolationSuffix?I.regexEscape(d.interpolationSuffix):E.interpolationSuffixEscaped,g="HTML"+f;return I.each(b,function(b,h){var i=c?c+E.keyseparator+b:b;"object"==typeof h&&null!==h?a=n(a,h,i,d):d.escapeInterpolation||E.escapeInterpolation?(a=a.replace(new RegExp([e,i,g].join(""),"g"),h),a=a.replace(new RegExp([e,i,f].join(""),"g"),I.escape(h))):a=a.replace(new RegExp([e,i,f].join(""),"g"),h)}),a}function o(a,b){var c=",",d="{",e="}",f=I.extend({},b);for(delete f.postProcess;-1!=a.indexOf(E.reusePrefix)&&(C++,!(C>E.maxRecursion));){var g=a.lastIndexOf(E.reusePrefix),h=a.indexOf(E.reuseSuffix,g)+E.reuseSuffix.length,i=a.substring(g,h),j=i.replace(E.reusePrefix,"").replace(E.reuseSuffix,"");if(-1!=j.indexOf(c)){var k=j.indexOf(c);if(-1!=j.indexOf(d,k)&&-1!=j.indexOf(e,k)){var l=j.indexOf(d,k),m=j.indexOf(e,l)+e.length;try{f=I.extend(f,JSON.parse(j.substring(l,m))),j=j.substring(0,k)}catch(n){}}}var o=v(j,f);a=a.replace(i,o)}return a}function p(a){return a.context&&"string"==typeof a.context}function q(a){return void 0!==a.count&&"string"!=typeof a.count&&1!==a.count}function r(a,b){b=b||{};var c=t(a,b),d=w(a,b);return void 0!==d||d===c}function s(a,b){return initialized?(C=0,v.apply(null,arguments)):(I.log("i18next not finished initialization. you might have called t function before loading resources finished."),b.defaultValue||"")}function t(a,b){return void 0!==b.defaultValue?b.defaultValue:a}function u(){for(var a=[],b=1;b-1&&(e=c.split(E.nsseparator),i=e[0],c=e[1]),void 0===g&&E.sendMissing&&(b.lng?J.postMissing(h[0],i,c,f,h):J.postMissing(E.lng,i,c,f,h));var j=b.postProcess||E.postProcess;void 0!==g&&j&&L[j]&&(g=L[j](g,c,b));var k=f;if(f.indexOf(E.nsseparator)>-1&&(e=f.split(E.nsseparator),k=e[1]),k===c&&E.parseMissingKey&&(f=E.parseMissingKey(f)),void 0===g&&(f=n(f,b),f=o(f,b),j&&L[j])){var l=t(c,b);g=L[j](l,c,b)}return void 0!==g?g:f}function w(a,b){b=b||{};var c,d,e=t(a,b),f=D;if(!B)return e;if(b.lng&&(f=I.toLanguages(b.lng),!B[f[0]])){var g=E.getAsync;E.getAsync=!1,A.sync.load(f,E,function(a,b){I.extend(B,b),E.getAsync=g})}var h=b.ns||E.ns.defaultNs;if(a.indexOf(E.nsseparator)>-1){var i=a.split(E.nsseparator);h=i[0],a=i[1]}if(p(b)){c=I.extend({},b),delete c.context,c.defaultValue=E.contextNotFound;var j=h+E.nsseparator+a+"_"+b.context;if(d=s(j,c),d!=E.contextNotFound)return n(d,{context:b.context})}if(q(b)){c=I.extend({},b),delete c.count,c.defaultValue=E.pluralNotFound;var k=h+E.nsseparator+a+E.pluralSuffix,l=K.get(f[0],b.count);if(l>=0?k=k+"_"+l:1===l&&(k=h+E.nsseparator+a),d=s(k,c),d!=E.pluralNotFound)return n(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix})}for(var m,r=a.split(E.keyseparator),u=0,x=f.length;x>u&&void 0===m;u++){for(var y=f[u],z=0,C=B[y]&&B[y][h];r[z];)C=C&&C[r[z]],z++;if(void 0!==C){if("string"==typeof C)C=n(C,b),C=o(C,b);else if("[object Array]"!==Object.prototype.toString.apply(C)||E.returnObjectTrees||b.returnObjectTrees){if(null===C&&E.fallbackOnNull===!0)C=void 0;else if(null!==C)if(E.returnObjectTrees||b.returnObjectTrees){if("number"!=typeof C){var F={};I.each(C,function(c){F[c]=v(h+E.nsseparator+a+E.keyseparator+c,b)}),C=F}}else C="key '"+h+":"+a+" ("+y+")' "+"returned a object instead of string.",I.log(C)}else C=C.join("\n"),C=n(C,b),C=o(C,b);m=C}}if(void 0===m&&!b.isFallbackLookup&&(E.fallbackToDefaultNS===!0||E.fallbackNS&&E.fallbackNS.length>0))if(b.isFallbackLookup=!0,E.fallbackNS.length){for(var G=0,H=E.fallbackNS.length;H>G;G++)if(m=w(E.fallbackNS[G]+E.nsseparator+a,b)){var J=m.indexOf(E.nsseparator)>-1?m.split(E.nsseparator)[1]:m,L=e.indexOf(E.nsseparator)>-1?e.split(E.nsseparator)[1]:e;if(J!==L)break}}else m=w(a,b);return m}function x(){var a,b=[];if("undefined"!=typeof window&&(!function(){for(var a=window.location.search.substring(1),c=a.split("&"),d=0;d0){var f=c[d].substring(0,e),g=c[d].substring(e+1);b[f]=g}}}(),b[E.detectLngQS]&&(a=b[E.detectLngQS])),!a&&"undefined"!=typeof document&&E.useCookie){var c=I.cookie.read(E.cookieName);c&&(a=c)}return a||"undefined"==typeof navigator||(a=navigator.language?navigator.language:navigator.userLanguage),a}Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>0&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&1/0!=d&&d!=-1/0&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=c;arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d))));for(var e=d>=0?Math.min(d,c-1):c-Math.abs(d);e>=0;e--)if(e in b&&b[e]===a)return e;return-1});var y,z=void 0,A={},B={},C=0,D=[],E={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:"dev",fallbackNS:[],detectLngQS:"setLng",ns:"translation",fallbackOnNull:!0,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",cookieDomain:void 0,postProcess:void 0,parseMissingKey:void 0,shortcutFunction:"sprintf"},F={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},G={create:function(a,b,c,d){var e;if(c){var f=new Date;f.setTime(f.getTime()+1e3*60*c),e="; expires="+f.toGMTString()}else e="";d=d?"domain="+d+";":"",document.cookie=a+"="+b+e+";"+d+"path=/"},read:function(a){for(var b=a+"=",c=document.cookie.split(";"),d=0;d-1){var c=a.split("-");a=E.lowerCaseLng?c[0].toLowerCase()+"-"+c[1].toLowerCase():c[0].toLowerCase()+"-"+c[1].toUpperCase(),"unspecific"!==E.load&&b.push(a),"current"!==E.load&&b.push(c[0])}else b.push(a);return-1===b.indexOf(E.fallbackLng)&&E.fallbackLng&&b.push(E.fallbackLng),b},regexEscape:function(a){return a.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}};I.applyReplacement=n;var J={load:function(a,b,c){b.useLocalStorage?J._loadLocal(a,b,function(d,e){for(var f=[],g=0,h=a.length;h>g;g++)e[a[g]]||f.push(a[g]);f.length>0?J._fetch(f,b,function(a,b){I.extend(e,b),J._storeLocal(b),c(null,e)}):c(null,e)}):J._fetch(a,b,function(a,b){c(null,b)})},_loadLocal:function(a,b,c){var d={},e=(new Date).getTime();if(window.localStorage){var f=a.length;I.each(a,function(a,g){var h=window.localStorage.getItem("res_"+g);h&&(h=JSON.parse(h),h.i18nStamp&&h.i18nStamp+b.localStorageExpirationTime>e&&(d[g]=h)),f--,0===f&&c(null,d)})}},_storeLocal:function(a){if(window.localStorage)for(var b in a)a[b].i18nStamp=(new Date).getTime(),window.localStorage.setItem("res_"+b,JSON.stringify(a[b]))},_fetch:function(a,b,c){var d=b.ns,e={};if(b.dynamicLoad){var f=function(a,b){c(null,b)};if("function"==typeof b.customLoad)b.customLoad(a,d.namespaces,b,f);else{var g=n(b.resGetPath,{lng:a.join("+"),ns:d.namespaces.join("+")});I.ajax({url:g,success:function(a){I.log("loaded: "+g),f(null,a)},error:function(a,b,c){I.log("failed loading: "+g),f("failed loading resource.json error: "+c)},dataType:"json",async:b.getAsync})}}else{var h,i=d.namespaces.length*a.length;I.each(d.namespaces,function(d,f){I.each(a,function(a,d){var g=function(a,b){a&&(h=h||[],h.push(a)),e[d]=e[d]||{},e[d][f]=b,i--,0===i&&c(h,e)};"function"==typeof b.customLoad?b.customLoad(d,f,b,g):J._fetchOne(d,f,b,g)})})}},_fetchOne:function(a,b,c,d){var e=n(c.resGetPath,{lng:a,ns:b});I.ajax({url:e,success:function(a){I.log("loaded: "+e),d(null,a)},error:function(a,b,c){I.log("failed loading: "+e),d(c,{})},dataType:"json",async:c.getAsync})},postMissing:function(a,b,c,d,e){var f={};f[c]=d;var g=[];if("fallback"===E.sendMissingTo&&E.fallbackLng!==!1)g.push({lng:E.fallbackLng,url:n(E.resPostPath,{lng:E.fallbackLng,ns:b})});else if("current"===E.sendMissingTo||"fallback"===E.sendMissingTo&&E.fallbackLng===!1)g.push({lng:a,url:n(E.resPostPath,{lng:a,ns:b})});else if("all"===E.sendMissingTo)for(var h=0,i=e.length;i>h;h++)g.push({lng:e[h],url:n(E.resPostPath,{lng:e[h],ns:b})});for(var j=0,k=g.length;k>j;j++){var l=g[j];I.ajax({url:l.url,type:E.sendType,data:f,success:function(){I.log("posted missing key '"+c+"' to: "+l.url);for(var a=c.split("."),e=0,f=B[l.lng][b];a[e];)f=f[a[e]]=e===a.length-1?d:f[a[e]]||{},e++},error:function(){I.log("failed posting missing key '"+c+"' to: "+l.url)},dataType:"json",async:E.postAsync})}}},K={rules:{ach:{name:"Acholi",numbers:[1,2],plurals:function(a){return Number(a>1)}},af:{name:"Afrikaans",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ak:{name:"Akan",numbers:[1,2],plurals:function(a){return Number(a>1)}},am:{name:"Amharic",numbers:[1,2],plurals:function(a){return Number(a>1)}},an:{name:"Aragonese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ar:{name:"Arabic",numbers:[0,1,2,3,11,100],plurals:function(a){return Number(0===a?0:1==a?1:2==a?2:a%100>=3&&10>=a%100?3:a%100>=11?4:5)}},arn:{name:"Mapudungun",numbers:[1,2],plurals:function(a){return Number(a>1)}},ast:{name:"Asturian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ay:{name:"Aymará",numbers:[1],plurals:function(){return 0}},az:{name:"Azerbaijani",numbers:[1,2],plurals:function(a){return Number(1!=a)}},be:{name:"Belarusian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},bg:{name:"Bulgarian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},bn:{name:"Bengali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},bo:{name:"Tibetan",numbers:[1],plurals:function(){return 0}},br:{name:"Breton",numbers:[1,2],plurals:function(a){return Number(a>1)}},bs:{name:"Bosnian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},ca:{name:"Catalan",numbers:[1,2],plurals:function(a){return Number(1!=a)}},cgg:{name:"Chiga",numbers:[1],plurals:function(){return 0}},cs:{name:"Czech",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)}},csb:{name:"Kashubian",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},cy:{name:"Welsh",numbers:[1,2,3,8],plurals:function(a){return Number(1==a?0:2==a?1:8!=a&&11!=a?2:3)}},da:{name:"Danish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},de:{name:"German",numbers:[1,2],plurals:function(a){return Number(1!=a)}},dz:{name:"Dzongkha",numbers:[1],plurals:function(){return 0}},el:{name:"Greek",numbers:[1,2],plurals:function(a){return Number(1!=a)}},en:{name:"English",numbers:[1,2],plurals:function(a){return Number(1!=a)}},eo:{name:"Esperanto",numbers:[1,2],plurals:function(a){return Number(1!=a)}},es:{name:"Spanish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},es_ar:{name:"Argentinean Spanish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},et:{name:"Estonian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},eu:{name:"Basque",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fa:{name:"Persian",numbers:[1],plurals:function(){return 0}},fi:{name:"Finnish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fil:{name:"Filipino",numbers:[1,2],plurals:function(a){return Number(a>1)}},fo:{name:"Faroese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fr:{name:"French",numbers:[1,2],plurals:function(a){return Number(a>1)}},fur:{name:"Friulian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fy:{name:"Frisian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ga:{name:"Irish",numbers:[1,2,3,7,11],plurals:function(a){return Number(1==a?0:2==a?1:7>a?2:11>a?3:4)}},gd:{name:"Scottish Gaelic",numbers:[1,2,3,20],plurals:function(a){return Number(1==a||11==a?0:2==a||12==a?1:a>2&&20>a?2:3)}},gl:{name:"Galician",numbers:[1,2],plurals:function(a){return Number(1!=a)}},gu:{name:"Gujarati",numbers:[1,2],plurals:function(a){return Number(1!=a)}},gun:{name:"Gun",numbers:[1,2],plurals:function(a){return Number(a>1)}},ha:{name:"Hausa",numbers:[1,2],plurals:function(a){return Number(1!=a)}},he:{name:"Hebrew",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hi:{name:"Hindi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hr:{name:"Croatian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},hu:{name:"Hungarian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hy:{name:"Armenian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ia:{name:"Interlingua",numbers:[1,2],plurals:function(a){return Number(1!=a)}},id:{name:"Indonesian",numbers:[1],plurals:function(){return 0}},is:{name:"Icelandic",numbers:[1,2],plurals:function(a){return Number(1!=a%10||11==a%100)}},it:{name:"Italian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ja:{name:"Japanese",numbers:[1],plurals:function(){return 0}},jbo:{name:"Lojban",numbers:[1],plurals:function(){return 0}},jv:{name:"Javanese",numbers:[0,1],plurals:function(a){return Number(0!==a)}},ka:{name:"Georgian",numbers:[1],plurals:function(){return 0}},kk:{name:"Kazakh",numbers:[1],plurals:function(){return 0}},km:{name:"Khmer",numbers:[1],plurals:function(){return 0}},kn:{name:"Kannada",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ko:{name:"Korean",numbers:[1],plurals:function(){return 0}},ku:{name:"Kurdish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},kw:{name:"Cornish",numbers:[1,2,3,4],plurals:function(a){return Number(1==a?0:2==a?1:3==a?2:3)}},ky:{name:"Kyrgyz",numbers:[1],plurals:function(){return 0}},lb:{name:"Letzeburgesch",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ln:{name:"Lingala",numbers:[1,2],plurals:function(a){return Number(a>1)}},lo:{name:"Lao",numbers:[1],plurals:function(){return 0}},lt:{name:"Lithuanian",numbers:[1,2,10],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&(10>a%100||a%100>=20)?1:2)}},lv:{name:"Latvian",numbers:[0,1,2],plurals:function(a){return Number(1==a%10&&11!=a%100?0:0!==a?1:2)}},mai:{name:"Maithili",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mfe:{name:"Mauritian Creole",numbers:[1,2],plurals:function(a){return Number(a>1)}},mg:{name:"Malagasy",numbers:[1,2],plurals:function(a){return Number(a>1)}},mi:{name:"Maori",numbers:[1,2],plurals:function(a){return Number(a>1)}},mk:{name:"Macedonian",numbers:[1,2],plurals:function(a){return Number(1==a||1==a%10?0:1)}},ml:{name:"Malayalam",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mn:{name:"Mongolian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mnk:{name:"Mandinka",numbers:[0,1,2],plurals:function(a){return Number(1==a?1:2)}},mr:{name:"Marathi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ms:{name:"Malay",numbers:[1],plurals:function(){return 0}},mt:{name:"Maltese",numbers:[1,2,11,20],plurals:function(a){return Number(1==a?0:0===a||a%100>1&&11>a%100?1:a%100>10&&20>a%100?2:3)}},nah:{name:"Nahuatl",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nap:{name:"Neapolitan",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nb:{name:"Norwegian Bokmal",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ne:{name:"Nepali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nl:{name:"Dutch",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nn:{name:"Norwegian Nynorsk",numbers:[1,2],plurals:function(a){return Number(1!=a)}},no:{name:"Norwegian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nso:{name:"Northern Sotho",numbers:[1,2],plurals:function(a){return Number(1!=a)}},oc:{name:"Occitan",numbers:[1,2],plurals:function(a){return Number(a>1)}},or:{name:"Oriya",numbers:[2,1],plurals:function(a){return Number(1!=a)}},pa:{name:"Punjabi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pap:{name:"Papiamento",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pl:{name:"Polish",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},pms:{name:"Piemontese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ps:{name:"Pashto",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pt:{name:"Portuguese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pt_br:{name:"Brazilian Portuguese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},rm:{name:"Romansh",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ro:{name:"Romanian",numbers:[1,2,20],plurals:function(a){return Number(1==a?0:0===a||a%100>0&&20>a%100?1:2)}},ru:{name:"Russian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},sah:{name:"Yakut",numbers:[1],plurals:function(){return 0}},sco:{name:"Scots",numbers:[1,2],plurals:function(a){return Number(1!=a)}},se:{name:"Northern Sami",numbers:[1,2],plurals:function(a){return Number(1!=a)}},si:{name:"Sinhala",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sk:{name:"Slovak",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)}},sl:{name:"Slovenian",numbers:[5,1,2,3],plurals:function(a){return Number(1==a%100?1:2==a%100?2:3==a%100||4==a%100?3:0)}},so:{name:"Somali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},son:{name:"Songhay",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sq:{name:"Albanian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sr:{name:"Serbian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},su:{name:"Sundanese",numbers:[1],plurals:function(){return 0}},sv:{name:"Swedish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sw:{name:"Swahili",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ta:{name:"Tamil",numbers:[1,2],plurals:function(a){return Number(1!=a)}},te:{name:"Telugu",numbers:[1,2],plurals:function(a){return Number(1!=a)}},tg:{name:"Tajik",numbers:[1,2],plurals:function(a){return Number(a>1)}},th:{name:"Thai",numbers:[1],plurals:function(){return 0}},ti:{name:"Tigrinya",numbers:[1,2],plurals:function(a){return Number(a>1)}},tk:{name:"Turkmen",numbers:[1,2],plurals:function(a){return Number(1!=a)}},tr:{name:"Turkish",numbers:[1,2],plurals:function(a){return Number(a>1)}},tt:{name:"Tatar",numbers:[1],plurals:function(){return 0}},ug:{name:"Uyghur",numbers:[1],plurals:function(){return 0}},uk:{name:"Ukrainian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},ur:{name:"Urdu",numbers:[1,2],plurals:function(a){return Number(1!=a)}},uz:{name:"Uzbek",numbers:[1,2],plurals:function(a){return Number(a>1)}},vi:{name:"Vietnamese",numbers:[1],plurals:function(){return 0}},wa:{name:"Walloon",numbers:[1,2],plurals:function(a){return Number(a>1)}},wo:{name:"Wolof",numbers:[1],plurals:function(){return 0}},yo:{name:"Yoruba",numbers:[1,2],plurals:function(a){return Number(1!=a)}},zh:{name:"Chinese",numbers:[1],plurals:function(){return 0}}},addRule:function(a,b){K.rules[a]=b},setCurrentLng:function(a){if(!K.currentRule||K.currentRule.lng!==a){var b=a.split("-");K.currentRule={lng:a,rule:K.rules[b[0]]}}},get:function(a,b){function c(b,c){var d;if(d=K.currentRule&&K.currentRule.lng===a?K.currentRule.rule:K.rules[b]){var e=d.plurals(c),f=d.numbers[e];return 2===d.numbers.length&&1===d.numbers[0]&&(2===f?f=-1:1===f&&(f=1)),f}return 1===c?"1":"-1"}var d=a.split("-");return c(d[0],b)}},L={},M=function(a,b){L[a]=b},N=function(){function a(a){return Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}function b(a,b){for(var c=[];b>0;c[--b]=a);return c.join("")}var c=function(){return c.cache.hasOwnProperty(arguments[0])||(c.cache[arguments[0]]=c.parse(arguments[0])),c.format.call(null,c.cache[arguments[0]],arguments)};return c.format=function(c,d){var e,f,g,h,i,j,k,l=1,m=c.length,n="",o=[];for(f=0;m>f;f++)if(n=a(c[f]),"string"===n)o.push(c[f]);else if("array"===n){if(h=c[f],h[2])for(e=d[l],g=0;g=0?"+"+e:e,j=h[4]?"0"==h[4]?"0":h[4].charAt(1):" ",k=h[6]-String(e).length,i=h[6]?b(j,k):"",o.push(h[5]?e+i:i+e)}return o.join("")},c.cache={},c.parse=function(a){for(var b=a,c=[],d=[],e=0;b;){if(null!==(c=/^[^\x25]+/.exec(b)))d.push(c[0]);else if(null!==(c=/^\x25{2}/.exec(b)))d.push("%");else{if(null===(c=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(b)))throw"[sprintf] huh?";if(c[2]){e|=1;var f=[],g=c[2],h=[];if(null===(h=/^([a-z_][a-z_\d]*)/i.exec(g)))throw"[sprintf] huh?";for(f.push(h[1]);""!==(g=g.substring(h[0].length));)if(null!==(h=/^\.([a-z_][a-z_\d]*)/i.exec(g)))f.push(h[1]);else{if(null===(h=/^\[(\d+)\]/.exec(g)))throw"[sprintf] huh?";f.push(h[1])}c[2]=f}else e|=2;if(3===e)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";d.push(c)}b=b.substring(c[0].length)}return d},c}(),O=function(a,b){return b.unshift(a),N.apply(null,b)};return M("sprintf",function(a,b,c){return c.sprintf?"[object Array]"===Object.prototype.toString.apply(c.sprintf)?O(a,c.sprintf):"object"==typeof c.sprintf?N(a,c.sprintf):a:a}),A.init=e,A.setLng=k,A.preload=f,A.addResourceBundle=g,A.loadNamespace=i,A.loadNamespaces=j,A.setDefaultNamespace=h,A.t=s,A.translate=s,A.exists=r,A.detectLanguage=I.detectLanguage,A.pluralExtensions=K,A.sync=J,A.functions=I,A.lng=l,A.addPostProcessor=M,A.options=E,A}); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd-1.7.0.zip b/libs/i18next/release/i18next.amd-1.7.0.zip new file mode 100644 index 00000000..fe4fb08a Binary files /dev/null and b/libs/i18next/release/i18next.amd-1.7.0.zip differ diff --git a/libs/i18next/release/i18next.amd-1.7.1.js b/libs/i18next/release/i18next.amd-1.7.1.js new file mode 100644 index 00000000..aac35165 --- /dev/null +++ b/libs/i18next/release/i18next.amd-1.7.1.js @@ -0,0 +1,2666 @@ +// i18next, v1.7.1 +// Copyright (c)2014 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function (root, factory) { + if (typeof exports === 'object') { + + module.exports = factory(); + + } else if (typeof define === 'function' && define.amd) { + + define([], factory); + + } +}(this, function () { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + var $ = undefined + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = [] + , initialized = false; + + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: 'dev', + fallbackNS: [], + detectLngQS: 'setLng', + ns: 'translation', + fallbackOnNull: true, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + cookieDomain: undefined, + + postProcess: undefined, + parseMissingKey: undefined, + + shortcutFunction: 'sprintf' // or: defaultValue + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + return JSON.parse(data); + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + if (status === 200) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes,domain) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + domain = (domain)? "domain="+domain+";" : ""; + document.cookie = name+"="+value+expires+";"+domain+"path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes,domain) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : _ajax, + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + toLanguages: function(lng) { + var languages = []; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + + if (o.load !== 'unspecific') languages.push(lng); + if (o.load !== 'current') languages.push(parts[0]); + } else { + languages.push(lng); + } + + if (languages.indexOf(o.fallbackLng) === -1 && o.fallbackLng) languages.push(o.fallbackLng); + + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + delete o.fixLng; /* passed in each time */ + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + if (o.lng) { + // set cookie with lng set (as detectLanguage will set cookie on need) + if (o.useCookie) f.cookie.create(o.cookieName, o.lng, o.cookieExpirationTime, o.cookieDomain); + } else { + o.lng = o.fallbackLng; + if (o.useCookie) f.cookie.remove(o.cookieName); + } + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + var lngTranslate = translate; + if (options.fixLng) { + lngTranslate = function(key, options) { + options = options || {}; + options.lng = options.lng || lngTranslate.lng; + return translate(key, options); + }; + lngTranslate.lng = currentLng; + } + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + initialized = true; + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + initialized = true; + + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + f.extend(resStore[lng][ns], resources); + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, options, cb) { + if (typeof options === 'function') { + cb = options; + options = {}; + } + options.lng = lng; + return init(options, cb); + } + + function lng() { + return currentLng; + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } + else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key && typeof key !== 'undefined' && key !== false) key = ele.text() || ele.val(); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + f.each(replacementHash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), value); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.escape(value)); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), value); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, translated_token); + } + return translated; + } + + function hasContext(options) { + return (options.context && typeof options.context == 'string'); + } + + function needsPlural(options) { + return (options.count !== undefined && typeof options.count != 'string' && options.count !== 1); + } + + function exists(key, options) { + options = options || {}; + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + options = options || {}; + + if (!initialized) { + f.log('i18next not finished initialization. you might have called t function before loading resources finished.') + return options.defaultValue || ''; + }; + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _getDefaultValue(key, options) { + return (options.defaultValue !== undefined) ? options.defaultValue : key; + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(potentialKeys, options) { + if (typeof options == 'string') { + if (o.shortcutFunction === 'sprintf') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else if (o.shortcutFunction === 'defaultValue') { + options = { + defaultValue: options + } + } + } else { + options = options || {}; + } + + if (typeof potentialKeys == 'string') { + potentialKeys = [potentialKeys]; + } + + var key = null; + + for (var i = 0; i < potentialKeys.length; i++) { + key = potentialKeys[i]; + if (exists(key)) { + break; + } + } + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng) : languages + , ns = options.ns || o.ns.defaultNs + , parts; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing) { + if (options.lng) { + sync.postMissing(lngs[0], ns, key, notFound, lngs); + } else { + sync.postMissing(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found !== undefined && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + // process notFound if function exists + var splitNotFound = notFound; + if (notFound.indexOf(o.nsseparator) > -1) { + parts = notFound.split(o.nsseparator); + splitNotFound = parts[1]; + } + if (splitNotFound === key && o.parseMissingKey) { + notFound = o.parseMissingKey(notFound); + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessor && postProcessors[postProcessor]) { + var val = _getDefaultValue(key, options); + found = postProcessors[postProcessor](val, key, options); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options){ + options = options || {}; + + var optionWithoutCount, translated + , notFound = _getDefaultValue(key, options) + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + if (options.lng) { + lngs = f.toLanguages(options.lng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.count; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(lngs[0], options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + + translated = translate(pluralKey, optionWithoutCount); + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } // else continue translation with original/singular key + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (Object.prototype.toString.apply(value) === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned an object instead of string.'; + f.log(value); + } else if (typeof value !== 'number') { + var copy = {}; // apply child translation on a copy + f.each(value, function(m) { + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + }); + value = copy; + } + } + + if (typeof value === 'string' && value.trim() === '' && o.fallbackOnEmpty === true) + value = undefined; + + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length > 0))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + } + + return found; + } + function detectLanguage() { + var detectedLng; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var parms = query.split('&'); + for (var i=0; i 0) { + var key = parms[i].substring(0,pos); + var val = parms[i].substring(pos+1); + qsParm[key] = val; + } + } + })(); + if (qsParm[o.detectLngQS]) { + detectedLng = qsParm[o.detectLngQS]; + } + } + + // get from cookie + if (!detectedLng && typeof document !== 'undefined' && o.useCookie ) { + var c = f.cookie.read(o.cookieName); + if (c) detectedLng = c; + } + + // get from navigator + if (!detectedLng && typeof navigator !== 'undefined') { + detectedLng = (navigator.language) ? navigator.language : navigator.userLanguage; + } + + return detectedLng; + } + var sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + window.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback' && o.fallbackLng !== false) { + urls.push({lng: o.fallbackLng, url: applyReplacement(o.resPostPath, { lng: o.fallbackLng, ns: ns })}); + } else if (o.sendMissingTo === 'current' || (o.sendMissingTo === 'fallback' && o.fallbackLng === false) ) { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + } + }; + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + var pluralExtensions = { + + rules: { + "ach": { + "name": "Acholi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "af": { + "name": "Afrikaans", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ak": { + "name": "Akan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "am": { + "name": "Amharic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "an": { + "name": "Aragonese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ar": { + "name": "Arabic", + "numbers": [ + 0, + 1, + 2, + 3, + 11, + 100 + ], + "plurals": function(n) { return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5); } + }, + "arn": { + "name": "Mapudungun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ast": { + "name": "Asturian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ay": { + "name": "Aymar\u00e1", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "az": { + "name": "Azerbaijani", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "be": { + "name": "Belarusian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "bg": { + "name": "Bulgarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bn": { + "name": "Bengali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bo": { + "name": "Tibetan", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "br": { + "name": "Breton", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "bs": { + "name": "Bosnian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ca": { + "name": "Catalan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "cgg": { + "name": "Chiga", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "cs": { + "name": "Czech", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "csb": { + "name": "Kashubian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "cy": { + "name": "Welsh", + "numbers": [ + 1, + 2, + 3, + 8 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3); } + }, + "da": { + "name": "Danish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "de": { + "name": "German", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "dz": { + "name": "Dzongkha", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "el": { + "name": "Greek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "en": { + "name": "English", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eo": { + "name": "Esperanto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es": { + "name": "Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es_ar": { + "name": "Argentinean Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "et": { + "name": "Estonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eu": { + "name": "Basque", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fa": { + "name": "Persian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "fi": { + "name": "Finnish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fil": { + "name": "Filipino", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fo": { + "name": "Faroese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fr": { + "name": "French", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fur": { + "name": "Friulian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fy": { + "name": "Frisian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ga": { + "name": "Irish", + "numbers": [ + 1, + 2, + 3, + 7, + 11 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;} + }, + "gd": { + "name": "Scottish Gaelic", + "numbers": [ + 1, + 2, + 3, + 20 + ], + "plurals": function(n) { return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3); } + }, + "gl": { + "name": "Galician", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gu": { + "name": "Gujarati", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gun": { + "name": "Gun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ha": { + "name": "Hausa", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "he": { + "name": "Hebrew", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hi": { + "name": "Hindi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hr": { + "name": "Croatian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "hu": { + "name": "Hungarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hy": { + "name": "Armenian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ia": { + "name": "Interlingua", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "id": { + "name": "Indonesian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "is": { + "name": "Icelandic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n%10!=1 || n%100==11); } + }, + "it": { + "name": "Italian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ja": { + "name": "Japanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jbo": { + "name": "Lojban", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jv": { + "name": "Javanese", + "numbers": [ + 0, + 1 + ], + "plurals": function(n) { return Number(n !== 0); } + }, + "ka": { + "name": "Georgian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kk": { + "name": "Kazakh", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "km": { + "name": "Khmer", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kn": { + "name": "Kannada", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ko": { + "name": "Korean", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ku": { + "name": "Kurdish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "kw": { + "name": "Cornish", + "numbers": [ + 1, + 2, + 3, + 4 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3); } + }, + "ky": { + "name": "Kyrgyz", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lb": { + "name": "Letzeburgesch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ln": { + "name": "Lingala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "lo": { + "name": "Lao", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lt": { + "name": "Lithuanian", + "numbers": [ + 1, + 2, + 10 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "lv": { + "name": "Latvian", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2); } + }, + "mai": { + "name": "Maithili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mfe": { + "name": "Mauritian Creole", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mg": { + "name": "Malagasy", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mi": { + "name": "Maori", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mk": { + "name": "Macedonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 || n%10==1 ? 0 : 1); } + }, + "ml": { + "name": "Malayalam", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mn": { + "name": "Mongolian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mnk": { + "name": "Mandinka", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(0 ? 0 : n==1 ? 1 : 2); } + }, + "mr": { + "name": "Marathi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ms": { + "name": "Malay", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "mt": { + "name": "Maltese", + "numbers": [ + 1, + 2, + 11, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3); } + }, + "nah": { + "name": "Nahuatl", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nap": { + "name": "Neapolitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nb": { + "name": "Norwegian Bokmal", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ne": { + "name": "Nepali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nl": { + "name": "Dutch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nn": { + "name": "Norwegian Nynorsk", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "no": { + "name": "Norwegian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nso": { + "name": "Northern Sotho", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "oc": { + "name": "Occitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "or": { + "name": "Oriya", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pa": { + "name": "Punjabi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pap": { + "name": "Papiamento", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pl": { + "name": "Polish", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "pms": { + "name": "Piemontese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ps": { + "name": "Pashto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt": { + "name": "Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt_br": { + "name": "Brazilian Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "rm": { + "name": "Romansh", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ro": { + "name": "Romanian", + "numbers": [ + 1, + 2, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2); } + }, + "ru": { + "name": "Russian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "sah": { + "name": "Yakut", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sco": { + "name": "Scots", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "se": { + "name": "Northern Sami", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "si": { + "name": "Sinhala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sk": { + "name": "Slovak", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "sl": { + "name": "Slovenian", + "numbers": [ + 5, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }, + "so": { + "name": "Somali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "son": { + "name": "Songhay", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sq": { + "name": "Albanian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sr": { + "name": "Serbian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "su": { + "name": "Sundanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sv": { + "name": "Swedish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sw": { + "name": "Swahili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ta": { + "name": "Tamil", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "te": { + "name": "Telugu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tg": { + "name": "Tajik", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "th": { + "name": "Thai", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ti": { + "name": "Tigrinya", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tk": { + "name": "Turkmen", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tr": { + "name": "Turkish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tt": { + "name": "Tatar", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ug": { + "name": "Uyghur", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "uk": { + "name": "Ukrainian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ur": { + "name": "Urdu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "uz": { + "name": "Uzbek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "vi": { + "name": "Vietnamese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "wa": { + "name": "Walloon", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "wo": { + "name": "Wolof", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "yo": { + "name": "Yoruba", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "zh": { + "name": "Chinese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + } + }, + + // for demonstration only sl and ar is added but you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i = ext.plurals(c); + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[0], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + + return i18n; + +})); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd-1.7.1.min.js b/libs/i18next/release/i18next.amd-1.7.1.min.js new file mode 100644 index 00000000..1c182abc --- /dev/null +++ b/libs/i18next/release/i18next.amd-1.7.1.min.js @@ -0,0 +1,5 @@ +// i18next, v1.7.1 +// Copyright (c)2014 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +!function(a,b){"object"==typeof exports?module.exports=b():"function"==typeof define&&define.amd&&define([],b)}(this,function(){function a(a,b){if(!b||"function"==typeof b)return a;for(var c in b)a[c]=b[c];return a}function b(a,b,c){var d,e=0,f=a.length,g=void 0===f||"function"==typeof a;if(c)if(g){for(d in a)if(b.apply(a[d],c)===!1)break}else for(;f>e&&b.apply(a[e++],c)!==!1;);else if(g){for(d in a)if(b.call(a[d],d,a[d])===!1)break}else for(;f>e&&b.call(a[e],e,a[e++])!==!1;);return a}function c(a){return"string"==typeof a?a.replace(/[&<>"'\/]/g,function(a){return G[a]}):a}function d(a){var b=function(a){if(window.XMLHttpRequest)return a(null,new XMLHttpRequest);if(window.ActiveXObject)try{return a(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(b){return a(null,new ActiveXObject("Microsoft.XMLHTTP"))}return a(new Error)},c=function(a){if("string"==typeof a)return a;var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")},d=function(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;cd?b+=String.fromCharCode(d):d>127&&2048>d?(b+=String.fromCharCode(d>>6|192),b+=String.fromCharCode(63&d|128)):(b+=String.fromCharCode(d>>12|224),b+=String.fromCharCode(d>>6&63|128),b+=String.fromCharCode(63&d|128))}return b},e=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";a=d(a);var c,e,f,g,h,i,j,k="",l=0;do c=a.charCodeAt(l++),e=a.charCodeAt(l++),f=a.charCodeAt(l++),g=c>>2,h=(3&c)<<4|e>>4,i=(15&e)<<2|f>>6,j=63&f,isNaN(e)?i=j=64:isNaN(f)&&(j=64),k+=b.charAt(g)+b.charAt(h)+b.charAt(i)+b.charAt(j),c=e=f="",g=h=i=j="";while(l1&&(d+=d.indexOf("?")>-1?"&"+k:"?"+k),e.jsonp){var l=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=d,void l.appendChild(m)}}b(function(b,c){if(b)return h(b);c.open(a,d,e.async);for(var f in j)j.hasOwnProperty(f)&&c.setRequestHeader(f,j[f]);c.onreadystatechange=function(){if(4===c.readyState){var a=c.responseText||"";if(!h)return;h(c.status,{text:function(){return a},json:function(){return JSON.parse(a)}})}},c.send(i)})},h={authBasic:function(a,b){g.headers.Authorization="Basic "+e(a+":"+b)},connect:function(a,b,c){return g("CONNECT",a,b,c)},del:function(a,b,c){return g("DELETE",a,b,c)},get:function(a,b,c){return g("GET",a,b,c)},head:function(a,b,c){return g("HEAD",a,b,c)},headers:function(a){g.headers=a||{}},isAllowed:function(a,b,c){this.options(a,function(a,d){c(-1!==d.text().indexOf(b))})},options:function(a,b,c){return g("OPTIONS",a,b,c)},patch:function(a,b,c){return g("PATCH",a,b,c)},post:function(a,b,c){return g("POST",a,b,c)},put:function(a,b,c){return g("PUT",a,b,c)},trace:function(a,b,c){return g("TRACE",a,b,c)}},i=a.type?a.type.toLowerCase():"get";h[i](a.url,a,function(b,c){200===b?a.success(c.json(),b,null):a.error(c.text(),b,null)})}function e(a,b){"function"==typeof a&&(b=a,a={}),a=a||{},J.extend(F,a),delete F.fixLng,"string"==typeof F.ns&&(F.ns={namespaces:[F.ns],defaultNs:F.ns}),"string"==typeof F.fallbackNS&&(F.fallbackNS=[F.fallbackNS]),F.interpolationPrefixEscaped=J.regexEscape(F.interpolationPrefix),F.interpolationSuffixEscaped=J.regexEscape(F.interpolationSuffix),F.lng||(F.lng=J.detectLanguage()),F.lng?F.useCookie&&J.cookie.create(F.cookieName,F.lng,F.cookieExpirationTime,F.cookieDomain):(F.lng=F.fallbackLng,F.useCookie&&J.cookie.remove(F.cookieName)),D=J.toLanguages(F.lng),y=D[0],J.log("currentLng set to: "+y);var c=s;a.fixLng&&(c=function(a,b){return b=b||{},b.lng=b.lng||c.lng,s(a,b)},c.lng=y),L.setCurrentLng(y),z&&F.setJqueryExt&&m();var d;if(z&&z.Deferred&&(d=z.Deferred()),!F.resStore){var e=J.toLanguages(F.lng);"string"==typeof F.preload&&(F.preload=[F.preload]);for(var f=0,g=F.preload.length;g>f;f++)for(var h=J.toLanguages(F.preload[f]),i=0,j=h.length;j>i;i++)e.indexOf(h[i])<0&&e.push(h[i]);return A.sync.load(e,F,function(a,e){B=e,E=!0,b&&b(c),d&&d.resolve(c)}),d?d.promise():void 0}return B=F.resStore,E=!0,b&&b(c),d&&d.resolve(c),d?d.promise():void 0}function f(a,b){"string"==typeof a&&(a=[a]);for(var c=0,d=a.length;d>c;c++)F.preload.indexOf(a[c])<0&&F.preload.push(a[c]);return e(b)}function g(a,b,c){"string"!=typeof b?(c=b,b=F.ns.defaultNs):F.ns.namespaces.indexOf(b)<0&&F.ns.namespaces.push(b),B[a]=B[a]||{},B[a][b]=B[a][b]||{},J.extend(B[a][b],c)}function h(a){F.ns.defaultNs=a}function i(a,b){j([a],b)}function j(a,b){var c={dynamicLoad:F.dynamicLoad,resGetPath:F.resGetPath,getAsync:F.getAsync,customLoad:F.customLoad,ns:{namespaces:a,defaultNs:""}},d=J.toLanguages(F.lng);"string"==typeof F.preload&&(F.preload=[F.preload]);for(var e=0,f=F.preload.length;f>e;e++)for(var g=J.toLanguages(F.preload[e]),h=0,i=g.length;i>h;h++)d.indexOf(g[h])<0&&d.push(g[h]);for(var j=[],k=0,l=d.length;l>k;k++){var m=!1,n=B[d[k]];if(n)for(var o=0,p=a.length;p>o;o++)n[a[o]]||(m=!0);else m=!0;m&&j.push(d[k])}j.length?A.sync._fetch(j,c,function(c,d){var e=a.length*j.length;J.each(a,function(a,c){F.ns.namespaces.indexOf(c)<0&&F.ns.namespaces.push(c),J.each(j,function(a,f){B[f]=B[f]||{},B[f][c]=d[f][c],e--,0===e&&b&&(F.useLocalStorage&&A.sync._storeLocal(B),b())})})}):b&&b()}function k(a,b,c){return"function"==typeof b&&(c=b,b={}),b.lng=a,e(b,c)}function l(){return y}function m(){function a(a,b,c){if(0!==b.length){var d="text";if(0===b.indexOf("[")){var e=b.split("]");b=e[1],d=e[0].substr(1,e[0].length-1)}b.indexOf(";")===b.length-1&&(b=b.substr(0,b.length-2));var f;"html"===d?(f=F.defaultValueFromContent?z.extend({defaultValue:a.html()},c):c,a.html(z.t(b,f))):"text"===d?(f=F.defaultValueFromContent?z.extend({defaultValue:a.text()},c):c,a.text(z.t(b,f))):(f=F.defaultValueFromContent?z.extend({defaultValue:a.attr(d)},c):c,a.attr(d,z.t(b,f)))}}function b(b,c){var d=b.attr(F.selectorAttr);if(d||"undefined"==typeof d||d===!1||(d=b.text()||b.val()),d){var e=b,f=b.data("i18n-target");if(f&&(e=b.find(f)||b),c||F.useDataAttrOptions!==!0||(c=b.data("i18n-options")),c=c||{},d.indexOf(";")>=0){var g=d.split(";");z.each(g,function(b,d){""!==d&&a(e,d,c)})}else a(e,d,c);F.useDataAttrOptions===!0&&b.data("i18n-options",c)}}z.t=z.t||s,z.fn.i18n=function(a){return this.each(function(){b(z(this),a);var c=z(this).find("["+F.selectorAttr+"]");c.each(function(){b(z(this),a)})})}}function n(a,b,c,d){if(!a)return a;if(d=d||b,a.indexOf(d.interpolationPrefix||F.interpolationPrefix)<0)return a;var e=d.interpolationPrefix?J.regexEscape(d.interpolationPrefix):F.interpolationPrefixEscaped,f=d.interpolationSuffix?J.regexEscape(d.interpolationSuffix):F.interpolationSuffixEscaped,g="HTML"+f;return J.each(b,function(b,h){var i=c?c+F.keyseparator+b:b;"object"==typeof h&&null!==h?a=n(a,h,i,d):d.escapeInterpolation||F.escapeInterpolation?(a=a.replace(new RegExp([e,i,g].join(""),"g"),h),a=a.replace(new RegExp([e,i,f].join(""),"g"),J.escape(h))):a=a.replace(new RegExp([e,i,f].join(""),"g"),h)}),a}function o(a,b){var c=",",d="{",e="}",f=J.extend({},b);for(delete f.postProcess;-1!=a.indexOf(F.reusePrefix)&&(C++,!(C>F.maxRecursion));){var g=a.lastIndexOf(F.reusePrefix),h=a.indexOf(F.reuseSuffix,g)+F.reuseSuffix.length,i=a.substring(g,h),j=i.replace(F.reusePrefix,"").replace(F.reuseSuffix,"");if(-1!=j.indexOf(c)){var k=j.indexOf(c);if(-1!=j.indexOf(d,k)&&-1!=j.indexOf(e,k)){var l=j.indexOf(d,k),m=j.indexOf(e,l)+e.length;try{f=J.extend(f,JSON.parse(j.substring(l,m))),j=j.substring(0,k)}catch(n){}}}var o=v(j,f);a=a.replace(i,o)}return a}function p(a){return a.context&&"string"==typeof a.context}function q(a){return void 0!==a.count&&"string"!=typeof a.count&&1!==a.count}function r(a,b){b=b||{};var c=t(a,b),d=w(a,b);return void 0!==d||d===c}function s(a,b){return b=b||{},E?(C=0,v.apply(null,arguments)):(J.log("i18next not finished initialization. you might have called t function before loading resources finished."),b.defaultValue||"")}function t(a,b){return void 0!==b.defaultValue?b.defaultValue:a}function u(){for(var a=[],b=1;b-1&&(e=c.split(F.nsseparator),i=e[0],c=e[1]),void 0===g&&F.sendMissing&&(b.lng?K.postMissing(h[0],i,c,f,h):K.postMissing(F.lng,i,c,f,h));var j=b.postProcess||F.postProcess;void 0!==g&&j&&M[j]&&(g=M[j](g,c,b));var k=f;if(f.indexOf(F.nsseparator)>-1&&(e=f.split(F.nsseparator),k=e[1]),k===c&&F.parseMissingKey&&(f=F.parseMissingKey(f)),void 0===g&&(f=n(f,b),f=o(f,b),j&&M[j])){var l=t(c,b);g=M[j](l,c,b)}return void 0!==g?g:f}function w(a,b){b=b||{};var c,d,e=t(a,b),f=D;if(!B)return e;if(b.lng&&(f=J.toLanguages(b.lng),!B[f[0]])){var g=F.getAsync;F.getAsync=!1,A.sync.load(f,F,function(a,b){J.extend(B,b),F.getAsync=g})}var h=b.ns||F.ns.defaultNs;if(a.indexOf(F.nsseparator)>-1){var i=a.split(F.nsseparator);h=i[0],a=i[1]}if(p(b)){c=J.extend({},b),delete c.context,c.defaultValue=F.contextNotFound;var j=h+F.nsseparator+a+"_"+b.context;if(d=s(j,c),d!=F.contextNotFound)return n(d,{context:b.context})}if(q(b)){c=J.extend({},b),delete c.count,c.defaultValue=F.pluralNotFound;var k=h+F.nsseparator+a+F.pluralSuffix,l=L.get(f[0],b.count);if(l>=0?k=k+"_"+l:1===l&&(k=h+F.nsseparator+a),d=s(k,c),d!=F.pluralNotFound)return n(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix})}for(var m,r=a.split(F.keyseparator),u=0,x=f.length;x>u&&void 0===m;u++){for(var y=f[u],z=0,C=B[y]&&B[y][h];r[z];)C=C&&C[r[z]],z++;if(void 0!==C){if("string"==typeof C)C=n(C,b),C=o(C,b);else if("[object Array]"!==Object.prototype.toString.apply(C)||F.returnObjectTrees||b.returnObjectTrees){if(null===C&&F.fallbackOnNull===!0)C=void 0;else if(null!==C)if(F.returnObjectTrees||b.returnObjectTrees){if("number"!=typeof C){var E={};J.each(C,function(c){E[c]=v(h+F.nsseparator+a+F.keyseparator+c,b)}),C=E}}else C="key '"+h+":"+a+" ("+y+")' returned an object instead of string.",J.log(C)}else C=C.join("\n"),C=n(C,b),C=o(C,b);"string"==typeof C&&""===C.trim()&&F.fallbackOnEmpty===!0&&(C=void 0),m=C}}if(void 0===m&&!b.isFallbackLookup&&(F.fallbackToDefaultNS===!0||F.fallbackNS&&F.fallbackNS.length>0))if(b.isFallbackLookup=!0,F.fallbackNS.length){for(var G=0,H=F.fallbackNS.length;H>G;G++)if(m=w(F.fallbackNS[G]+F.nsseparator+a,b)){var I=m.indexOf(F.nsseparator)>-1?m.split(F.nsseparator)[1]:m,K=e.indexOf(F.nsseparator)>-1?e.split(F.nsseparator)[1]:e;if(I!==K)break}}else m=w(a,b);return m}function x(){var a,b=[];if("undefined"!=typeof window&&(!function(){for(var a=window.location.search.substring(1),c=a.split("&"),d=0;d0){var f=c[d].substring(0,e),g=c[d].substring(e+1);b[f]=g}}}(),b[F.detectLngQS]&&(a=b[F.detectLngQS])),!a&&"undefined"!=typeof document&&F.useCookie){var c=J.cookie.read(F.cookieName);c&&(a=c)}return a||"undefined"==typeof navigator||(a=navigator.language?navigator.language:navigator.userLanguage),a}Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>0&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&1/0!=d&&d!=-1/0&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=c;arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d))));for(var e=d>=0?Math.min(d,c-1):c-Math.abs(d);e>=0;e--)if(e in b&&b[e]===a)return e;return-1});var y,z=void 0,A={},B={},C=0,D=[],E=!1,F={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:"dev",fallbackNS:[],detectLngQS:"setLng",ns:"translation",fallbackOnNull:!0,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",cookieDomain:void 0,postProcess:void 0,parseMissingKey:void 0,shortcutFunction:"sprintf"},G={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},H={create:function(a,b,c,d){var e;if(c){var f=new Date;f.setTime(f.getTime()+60*c*1e3),e="; expires="+f.toGMTString()}else e="";d=d?"domain="+d+";":"",document.cookie=a+"="+b+e+";"+d+"path=/"},read:function(a){for(var b=a+"=",c=document.cookie.split(";"),d=0;d-1){var c=a.split("-");a=F.lowerCaseLng?c[0].toLowerCase()+"-"+c[1].toLowerCase():c[0].toLowerCase()+"-"+c[1].toUpperCase(),"unspecific"!==F.load&&b.push(a),"current"!==F.load&&b.push(c[0])}else b.push(a);return-1===b.indexOf(F.fallbackLng)&&F.fallbackLng&&b.push(F.fallbackLng),b},regexEscape:function(a){return a.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}};J.applyReplacement=n;var K={load:function(a,b,c){b.useLocalStorage?K._loadLocal(a,b,function(d,e){for(var f=[],g=0,h=a.length;h>g;g++)e[a[g]]||f.push(a[g]);f.length>0?K._fetch(f,b,function(a,b){J.extend(e,b),K._storeLocal(b),c(null,e)}):c(null,e)}):K._fetch(a,b,function(a,b){c(null,b)})},_loadLocal:function(a,b,c){var d={},e=(new Date).getTime();if(window.localStorage){var f=a.length;J.each(a,function(a,g){var h=window.localStorage.getItem("res_"+g);h&&(h=JSON.parse(h),h.i18nStamp&&h.i18nStamp+b.localStorageExpirationTime>e&&(d[g]=h)),f--,0===f&&c(null,d)})}},_storeLocal:function(a){if(window.localStorage)for(var b in a)a[b].i18nStamp=(new Date).getTime(),window.localStorage.setItem("res_"+b,JSON.stringify(a[b]))},_fetch:function(a,b,c){var d=b.ns,e={};if(b.dynamicLoad){var f=function(a,b){c(null,b)};if("function"==typeof b.customLoad)b.customLoad(a,d.namespaces,b,f);else{var g=n(b.resGetPath,{lng:a.join("+"),ns:d.namespaces.join("+")});J.ajax({url:g,success:function(a){J.log("loaded: "+g),f(null,a)},error:function(a,b,c){J.log("failed loading: "+g),f("failed loading resource.json error: "+c)},dataType:"json",async:b.getAsync})}}else{var h,i=d.namespaces.length*a.length;J.each(d.namespaces,function(d,f){J.each(a,function(a,d){var g=function(a,b){a&&(h=h||[],h.push(a)),e[d]=e[d]||{},e[d][f]=b,i--,0===i&&c(h,e)};"function"==typeof b.customLoad?b.customLoad(d,f,b,g):K._fetchOne(d,f,b,g)})})}},_fetchOne:function(a,b,c,d){var e=n(c.resGetPath,{lng:a,ns:b});J.ajax({url:e,success:function(a){J.log("loaded: "+e),d(null,a)},error:function(a,b,c){J.log("failed loading: "+e),d(c,{})},dataType:"json",async:c.getAsync})},postMissing:function(a,b,c,d,e){var f={};f[c]=d;var g=[];if("fallback"===F.sendMissingTo&&F.fallbackLng!==!1)g.push({lng:F.fallbackLng,url:n(F.resPostPath,{lng:F.fallbackLng,ns:b})});else if("current"===F.sendMissingTo||"fallback"===F.sendMissingTo&&F.fallbackLng===!1)g.push({lng:a,url:n(F.resPostPath,{lng:a,ns:b})});else if("all"===F.sendMissingTo)for(var h=0,i=e.length;i>h;h++)g.push({lng:e[h],url:n(F.resPostPath,{lng:e[h],ns:b})});for(var j=0,k=g.length;k>j;j++){var l=g[j];J.ajax({url:l.url,type:F.sendType,data:f,success:function(){J.log("posted missing key '"+c+"' to: "+l.url);for(var a=c.split("."),e=0,f=B[l.lng][b];a[e];)f=f[a[e]]=e===a.length-1?d:f[a[e]]||{},e++},error:function(){J.log("failed posting missing key '"+c+"' to: "+l.url)},dataType:"json",async:F.postAsync})}}},L={rules:{ach:{name:"Acholi",numbers:[1,2],plurals:function(a){return Number(a>1)}},af:{name:"Afrikaans",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ak:{name:"Akan",numbers:[1,2],plurals:function(a){return Number(a>1)}},am:{name:"Amharic",numbers:[1,2],plurals:function(a){return Number(a>1)}},an:{name:"Aragonese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ar:{name:"Arabic",numbers:[0,1,2,3,11,100],plurals:function(a){return Number(0===a?0:1==a?1:2==a?2:a%100>=3&&10>=a%100?3:a%100>=11?4:5)}},arn:{name:"Mapudungun",numbers:[1,2],plurals:function(a){return Number(a>1)}},ast:{name:"Asturian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ay:{name:"Aymará",numbers:[1],plurals:function(){return 0}},az:{name:"Azerbaijani",numbers:[1,2],plurals:function(a){return Number(1!=a)}},be:{name:"Belarusian",numbers:[1,2,5],plurals:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},bg:{name:"Bulgarian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},bn:{name:"Bengali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},bo:{name:"Tibetan",numbers:[1],plurals:function(){return 0}},br:{name:"Breton",numbers:[1,2],plurals:function(a){return Number(a>1)}},bs:{name:"Bosnian",numbers:[1,2,5],plurals:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},ca:{name:"Catalan",numbers:[1,2],plurals:function(a){return Number(1!=a)}},cgg:{name:"Chiga",numbers:[1],plurals:function(){return 0}},cs:{name:"Czech",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)}},csb:{name:"Kashubian",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},cy:{name:"Welsh",numbers:[1,2,3,8],plurals:function(a){return Number(1==a?0:2==a?1:8!=a&&11!=a?2:3)}},da:{name:"Danish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},de:{name:"German",numbers:[1,2],plurals:function(a){return Number(1!=a)}},dz:{name:"Dzongkha",numbers:[1],plurals:function(){return 0}},el:{name:"Greek",numbers:[1,2],plurals:function(a){return Number(1!=a)}},en:{name:"English",numbers:[1,2],plurals:function(a){return Number(1!=a)}},eo:{name:"Esperanto",numbers:[1,2],plurals:function(a){return Number(1!=a)}},es:{name:"Spanish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},es_ar:{name:"Argentinean Spanish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},et:{name:"Estonian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},eu:{name:"Basque",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fa:{name:"Persian",numbers:[1],plurals:function(){return 0}},fi:{name:"Finnish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fil:{name:"Filipino",numbers:[1,2],plurals:function(a){return Number(a>1)}},fo:{name:"Faroese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fr:{name:"French",numbers:[1,2],plurals:function(a){return Number(a>1)}},fur:{name:"Friulian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fy:{name:"Frisian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ga:{name:"Irish",numbers:[1,2,3,7,11],plurals:function(a){return Number(1==a?0:2==a?1:7>a?2:11>a?3:4)}},gd:{name:"Scottish Gaelic",numbers:[1,2,3,20],plurals:function(a){return Number(1==a||11==a?0:2==a||12==a?1:a>2&&20>a?2:3)}},gl:{name:"Galician",numbers:[1,2],plurals:function(a){return Number(1!=a)}},gu:{name:"Gujarati",numbers:[1,2],plurals:function(a){return Number(1!=a)}},gun:{name:"Gun",numbers:[1,2],plurals:function(a){return Number(a>1)}},ha:{name:"Hausa",numbers:[1,2],plurals:function(a){return Number(1!=a)}},he:{name:"Hebrew",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hi:{name:"Hindi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hr:{name:"Croatian",numbers:[1,2,5],plurals:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},hu:{name:"Hungarian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hy:{name:"Armenian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ia:{name:"Interlingua",numbers:[1,2],plurals:function(a){return Number(1!=a)}},id:{name:"Indonesian",numbers:[1],plurals:function(){return 0}},is:{name:"Icelandic",numbers:[1,2],plurals:function(a){return Number(a%10!=1||a%100==11)}},it:{name:"Italian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ja:{name:"Japanese",numbers:[1],plurals:function(){return 0}},jbo:{name:"Lojban",numbers:[1],plurals:function(){return 0}},jv:{name:"Javanese",numbers:[0,1],plurals:function(a){return Number(0!==a)}},ka:{name:"Georgian",numbers:[1],plurals:function(){return 0}},kk:{name:"Kazakh",numbers:[1],plurals:function(){return 0}},km:{name:"Khmer",numbers:[1],plurals:function(){return 0}},kn:{name:"Kannada",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ko:{name:"Korean",numbers:[1],plurals:function(){return 0}},ku:{name:"Kurdish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},kw:{name:"Cornish",numbers:[1,2,3,4],plurals:function(a){return Number(1==a?0:2==a?1:3==a?2:3)}},ky:{name:"Kyrgyz",numbers:[1],plurals:function(){return 0}},lb:{name:"Letzeburgesch",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ln:{name:"Lingala",numbers:[1,2],plurals:function(a){return Number(a>1)}},lo:{name:"Lao",numbers:[1],plurals:function(){return 0}},lt:{name:"Lithuanian",numbers:[1,2,10],plurals:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&(10>a%100||a%100>=20)?1:2)}},lv:{name:"Latvian",numbers:[0,1,2],plurals:function(a){return Number(a%10==1&&a%100!=11?0:0!==a?1:2)}},mai:{name:"Maithili",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mfe:{name:"Mauritian Creole",numbers:[1,2],plurals:function(a){return Number(a>1)}},mg:{name:"Malagasy",numbers:[1,2],plurals:function(a){return Number(a>1)}},mi:{name:"Maori",numbers:[1,2],plurals:function(a){return Number(a>1)}},mk:{name:"Macedonian",numbers:[1,2],plurals:function(a){return Number(1==a||a%10==1?0:1)}},ml:{name:"Malayalam",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mn:{name:"Mongolian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mnk:{name:"Mandinka",numbers:[0,1,2],plurals:function(a){return Number(1==a?1:2)}},mr:{name:"Marathi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ms:{name:"Malay",numbers:[1],plurals:function(){return 0}},mt:{name:"Maltese",numbers:[1,2,11,20],plurals:function(a){return Number(1==a?0:0===a||a%100>1&&11>a%100?1:a%100>10&&20>a%100?2:3)}},nah:{name:"Nahuatl",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nap:{name:"Neapolitan",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nb:{name:"Norwegian Bokmal",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ne:{name:"Nepali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nl:{name:"Dutch",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nn:{name:"Norwegian Nynorsk",numbers:[1,2],plurals:function(a){return Number(1!=a)}},no:{name:"Norwegian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nso:{name:"Northern Sotho",numbers:[1,2],plurals:function(a){return Number(1!=a)}},oc:{name:"Occitan",numbers:[1,2],plurals:function(a){return Number(a>1)}},or:{name:"Oriya",numbers:[2,1],plurals:function(a){return Number(1!=a)}},pa:{name:"Punjabi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pap:{name:"Papiamento",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pl:{name:"Polish",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},pms:{name:"Piemontese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ps:{name:"Pashto",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pt:{name:"Portuguese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pt_br:{name:"Brazilian Portuguese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},rm:{name:"Romansh",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ro:{name:"Romanian",numbers:[1,2,20],plurals:function(a){return Number(1==a?0:0===a||a%100>0&&20>a%100?1:2)}},ru:{name:"Russian",numbers:[1,2,5],plurals:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},sah:{name:"Yakut",numbers:[1],plurals:function(){return 0}},sco:{name:"Scots",numbers:[1,2],plurals:function(a){return Number(1!=a)}},se:{name:"Northern Sami",numbers:[1,2],plurals:function(a){return Number(1!=a)}},si:{name:"Sinhala",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sk:{name:"Slovak",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)}},sl:{name:"Slovenian",numbers:[5,1,2,3],plurals:function(a){return Number(a%100==1?1:a%100==2?2:a%100==3||a%100==4?3:0)}},so:{name:"Somali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},son:{name:"Songhay",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sq:{name:"Albanian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sr:{name:"Serbian",numbers:[1,2,5],plurals:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},su:{name:"Sundanese",numbers:[1],plurals:function(){return 0}},sv:{name:"Swedish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sw:{name:"Swahili",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ta:{name:"Tamil",numbers:[1,2],plurals:function(a){return Number(1!=a)}},te:{name:"Telugu",numbers:[1,2],plurals:function(a){return Number(1!=a)}},tg:{name:"Tajik",numbers:[1,2],plurals:function(a){return Number(a>1)}},th:{name:"Thai",numbers:[1],plurals:function(){return 0}},ti:{name:"Tigrinya",numbers:[1,2],plurals:function(a){return Number(a>1)}},tk:{name:"Turkmen",numbers:[1,2],plurals:function(a){return Number(1!=a)}},tr:{name:"Turkish",numbers:[1,2],plurals:function(a){return Number(a>1)}},tt:{name:"Tatar",numbers:[1],plurals:function(){return 0}},ug:{name:"Uyghur",numbers:[1],plurals:function(){return 0}},uk:{name:"Ukrainian",numbers:[1,2,5],plurals:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},ur:{name:"Urdu",numbers:[1,2],plurals:function(a){return Number(1!=a)}},uz:{name:"Uzbek",numbers:[1,2],plurals:function(a){return Number(a>1)}},vi:{name:"Vietnamese",numbers:[1],plurals:function(){return 0}},wa:{name:"Walloon",numbers:[1,2],plurals:function(a){return Number(a>1)}},wo:{name:"Wolof",numbers:[1],plurals:function(){return 0}},yo:{name:"Yoruba",numbers:[1,2],plurals:function(a){return Number(1!=a)}},zh:{name:"Chinese",numbers:[1],plurals:function(){return 0}}},addRule:function(a,b){L.rules[a]=b},setCurrentLng:function(a){if(!L.currentRule||L.currentRule.lng!==a){var b=a.split("-");L.currentRule={lng:a,rule:L.rules[b[0]]}}},get:function(a,b){function c(b,c){var d;if(d=L.currentRule&&L.currentRule.lng===a?L.currentRule.rule:L.rules[b]){var e=d.plurals(c),f=d.numbers[e];return 2===d.numbers.length&&1===d.numbers[0]&&(2===f?f=-1:1===f&&(f=1)),f}return 1===c?"1":"-1"}var d=a.split("-");return c(d[0],b)}},M={},N=function(a,b){M[a]=b},O=function(){function a(a){return Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}function b(a,b){for(var c=[];b>0;c[--b]=a);return c.join("")}var c=function(){return c.cache.hasOwnProperty(arguments[0])||(c.cache[arguments[0]]=c.parse(arguments[0])),c.format.call(null,c.cache[arguments[0]],arguments)};return c.format=function(c,d){var e,f,g,h,i,j,k,l=1,m=c.length,n="",o=[];for(f=0;m>f;f++)if(n=a(c[f]),"string"===n)o.push(c[f]);else if("array"===n){if(h=c[f],h[2])for(e=d[l],g=0;g=0?"+"+e:e,j=h[4]?"0"==h[4]?"0":h[4].charAt(1):" ",k=h[6]-String(e).length,i=h[6]?b(j,k):"",o.push(h[5]?e+i:i+e)}return o.join("")},c.cache={},c.parse=function(a){for(var b=a,c=[],d=[],e=0;b;){if(null!==(c=/^[^\x25]+/.exec(b)))d.push(c[0]);else if(null!==(c=/^\x25{2}/.exec(b)))d.push("%");else{if(null===(c=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(b)))throw"[sprintf] huh?";if(c[2]){e|=1;var f=[],g=c[2],h=[];if(null===(h=/^([a-z_][a-z_\d]*)/i.exec(g)))throw"[sprintf] huh?";for(f.push(h[1]);""!==(g=g.substring(h[0].length));)if(null!==(h=/^\.([a-z_][a-z_\d]*)/i.exec(g)))f.push(h[1]);else{if(null===(h=/^\[(\d+)\]/.exec(g)))throw"[sprintf] huh?";f.push(h[1])}c[2]=f}else e|=2;if(3===e)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";d.push(c)}b=b.substring(c[0].length)}return d},c}(),P=function(a,b){return b.unshift(a),O.apply(null,b)};return N("sprintf",function(a,b,c){return c.sprintf?"[object Array]"===Object.prototype.toString.apply(c.sprintf)?P(a,c.sprintf):"object"==typeof c.sprintf?O(a,c.sprintf):a:a}),A.init=e,A.setLng=k,A.preload=f,A.addResourceBundle=g,A.loadNamespace=i,A.loadNamespaces=j,A.setDefaultNamespace=h,A.t=s,A.translate=s,A.exists=r,A.detectLanguage=J.detectLanguage,A.pluralExtensions=L,A.sync=K,A.functions=J,A.lng=l,A.addPostProcessor=N,A.options=F,A}); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd-1.7.1.zip b/libs/i18next/release/i18next.amd-1.7.1.zip new file mode 100644 index 00000000..8f3d7385 Binary files /dev/null and b/libs/i18next/release/i18next.amd-1.7.1.zip differ diff --git a/libs/i18next/release/i18next.amd-1.7.2.js b/libs/i18next/release/i18next.amd-1.7.2.js new file mode 100644 index 00000000..8e20d84d --- /dev/null +++ b/libs/i18next/release/i18next.amd-1.7.2.js @@ -0,0 +1,2703 @@ +// i18next, v1.7.2 +// Copyright (c)2014 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function (root, factory) { + if (typeof exports === 'object') { + + module.exports = factory(); + + } else if (typeof define === 'function' && define.amd) { + + define([], factory); + + } +}(this, function () { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + var $ = undefined + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = [] + , initialized = false; + + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: 'dev', + fallbackNS: [], + detectLngQS: 'setLng', + ns: 'translation', + fallbackOnNull: true, + fallbackOnEmpty: false, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + cookieDomain: undefined, + + objectTreeKeyHandler: undefined, + postProcess: undefined, + parseMissingKey: undefined, + + shortcutFunction: 'sprintf' // or: defaultValue + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + return JSON.parse(data); + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + if (status === 200) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes,domain) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + domain = (domain)? "domain="+domain+";" : ""; + document.cookie = name+"="+value+expires+";"+domain+"path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes,domain) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : (typeof document !== 'undefined' ? _ajax : function() {}), + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + toLanguages: function(lng) { + var languages = []; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + + if (o.load !== 'unspecific') languages.push(lng); + if (o.load !== 'current') languages.push(parts[0]); + } else { + languages.push(lng); + } + + if (languages.indexOf(o.fallbackLng) === -1 && o.fallbackLng) languages.push(o.fallbackLng); + + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + delete o.fixLng; /* passed in each time */ + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + if (o.lng) { + // set cookie with lng set (as detectLanguage will set cookie on need) + if (o.useCookie) f.cookie.create(o.cookieName, o.lng, o.cookieExpirationTime, o.cookieDomain); + } else { + o.lng = o.fallbackLng; + if (o.useCookie) f.cookie.remove(o.cookieName); + } + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + var lngTranslate = translate; + if (options.fixLng) { + lngTranslate = function(key, options) { + options = options || {}; + options.lng = options.lng || lngTranslate.lng; + return translate(key, options); + }; + lngTranslate.lng = currentLng; + } + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + initialized = true; + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + initialized = true; + + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + f.extend(resStore[lng][ns], resources); + } + + function removeResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = {}; + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, options, cb) { + if (typeof options === 'function') { + cb = options; + options = {}; + } else if (!options) { + options = {}; + } + + options.lng = lng; + return init(options, cb); + } + + function lng() { + return currentLng; + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else if (attr === 'prepend') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.prepend($.t(key, optionsToUse)); + } else if (attr === 'append') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.append($.t(key, optionsToUse)); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key && typeof key !== 'undefined' && key !== false) key = ele.text() || ele.val(); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + f.each(replacementHash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), value); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.escape(value)); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), value); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, translated_token); + } + return translated; + } + + function hasContext(options) { + return (options.context && (typeof options.context == 'string' || typeof options.context == 'number')); + } + + function needsPlural(options) { + return (options.count !== undefined && typeof options.count != 'string' && options.count !== 1); + } + + function exists(key, options) { + options = options || {}; + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + options = options || {}; + + if (!initialized) { + f.log('i18next not finished initialization. you might have called t function before loading resources finished.') + return options.defaultValue || ''; + }; + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _getDefaultValue(key, options) { + return (options.defaultValue !== undefined) ? options.defaultValue : key; + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(potentialKeys, options) { + if (typeof options == 'string') { + if (o.shortcutFunction === 'sprintf') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else if (o.shortcutFunction === 'defaultValue') { + options = { + defaultValue: options + } + } + } else { + options = options || {}; + } + + if (potentialKeys === undefined || potentialKeys === null) return ''; + + if (typeof potentialKeys == 'string') { + potentialKeys = [potentialKeys]; + } + + var key = potentialKeys[0]; + + if (potentialKeys.length > 1) { + for (var i = 0; i < potentialKeys.length; i++) { + key = potentialKeys[i]; + if (exists(key)) { + break; + } + } + } + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng) : languages + , ns = options.ns || o.ns.defaultNs + , parts; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing) { + if (options.lng) { + sync.postMissing(lngs[0], ns, key, notFound, lngs); + } else { + sync.postMissing(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found !== undefined && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + // process notFound if function exists + var splitNotFound = notFound; + if (notFound.indexOf(o.nsseparator) > -1) { + parts = notFound.split(o.nsseparator); + splitNotFound = parts[1]; + } + if (splitNotFound === key && o.parseMissingKey) { + notFound = o.parseMissingKey(notFound); + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessor && postProcessors[postProcessor]) { + var val = _getDefaultValue(key, options); + found = postProcessors[postProcessor](val, key, options); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options) { + options = options || {}; + + var optionWithoutCount, translated + , notFound = _getDefaultValue(key, options) + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + if (options.lng) { + lngs = f.toLanguages(options.lng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.count; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(lngs[0], options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + + translated = translate(pluralKey, optionWithoutCount); + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } // else continue translation with original/singular key + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + var valueType = Object.prototype.toString.apply(value); + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (valueType === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + if (o.objectTreeKeyHandler && typeof o.objectTreeKeyHandler == 'function') { + value = o.objectTreeKeyHandler(key, value, l, ns, options); + } else { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned an object instead of string.'; + f.log(value); + } + } else if (valueType !== '[object Number]' && valueType !== '[object Function]' && valueType !== '[object RegExp]') { + var copy = (valueType === '[object Array]') ? [] : {}; // apply child translation on a copy + f.each(value, function(m) { + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + }); + value = copy; + } + } + + if (typeof value === 'string' && value.trim() === '' && o.fallbackOnEmpty === true) + value = undefined; + + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length > 0))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + } + + return found; + } + function detectLanguage() { + var detectedLng; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var parms = query.split('&'); + for (var i=0; i 0) { + var key = parms[i].substring(0,pos); + var val = parms[i].substring(pos+1); + qsParm[key] = val; + } + } + })(); + if (qsParm[o.detectLngQS]) { + detectedLng = qsParm[o.detectLngQS]; + } + } + + // get from cookie + if (!detectedLng && typeof document !== 'undefined' && o.useCookie ) { + var c = f.cookie.read(o.cookieName); + if (c) detectedLng = c; + } + + // get from navigator + if (!detectedLng && typeof navigator !== 'undefined') { + detectedLng = (navigator.language) ? navigator.language : navigator.userLanguage; + } + + return detectedLng; + } + var sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + window.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + if (error.status == 200) { + // file loaded but invalid json, stop waste time ! + f.log('There is a typo in: ' + url); + } else if (error.status == 404) { + f.log('Does not exist: ' + url); + } else { + f.log(error.status + ' when loading ' + url); + } + + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback' && o.fallbackLng !== false) { + urls.push({lng: o.fallbackLng, url: applyReplacement(o.resPostPath, { lng: o.fallbackLng, ns: ns })}); + } else if (o.sendMissingTo === 'current' || (o.sendMissingTo === 'fallback' && o.fallbackLng === false) ) { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + } + }; + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + var pluralExtensions = { + + rules: { + "ach": { + "name": "Acholi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "af": { + "name": "Afrikaans", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ak": { + "name": "Akan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "am": { + "name": "Amharic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "an": { + "name": "Aragonese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ar": { + "name": "Arabic", + "numbers": [ + 0, + 1, + 2, + 3, + 11, + 100 + ], + "plurals": function(n) { return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5); } + }, + "arn": { + "name": "Mapudungun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ast": { + "name": "Asturian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ay": { + "name": "Aymar\u00e1", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "az": { + "name": "Azerbaijani", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "be": { + "name": "Belarusian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "bg": { + "name": "Bulgarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bn": { + "name": "Bengali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bo": { + "name": "Tibetan", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "br": { + "name": "Breton", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "bs": { + "name": "Bosnian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ca": { + "name": "Catalan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "cgg": { + "name": "Chiga", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "cs": { + "name": "Czech", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "csb": { + "name": "Kashubian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "cy": { + "name": "Welsh", + "numbers": [ + 1, + 2, + 3, + 8 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3); } + }, + "da": { + "name": "Danish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "de": { + "name": "German", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "dz": { + "name": "Dzongkha", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "el": { + "name": "Greek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "en": { + "name": "English", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eo": { + "name": "Esperanto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es": { + "name": "Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es_ar": { + "name": "Argentinean Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "et": { + "name": "Estonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eu": { + "name": "Basque", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fa": { + "name": "Persian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "fi": { + "name": "Finnish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fil": { + "name": "Filipino", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fo": { + "name": "Faroese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fr": { + "name": "French", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fur": { + "name": "Friulian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fy": { + "name": "Frisian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ga": { + "name": "Irish", + "numbers": [ + 1, + 2, + 3, + 7, + 11 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;} + }, + "gd": { + "name": "Scottish Gaelic", + "numbers": [ + 1, + 2, + 3, + 20 + ], + "plurals": function(n) { return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3); } + }, + "gl": { + "name": "Galician", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gu": { + "name": "Gujarati", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gun": { + "name": "Gun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ha": { + "name": "Hausa", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "he": { + "name": "Hebrew", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hi": { + "name": "Hindi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hr": { + "name": "Croatian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "hu": { + "name": "Hungarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hy": { + "name": "Armenian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ia": { + "name": "Interlingua", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "id": { + "name": "Indonesian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "is": { + "name": "Icelandic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n%10!=1 || n%100==11); } + }, + "it": { + "name": "Italian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ja": { + "name": "Japanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jbo": { + "name": "Lojban", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jv": { + "name": "Javanese", + "numbers": [ + 0, + 1 + ], + "plurals": function(n) { return Number(n !== 0); } + }, + "ka": { + "name": "Georgian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kk": { + "name": "Kazakh", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "km": { + "name": "Khmer", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kn": { + "name": "Kannada", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ko": { + "name": "Korean", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ku": { + "name": "Kurdish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "kw": { + "name": "Cornish", + "numbers": [ + 1, + 2, + 3, + 4 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3); } + }, + "ky": { + "name": "Kyrgyz", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lb": { + "name": "Letzeburgesch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ln": { + "name": "Lingala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "lo": { + "name": "Lao", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lt": { + "name": "Lithuanian", + "numbers": [ + 1, + 2, + 10 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "lv": { + "name": "Latvian", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2); } + }, + "mai": { + "name": "Maithili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mfe": { + "name": "Mauritian Creole", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mg": { + "name": "Malagasy", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mi": { + "name": "Maori", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mk": { + "name": "Macedonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 || n%10==1 ? 0 : 1); } + }, + "ml": { + "name": "Malayalam", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mn": { + "name": "Mongolian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mnk": { + "name": "Mandinka", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(0 ? 0 : n==1 ? 1 : 2); } + }, + "mr": { + "name": "Marathi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ms": { + "name": "Malay", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "mt": { + "name": "Maltese", + "numbers": [ + 1, + 2, + 11, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3); } + }, + "nah": { + "name": "Nahuatl", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nap": { + "name": "Neapolitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nb": { + "name": "Norwegian Bokmal", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ne": { + "name": "Nepali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nl": { + "name": "Dutch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nn": { + "name": "Norwegian Nynorsk", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "no": { + "name": "Norwegian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nso": { + "name": "Northern Sotho", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "oc": { + "name": "Occitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "or": { + "name": "Oriya", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pa": { + "name": "Punjabi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pap": { + "name": "Papiamento", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pl": { + "name": "Polish", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "pms": { + "name": "Piemontese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ps": { + "name": "Pashto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt": { + "name": "Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt_br": { + "name": "Brazilian Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "rm": { + "name": "Romansh", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ro": { + "name": "Romanian", + "numbers": [ + 1, + 2, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2); } + }, + "ru": { + "name": "Russian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "sah": { + "name": "Yakut", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sco": { + "name": "Scots", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "se": { + "name": "Northern Sami", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "si": { + "name": "Sinhala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sk": { + "name": "Slovak", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "sl": { + "name": "Slovenian", + "numbers": [ + 5, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }, + "so": { + "name": "Somali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "son": { + "name": "Songhay", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sq": { + "name": "Albanian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sr": { + "name": "Serbian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "su": { + "name": "Sundanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sv": { + "name": "Swedish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sw": { + "name": "Swahili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ta": { + "name": "Tamil", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "te": { + "name": "Telugu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tg": { + "name": "Tajik", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "th": { + "name": "Thai", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ti": { + "name": "Tigrinya", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tk": { + "name": "Turkmen", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tr": { + "name": "Turkish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tt": { + "name": "Tatar", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ug": { + "name": "Uyghur", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "uk": { + "name": "Ukrainian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ur": { + "name": "Urdu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "uz": { + "name": "Uzbek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "vi": { + "name": "Vietnamese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "wa": { + "name": "Walloon", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "wo": { + "name": "Wolof", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "yo": { + "name": "Yoruba", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "zh": { + "name": "Chinese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + } + }, + + // for demonstration only sl and ar is added but you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i = ext.plurals(c); + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[0], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.removeResourceBundle = removeResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + + return i18n; + +})); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd-1.7.2.min.js b/libs/i18next/release/i18next.amd-1.7.2.min.js new file mode 100644 index 00000000..3567b2c9 --- /dev/null +++ b/libs/i18next/release/i18next.amd-1.7.2.min.js @@ -0,0 +1,5 @@ +// i18next, v1.7.2 +// Copyright (c)2014 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +!function(a,b){"object"==typeof exports?module.exports=b():"function"==typeof define&&define.amd&&define([],b)}(this,function(){function a(a,b){if(!b||"function"==typeof b)return a;for(var c in b)a[c]=b[c];return a}function b(a,b,c){var d,e=0,f=a.length,g=void 0===f||"function"==typeof a;if(c)if(g){for(d in a)if(b.apply(a[d],c)===!1)break}else for(;f>e&&b.apply(a[e++],c)!==!1;);else if(g){for(d in a)if(b.call(a[d],d,a[d])===!1)break}else for(;f>e&&b.call(a[e],e,a[e++])!==!1;);return a}function c(a){return"string"==typeof a?a.replace(/[&<>"'\/]/g,function(a){return H[a]}):a}function d(a){var b=function(a){if(window.XMLHttpRequest)return a(null,new XMLHttpRequest);if(window.ActiveXObject)try{return a(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(b){return a(null,new ActiveXObject("Microsoft.XMLHTTP"))}return a(new Error)},c=function(a){if("string"==typeof a)return a;var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")},d=function(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;cd?b+=String.fromCharCode(d):d>127&&2048>d?(b+=String.fromCharCode(192|d>>6),b+=String.fromCharCode(128|63&d)):(b+=String.fromCharCode(224|d>>12),b+=String.fromCharCode(128|63&d>>6),b+=String.fromCharCode(128|63&d))}return b},e=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";a=d(a);var c,e,f,g,h,i,j,k="",l=0;do c=a.charCodeAt(l++),e=a.charCodeAt(l++),f=a.charCodeAt(l++),g=c>>2,h=(3&c)<<4|e>>4,i=(15&e)<<2|f>>6,j=63&f,isNaN(e)?i=j=64:isNaN(f)&&(j=64),k+=b.charAt(g)+b.charAt(h)+b.charAt(i)+b.charAt(j),c=e=f="",g=h=i=j="";while(l1&&(d+=d.indexOf("?")>-1?"&"+k:"?"+k),e.jsonp){var l=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=d,l.appendChild(m),void 0}}b(function(b,c){if(b)return h(b);c.open(a,d,e.async);for(var f in j)j.hasOwnProperty(f)&&c.setRequestHeader(f,j[f]);c.onreadystatechange=function(){if(4===c.readyState){var a=c.responseText||"";if(!h)return;h(c.status,{text:function(){return a},json:function(){return JSON.parse(a)}})}},c.send(i)})},h={authBasic:function(a,b){g.headers.Authorization="Basic "+e(a+":"+b)},connect:function(a,b,c){return g("CONNECT",a,b,c)},del:function(a,b,c){return g("DELETE",a,b,c)},get:function(a,b,c){return g("GET",a,b,c)},head:function(a,b,c){return g("HEAD",a,b,c)},headers:function(a){g.headers=a||{}},isAllowed:function(a,b,c){this.options(a,function(a,d){c(-1!==d.text().indexOf(b))})},options:function(a,b,c){return g("OPTIONS",a,b,c)},patch:function(a,b,c){return g("PATCH",a,b,c)},post:function(a,b,c){return g("POST",a,b,c)},put:function(a,b,c){return g("PUT",a,b,c)},trace:function(a,b,c){return g("TRACE",a,b,c)}},i=a.type?a.type.toLowerCase():"get";h[i](a.url,a,function(b,c){200===b?a.success(c.json(),b,null):a.error(c.text(),b,null)})}function e(a,b){"function"==typeof a&&(b=a,a={}),a=a||{},K.extend(G,a),delete G.fixLng,"string"==typeof G.ns&&(G.ns={namespaces:[G.ns],defaultNs:G.ns}),"string"==typeof G.fallbackNS&&(G.fallbackNS=[G.fallbackNS]),G.interpolationPrefixEscaped=K.regexEscape(G.interpolationPrefix),G.interpolationSuffixEscaped=K.regexEscape(G.interpolationSuffix),G.lng||(G.lng=K.detectLanguage()),G.lng?G.useCookie&&K.cookie.create(G.cookieName,G.lng,G.cookieExpirationTime,G.cookieDomain):(G.lng=G.fallbackLng,G.useCookie&&K.cookie.remove(G.cookieName)),E=K.toLanguages(G.lng),z=E[0],K.log("currentLng set to: "+z);var c=t;a.fixLng&&(c=function(a,b){return b=b||{},b.lng=b.lng||c.lng,t(a,b)},c.lng=z),M.setCurrentLng(z),A&&G.setJqueryExt&&n();var d;if(A&&A.Deferred&&(d=A.Deferred()),!G.resStore){var e=K.toLanguages(G.lng);"string"==typeof G.preload&&(G.preload=[G.preload]);for(var f=0,g=G.preload.length;g>f;f++)for(var h=K.toLanguages(G.preload[f]),i=0,j=h.length;j>i;i++)e.indexOf(h[i])<0&&e.push(h[i]);return B.sync.load(e,G,function(a,e){C=e,F=!0,b&&b(c),d&&d.resolve(c)}),d?d.promise():void 0}return C=G.resStore,F=!0,b&&b(c),d&&d.resolve(c),d?d.promise():void 0}function f(a,b){"string"==typeof a&&(a=[a]);for(var c=0,d=a.length;d>c;c++)G.preload.indexOf(a[c])<0&&G.preload.push(a[c]);return e(b)}function g(a,b,c){"string"!=typeof b?(c=b,b=G.ns.defaultNs):G.ns.namespaces.indexOf(b)<0&&G.ns.namespaces.push(b),C[a]=C[a]||{},C[a][b]=C[a][b]||{},K.extend(C[a][b],c)}function h(a,b){"string"!=typeof b&&(b=G.ns.defaultNs),C[a]=C[a]||{},C[a][b]={}}function i(a){G.ns.defaultNs=a}function j(a,b){k([a],b)}function k(a,b){var c={dynamicLoad:G.dynamicLoad,resGetPath:G.resGetPath,getAsync:G.getAsync,customLoad:G.customLoad,ns:{namespaces:a,defaultNs:""}},d=K.toLanguages(G.lng);"string"==typeof G.preload&&(G.preload=[G.preload]);for(var e=0,f=G.preload.length;f>e;e++)for(var g=K.toLanguages(G.preload[e]),h=0,i=g.length;i>h;h++)d.indexOf(g[h])<0&&d.push(g[h]);for(var j=[],k=0,l=d.length;l>k;k++){var m=!1,n=C[d[k]];if(n)for(var o=0,p=a.length;p>o;o++)n[a[o]]||(m=!0);else m=!0;m&&j.push(d[k])}j.length?B.sync._fetch(j,c,function(c,d){var e=a.length*j.length;K.each(a,function(a,c){G.ns.namespaces.indexOf(c)<0&&G.ns.namespaces.push(c),K.each(j,function(a,f){C[f]=C[f]||{},C[f][c]=d[f][c],e--,0===e&&b&&(G.useLocalStorage&&B.sync._storeLocal(C),b())})})}):b&&b()}function l(a,b,c){return"function"==typeof b?(c=b,b={}):b||(b={}),b.lng=a,e(b,c)}function m(){return z}function n(){function a(a,b,c){if(0!==b.length){var d="text";if(0===b.indexOf("[")){var e=b.split("]");b=e[1],d=e[0].substr(1,e[0].length-1)}b.indexOf(";")===b.length-1&&(b=b.substr(0,b.length-2));var f;"html"===d?(f=G.defaultValueFromContent?A.extend({defaultValue:a.html()},c):c,a.html(A.t(b,f))):"text"===d?(f=G.defaultValueFromContent?A.extend({defaultValue:a.text()},c):c,a.text(A.t(b,f))):"prepend"===d?(f=G.defaultValueFromContent?A.extend({defaultValue:a.html()},c):c,a.prepend(A.t(b,f))):"append"===d?(f=G.defaultValueFromContent?A.extend({defaultValue:a.html()},c):c,a.append(A.t(b,f))):(f=G.defaultValueFromContent?A.extend({defaultValue:a.attr(d)},c):c,a.attr(d,A.t(b,f)))}}function b(b,c){var d=b.attr(G.selectorAttr);if(d||"undefined"==typeof d||d===!1||(d=b.text()||b.val()),d){var e=b,f=b.data("i18n-target");if(f&&(e=b.find(f)||b),c||G.useDataAttrOptions!==!0||(c=b.data("i18n-options")),c=c||{},d.indexOf(";")>=0){var g=d.split(";");A.each(g,function(b,d){""!==d&&a(e,d,c)})}else a(e,d,c);G.useDataAttrOptions===!0&&b.data("i18n-options",c)}}A.t=A.t||t,A.fn.i18n=function(a){return this.each(function(){b(A(this),a);var c=A(this).find("["+G.selectorAttr+"]");c.each(function(){b(A(this),a)})})}}function o(a,b,c,d){if(!a)return a;if(d=d||b,a.indexOf(d.interpolationPrefix||G.interpolationPrefix)<0)return a;var e=d.interpolationPrefix?K.regexEscape(d.interpolationPrefix):G.interpolationPrefixEscaped,f=d.interpolationSuffix?K.regexEscape(d.interpolationSuffix):G.interpolationSuffixEscaped,g="HTML"+f;return K.each(b,function(b,h){var i=c?c+G.keyseparator+b:b;"object"==typeof h&&null!==h?a=o(a,h,i,d):d.escapeInterpolation||G.escapeInterpolation?(a=a.replace(new RegExp([e,i,g].join(""),"g"),h),a=a.replace(new RegExp([e,i,f].join(""),"g"),K.escape(h))):a=a.replace(new RegExp([e,i,f].join(""),"g"),h)}),a}function p(a,b){var c=",",d="{",e="}",f=K.extend({},b);for(delete f.postProcess;-1!=a.indexOf(G.reusePrefix)&&(D++,!(D>G.maxRecursion));){var g=a.lastIndexOf(G.reusePrefix),h=a.indexOf(G.reuseSuffix,g)+G.reuseSuffix.length,i=a.substring(g,h),j=i.replace(G.reusePrefix,"").replace(G.reuseSuffix,"");if(-1!=j.indexOf(c)){var k=j.indexOf(c);if(-1!=j.indexOf(d,k)&&-1!=j.indexOf(e,k)){var l=j.indexOf(d,k),m=j.indexOf(e,l)+e.length;try{f=K.extend(f,JSON.parse(j.substring(l,m))),j=j.substring(0,k)}catch(n){}}}var o=w(j,f);a=a.replace(i,o)}return a}function q(a){return a.context&&("string"==typeof a.context||"number"==typeof a.context)}function r(a){return void 0!==a.count&&"string"!=typeof a.count&&1!==a.count}function s(a,b){b=b||{};var c=u(a,b),d=x(a,b);return void 0!==d||d===c}function t(a,b){return b=b||{},F?(D=0,w.apply(null,arguments)):(K.log("i18next not finished initialization. you might have called t function before loading resources finished."),b.defaultValue||"")}function u(a,b){return void 0!==b.defaultValue?b.defaultValue:a}function v(){for(var a=[],b=1;b1)for(var d=0;d-1&&(e=c.split(G.nsseparator),i=e[0],c=e[1]),void 0===g&&G.sendMissing&&(b.lng?L.postMissing(h[0],i,c,f,h):L.postMissing(G.lng,i,c,f,h));var j=b.postProcess||G.postProcess;void 0!==g&&j&&N[j]&&(g=N[j](g,c,b));var k=f;if(f.indexOf(G.nsseparator)>-1&&(e=f.split(G.nsseparator),k=e[1]),k===c&&G.parseMissingKey&&(f=G.parseMissingKey(f)),void 0===g&&(f=o(f,b),f=p(f,b),j&&N[j])){var l=u(c,b);g=N[j](l,c,b)}return void 0!==g?g:f}function x(a,b){b=b||{};var c,d,e=u(a,b),f=E;if(!C)return e;if(b.lng&&(f=K.toLanguages(b.lng),!C[f[0]])){var g=G.getAsync;G.getAsync=!1,B.sync.load(f,G,function(a,b){K.extend(C,b),G.getAsync=g})}var h=b.ns||G.ns.defaultNs;if(a.indexOf(G.nsseparator)>-1){var i=a.split(G.nsseparator);h=i[0],a=i[1]}if(q(b)){c=K.extend({},b),delete c.context,c.defaultValue=G.contextNotFound;var j=h+G.nsseparator+a+"_"+b.context;if(d=t(j,c),d!=G.contextNotFound)return o(d,{context:b.context})}if(r(b)){c=K.extend({},b),delete c.count,c.defaultValue=G.pluralNotFound;var k=h+G.nsseparator+a+G.pluralSuffix,l=M.get(f[0],b.count);if(l>=0?k=k+"_"+l:1===l&&(k=h+G.nsseparator+a),d=t(k,c),d!=G.pluralNotFound)return o(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix})}for(var m,n=a.split(G.keyseparator),s=0,v=f.length;v>s&&void 0===m;s++){for(var y=f[s],z=0,A=C[y]&&C[y][h];n[z];)A=A&&A[n[z]],z++;if(void 0!==A){var D=Object.prototype.toString.apply(A);if("string"==typeof A)A=o(A,b),A=p(A,b);else if("[object Array]"!==D||G.returnObjectTrees||b.returnObjectTrees){if(null===A&&G.fallbackOnNull===!0)A=void 0;else if(null!==A)if(G.returnObjectTrees||b.returnObjectTrees){if("[object Number]"!==D&&"[object Function]"!==D&&"[object RegExp]"!==D){var F="[object Array]"===D?[]:{};K.each(A,function(c){F[c]=w(h+G.nsseparator+a+G.keyseparator+c,b)}),A=F}}else G.objectTreeKeyHandler&&"function"==typeof G.objectTreeKeyHandler?A=G.objectTreeKeyHandler(a,A,y,h,b):(A="key '"+h+":"+a+" ("+y+")' "+"returned an object instead of string.",K.log(A))}else A=A.join("\n"),A=o(A,b),A=p(A,b);"string"==typeof A&&""===A.trim()&&G.fallbackOnEmpty===!0&&(A=void 0),m=A}}if(void 0===m&&!b.isFallbackLookup&&(G.fallbackToDefaultNS===!0||G.fallbackNS&&G.fallbackNS.length>0))if(b.isFallbackLookup=!0,G.fallbackNS.length){for(var H=0,I=G.fallbackNS.length;I>H;H++)if(m=x(G.fallbackNS[H]+G.nsseparator+a,b)){var J=m.indexOf(G.nsseparator)>-1?m.split(G.nsseparator)[1]:m,L=e.indexOf(G.nsseparator)>-1?e.split(G.nsseparator)[1]:e;if(J!==L)break}}else m=x(a,b);return m}function y(){var a,b=[];if("undefined"!=typeof window&&(!function(){for(var a=window.location.search.substring(1),c=a.split("&"),d=0;d0){var f=c[d].substring(0,e),g=c[d].substring(e+1);b[f]=g}}}(),b[G.detectLngQS]&&(a=b[G.detectLngQS])),!a&&"undefined"!=typeof document&&G.useCookie){var c=K.cookie.read(G.cookieName);c&&(a=c)}return a||"undefined"==typeof navigator||(a=navigator.language?navigator.language:navigator.userLanguage),a}Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>0&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&1/0!=d&&d!=-1/0&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=c;arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d))));for(var e=d>=0?Math.min(d,c-1):c-Math.abs(d);e>=0;e--)if(e in b&&b[e]===a)return e;return-1});var z,A=void 0,B={},C={},D=0,E=[],F=!1,G={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:"dev",fallbackNS:[],detectLngQS:"setLng",ns:"translation",fallbackOnNull:!0,fallbackOnEmpty:!1,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",cookieDomain:void 0,objectTreeKeyHandler:void 0,postProcess:void 0,parseMissingKey:void 0,shortcutFunction:"sprintf"},H={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},I={create:function(a,b,c,d){var e;if(c){var f=new Date;f.setTime(f.getTime()+1e3*60*c),e="; expires="+f.toGMTString()}else e="";d=d?"domain="+d+";":"",document.cookie=a+"="+b+e+";"+d+"path=/"},read:function(a){for(var b=a+"=",c=document.cookie.split(";"),d=0;d-1){var c=a.split("-");a=G.lowerCaseLng?c[0].toLowerCase()+"-"+c[1].toLowerCase():c[0].toLowerCase()+"-"+c[1].toUpperCase(),"unspecific"!==G.load&&b.push(a),"current"!==G.load&&b.push(c[0])}else b.push(a);return-1===b.indexOf(G.fallbackLng)&&G.fallbackLng&&b.push(G.fallbackLng),b},regexEscape:function(a){return a.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}};K.applyReplacement=o;var L={load:function(a,b,c){b.useLocalStorage?L._loadLocal(a,b,function(d,e){for(var f=[],g=0,h=a.length;h>g;g++)e[a[g]]||f.push(a[g]);f.length>0?L._fetch(f,b,function(a,b){K.extend(e,b),L._storeLocal(b),c(null,e)}):c(null,e)}):L._fetch(a,b,function(a,b){c(null,b)})},_loadLocal:function(a,b,c){var d={},e=(new Date).getTime();if(window.localStorage){var f=a.length;K.each(a,function(a,g){var h=window.localStorage.getItem("res_"+g);h&&(h=JSON.parse(h),h.i18nStamp&&h.i18nStamp+b.localStorageExpirationTime>e&&(d[g]=h)),f--,0===f&&c(null,d)})}},_storeLocal:function(a){if(window.localStorage)for(var b in a)a[b].i18nStamp=(new Date).getTime(),window.localStorage.setItem("res_"+b,JSON.stringify(a[b]))},_fetch:function(a,b,c){var d=b.ns,e={};if(b.dynamicLoad){var f=function(a,b){c(null,b)};if("function"==typeof b.customLoad)b.customLoad(a,d.namespaces,b,f);else{var g=o(b.resGetPath,{lng:a.join("+"),ns:d.namespaces.join("+")});K.ajax({url:g,success:function(a){K.log("loaded: "+g),f(null,a)},error:function(a,b,c){K.log("failed loading: "+g),f("failed loading resource.json error: "+c)},dataType:"json",async:b.getAsync})}}else{var h,i=d.namespaces.length*a.length;K.each(d.namespaces,function(d,f){K.each(a,function(a,d){var g=function(a,b){a&&(h=h||[],h.push(a)),e[d]=e[d]||{},e[d][f]=b,i--,0===i&&c(h,e)};"function"==typeof b.customLoad?b.customLoad(d,f,b,g):L._fetchOne(d,f,b,g)})})}},_fetchOne:function(a,b,c,d){var e=o(c.resGetPath,{lng:a,ns:b});K.ajax({url:e,success:function(a){K.log("loaded: "+e),d(null,a)},error:function(a,b,c){200==c.status?K.log("There is a typo in: "+e):404==c.status?K.log("Does not exist: "+e):K.log(c.status+" when loading "+e),d(c,{})},dataType:"json",async:c.getAsync})},postMissing:function(a,b,c,d,e){var f={};f[c]=d;var g=[];if("fallback"===G.sendMissingTo&&G.fallbackLng!==!1)g.push({lng:G.fallbackLng,url:o(G.resPostPath,{lng:G.fallbackLng,ns:b})});else if("current"===G.sendMissingTo||"fallback"===G.sendMissingTo&&G.fallbackLng===!1)g.push({lng:a,url:o(G.resPostPath,{lng:a,ns:b})});else if("all"===G.sendMissingTo)for(var h=0,i=e.length;i>h;h++)g.push({lng:e[h],url:o(G.resPostPath,{lng:e[h],ns:b})});for(var j=0,k=g.length;k>j;j++){var l=g[j];K.ajax({url:l.url,type:G.sendType,data:f,success:function(){K.log("posted missing key '"+c+"' to: "+l.url);for(var a=c.split("."),e=0,f=C[l.lng][b];a[e];)f=f[a[e]]=e===a.length-1?d:f[a[e]]||{},e++},error:function(){K.log("failed posting missing key '"+c+"' to: "+l.url)},dataType:"json",async:G.postAsync})}}},M={rules:{ach:{name:"Acholi",numbers:[1,2],plurals:function(a){return Number(a>1)}},af:{name:"Afrikaans",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ak:{name:"Akan",numbers:[1,2],plurals:function(a){return Number(a>1)}},am:{name:"Amharic",numbers:[1,2],plurals:function(a){return Number(a>1)}},an:{name:"Aragonese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ar:{name:"Arabic",numbers:[0,1,2,3,11,100],plurals:function(a){return Number(0===a?0:1==a?1:2==a?2:a%100>=3&&10>=a%100?3:a%100>=11?4:5)}},arn:{name:"Mapudungun",numbers:[1,2],plurals:function(a){return Number(a>1)}},ast:{name:"Asturian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ay:{name:"Aymará",numbers:[1],plurals:function(){return 0}},az:{name:"Azerbaijani",numbers:[1,2],plurals:function(a){return Number(1!=a)}},be:{name:"Belarusian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},bg:{name:"Bulgarian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},bn:{name:"Bengali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},bo:{name:"Tibetan",numbers:[1],plurals:function(){return 0}},br:{name:"Breton",numbers:[1,2],plurals:function(a){return Number(a>1)}},bs:{name:"Bosnian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},ca:{name:"Catalan",numbers:[1,2],plurals:function(a){return Number(1!=a)}},cgg:{name:"Chiga",numbers:[1],plurals:function(){return 0}},cs:{name:"Czech",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)}},csb:{name:"Kashubian",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},cy:{name:"Welsh",numbers:[1,2,3,8],plurals:function(a){return Number(1==a?0:2==a?1:8!=a&&11!=a?2:3)}},da:{name:"Danish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},de:{name:"German",numbers:[1,2],plurals:function(a){return Number(1!=a)}},dz:{name:"Dzongkha",numbers:[1],plurals:function(){return 0}},el:{name:"Greek",numbers:[1,2],plurals:function(a){return Number(1!=a)}},en:{name:"English",numbers:[1,2],plurals:function(a){return Number(1!=a)}},eo:{name:"Esperanto",numbers:[1,2],plurals:function(a){return Number(1!=a)}},es:{name:"Spanish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},es_ar:{name:"Argentinean Spanish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},et:{name:"Estonian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},eu:{name:"Basque",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fa:{name:"Persian",numbers:[1],plurals:function(){return 0}},fi:{name:"Finnish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fil:{name:"Filipino",numbers:[1,2],plurals:function(a){return Number(a>1)}},fo:{name:"Faroese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fr:{name:"French",numbers:[1,2],plurals:function(a){return Number(a>1)}},fur:{name:"Friulian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fy:{name:"Frisian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ga:{name:"Irish",numbers:[1,2,3,7,11],plurals:function(a){return Number(1==a?0:2==a?1:7>a?2:11>a?3:4)}},gd:{name:"Scottish Gaelic",numbers:[1,2,3,20],plurals:function(a){return Number(1==a||11==a?0:2==a||12==a?1:a>2&&20>a?2:3)}},gl:{name:"Galician",numbers:[1,2],plurals:function(a){return Number(1!=a)}},gu:{name:"Gujarati",numbers:[1,2],plurals:function(a){return Number(1!=a)}},gun:{name:"Gun",numbers:[1,2],plurals:function(a){return Number(a>1)}},ha:{name:"Hausa",numbers:[1,2],plurals:function(a){return Number(1!=a)}},he:{name:"Hebrew",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hi:{name:"Hindi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hr:{name:"Croatian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},hu:{name:"Hungarian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hy:{name:"Armenian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ia:{name:"Interlingua",numbers:[1,2],plurals:function(a){return Number(1!=a)}},id:{name:"Indonesian",numbers:[1],plurals:function(){return 0}},is:{name:"Icelandic",numbers:[1,2],plurals:function(a){return Number(1!=a%10||11==a%100)}},it:{name:"Italian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ja:{name:"Japanese",numbers:[1],plurals:function(){return 0}},jbo:{name:"Lojban",numbers:[1],plurals:function(){return 0}},jv:{name:"Javanese",numbers:[0,1],plurals:function(a){return Number(0!==a)}},ka:{name:"Georgian",numbers:[1],plurals:function(){return 0}},kk:{name:"Kazakh",numbers:[1],plurals:function(){return 0}},km:{name:"Khmer",numbers:[1],plurals:function(){return 0}},kn:{name:"Kannada",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ko:{name:"Korean",numbers:[1],plurals:function(){return 0}},ku:{name:"Kurdish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},kw:{name:"Cornish",numbers:[1,2,3,4],plurals:function(a){return Number(1==a?0:2==a?1:3==a?2:3)}},ky:{name:"Kyrgyz",numbers:[1],plurals:function(){return 0}},lb:{name:"Letzeburgesch",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ln:{name:"Lingala",numbers:[1,2],plurals:function(a){return Number(a>1)}},lo:{name:"Lao",numbers:[1],plurals:function(){return 0}},lt:{name:"Lithuanian",numbers:[1,2,10],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&(10>a%100||a%100>=20)?1:2)}},lv:{name:"Latvian",numbers:[0,1,2],plurals:function(a){return Number(1==a%10&&11!=a%100?0:0!==a?1:2)}},mai:{name:"Maithili",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mfe:{name:"Mauritian Creole",numbers:[1,2],plurals:function(a){return Number(a>1)}},mg:{name:"Malagasy",numbers:[1,2],plurals:function(a){return Number(a>1)}},mi:{name:"Maori",numbers:[1,2],plurals:function(a){return Number(a>1)}},mk:{name:"Macedonian",numbers:[1,2],plurals:function(a){return Number(1==a||1==a%10?0:1)}},ml:{name:"Malayalam",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mn:{name:"Mongolian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mnk:{name:"Mandinka",numbers:[0,1,2],plurals:function(a){return Number(1==a?1:2)}},mr:{name:"Marathi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ms:{name:"Malay",numbers:[1],plurals:function(){return 0}},mt:{name:"Maltese",numbers:[1,2,11,20],plurals:function(a){return Number(1==a?0:0===a||a%100>1&&11>a%100?1:a%100>10&&20>a%100?2:3)}},nah:{name:"Nahuatl",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nap:{name:"Neapolitan",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nb:{name:"Norwegian Bokmal",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ne:{name:"Nepali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nl:{name:"Dutch",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nn:{name:"Norwegian Nynorsk",numbers:[1,2],plurals:function(a){return Number(1!=a)}},no:{name:"Norwegian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nso:{name:"Northern Sotho",numbers:[1,2],plurals:function(a){return Number(1!=a)}},oc:{name:"Occitan",numbers:[1,2],plurals:function(a){return Number(a>1)}},or:{name:"Oriya",numbers:[2,1],plurals:function(a){return Number(1!=a)}},pa:{name:"Punjabi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pap:{name:"Papiamento",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pl:{name:"Polish",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},pms:{name:"Piemontese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ps:{name:"Pashto",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pt:{name:"Portuguese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pt_br:{name:"Brazilian Portuguese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},rm:{name:"Romansh",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ro:{name:"Romanian",numbers:[1,2,20],plurals:function(a){return Number(1==a?0:0===a||a%100>0&&20>a%100?1:2)}},ru:{name:"Russian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},sah:{name:"Yakut",numbers:[1],plurals:function(){return 0}},sco:{name:"Scots",numbers:[1,2],plurals:function(a){return Number(1!=a)}},se:{name:"Northern Sami",numbers:[1,2],plurals:function(a){return Number(1!=a)}},si:{name:"Sinhala",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sk:{name:"Slovak",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)}},sl:{name:"Slovenian",numbers:[5,1,2,3],plurals:function(a){return Number(1==a%100?1:2==a%100?2:3==a%100||4==a%100?3:0)}},so:{name:"Somali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},son:{name:"Songhay",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sq:{name:"Albanian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sr:{name:"Serbian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},su:{name:"Sundanese",numbers:[1],plurals:function(){return 0}},sv:{name:"Swedish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sw:{name:"Swahili",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ta:{name:"Tamil",numbers:[1,2],plurals:function(a){return Number(1!=a)}},te:{name:"Telugu",numbers:[1,2],plurals:function(a){return Number(1!=a)}},tg:{name:"Tajik",numbers:[1,2],plurals:function(a){return Number(a>1)}},th:{name:"Thai",numbers:[1],plurals:function(){return 0}},ti:{name:"Tigrinya",numbers:[1,2],plurals:function(a){return Number(a>1)}},tk:{name:"Turkmen",numbers:[1,2],plurals:function(a){return Number(1!=a)}},tr:{name:"Turkish",numbers:[1,2],plurals:function(a){return Number(a>1)}},tt:{name:"Tatar",numbers:[1],plurals:function(){return 0}},ug:{name:"Uyghur",numbers:[1],plurals:function(){return 0}},uk:{name:"Ukrainian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},ur:{name:"Urdu",numbers:[1,2],plurals:function(a){return Number(1!=a)}},uz:{name:"Uzbek",numbers:[1,2],plurals:function(a){return Number(a>1)}},vi:{name:"Vietnamese",numbers:[1],plurals:function(){return 0}},wa:{name:"Walloon",numbers:[1,2],plurals:function(a){return Number(a>1)}},wo:{name:"Wolof",numbers:[1],plurals:function(){return 0}},yo:{name:"Yoruba",numbers:[1,2],plurals:function(a){return Number(1!=a)}},zh:{name:"Chinese",numbers:[1],plurals:function(){return 0}}},addRule:function(a,b){M.rules[a]=b},setCurrentLng:function(a){if(!M.currentRule||M.currentRule.lng!==a){var b=a.split("-");M.currentRule={lng:a,rule:M.rules[b[0]]}}},get:function(a,b){function c(b,c){var d;if(d=M.currentRule&&M.currentRule.lng===a?M.currentRule.rule:M.rules[b]){var e=d.plurals(c),f=d.numbers[e];return 2===d.numbers.length&&1===d.numbers[0]&&(2===f?f=-1:1===f&&(f=1)),f}return 1===c?"1":"-1"}var d=a.split("-");return c(d[0],b)}},N={},O=function(a,b){N[a]=b},P=function(){function a(a){return Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}function b(a,b){for(var c=[];b>0;c[--b]=a);return c.join("")}var c=function(){return c.cache.hasOwnProperty(arguments[0])||(c.cache[arguments[0]]=c.parse(arguments[0])),c.format.call(null,c.cache[arguments[0]],arguments)};return c.format=function(c,d){var e,f,g,h,i,j,k,l=1,m=c.length,n="",o=[];for(f=0;m>f;f++)if(n=a(c[f]),"string"===n)o.push(c[f]);else if("array"===n){if(h=c[f],h[2])for(e=d[l],g=0;g=0?"+"+e:e,j=h[4]?"0"==h[4]?"0":h[4].charAt(1):" ",k=h[6]-String(e).length,i=h[6]?b(j,k):"",o.push(h[5]?e+i:i+e)}return o.join("")},c.cache={},c.parse=function(a){for(var b=a,c=[],d=[],e=0;b;){if(null!==(c=/^[^\x25]+/.exec(b)))d.push(c[0]);else if(null!==(c=/^\x25{2}/.exec(b)))d.push("%");else{if(null===(c=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(b)))throw"[sprintf] huh?";if(c[2]){e|=1;var f=[],g=c[2],h=[];if(null===(h=/^([a-z_][a-z_\d]*)/i.exec(g)))throw"[sprintf] huh?";for(f.push(h[1]);""!==(g=g.substring(h[0].length));)if(null!==(h=/^\.([a-z_][a-z_\d]*)/i.exec(g)))f.push(h[1]);else{if(null===(h=/^\[(\d+)\]/.exec(g)))throw"[sprintf] huh?";f.push(h[1])}c[2]=f}else e|=2;if(3===e)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";d.push(c)}b=b.substring(c[0].length)}return d},c}(),Q=function(a,b){return b.unshift(a),P.apply(null,b)};return O("sprintf",function(a,b,c){return c.sprintf?"[object Array]"===Object.prototype.toString.apply(c.sprintf)?Q(a,c.sprintf):"object"==typeof c.sprintf?P(a,c.sprintf):a:a}),B.init=e,B.setLng=l,B.preload=f,B.addResourceBundle=g,B.removeResourceBundle=h,B.loadNamespace=j,B.loadNamespaces=k,B.setDefaultNamespace=i,B.t=t,B.translate=t,B.exists=s,B.detectLanguage=K.detectLanguage,B.pluralExtensions=M,B.sync=L,B.functions=K,B.lng=m,B.addPostProcessor=O,B.options=G,B}); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd-1.7.2.zip b/libs/i18next/release/i18next.amd-1.7.2.zip new file mode 100644 index 00000000..5c8ccff3 Binary files /dev/null and b/libs/i18next/release/i18next.amd-1.7.2.zip differ diff --git a/libs/i18next/release/i18next.amd-1.7.3.js b/libs/i18next/release/i18next.amd-1.7.3.js new file mode 100644 index 00000000..b08e206a --- /dev/null +++ b/libs/i18next/release/i18next.amd-1.7.3.js @@ -0,0 +1,2744 @@ +// i18next, v1.7.3 +// Copyright (c)2014 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function (root, factory) { + if (typeof exports === 'object') { + + module.exports = factory(); + + } else if (typeof define === 'function' && define.amd) { + + define([], factory); + + } +}(this, function () { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + // Add string trim for IE8. + if (typeof String.prototype.trim !== 'function') { + String.prototype.trim = function() { + return this.replace(/^\s+|\s+$/g, ''); + } + } + + var $ = undefined + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = [] + , initialized = false; + + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: ['dev'], + fallbackNS: [], + detectLngQS: 'setLng', + ns: 'translation', + fallbackOnNull: true, + fallbackOnEmpty: false, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + cookieDomain: undefined, + + objectTreeKeyHandler: undefined, + postProcess: undefined, + parseMissingKey: undefined, + + shortcutFunction: 'sprintf' // or: defaultValue + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || Object.prototype.toString.apply(object) !== '[object Array]' || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + return JSON.parse(data); + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + if (status === 200) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes,domain) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + domain = (domain)? "domain="+domain+";" : ""; + document.cookie = name+"="+value+expires+";"+domain+"path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes,domain) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : (typeof document !== 'undefined' ? _ajax : function() {}), + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + toLanguages: function(lng) { + var log = this.log; + var languages = []; + var whitelist = o.langWhitelist || false; + var addLanguage = function(language){ + //reject langs not whitelisted + if(!whitelist || whitelist.indexOf(language) > -1){ + languages.push(language); + }else{ + log('rejecting non-whitelisted language: ' + language); + } + }; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + + if (o.load !== 'unspecific') addLanguage(lng); + if (o.load !== 'current') addLanguage(parts[0]); + } else { + addLanguage(lng); + } + + for (var i = 0; i < o.fallbackLng.length; i++) { + if (languages.indexOf(o.fallbackLng[i]) === -1 && o.fallbackLng[i]) languages.push(o.fallbackLng[i]); + } + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + delete o.fixLng; /* passed in each time */ + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // fallback languages + if (typeof o.fallbackLng == 'string' || typeof o.fallbackLng == 'boolean') { + o.fallbackLng = [o.fallbackLng]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + if (o.useCookie && f.cookie.read(o.cookieName) !== currentLng){ //cookie is unset or invalid + f.cookie.create(o.cookieName, currentLng, o.cookieExpirationTime, o.cookieDomain); + } + + + var lngTranslate = translate; + if (options.fixLng) { + lngTranslate = function(key, options) { + options = options || {}; + options.lng = options.lng || lngTranslate.lng; + return translate(key, options); + }; + lngTranslate.lng = currentLng; + } + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + initialized = true; + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + initialized = true; + + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + f.extend(resStore[lng][ns], resources); + } + + function removeResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = {}; + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, options, cb) { + if (typeof options === 'function') { + cb = options; + options = {}; + } else if (!options) { + options = {}; + } + + options.lng = lng; + return init(options, cb); + } + + function lng() { + return currentLng; + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else if (attr === 'prepend') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.prepend($.t(key, optionsToUse)); + } else if (attr === 'append') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.append($.t(key, optionsToUse)); + } else if (attr.indexOf("data-") === 0) { + var dataAttr = attr.substr(("data-").length); + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.data(dataAttr) }, options) : options; + var translated = $.t(key, optionsToUse); + //we change into the data cache + ele.data(dataAttr, translated); + //we change into the dom + ele.attr(attr, translated); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key && typeof key !== 'undefined' && key !== false) key = ele.text() || ele.val(); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + f.each(replacementHash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), value); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.escape(value)); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), value); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, translated_token); + } + return translated; + } + + function hasContext(options) { + return (options.context && (typeof options.context == 'string' || typeof options.context == 'number')); + } + + function needsPlural(options) { + return (options.count !== undefined && typeof options.count != 'string' && options.count !== 1); + } + + function exists(key, options) { + options = options || {}; + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + options = options || {}; + + if (!initialized) { + f.log('i18next not finished initialization. you might have called t function before loading resources finished.') + return options.defaultValue || ''; + }; + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _getDefaultValue(key, options) { + return (options.defaultValue !== undefined) ? options.defaultValue : key; + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(potentialKeys, options) { + if (options && typeof options !== 'object') { + if (o.shortcutFunction === 'sprintf') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else if (o.shortcutFunction === 'defaultValue') { + options = { + defaultValue: options + } + } + } else { + options = options || {}; + } + + if (potentialKeys === undefined || potentialKeys === null) return ''; + + if (typeof potentialKeys == 'string') { + potentialKeys = [potentialKeys]; + } + + var key = potentialKeys[0]; + + if (potentialKeys.length > 1) { + for (var i = 0; i < potentialKeys.length; i++) { + key = potentialKeys[i]; + if (exists(key, options)) { + break; + } + } + } + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng) : languages + , ns = options.ns || o.ns.defaultNs + , parts; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing) { + if (options.lng) { + sync.postMissing(lngs[0], ns, key, notFound, lngs); + } else { + sync.postMissing(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found !== undefined && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + // process notFound if function exists + var splitNotFound = notFound; + if (notFound.indexOf(o.nsseparator) > -1) { + parts = notFound.split(o.nsseparator); + splitNotFound = parts[1]; + } + if (splitNotFound === key && o.parseMissingKey) { + notFound = o.parseMissingKey(notFound); + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessor && postProcessors[postProcessor]) { + var val = _getDefaultValue(key, options); + found = postProcessors[postProcessor](val, key, options); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options) { + options = options || {}; + + var optionWithoutCount, translated + , notFound = _getDefaultValue(key, options) + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + // CI mode + if (lngs[0].toLowerCase() === 'cimode') return notFound; + + // passed in lng + if (options.lng) { + lngs = f.toLanguages(options.lng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.count; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(lngs[0], options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + + translated = translate(pluralKey, optionWithoutCount); + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } // else continue translation with original/singular key + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + var valueType = Object.prototype.toString.apply(value); + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (valueType === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + if (o.objectTreeKeyHandler && typeof o.objectTreeKeyHandler == 'function') { + value = o.objectTreeKeyHandler(key, value, l, ns, options); + } else { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned an object instead of string.'; + f.log(value); + } + } else if (valueType !== '[object Number]' && valueType !== '[object Function]' && valueType !== '[object RegExp]') { + var copy = (valueType === '[object Array]') ? [] : {}; // apply child translation on a copy + f.each(value, function(m) { + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + }); + value = copy; + } + } + + if (typeof value === 'string' && value.trim() === '' && o.fallbackOnEmpty === true) + value = undefined; + + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length > 0))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + } + + return found; + } + function detectLanguage() { + var detectedLng; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var parms = query.split('&'); + for (var i=0; i 0) { + var key = parms[i].substring(0,pos); + var val = parms[i].substring(pos+1); + qsParm[key] = val; + } + } + })(); + if (qsParm[o.detectLngQS]) { + detectedLng = qsParm[o.detectLngQS]; + } + } + + // get from cookie + if (!detectedLng && typeof document !== 'undefined' && o.useCookie ) { + var c = f.cookie.read(o.cookieName); + if (c) detectedLng = c; + } + + // get from navigator + if (!detectedLng && typeof navigator !== 'undefined') { + detectedLng = (navigator.language) ? navigator.language : navigator.userLanguage; + } + + //fallback + if(!detectedLng){ + detectedLng = o.fallbackLng[0]; + } + + return detectedLng; + } + var sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + window.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + if ((status && status == 200) || (xhr && xhr.status && xhr.status == 200)) { + // file loaded but invalid json, stop waste time ! + f.log('There is a typo in: ' + url); + } else if ((status && status == 404) || (xhr && xhr.status && xhr.status == 404)) { + f.log('Does not exist: ' + url); + } else { + var theStatus = status ? status : ((xhr && xhr.status) ? xhr.status : null); + f.log(theStatus + ' when loading ' + url); + } + + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback' && o.fallbackLng[0] !== false) { + for (var i = 0; i < o.fallbackLng.length; i++) { + urls.push({lng: o.fallbackLng[i], url: applyReplacement(o.resPostPath, { lng: o.fallbackLng[i], ns: ns })}); + } + } else if (o.sendMissingTo === 'current' || (o.sendMissingTo === 'fallback' && o.fallbackLng[0] === false) ) { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + } + }; + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + var pluralExtensions = { + + rules: { + "ach": { + "name": "Acholi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "af": { + "name": "Afrikaans", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ak": { + "name": "Akan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "am": { + "name": "Amharic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "an": { + "name": "Aragonese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ar": { + "name": "Arabic", + "numbers": [ + 0, + 1, + 2, + 3, + 11, + 100 + ], + "plurals": function(n) { return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5); } + }, + "arn": { + "name": "Mapudungun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ast": { + "name": "Asturian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ay": { + "name": "Aymar\u00e1", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "az": { + "name": "Azerbaijani", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "be": { + "name": "Belarusian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "bg": { + "name": "Bulgarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bn": { + "name": "Bengali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bo": { + "name": "Tibetan", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "br": { + "name": "Breton", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "bs": { + "name": "Bosnian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ca": { + "name": "Catalan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "cgg": { + "name": "Chiga", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "cs": { + "name": "Czech", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "csb": { + "name": "Kashubian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "cy": { + "name": "Welsh", + "numbers": [ + 1, + 2, + 3, + 8 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3); } + }, + "da": { + "name": "Danish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "de": { + "name": "German", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "dz": { + "name": "Dzongkha", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "el": { + "name": "Greek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "en": { + "name": "English", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eo": { + "name": "Esperanto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es": { + "name": "Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es_ar": { + "name": "Argentinean Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "et": { + "name": "Estonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eu": { + "name": "Basque", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fa": { + "name": "Persian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "fi": { + "name": "Finnish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fil": { + "name": "Filipino", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fo": { + "name": "Faroese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fr": { + "name": "French", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fur": { + "name": "Friulian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fy": { + "name": "Frisian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ga": { + "name": "Irish", + "numbers": [ + 1, + 2, + 3, + 7, + 11 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;} + }, + "gd": { + "name": "Scottish Gaelic", + "numbers": [ + 1, + 2, + 3, + 20 + ], + "plurals": function(n) { return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3); } + }, + "gl": { + "name": "Galician", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gu": { + "name": "Gujarati", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gun": { + "name": "Gun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ha": { + "name": "Hausa", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "he": { + "name": "Hebrew", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hi": { + "name": "Hindi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hr": { + "name": "Croatian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "hu": { + "name": "Hungarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hy": { + "name": "Armenian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ia": { + "name": "Interlingua", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "id": { + "name": "Indonesian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "is": { + "name": "Icelandic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n%10!=1 || n%100==11); } + }, + "it": { + "name": "Italian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ja": { + "name": "Japanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jbo": { + "name": "Lojban", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jv": { + "name": "Javanese", + "numbers": [ + 0, + 1 + ], + "plurals": function(n) { return Number(n !== 0); } + }, + "ka": { + "name": "Georgian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kk": { + "name": "Kazakh", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "km": { + "name": "Khmer", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kn": { + "name": "Kannada", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ko": { + "name": "Korean", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ku": { + "name": "Kurdish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "kw": { + "name": "Cornish", + "numbers": [ + 1, + 2, + 3, + 4 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3); } + }, + "ky": { + "name": "Kyrgyz", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lb": { + "name": "Letzeburgesch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ln": { + "name": "Lingala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "lo": { + "name": "Lao", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lt": { + "name": "Lithuanian", + "numbers": [ + 1, + 2, + 10 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "lv": { + "name": "Latvian", + "numbers": [ + 1, + 2, + 0 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2); } + }, + "mai": { + "name": "Maithili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mfe": { + "name": "Mauritian Creole", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mg": { + "name": "Malagasy", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mi": { + "name": "Maori", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mk": { + "name": "Macedonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 || n%10==1 ? 0 : 1); } + }, + "ml": { + "name": "Malayalam", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mn": { + "name": "Mongolian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mnk": { + "name": "Mandinka", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(0 ? 0 : n==1 ? 1 : 2); } + }, + "mr": { + "name": "Marathi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ms": { + "name": "Malay", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "mt": { + "name": "Maltese", + "numbers": [ + 1, + 2, + 11, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3); } + }, + "nah": { + "name": "Nahuatl", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nap": { + "name": "Neapolitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nb": { + "name": "Norwegian Bokmal", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ne": { + "name": "Nepali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nl": { + "name": "Dutch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nn": { + "name": "Norwegian Nynorsk", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "no": { + "name": "Norwegian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nso": { + "name": "Northern Sotho", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "oc": { + "name": "Occitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "or": { + "name": "Oriya", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pa": { + "name": "Punjabi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pap": { + "name": "Papiamento", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pl": { + "name": "Polish", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "pms": { + "name": "Piemontese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ps": { + "name": "Pashto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt": { + "name": "Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt_br": { + "name": "Brazilian Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "rm": { + "name": "Romansh", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ro": { + "name": "Romanian", + "numbers": [ + 1, + 2, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2); } + }, + "ru": { + "name": "Russian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "sah": { + "name": "Yakut", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sco": { + "name": "Scots", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "se": { + "name": "Northern Sami", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "si": { + "name": "Sinhala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sk": { + "name": "Slovak", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "sl": { + "name": "Slovenian", + "numbers": [ + 5, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }, + "so": { + "name": "Somali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "son": { + "name": "Songhay", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sq": { + "name": "Albanian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sr": { + "name": "Serbian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "su": { + "name": "Sundanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sv": { + "name": "Swedish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sw": { + "name": "Swahili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ta": { + "name": "Tamil", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "te": { + "name": "Telugu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tg": { + "name": "Tajik", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "th": { + "name": "Thai", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ti": { + "name": "Tigrinya", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tk": { + "name": "Turkmen", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tr": { + "name": "Turkish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tt": { + "name": "Tatar", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ug": { + "name": "Uyghur", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "uk": { + "name": "Ukrainian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ur": { + "name": "Urdu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "uz": { + "name": "Uzbek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "vi": { + "name": "Vietnamese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "wa": { + "name": "Walloon", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "wo": { + "name": "Wolof", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "yo": { + "name": "Yoruba", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "zh": { + "name": "Chinese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + } + }, + + // for demonstration only sl and ar is added but you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i = ext.plurals(c); + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[0], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.removeResourceBundle = removeResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + + return i18n; + +})); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd-1.7.3.min.js b/libs/i18next/release/i18next.amd-1.7.3.min.js new file mode 100644 index 00000000..ccdd29b3 --- /dev/null +++ b/libs/i18next/release/i18next.amd-1.7.3.min.js @@ -0,0 +1,6 @@ +// i18next, v1.7.3 +// Copyright (c)2014 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +!function(a,b){"object"==typeof exports?module.exports=b():"function"==typeof define&&define.amd&&define([],b)}(this,function(){function a(a,b){if(!b||"function"==typeof b)return a;for(var c in b)a[c]=b[c];return a}function b(a,b,c){var d,e=0,f=a.length,g=void 0===f||"[object Array]"!==Object.prototype.toString.apply(a)||"function"==typeof a;if(c)if(g){for(d in a)if(b.apply(a[d],c)===!1)break}else for(;f>e&&b.apply(a[e++],c)!==!1;);else if(g){for(d in a)if(b.call(a[d],d,a[d])===!1)break}else for(;f>e&&b.call(a[e],e,a[e++])!==!1;);return a}function c(a){return"string"==typeof a?a.replace(/[&<>"'\/]/g,function(a){return H[a]}):a}function d(a){var b=function(a){if(window.XMLHttpRequest)return a(null,new XMLHttpRequest);if(window.ActiveXObject)try{return a(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(b){return a(null,new ActiveXObject("Microsoft.XMLHTTP"))}return a(new Error)},c=function(a){if("string"==typeof a)return a;var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")},d=function(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;cd?b+=String.fromCharCode(d):d>127&&2048>d?(b+=String.fromCharCode(d>>6|192),b+=String.fromCharCode(63&d|128)):(b+=String.fromCharCode(d>>12|224),b+=String.fromCharCode(d>>6&63|128),b+=String.fromCharCode(63&d|128))}return b},e=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";a=d(a);var c,e,f,g,h,i,j,k="",l=0;do c=a.charCodeAt(l++),e=a.charCodeAt(l++),f=a.charCodeAt(l++),g=c>>2,h=(3&c)<<4|e>>4,i=(15&e)<<2|f>>6,j=63&f,isNaN(e)?i=j=64:isNaN(f)&&(j=64),k+=b.charAt(g)+b.charAt(h)+b.charAt(i)+b.charAt(j),c=e=f="",g=h=i=j="";while(l1&&(d+=d.indexOf("?")>-1?"&"+k:"?"+k),e.jsonp){var l=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=d,void l.appendChild(m)}}b(function(b,c){if(b)return h(b);c.open(a,d,e.async);for(var f in j)j.hasOwnProperty(f)&&c.setRequestHeader(f,j[f]);c.onreadystatechange=function(){if(4===c.readyState){var a=c.responseText||"";if(!h)return;h(c.status,{text:function(){return a},json:function(){return JSON.parse(a)}})}},c.send(i)})},h={authBasic:function(a,b){g.headers.Authorization="Basic "+e(a+":"+b)},connect:function(a,b,c){return g("CONNECT",a,b,c)},del:function(a,b,c){return g("DELETE",a,b,c)},get:function(a,b,c){return g("GET",a,b,c)},head:function(a,b,c){return g("HEAD",a,b,c)},headers:function(a){g.headers=a||{}},isAllowed:function(a,b,c){this.options(a,function(a,d){c(-1!==d.text().indexOf(b))})},options:function(a,b,c){return g("OPTIONS",a,b,c)},patch:function(a,b,c){return g("PATCH",a,b,c)},post:function(a,b,c){return g("POST",a,b,c)},put:function(a,b,c){return g("PUT",a,b,c)},trace:function(a,b,c){return g("TRACE",a,b,c)}},i=a.type?a.type.toLowerCase():"get";h[i](a.url,a,function(b,c){200===b?a.success(c.json(),b,null):a.error(c.text(),b,null)})}function e(a,b){"function"==typeof a&&(b=a,a={}),a=a||{},K.extend(G,a),delete G.fixLng,"string"==typeof G.ns&&(G.ns={namespaces:[G.ns],defaultNs:G.ns}),"string"==typeof G.fallbackNS&&(G.fallbackNS=[G.fallbackNS]),("string"==typeof G.fallbackLng||"boolean"==typeof G.fallbackLng)&&(G.fallbackLng=[G.fallbackLng]),G.interpolationPrefixEscaped=K.regexEscape(G.interpolationPrefix),G.interpolationSuffixEscaped=K.regexEscape(G.interpolationSuffix),G.lng||(G.lng=K.detectLanguage()),E=K.toLanguages(G.lng),z=E[0],K.log("currentLng set to: "+z),G.useCookie&&K.cookie.read(G.cookieName)!==z&&K.cookie.create(G.cookieName,z,G.cookieExpirationTime,G.cookieDomain);var c=t;a.fixLng&&(c=function(a,b){return b=b||{},b.lng=b.lng||c.lng,t(a,b)},c.lng=z),M.setCurrentLng(z),A&&G.setJqueryExt&&n();var d;if(A&&A.Deferred&&(d=A.Deferred()),!G.resStore){var e=K.toLanguages(G.lng);"string"==typeof G.preload&&(G.preload=[G.preload]);for(var f=0,g=G.preload.length;g>f;f++)for(var h=K.toLanguages(G.preload[f]),i=0,j=h.length;j>i;i++)e.indexOf(h[i])<0&&e.push(h[i]);return B.sync.load(e,G,function(a,e){C=e,F=!0,b&&b(c),d&&d.resolve(c)}),d?d.promise():void 0}return C=G.resStore,F=!0,b&&b(c),d&&d.resolve(c),d?d.promise():void 0}function f(a,b){"string"==typeof a&&(a=[a]);for(var c=0,d=a.length;d>c;c++)G.preload.indexOf(a[c])<0&&G.preload.push(a[c]);return e(b)}function g(a,b,c){"string"!=typeof b?(c=b,b=G.ns.defaultNs):G.ns.namespaces.indexOf(b)<0&&G.ns.namespaces.push(b),C[a]=C[a]||{},C[a][b]=C[a][b]||{},K.extend(C[a][b],c)}function h(a,b){"string"!=typeof b&&(b=G.ns.defaultNs),C[a]=C[a]||{},C[a][b]={}}function i(a){G.ns.defaultNs=a}function j(a,b){k([a],b)}function k(a,b){var c={dynamicLoad:G.dynamicLoad,resGetPath:G.resGetPath,getAsync:G.getAsync,customLoad:G.customLoad,ns:{namespaces:a,defaultNs:""}},d=K.toLanguages(G.lng);"string"==typeof G.preload&&(G.preload=[G.preload]);for(var e=0,f=G.preload.length;f>e;e++)for(var g=K.toLanguages(G.preload[e]),h=0,i=g.length;i>h;h++)d.indexOf(g[h])<0&&d.push(g[h]);for(var j=[],k=0,l=d.length;l>k;k++){var m=!1,n=C[d[k]];if(n)for(var o=0,p=a.length;p>o;o++)n[a[o]]||(m=!0);else m=!0;m&&j.push(d[k])}j.length?B.sync._fetch(j,c,function(c,d){var e=a.length*j.length;K.each(a,function(a,c){G.ns.namespaces.indexOf(c)<0&&G.ns.namespaces.push(c),K.each(j,function(a,f){C[f]=C[f]||{},C[f][c]=d[f][c],e--,0===e&&b&&(G.useLocalStorage&&B.sync._storeLocal(C),b())})})}):b&&b()}function l(a,b,c){return"function"==typeof b?(c=b,b={}):b||(b={}),b.lng=a,e(b,c)}function m(){return z}function n(){function a(a,b,c){if(0!==b.length){var d="text";if(0===b.indexOf("[")){var e=b.split("]");b=e[1],d=e[0].substr(1,e[0].length-1)}b.indexOf(";")===b.length-1&&(b=b.substr(0,b.length-2));var f;if("html"===d)f=G.defaultValueFromContent?A.extend({defaultValue:a.html()},c):c,a.html(A.t(b,f));else if("text"===d)f=G.defaultValueFromContent?A.extend({defaultValue:a.text()},c):c,a.text(A.t(b,f));else if("prepend"===d)f=G.defaultValueFromContent?A.extend({defaultValue:a.html()},c):c,a.prepend(A.t(b,f));else if("append"===d)f=G.defaultValueFromContent?A.extend({defaultValue:a.html()},c):c,a.append(A.t(b,f));else if(0===d.indexOf("data-")){var g=d.substr("data-".length);f=G.defaultValueFromContent?A.extend({defaultValue:a.data(g)},c):c;var h=A.t(b,f);a.data(g,h),a.attr(d,h)}else f=G.defaultValueFromContent?A.extend({defaultValue:a.attr(d)},c):c,a.attr(d,A.t(b,f))}}function b(b,c){var d=b.attr(G.selectorAttr);if(d||"undefined"==typeof d||d===!1||(d=b.text()||b.val()),d){var e=b,f=b.data("i18n-target");if(f&&(e=b.find(f)||b),c||G.useDataAttrOptions!==!0||(c=b.data("i18n-options")),c=c||{},d.indexOf(";")>=0){var g=d.split(";");A.each(g,function(b,d){""!==d&&a(e,d,c)})}else a(e,d,c);G.useDataAttrOptions===!0&&b.data("i18n-options",c)}}A.t=A.t||t,A.fn.i18n=function(a){return this.each(function(){b(A(this),a);var c=A(this).find("["+G.selectorAttr+"]");c.each(function(){b(A(this),a)})})}}function o(a,b,c,d){if(!a)return a;if(d=d||b,a.indexOf(d.interpolationPrefix||G.interpolationPrefix)<0)return a;var e=d.interpolationPrefix?K.regexEscape(d.interpolationPrefix):G.interpolationPrefixEscaped,f=d.interpolationSuffix?K.regexEscape(d.interpolationSuffix):G.interpolationSuffixEscaped,g="HTML"+f;return K.each(b,function(b,h){var i=c?c+G.keyseparator+b:b;"object"==typeof h&&null!==h?a=o(a,h,i,d):d.escapeInterpolation||G.escapeInterpolation?(a=a.replace(new RegExp([e,i,g].join(""),"g"),h),a=a.replace(new RegExp([e,i,f].join(""),"g"),K.escape(h))):a=a.replace(new RegExp([e,i,f].join(""),"g"),h)}),a}function p(a,b){var c=",",d="{",e="}",f=K.extend({},b);for(delete f.postProcess;-1!=a.indexOf(G.reusePrefix)&&(D++,!(D>G.maxRecursion));){var g=a.lastIndexOf(G.reusePrefix),h=a.indexOf(G.reuseSuffix,g)+G.reuseSuffix.length,i=a.substring(g,h),j=i.replace(G.reusePrefix,"").replace(G.reuseSuffix,"");if(-1!=j.indexOf(c)){var k=j.indexOf(c);if(-1!=j.indexOf(d,k)&&-1!=j.indexOf(e,k)){var l=j.indexOf(d,k),m=j.indexOf(e,l)+e.length;try{f=K.extend(f,JSON.parse(j.substring(l,m))),j=j.substring(0,k)}catch(n){}}}var o=w(j,f);a=a.replace(i,o)}return a}function q(a){return a.context&&("string"==typeof a.context||"number"==typeof a.context)}function r(a){return void 0!==a.count&&"string"!=typeof a.count&&1!==a.count}function s(a,b){b=b||{};var c=u(a,b),d=x(a,b);return void 0!==d||d===c}function t(a,b){return b=b||{},F?(D=0,w.apply(null,arguments)):(K.log("i18next not finished initialization. you might have called t function before loading resources finished."),b.defaultValue||"")}function u(a,b){return void 0!==b.defaultValue?b.defaultValue:a}function v(){for(var a=[],b=1;b1)for(var d=0;d-1&&(e=c.split(G.nsseparator),i=e[0],c=e[1]),void 0===g&&G.sendMissing&&(b.lng?L.postMissing(h[0],i,c,f,h):L.postMissing(G.lng,i,c,f,h));var j=b.postProcess||G.postProcess;void 0!==g&&j&&N[j]&&(g=N[j](g,c,b));var k=f;if(f.indexOf(G.nsseparator)>-1&&(e=f.split(G.nsseparator),k=e[1]),k===c&&G.parseMissingKey&&(f=G.parseMissingKey(f)),void 0===g&&(f=o(f,b),f=p(f,b),j&&N[j])){var l=u(c,b);g=N[j](l,c,b)}return void 0!==g?g:f}function x(a,b){b=b||{};var c,d,e=u(a,b),f=E;if(!C)return e;if("cimode"===f[0].toLowerCase())return e;if(b.lng&&(f=K.toLanguages(b.lng),!C[f[0]])){var g=G.getAsync;G.getAsync=!1,B.sync.load(f,G,function(a,b){K.extend(C,b),G.getAsync=g})}var h=b.ns||G.ns.defaultNs;if(a.indexOf(G.nsseparator)>-1){var i=a.split(G.nsseparator);h=i[0],a=i[1]}if(q(b)){c=K.extend({},b),delete c.context,c.defaultValue=G.contextNotFound;var j=h+G.nsseparator+a+"_"+b.context;if(d=t(j,c),d!=G.contextNotFound)return o(d,{context:b.context})}if(r(b)){c=K.extend({},b),delete c.count,c.defaultValue=G.pluralNotFound;var k=h+G.nsseparator+a+G.pluralSuffix,l=M.get(f[0],b.count);if(l>=0?k=k+"_"+l:1===l&&(k=h+G.nsseparator+a),d=t(k,c),d!=G.pluralNotFound)return o(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix})}for(var m,n=a.split(G.keyseparator),s=0,v=f.length;v>s&&void 0===m;s++){for(var y=f[s],z=0,A=C[y]&&C[y][h];n[z];)A=A&&A[n[z]],z++;if(void 0!==A){var D=Object.prototype.toString.apply(A);if("string"==typeof A)A=o(A,b),A=p(A,b);else if("[object Array]"!==D||G.returnObjectTrees||b.returnObjectTrees){if(null===A&&G.fallbackOnNull===!0)A=void 0;else if(null!==A)if(G.returnObjectTrees||b.returnObjectTrees){if("[object Number]"!==D&&"[object Function]"!==D&&"[object RegExp]"!==D){var F="[object Array]"===D?[]:{};K.each(A,function(c){F[c]=w(h+G.nsseparator+a+G.keyseparator+c,b)}),A=F}}else G.objectTreeKeyHandler&&"function"==typeof G.objectTreeKeyHandler?A=G.objectTreeKeyHandler(a,A,y,h,b):(A="key '"+h+":"+a+" ("+y+")' returned an object instead of string.",K.log(A))}else A=A.join("\n"),A=o(A,b),A=p(A,b);"string"==typeof A&&""===A.trim()&&G.fallbackOnEmpty===!0&&(A=void 0),m=A}}if(void 0===m&&!b.isFallbackLookup&&(G.fallbackToDefaultNS===!0||G.fallbackNS&&G.fallbackNS.length>0))if(b.isFallbackLookup=!0,G.fallbackNS.length){for(var H=0,I=G.fallbackNS.length;I>H;H++)if(m=x(G.fallbackNS[H]+G.nsseparator+a,b)){var J=m.indexOf(G.nsseparator)>-1?m.split(G.nsseparator)[1]:m,L=e.indexOf(G.nsseparator)>-1?e.split(G.nsseparator)[1]:e;if(J!==L)break}}else m=x(a,b);return m}function y(){var a,b=[];if("undefined"!=typeof window&&(!function(){for(var a=window.location.search.substring(1),c=a.split("&"),d=0;d0){var f=c[d].substring(0,e),g=c[d].substring(e+1);b[f]=g}}}(),b[G.detectLngQS]&&(a=b[G.detectLngQS])),!a&&"undefined"!=typeof document&&G.useCookie){var c=K.cookie.read(G.cookieName);c&&(a=c)}return a||"undefined"==typeof navigator||(a=navigator.language?navigator.language:navigator.userLanguage),a||(a=G.fallbackLng[0]),a}Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>0&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&1/0!=d&&d!=-1/0&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=c;arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d))));for(var e=d>=0?Math.min(d,c-1):c-Math.abs(d);e>=0;e--)if(e in b&&b[e]===a)return e;return-1}),"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")});var z,A=void 0,B={},C={},D=0,E=[],F=!1,G={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:["dev"],fallbackNS:[],detectLngQS:"setLng",ns:"translation",fallbackOnNull:!0,fallbackOnEmpty:!1,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",cookieDomain:void 0,objectTreeKeyHandler:void 0,postProcess:void 0,parseMissingKey:void 0,shortcutFunction:"sprintf"},H={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},I={create:function(a,b,c,d){var e;if(c){var f=new Date;f.setTime(f.getTime()+60*c*1e3),e="; expires="+f.toGMTString()}else e="";d=d?"domain="+d+";":"",document.cookie=a+"="+b+e+";"+d+"path=/"},read:function(a){for(var b=a+"=",c=document.cookie.split(";"),d=0;d-1?c.push(a):b("rejecting non-whitelisted language: "+a)};if("string"==typeof a&&a.indexOf("-")>-1){var f=a.split("-");a=G.lowerCaseLng?f[0].toLowerCase()+"-"+f[1].toLowerCase():f[0].toLowerCase()+"-"+f[1].toUpperCase(),"unspecific"!==G.load&&e(a),"current"!==G.load&&e(f[0])}else e(a);for(var g=0;gg;g++)e[a[g]]||f.push(a[g]);f.length>0?L._fetch(f,b,function(a,b){K.extend(e,b),L._storeLocal(b),c(null,e)}):c(null,e)}):L._fetch(a,b,function(a,b){c(null,b)})},_loadLocal:function(a,b,c){var d={},e=(new Date).getTime();if(window.localStorage){var f=a.length;K.each(a,function(a,g){var h=window.localStorage.getItem("res_"+g);h&&(h=JSON.parse(h),h.i18nStamp&&h.i18nStamp+b.localStorageExpirationTime>e&&(d[g]=h)),f--,0===f&&c(null,d)})}},_storeLocal:function(a){if(window.localStorage)for(var b in a)a[b].i18nStamp=(new Date).getTime(),window.localStorage.setItem("res_"+b,JSON.stringify(a[b]))},_fetch:function(a,b,c){var d=b.ns,e={};if(b.dynamicLoad){var f=function(a,b){c(null,b)};if("function"==typeof b.customLoad)b.customLoad(a,d.namespaces,b,f);else{var g=o(b.resGetPath,{lng:a.join("+"),ns:d.namespaces.join("+")});K.ajax({url:g,success:function(a){K.log("loaded: "+g),f(null,a)},error:function(a,b,c){K.log("failed loading: "+g),f("failed loading resource.json error: "+c)},dataType:"json",async:b.getAsync})}}else{var h,i=d.namespaces.length*a.length;K.each(d.namespaces,function(d,f){K.each(a,function(a,d){var g=function(a,b){a&&(h=h||[],h.push(a)),e[d]=e[d]||{},e[d][f]=b,i--,0===i&&c(h,e)};"function"==typeof b.customLoad?b.customLoad(d,f,b,g):L._fetchOne(d,f,b,g)})})}},_fetchOne:function(a,b,c,d){var e=o(c.resGetPath,{lng:a,ns:b});K.ajax({url:e,success:function(a){K.log("loaded: "+e),d(null,a)},error:function(a,b,c){if(b&&200==b||a&&a.status&&200==a.status)K.log("There is a typo in: "+e);else if(b&&404==b||a&&a.status&&404==a.status)K.log("Does not exist: "+e);else{var f=b?b:a&&a.status?a.status:null;K.log(f+" when loading "+e)}d(c,{})},dataType:"json",async:c.getAsync})},postMissing:function(a,b,c,d,e){var f={};f[c]=d;var g=[];if("fallback"===G.sendMissingTo&&G.fallbackLng[0]!==!1)for(var h=0;hh;h++)g.push({lng:e[h],url:o(G.resPostPath,{lng:e[h],ns:b})});for(var j=0,k=g.length;k>j;j++){var l=g[j];K.ajax({url:l.url,type:G.sendType,data:f,success:function(){K.log("posted missing key '"+c+"' to: "+l.url);for(var a=c.split("."),e=0,f=C[l.lng][b];a[e];)f=f[a[e]]=e===a.length-1?d:f[a[e]]||{},e++},error:function(){K.log("failed posting missing key '"+c+"' to: "+l.url)},dataType:"json",async:G.postAsync})}}},M={rules:{ach:{name:"Acholi",numbers:[1,2],plurals:function(a){return Number(a>1)}},af:{name:"Afrikaans",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ak:{name:"Akan",numbers:[1,2],plurals:function(a){return Number(a>1)}},am:{name:"Amharic",numbers:[1,2],plurals:function(a){return Number(a>1)}},an:{name:"Aragonese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ar:{name:"Arabic",numbers:[0,1,2,3,11,100],plurals:function(a){return Number(0===a?0:1==a?1:2==a?2:a%100>=3&&10>=a%100?3:a%100>=11?4:5)}},arn:{name:"Mapudungun",numbers:[1,2],plurals:function(a){return Number(a>1)}},ast:{name:"Asturian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ay:{name:"Aymará",numbers:[1],plurals:function(){return 0}},az:{name:"Azerbaijani",numbers:[1,2],plurals:function(a){return Number(1!=a)}},be:{name:"Belarusian",numbers:[1,2,5],plurals:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},bg:{name:"Bulgarian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},bn:{name:"Bengali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},bo:{name:"Tibetan",numbers:[1],plurals:function(){return 0}},br:{name:"Breton",numbers:[1,2],plurals:function(a){return Number(a>1)}},bs:{name:"Bosnian",numbers:[1,2,5],plurals:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},ca:{name:"Catalan",numbers:[1,2],plurals:function(a){return Number(1!=a)}},cgg:{name:"Chiga",numbers:[1],plurals:function(){return 0}},cs:{name:"Czech",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)}},csb:{name:"Kashubian",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},cy:{name:"Welsh",numbers:[1,2,3,8],plurals:function(a){return Number(1==a?0:2==a?1:8!=a&&11!=a?2:3)}},da:{name:"Danish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},de:{name:"German",numbers:[1,2],plurals:function(a){return Number(1!=a)}},dz:{name:"Dzongkha",numbers:[1],plurals:function(){return 0}},el:{name:"Greek",numbers:[1,2],plurals:function(a){return Number(1!=a)}},en:{name:"English",numbers:[1,2],plurals:function(a){return Number(1!=a)}},eo:{name:"Esperanto",numbers:[1,2],plurals:function(a){return Number(1!=a)}},es:{name:"Spanish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},es_ar:{name:"Argentinean Spanish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},et:{name:"Estonian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},eu:{name:"Basque",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fa:{name:"Persian",numbers:[1],plurals:function(){return 0}},fi:{name:"Finnish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fil:{name:"Filipino",numbers:[1,2],plurals:function(a){return Number(a>1)}},fo:{name:"Faroese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fr:{name:"French",numbers:[1,2],plurals:function(a){return Number(a>1)}},fur:{name:"Friulian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fy:{name:"Frisian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ga:{name:"Irish",numbers:[1,2,3,7,11],plurals:function(a){return Number(1==a?0:2==a?1:7>a?2:11>a?3:4)}},gd:{name:"Scottish Gaelic",numbers:[1,2,3,20],plurals:function(a){return Number(1==a||11==a?0:2==a||12==a?1:a>2&&20>a?2:3)}},gl:{name:"Galician",numbers:[1,2],plurals:function(a){return Number(1!=a)}},gu:{name:"Gujarati",numbers:[1,2],plurals:function(a){return Number(1!=a)}},gun:{name:"Gun",numbers:[1,2],plurals:function(a){return Number(a>1)}},ha:{name:"Hausa",numbers:[1,2],plurals:function(a){return Number(1!=a)}},he:{name:"Hebrew",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hi:{name:"Hindi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hr:{name:"Croatian",numbers:[1,2,5],plurals:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},hu:{name:"Hungarian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hy:{name:"Armenian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ia:{name:"Interlingua",numbers:[1,2],plurals:function(a){return Number(1!=a)}},id:{name:"Indonesian",numbers:[1],plurals:function(){return 0}},is:{name:"Icelandic",numbers:[1,2],plurals:function(a){return Number(a%10!=1||a%100==11)}},it:{name:"Italian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ja:{name:"Japanese",numbers:[1],plurals:function(){return 0}},jbo:{name:"Lojban",numbers:[1],plurals:function(){return 0}},jv:{name:"Javanese",numbers:[0,1],plurals:function(a){return Number(0!==a)}},ka:{name:"Georgian",numbers:[1],plurals:function(){return 0}},kk:{name:"Kazakh",numbers:[1],plurals:function(){return 0}},km:{name:"Khmer",numbers:[1],plurals:function(){return 0}},kn:{name:"Kannada",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ko:{name:"Korean",numbers:[1],plurals:function(){return 0}},ku:{name:"Kurdish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},kw:{name:"Cornish",numbers:[1,2,3,4],plurals:function(a){return Number(1==a?0:2==a?1:3==a?2:3)}},ky:{name:"Kyrgyz",numbers:[1],plurals:function(){return 0}},lb:{name:"Letzeburgesch",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ln:{name:"Lingala",numbers:[1,2],plurals:function(a){return Number(a>1)}},lo:{name:"Lao",numbers:[1],plurals:function(){return 0}},lt:{name:"Lithuanian",numbers:[1,2,10],plurals:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&(10>a%100||a%100>=20)?1:2)}},lv:{name:"Latvian",numbers:[1,2,0],plurals:function(a){return Number(a%10==1&&a%100!=11?0:0!==a?1:2)}},mai:{name:"Maithili",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mfe:{name:"Mauritian Creole",numbers:[1,2],plurals:function(a){return Number(a>1)}},mg:{name:"Malagasy",numbers:[1,2],plurals:function(a){return Number(a>1)}},mi:{name:"Maori",numbers:[1,2],plurals:function(a){return Number(a>1)}},mk:{name:"Macedonian",numbers:[1,2],plurals:function(a){return Number(1==a||a%10==1?0:1)}},ml:{name:"Malayalam",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mn:{name:"Mongolian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mnk:{name:"Mandinka",numbers:[0,1,2],plurals:function(a){return Number(1==a?1:2)}},mr:{name:"Marathi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ms:{name:"Malay",numbers:[1],plurals:function(){return 0}},mt:{name:"Maltese",numbers:[1,2,11,20],plurals:function(a){return Number(1==a?0:0===a||a%100>1&&11>a%100?1:a%100>10&&20>a%100?2:3)}},nah:{name:"Nahuatl",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nap:{name:"Neapolitan",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nb:{name:"Norwegian Bokmal",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ne:{name:"Nepali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nl:{name:"Dutch",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nn:{name:"Norwegian Nynorsk",numbers:[1,2],plurals:function(a){return Number(1!=a)}},no:{name:"Norwegian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nso:{name:"Northern Sotho",numbers:[1,2],plurals:function(a){return Number(1!=a)}},oc:{name:"Occitan",numbers:[1,2],plurals:function(a){return Number(a>1)}},or:{name:"Oriya",numbers:[2,1],plurals:function(a){return Number(1!=a)}},pa:{name:"Punjabi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pap:{name:"Papiamento",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pl:{name:"Polish",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},pms:{name:"Piemontese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ps:{name:"Pashto",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pt:{name:"Portuguese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pt_br:{name:"Brazilian Portuguese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},rm:{name:"Romansh",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ro:{name:"Romanian",numbers:[1,2,20],plurals:function(a){return Number(1==a?0:0===a||a%100>0&&20>a%100?1:2)}},ru:{name:"Russian",numbers:[1,2,5],plurals:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},sah:{name:"Yakut",numbers:[1],plurals:function(){return 0}},sco:{name:"Scots",numbers:[1,2],plurals:function(a){return Number(1!=a)}},se:{name:"Northern Sami",numbers:[1,2],plurals:function(a){return Number(1!=a)}},si:{name:"Sinhala",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sk:{name:"Slovak",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)}},sl:{name:"Slovenian",numbers:[5,1,2,3],plurals:function(a){return Number(a%100==1?1:a%100==2?2:a%100==3||a%100==4?3:0)}},so:{name:"Somali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},son:{name:"Songhay",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sq:{name:"Albanian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sr:{name:"Serbian",numbers:[1,2,5],plurals:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},su:{name:"Sundanese",numbers:[1],plurals:function(){return 0}},sv:{name:"Swedish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sw:{name:"Swahili",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ta:{name:"Tamil",numbers:[1,2],plurals:function(a){return Number(1!=a)}},te:{name:"Telugu",numbers:[1,2],plurals:function(a){return Number(1!=a)}},tg:{name:"Tajik",numbers:[1,2],plurals:function(a){return Number(a>1)}},th:{name:"Thai",numbers:[1],plurals:function(){return 0}},ti:{name:"Tigrinya",numbers:[1,2],plurals:function(a){return Number(a>1)}},tk:{name:"Turkmen",numbers:[1,2],plurals:function(a){return Number(1!=a)}},tr:{name:"Turkish",numbers:[1,2],plurals:function(a){return Number(a>1)}},tt:{name:"Tatar",numbers:[1],plurals:function(){return 0}},ug:{name:"Uyghur",numbers:[1],plurals:function(){return 0}},uk:{name:"Ukrainian",numbers:[1,2,5],plurals:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},ur:{name:"Urdu",numbers:[1,2],plurals:function(a){return Number(1!=a)}},uz:{name:"Uzbek",numbers:[1,2],plurals:function(a){return Number(a>1)}},vi:{name:"Vietnamese",numbers:[1],plurals:function(){return 0}},wa:{name:"Walloon",numbers:[1,2],plurals:function(a){return Number(a>1)}},wo:{name:"Wolof",numbers:[1],plurals:function(){return 0}},yo:{name:"Yoruba",numbers:[1,2],plurals:function(a){return Number(1!=a)}},zh:{name:"Chinese",numbers:[1],plurals:function(){return 0}}},addRule:function(a,b){M.rules[a]=b},setCurrentLng:function(a){if(!M.currentRule||M.currentRule.lng!==a){var b=a.split("-");M.currentRule={lng:a,rule:M.rules[b[0]]}}},get:function(a,b){function c(b,c){var d;if(d=M.currentRule&&M.currentRule.lng===a?M.currentRule.rule:M.rules[b]){var e=d.plurals(c),f=d.numbers[e];return 2===d.numbers.length&&1===d.numbers[0]&&(2===f?f=-1:1===f&&(f=1)),f}return 1===c?"1":"-1"}var d=a.split("-");return c(d[0],b)}},N={},O=function(a,b){N[a]=b},P=function(){function a(a){return Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}function b(a,b){for(var c=[];b>0;c[--b]=a);return c.join("")}var c=function(){return c.cache.hasOwnProperty(arguments[0])||(c.cache[arguments[0]]=c.parse(arguments[0])),c.format.call(null,c.cache[arguments[0]],arguments)};return c.format=function(c,d){var e,f,g,h,i,j,k,l=1,m=c.length,n="",o=[];for(f=0;m>f;f++)if(n=a(c[f]),"string"===n)o.push(c[f]);else if("array"===n){if(h=c[f],h[2])for(e=d[l],g=0;g=0?"+"+e:e,j=h[4]?"0"==h[4]?"0":h[4].charAt(1):" ",k=h[6]-String(e).length,i=h[6]?b(j,k):"",o.push(h[5]?e+i:i+e)}return o.join("")},c.cache={},c.parse=function(a){for(var b=a,c=[],d=[],e=0;b;){if(null!==(c=/^[^\x25]+/.exec(b)))d.push(c[0]);else if(null!==(c=/^\x25{2}/.exec(b)))d.push("%");else{if(null===(c=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(b)))throw"[sprintf] huh?";if(c[2]){e|=1;var f=[],g=c[2],h=[];if(null===(h=/^([a-z_][a-z_\d]*)/i.exec(g)))throw"[sprintf] huh?";for(f.push(h[1]);""!==(g=g.substring(h[0].length));)if(null!==(h=/^\.([a-z_][a-z_\d]*)/i.exec(g)))f.push(h[1]);else{if(null===(h=/^\[(\d+)\]/.exec(g)))throw"[sprintf] huh?";f.push(h[1])}c[2]=f}else e|=2;if(3===e)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";d.push(c)}b=b.substring(c[0].length)}return d},c}(),Q=function(a,b){return b.unshift(a),P.apply(null,b)};return O("sprintf",function(a,b,c){return c.sprintf?"[object Array]"===Object.prototype.toString.apply(c.sprintf)?Q(a,c.sprintf):"object"==typeof c.sprintf?P(a,c.sprintf):a:a +}),B.init=e,B.setLng=l,B.preload=f,B.addResourceBundle=g,B.removeResourceBundle=h,B.loadNamespace=j,B.loadNamespaces=k,B.setDefaultNamespace=i,B.t=t,B.translate=t,B.exists=s,B.detectLanguage=K.detectLanguage,B.pluralExtensions=M,B.sync=L,B.functions=K,B.lng=m,B.addPostProcessor=O,B.options=G,B}); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd-1.7.3.zip b/libs/i18next/release/i18next.amd-1.7.3.zip new file mode 100644 index 00000000..30ac6551 Binary files /dev/null and b/libs/i18next/release/i18next.amd-1.7.3.zip differ diff --git a/libs/i18next/release/i18next.amd-1.7.4.js b/libs/i18next/release/i18next.amd-1.7.4.js new file mode 100644 index 00000000..9a57168b --- /dev/null +++ b/libs/i18next/release/i18next.amd-1.7.4.js @@ -0,0 +1,2875 @@ +// i18next, v1.7.4 +// Copyright (c)2014 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function (root, factory) { + if (typeof exports === 'object') { + + module.exports = factory(); + + } else if (typeof define === 'function' && define.amd) { + + define([], factory); + + } +}(this, function () { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + // Add string trim for IE8. + if (typeof String.prototype.trim !== 'function') { + String.prototype.trim = function() { + return this.replace(/^\s+|\s+$/g, ''); + } + } + + var $ = undefined + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = [] + , initialized = false; + + sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + window.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + if ((status && status == 200) || (xhr && xhr.status && xhr.status == 200)) { + // file loaded but invalid json, stop waste time ! + f.error('There is a typo in: ' + url); + } else if ((status && status == 404) || (xhr && xhr.status && xhr.status == 404)) { + f.log('Does not exist: ' + url); + } else { + var theStatus = status ? status : ((xhr && xhr.status) ? xhr.status : null); + f.log(theStatus + ' when loading ' + url); + } + + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback' && o.fallbackLng[0] !== false) { + for (var i = 0; i < o.fallbackLng.length; i++) { + urls.push({lng: o.fallbackLng[i], url: applyReplacement(o.resPostPath, { lng: o.fallbackLng[i], ns: ns })}); + } + } else if (o.sendMissingTo === 'current' || (o.sendMissingTo === 'fallback' && o.fallbackLng[0] === false) ) { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + } + }; + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: ['dev'], + fallbackNS: [], + detectLngQS: 'setLng', + detectLngFromLocalStorage: false, + ns: 'translation', + fallbackOnNull: true, + fallbackOnEmpty: false, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + indefiniteSuffix: '_indefinite', + indefiniteNotFound: ['indefinite_not_found', Math.random()].join(''), + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + cookieDomain: undefined, + + objectTreeKeyHandler: undefined, + postProcess: undefined, + parseMissingKey: undefined, + missingKeyHandler: sync.postMissing, + + shortcutFunction: 'sprintf' // or: defaultValue + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _deepExtend(target, source) { + for (var prop in source) + if (prop in target) + _deepExtend(target[prop], source[prop]); + else + target[prop] = source[prop]; + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || Object.prototype.toString.apply(object) !== '[object Array]' || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + return JSON.parse(data); + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + // file: protocol always gives status code 0, so check for data + if (status === 200 || (status === 0 && data.text())) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes,domain) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + domain = (domain)? "domain="+domain+";" : ""; + document.cookie = name+"="+value+expires+";"+domain+"path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes,domain) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + deepExtend: _deepExtend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : (typeof document !== 'undefined' ? _ajax : function() {}), + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + error: function(str) { + if (typeof console !== "undefined") console.error(str); + }, + getCountyIndexOfLng: function(lng) { + var lng_index = 0; + if (lng === 'nb-NO' || lng === 'nn-NO') lng_index = 1; + return lng_index; + }, + toLanguages: function(lng) { + var log = this.log; + + var languages = []; + var whitelist = o.lngWhitelist || false; + var addLanguage = function(language){ + //reject langs not whitelisted + if(!whitelist || whitelist.indexOf(language) > -1){ + languages.push(language); + }else{ + log('rejecting non-whitelisted language: ' + language); + } + }; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + + if (o.load !== 'unspecific') addLanguage(lng); + if (o.load !== 'current') addLanguage(parts[this.getCountyIndexOfLng(lng)]); + } else { + addLanguage(lng); + } + + for (var i = 0; i < o.fallbackLng.length; i++) { + if (languages.indexOf(o.fallbackLng[i]) === -1 && o.fallbackLng[i]) languages.push(o.fallbackLng[i]); + } + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + }, + regexReplacementEscape: function(strOrFn) { + if (typeof strOrFn === 'string') { + return strOrFn.replace(/\$/g, "$$$$"); + } else { + return strOrFn; + } + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + delete o.fixLng; /* passed in each time */ + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // fallback languages + if (typeof o.fallbackLng == 'string' || typeof o.fallbackLng == 'boolean') { + o.fallbackLng = [o.fallbackLng]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + if (o.useCookie && f.cookie.read(o.cookieName) !== currentLng){ //cookie is unset or invalid + f.cookie.create(o.cookieName, currentLng, o.cookieExpirationTime, o.cookieDomain); + } + if (o.detectLngFromLocalStorage && typeof document !== 'undefined' && window.localstorage) { + window.localStorage.setItem('i18next_lng', currentLng); + } + + var lngTranslate = translate; + if (options.fixLng) { + lngTranslate = function(key, options) { + options = options || {}; + options.lng = options.lng || lngTranslate.lng; + return translate(key, options); + }; + lngTranslate.lng = currentLng; + } + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + initialized = true; + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + initialized = true; + + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources, deep) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + if (deep) { + f.deepExtend(resStore[lng][ns], resources); + } else { + f.extend(resStore[lng][ns], resources); + } + } + + function removeResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = {}; + } + + function addResource(lng, ns, key, value) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + var keys = key.split(o.keyseparator); + var x = 0; + var node = resStore[o.lng][ns]; + var origRef = node; + + while (keys[x]) { + if (x == keys.length - 1) + node[keys[x]] = value; + else { + if (node[keys[x]] == null) + node[keys[x]] = {}; + + node = node[keys[x]]; + } + x++; + } + } + + function addResources(lng, ns, resources) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + for (var m in resources) { + if (typeof resources[m] === 'string') addResource(lng, ns, m, resources[m]); + } + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, options, cb) { + if (typeof options === 'function') { + cb = options; + options = {}; + } else if (!options) { + options = {}; + } + + options.lng = lng; + return init(options, cb); + } + + function lng() { + return currentLng; + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else if (attr === 'prepend') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.prepend($.t(key, optionsToUse)); + } else if (attr === 'append') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.append($.t(key, optionsToUse)); + } else if (attr.indexOf("data-") === 0) { + var dataAttr = attr.substr(("data-").length); + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.data(dataAttr) }, options) : options; + var translated = $.t(key, optionsToUse); + //we change into the data cache + ele.data(dataAttr, translated); + //we change into the dom + ele.attr(attr, translated); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key && typeof key !== 'undefined' && key !== false) key = ele.text() || ele.val(); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + var hash = replacementHash.replace && typeof replacementHash.replace === 'object' ? replacementHash.replace : replacementHash; + f.each(hash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), f.regexReplacementEscape(value)); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(f.escape(value))); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(value)); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + if (index_of_end_of_closing <= index_of_opening) { + f.error('there is an missing closing in following translation value', translated); + return ''; + } + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, f.regexReplacementEscape(translated_token)); + } + return translated; + } + + function hasContext(options) { + return (options.context && (typeof options.context == 'string' || typeof options.context == 'number')); + } + + function needsPlural(options, lng) { + return (options.count !== undefined && typeof options.count != 'string' && pluralExtensions.needsPlural(lng, options.count)); + } + + function needsIndefiniteArticle(options) { + return (options.indefinite_article !== undefined && typeof options.indefinite_article != 'string' && options.indefinite_article); + } + + function exists(key, options) { + options = options || {}; + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + options = options || {}; + + if (!initialized) { + f.log('i18next not finished initialization. you might have called t function before loading resources finished.') + return options.defaultValue || ''; + }; + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _getDefaultValue(key, options) { + return (options.defaultValue !== undefined) ? options.defaultValue : key; + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(potentialKeys, options) { + if (options && typeof options !== 'object') { + if (o.shortcutFunction === 'sprintf') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else if (o.shortcutFunction === 'defaultValue') { + options = { + defaultValue: options + } + } + } else { + options = options || {}; + } + + if (potentialKeys === undefined || potentialKeys === null || potentialKeys === '') return ''; + + if (typeof potentialKeys == 'string') { + potentialKeys = [potentialKeys]; + } + + var key = potentialKeys[0]; + + if (potentialKeys.length > 1) { + for (var i = 0; i < potentialKeys.length; i++) { + key = potentialKeys[i]; + if (exists(key, options)) { + break; + } + } + } + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng, options.fallbackLng) : languages + , ns = options.ns || o.ns.defaultNs + , parts; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing && typeof o.missingKeyHandler === 'function') { + if (options.lng) { + o.missingKeyHandler(lngs[0], ns, key, notFound, lngs); + } else { + o.missingKeyHandler(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found !== undefined && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + // process notFound if function exists + var splitNotFound = notFound; + if (notFound.indexOf(o.nsseparator) > -1) { + parts = notFound.split(o.nsseparator); + splitNotFound = parts[1]; + } + if (splitNotFound === key && o.parseMissingKey) { + notFound = o.parseMissingKey(notFound); + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessor && postProcessors[postProcessor]) { + var val = _getDefaultValue(key, options); + found = postProcessors[postProcessor](val, key, options); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options) { + options = options || {}; + + var optionWithoutCount, translated + , notFound = _getDefaultValue(key, options) + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + // CI mode + if (lngs[0].toLowerCase() === 'cimode') return notFound; + + // passed in lng + if (options.lng) { + lngs = f.toLanguages(options.lng, options.fallbackLng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options, lngs[0])) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.count; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(lngs[0], options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + + translated = translate(pluralKey, optionWithoutCount); + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } // else continue translation with original/singular key + } + + if (needsIndefiniteArticle(options)) { + var optionsWithoutIndef = f.extend({}, options); + delete optionsWithoutIndef.indefinite_article; + optionsWithoutIndef.defaultValue = o.indefiniteNotFound; + // If we don't have a count, we want the indefinite, if we do have a count, and needsPlural is false + var indefiniteKey = ns + o.nsseparator + key + (((options.count && !needsPlural(options, lngs[0])) || !options.count) ? o.indefiniteSuffix : ""); + translated = translate(indefiniteKey, optionsWithoutIndef); + if (translated != o.indefiniteNotFound) { + return translated; + } + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + var valueType = Object.prototype.toString.apply(value); + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (valueType === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + if (o.objectTreeKeyHandler && typeof o.objectTreeKeyHandler == 'function') { + value = o.objectTreeKeyHandler(key, value, l, ns, options); + } else { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned an object instead of string.'; + f.log(value); + } + } else if (valueType !== '[object Number]' && valueType !== '[object Function]' && valueType !== '[object RegExp]') { + var copy = (valueType === '[object Array]') ? [] : {}; // apply child translation on a copy + f.each(value, function(m) { + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + }); + value = copy; + } + } + + if (typeof value === 'string' && value.trim() === '' && o.fallbackOnEmpty === true) + value = undefined; + + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length > 0))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + options.isFallbackLookup = false; + } + + return found; + } + function detectLanguage() { + var detectedLng; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var parms = query.split('&'); + for (var i=0; i 0) { + var key = parms[i].substring(0,pos); + var val = parms[i].substring(pos+1); + qsParm[key] = val; + } + } + })(); + if (qsParm[o.detectLngQS]) { + detectedLng = qsParm[o.detectLngQS]; + } + } + + // get from cookie + if (!detectedLng && typeof document !== 'undefined' && o.useCookie ) { + var c = f.cookie.read(o.cookieName); + if (c) detectedLng = c; + } + + // get from localstorage + if (!detectedLng && typeof document !== 'undefined' && window.localstorage && o.detectLngFromLocalStorage) { + detectedLng = window.localStorage.getItem('i18next_lng'); + } + + // get from navigator + if (!detectedLng && typeof navigator !== 'undefined') { + detectedLng = (navigator.language) ? navigator.language : navigator.userLanguage; + } + + //fallback + if(!detectedLng){ + detectedLng = o.fallbackLng[0]; + } + + return detectedLng; + } + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + var pluralExtensions = { + + rules: { + "ach": { + "name": "Acholi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "af": { + "name": "Afrikaans", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ak": { + "name": "Akan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "am": { + "name": "Amharic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "an": { + "name": "Aragonese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ar": { + "name": "Arabic", + "numbers": [ + 0, + 1, + 2, + 3, + 11, + 100 + ], + "plurals": function(n) { return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5); } + }, + "arn": { + "name": "Mapudungun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ast": { + "name": "Asturian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ay": { + "name": "Aymar\u00e1", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "az": { + "name": "Azerbaijani", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "be": { + "name": "Belarusian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "bg": { + "name": "Bulgarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bn": { + "name": "Bengali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bo": { + "name": "Tibetan", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "br": { + "name": "Breton", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "bs": { + "name": "Bosnian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ca": { + "name": "Catalan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "cgg": { + "name": "Chiga", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "cs": { + "name": "Czech", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "csb": { + "name": "Kashubian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "cy": { + "name": "Welsh", + "numbers": [ + 1, + 2, + 3, + 8 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3); } + }, + "da": { + "name": "Danish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "de": { + "name": "German", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "dz": { + "name": "Dzongkha", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "el": { + "name": "Greek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "en": { + "name": "English", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eo": { + "name": "Esperanto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es": { + "name": "Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es_ar": { + "name": "Argentinean Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "et": { + "name": "Estonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eu": { + "name": "Basque", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fa": { + "name": "Persian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "fi": { + "name": "Finnish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fil": { + "name": "Filipino", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fo": { + "name": "Faroese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fr": { + "name": "French", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n >= 2); } + }, + "fur": { + "name": "Friulian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fy": { + "name": "Frisian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ga": { + "name": "Irish", + "numbers": [ + 1, + 2, + 3, + 7, + 11 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;} + }, + "gd": { + "name": "Scottish Gaelic", + "numbers": [ + 1, + 2, + 3, + 20 + ], + "plurals": function(n) { return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3); } + }, + "gl": { + "name": "Galician", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gu": { + "name": "Gujarati", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gun": { + "name": "Gun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ha": { + "name": "Hausa", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "he": { + "name": "Hebrew", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hi": { + "name": "Hindi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hr": { + "name": "Croatian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "hu": { + "name": "Hungarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hy": { + "name": "Armenian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ia": { + "name": "Interlingua", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "id": { + "name": "Indonesian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "is": { + "name": "Icelandic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n%10!=1 || n%100==11); } + }, + "it": { + "name": "Italian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ja": { + "name": "Japanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jbo": { + "name": "Lojban", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jv": { + "name": "Javanese", + "numbers": [ + 0, + 1 + ], + "plurals": function(n) { return Number(n !== 0); } + }, + "ka": { + "name": "Georgian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kk": { + "name": "Kazakh", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "km": { + "name": "Khmer", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kn": { + "name": "Kannada", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ko": { + "name": "Korean", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ku": { + "name": "Kurdish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "kw": { + "name": "Cornish", + "numbers": [ + 1, + 2, + 3, + 4 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3); } + }, + "ky": { + "name": "Kyrgyz", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lb": { + "name": "Letzeburgesch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ln": { + "name": "Lingala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "lo": { + "name": "Lao", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lt": { + "name": "Lithuanian", + "numbers": [ + 1, + 2, + 10 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "lv": { + "name": "Latvian", + "numbers": [ + 1, + 2, + 0 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2); } + }, + "mai": { + "name": "Maithili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mfe": { + "name": "Mauritian Creole", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mg": { + "name": "Malagasy", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mi": { + "name": "Maori", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mk": { + "name": "Macedonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 || n%10==1 ? 0 : 1); } + }, + "ml": { + "name": "Malayalam", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mn": { + "name": "Mongolian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mnk": { + "name": "Mandinka", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(0 ? 0 : n==1 ? 1 : 2); } + }, + "mr": { + "name": "Marathi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ms": { + "name": "Malay", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "mt": { + "name": "Maltese", + "numbers": [ + 1, + 2, + 11, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3); } + }, + "nah": { + "name": "Nahuatl", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nap": { + "name": "Neapolitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nb": { + "name": "Norwegian Bokmal", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ne": { + "name": "Nepali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nl": { + "name": "Dutch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nn": { + "name": "Norwegian Nynorsk", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "no": { + "name": "Norwegian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nso": { + "name": "Northern Sotho", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "oc": { + "name": "Occitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "or": { + "name": "Oriya", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pa": { + "name": "Punjabi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pap": { + "name": "Papiamento", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pl": { + "name": "Polish", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "pms": { + "name": "Piemontese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ps": { + "name": "Pashto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt": { + "name": "Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt_br": { + "name": "Brazilian Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "rm": { + "name": "Romansh", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ro": { + "name": "Romanian", + "numbers": [ + 1, + 2, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2); } + }, + "ru": { + "name": "Russian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "sah": { + "name": "Yakut", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sco": { + "name": "Scots", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "se": { + "name": "Northern Sami", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "si": { + "name": "Sinhala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sk": { + "name": "Slovak", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "sl": { + "name": "Slovenian", + "numbers": [ + 5, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }, + "so": { + "name": "Somali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "son": { + "name": "Songhay", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sq": { + "name": "Albanian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sr": { + "name": "Serbian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "su": { + "name": "Sundanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sv": { + "name": "Swedish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sw": { + "name": "Swahili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ta": { + "name": "Tamil", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "te": { + "name": "Telugu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tg": { + "name": "Tajik", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "th": { + "name": "Thai", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ti": { + "name": "Tigrinya", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tk": { + "name": "Turkmen", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tr": { + "name": "Turkish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tt": { + "name": "Tatar", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ug": { + "name": "Uyghur", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "uk": { + "name": "Ukrainian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ur": { + "name": "Urdu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "uz": { + "name": "Uzbek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "vi": { + "name": "Vietnamese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "wa": { + "name": "Walloon", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "wo": { + "name": "Wolof", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "yo": { + "name": "Yoruba", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "zh": { + "name": "Chinese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + } + }, + + // for demonstration only sl and ar is added but you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + needsPlural: function(lng, count) { + var parts = lng.split('-'); + + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[parts[f.getCountyIndexOfLng(lng)]]; + } + + if (ext && ext.numbers.length <= 1) { + return false; + } else { + return this.get(lng, count) !== 1; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i; + if (ext.noAbs) { + i = ext.plurals(c); + } else { + i = ext.plurals(Math.abs(c)); + } + + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[f.getCountyIndexOfLng(lng)], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.addResource = addResource; + i18n.addResources = addResources; + i18n.removeResourceBundle = removeResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + + return i18n; + +})); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd-1.7.4.min.js b/libs/i18next/release/i18next.amd-1.7.4.min.js new file mode 100644 index 00000000..9577404b --- /dev/null +++ b/libs/i18next/release/i18next.amd-1.7.4.min.js @@ -0,0 +1,6 @@ +// i18next, v1.7.4 +// Copyright (c)2014 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +!function(a,b){"object"==typeof exports?module.exports=b():"function"==typeof define&&define.amd&&define([],b)}(this,function(){function a(a,b){if(!b||"function"==typeof b)return a;for(var c in b)a[c]=b[c];return a}function b(a,c){for(var d in c)d in a?b(a[d],c[d]):a[d]=c[d];return a}function c(a,b,c){var d,e=0,f=a.length,g=void 0===f||"[object Array]"!==Object.prototype.toString.apply(a)||"function"==typeof a;if(c)if(g){for(d in a)if(b.apply(a[d],c)===!1)break}else for(;f>e&&b.apply(a[e++],c)!==!1;);else if(g){for(d in a)if(b.call(a[d],d,a[d])===!1)break}else for(;f>e&&b.call(a[e],e,a[e++])!==!1;);return a}function d(a){return"string"==typeof a?a.replace(/[&<>"'\/]/g,function(a){return L[a]}):a}function e(a){var b=function(a){if(window.XMLHttpRequest)return a(null,new XMLHttpRequest);if(window.ActiveXObject)try{return a(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(b){return a(null,new ActiveXObject("Microsoft.XMLHTTP"))}return a(new Error)},c=function(a){if("string"==typeof a)return a;var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")},d=function(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;cd?b+=String.fromCharCode(d):d>127&&2048>d?(b+=String.fromCharCode(192|d>>6),b+=String.fromCharCode(128|63&d)):(b+=String.fromCharCode(224|d>>12),b+=String.fromCharCode(128|63&d>>6),b+=String.fromCharCode(128|63&d))}return b},e=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";a=d(a);var c,e,f,g,h,i,j,k="",l=0;do c=a.charCodeAt(l++),e=a.charCodeAt(l++),f=a.charCodeAt(l++),g=c>>2,h=(3&c)<<4|e>>4,i=(15&e)<<2|f>>6,j=63&f,isNaN(e)?i=j=64:isNaN(f)&&(j=64),k+=b.charAt(g)+b.charAt(h)+b.charAt(i)+b.charAt(j),c=e=f="",g=h=i=j="";while(l1&&(d+=d.indexOf("?")>-1?"&"+k:"?"+k),e.jsonp){var l=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=d,l.appendChild(m),void 0}}b(function(b,c){if(b)return h(b);c.open(a,d,e.async);for(var f in j)j.hasOwnProperty(f)&&c.setRequestHeader(f,j[f]);c.onreadystatechange=function(){if(4===c.readyState){var a=c.responseText||"";if(!h)return;h(c.status,{text:function(){return a},json:function(){return JSON.parse(a)}})}},c.send(i)})},h={authBasic:function(a,b){g.headers.Authorization="Basic "+e(a+":"+b)},connect:function(a,b,c){return g("CONNECT",a,b,c)},del:function(a,b,c){return g("DELETE",a,b,c)},get:function(a,b,c){return g("GET",a,b,c)},head:function(a,b,c){return g("HEAD",a,b,c)},headers:function(a){g.headers=a||{}},isAllowed:function(a,b,c){this.options(a,function(a,d){c(-1!==d.text().indexOf(b))})},options:function(a,b,c){return g("OPTIONS",a,b,c)},patch:function(a,b,c){return g("PATCH",a,b,c)},post:function(a,b,c){return g("POST",a,b,c)},put:function(a,b,c){return g("PUT",a,b,c)},trace:function(a,b,c){return g("TRACE",a,b,c)}},i=a.type?a.type.toLowerCase():"get";h[i](a.url,a,function(b,c){200===b||0===b&&c.text()?a.success(c.json(),b,null):a.error(c.text(),b,null)})}function f(a,b){"function"==typeof a&&(b=a,a={}),a=a||{},O.extend(K,a),delete K.fixLng,"string"==typeof K.ns&&(K.ns={namespaces:[K.ns],defaultNs:K.ns}),"string"==typeof K.fallbackNS&&(K.fallbackNS=[K.fallbackNS]),("string"==typeof K.fallbackLng||"boolean"==typeof K.fallbackLng)&&(K.fallbackLng=[K.fallbackLng]),K.interpolationPrefixEscaped=O.regexEscape(K.interpolationPrefix),K.interpolationSuffixEscaped=O.regexEscape(K.interpolationSuffix),K.lng||(K.lng=O.detectLanguage()),I=O.toLanguages(K.lng),D=I[0],O.log("currentLng set to: "+D),K.useCookie&&O.cookie.read(K.cookieName)!==D&&O.cookie.create(K.cookieName,D,K.cookieExpirationTime,K.cookieDomain),K.detectLngFromLocalStorage&&"undefined"!=typeof document&&window.localstorage&&window.localStorage.setItem("i18next_lng",D);var c=x;a.fixLng&&(c=function(a,b){return b=b||{},b.lng=b.lng||c.lng,x(a,b)},c.lng=D),P.setCurrentLng(D),E&&K.setJqueryExt&&q();var d;if(E&&E.Deferred&&(d=E.Deferred()),!K.resStore){var e=O.toLanguages(K.lng);"string"==typeof K.preload&&(K.preload=[K.preload]);for(var f=0,g=K.preload.length;g>f;f++)for(var h=O.toLanguages(K.preload[f]),i=0,j=h.length;j>i;i++)e.indexOf(h[i])<0&&e.push(h[i]);return F.sync.load(e,K,function(a,e){G=e,J=!0,b&&b(c),d&&d.resolve(c)}),d?d.promise():void 0}return G=K.resStore,J=!0,b&&b(c),d&&d.resolve(c),d?d.promise():void 0}function g(a,b){"string"==typeof a&&(a=[a]);for(var c=0,d=a.length;d>c;c++)K.preload.indexOf(a[c])<0&&K.preload.push(a[c]);return f(b)}function h(a,b,c,d){"string"!=typeof b?(c=b,b=K.ns.defaultNs):K.ns.namespaces.indexOf(b)<0&&K.ns.namespaces.push(b),G[a]=G[a]||{},G[a][b]=G[a][b]||{},d?O.deepExtend(G[a][b],c):O.extend(G[a][b],c)}function i(a,b){"string"!=typeof b&&(b=K.ns.defaultNs),G[a]=G[a]||{},G[a][b]={}}function j(a,b,c,d){"string"!=typeof b?(resource=b,b=K.ns.defaultNs):K.ns.namespaces.indexOf(b)<0&&K.ns.namespaces.push(b),G[a]=G[a]||{},G[a][b]=G[a][b]||{};for(var e=c.split(K.keyseparator),f=0,g=G[K.lng][b];e[f];)f==e.length-1?g[e[f]]=d:(null==g[e[f]]&&(g[e[f]]={}),g=g[e[f]]),f++}function k(a,b,c){"string"!=typeof b?(resource=b,b=K.ns.defaultNs):K.ns.namespaces.indexOf(b)<0&&K.ns.namespaces.push(b);for(var d in c)"string"==typeof c[d]&&j(a,b,d,c[d])}function l(a){K.ns.defaultNs=a}function m(a,b){n([a],b)}function n(a,b){var c={dynamicLoad:K.dynamicLoad,resGetPath:K.resGetPath,getAsync:K.getAsync,customLoad:K.customLoad,ns:{namespaces:a,defaultNs:""}},d=O.toLanguages(K.lng);"string"==typeof K.preload&&(K.preload=[K.preload]);for(var e=0,f=K.preload.length;f>e;e++)for(var g=O.toLanguages(K.preload[e]),h=0,i=g.length;i>h;h++)d.indexOf(g[h])<0&&d.push(g[h]);for(var j=[],k=0,l=d.length;l>k;k++){var m=!1,n=G[d[k]];if(n)for(var o=0,p=a.length;p>o;o++)n[a[o]]||(m=!0);else m=!0;m&&j.push(d[k])}j.length?F.sync._fetch(j,c,function(c,d){var e=a.length*j.length;O.each(a,function(a,c){K.ns.namespaces.indexOf(c)<0&&K.ns.namespaces.push(c),O.each(j,function(a,f){G[f]=G[f]||{},G[f][c]=d[f][c],e--,0===e&&b&&(K.useLocalStorage&&F.sync._storeLocal(G),b())})})}):b&&b()}function o(a,b,c){return"function"==typeof b?(c=b,b={}):b||(b={}),b.lng=a,f(b,c)}function p(){return D}function q(){function a(a,b,c){if(0!==b.length){var d="text";if(0===b.indexOf("[")){var e=b.split("]");b=e[1],d=e[0].substr(1,e[0].length-1)}b.indexOf(";")===b.length-1&&(b=b.substr(0,b.length-2));var f;if("html"===d)f=K.defaultValueFromContent?E.extend({defaultValue:a.html()},c):c,a.html(E.t(b,f));else if("text"===d)f=K.defaultValueFromContent?E.extend({defaultValue:a.text()},c):c,a.text(E.t(b,f));else if("prepend"===d)f=K.defaultValueFromContent?E.extend({defaultValue:a.html()},c):c,a.prepend(E.t(b,f));else if("append"===d)f=K.defaultValueFromContent?E.extend({defaultValue:a.html()},c):c,a.append(E.t(b,f));else if(0===d.indexOf("data-")){var g=d.substr("data-".length);f=K.defaultValueFromContent?E.extend({defaultValue:a.data(g)},c):c;var h=E.t(b,f);a.data(g,h),a.attr(d,h)}else f=K.defaultValueFromContent?E.extend({defaultValue:a.attr(d)},c):c,a.attr(d,E.t(b,f))}}function b(b,c){var d=b.attr(K.selectorAttr);if(d||"undefined"==typeof d||d===!1||(d=b.text()||b.val()),d){var e=b,f=b.data("i18n-target");if(f&&(e=b.find(f)||b),c||K.useDataAttrOptions!==!0||(c=b.data("i18n-options")),c=c||{},d.indexOf(";")>=0){var g=d.split(";");E.each(g,function(b,d){""!==d&&a(e,d,c)})}else a(e,d,c);K.useDataAttrOptions===!0&&b.data("i18n-options",c)}}E.t=E.t||x,E.fn.i18n=function(a){return this.each(function(){b(E(this),a);var c=E(this).find("["+K.selectorAttr+"]");c.each(function(){b(E(this),a)})})}}function r(a,b,c,d){if(!a)return a;if(d=d||b,a.indexOf(d.interpolationPrefix||K.interpolationPrefix)<0)return a;var e=d.interpolationPrefix?O.regexEscape(d.interpolationPrefix):K.interpolationPrefixEscaped,f=d.interpolationSuffix?O.regexEscape(d.interpolationSuffix):K.interpolationSuffixEscaped,g="HTML"+f,h=b.replace&&"object"==typeof b.replace?b.replace:b;return O.each(h,function(b,h){var i=c?c+K.keyseparator+b:b;"object"==typeof h&&null!==h?a=r(a,h,i,d):d.escapeInterpolation||K.escapeInterpolation?(a=a.replace(new RegExp([e,i,g].join(""),"g"),O.regexReplacementEscape(h)),a=a.replace(new RegExp([e,i,f].join(""),"g"),O.regexReplacementEscape(O.escape(h)))):a=a.replace(new RegExp([e,i,f].join(""),"g"),O.regexReplacementEscape(h))}),a}function s(a,b){var c=",",d="{",e="}",f=O.extend({},b);for(delete f.postProcess;-1!=a.indexOf(K.reusePrefix)&&(H++,!(H>K.maxRecursion));){var g=a.lastIndexOf(K.reusePrefix),h=a.indexOf(K.reuseSuffix,g)+K.reuseSuffix.length,i=a.substring(g,h),j=i.replace(K.reusePrefix,"").replace(K.reuseSuffix,"");if(g>=h)return O.error("there is an missing closing in following translation value",a),"";if(-1!=j.indexOf(c)){var k=j.indexOf(c);if(-1!=j.indexOf(d,k)&&-1!=j.indexOf(e,k)){var l=j.indexOf(d,k),m=j.indexOf(e,l)+e.length;try{f=O.extend(f,JSON.parse(j.substring(l,m))),j=j.substring(0,k)}catch(n){}}}var o=A(j,f);a=a.replace(i,O.regexReplacementEscape(o))}return a}function t(a){return a.context&&("string"==typeof a.context||"number"==typeof a.context)}function u(a,b){return void 0!==a.count&&"string"!=typeof a.count&&P.needsPlural(b,a.count)}function v(a){return void 0!==a.indefinite_article&&"string"!=typeof a.indefinite_article&&a.indefinite_article}function w(a,b){b=b||{};var c=y(a,b),d=B(a,b);return void 0!==d||d===c}function x(a,b){return b=b||{},J?(H=0,A.apply(null,arguments)):(O.log("i18next not finished initialization. you might have called t function before loading resources finished."),b.defaultValue||"")}function y(a,b){return void 0!==b.defaultValue?b.defaultValue:a}function z(){for(var a=[],b=1;b1)for(var d=0;d-1&&(e=c.split(K.nsseparator),i=e[0],c=e[1]),void 0===g&&K.sendMissing&&"function"==typeof K.missingKeyHandler&&(b.lng?K.missingKeyHandler(h[0],i,c,f,h):K.missingKeyHandler(K.lng,i,c,f,h));var j=b.postProcess||K.postProcess;void 0!==g&&j&&Q[j]&&(g=Q[j](g,c,b));var k=f;if(f.indexOf(K.nsseparator)>-1&&(e=f.split(K.nsseparator),k=e[1]),k===c&&K.parseMissingKey&&(f=K.parseMissingKey(f)),void 0===g&&(f=r(f,b),f=s(f,b),j&&Q[j])){var l=y(c,b);g=Q[j](l,c,b)}return void 0!==g?g:f}function B(a,b){b=b||{};var c,d,e=y(a,b),f=I;if(!G)return e;if("cimode"===f[0].toLowerCase())return e;if(b.lng&&(f=O.toLanguages(b.lng,b.fallbackLng),!G[f[0]])){var g=K.getAsync;K.getAsync=!1,F.sync.load(f,K,function(a,b){O.extend(G,b),K.getAsync=g})}var h=b.ns||K.ns.defaultNs;if(a.indexOf(K.nsseparator)>-1){var i=a.split(K.nsseparator);h=i[0],a=i[1]}if(t(b)){c=O.extend({},b),delete c.context,c.defaultValue=K.contextNotFound;var j=h+K.nsseparator+a+"_"+b.context;if(d=x(j,c),d!=K.contextNotFound)return r(d,{context:b.context})}if(u(b,f[0])){c=O.extend({},b),delete c.count,c.defaultValue=K.pluralNotFound;var k=h+K.nsseparator+a+K.pluralSuffix,l=P.get(f[0],b.count);if(l>=0?k=k+"_"+l:1===l&&(k=h+K.nsseparator+a),d=x(k,c),d!=K.pluralNotFound)return r(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix})}if(v(b)){var m=O.extend({},b);delete m.indefinite_article,m.defaultValue=K.indefiniteNotFound;var n=h+K.nsseparator+a+(b.count&&!u(b,f[0])||!b.count?K.indefiniteSuffix:"");if(d=x(n,m),d!=K.indefiniteNotFound)return d}for(var o,p=a.split(K.keyseparator),q=0,w=f.length;w>q&&void 0===o;q++){for(var z=f[q],C=0,D=G[z]&&G[z][h];p[C];)D=D&&D[p[C]],C++;if(void 0!==D){var E=Object.prototype.toString.apply(D);if("string"==typeof D)D=r(D,b),D=s(D,b);else if("[object Array]"!==E||K.returnObjectTrees||b.returnObjectTrees){if(null===D&&K.fallbackOnNull===!0)D=void 0;else if(null!==D)if(K.returnObjectTrees||b.returnObjectTrees){if("[object Number]"!==E&&"[object Function]"!==E&&"[object RegExp]"!==E){var H="[object Array]"===E?[]:{};O.each(D,function(c){H[c]=A(h+K.nsseparator+a+K.keyseparator+c,b)}),D=H}}else K.objectTreeKeyHandler&&"function"==typeof K.objectTreeKeyHandler?D=K.objectTreeKeyHandler(a,D,z,h,b):(D="key '"+h+":"+a+" ("+z+")' "+"returned an object instead of string.",O.log(D))}else D=D.join("\n"),D=r(D,b),D=s(D,b);"string"==typeof D&&""===D.trim()&&K.fallbackOnEmpty===!0&&(D=void 0),o=D}}if(void 0===o&&!b.isFallbackLookup&&(K.fallbackToDefaultNS===!0||K.fallbackNS&&K.fallbackNS.length>0)){if(b.isFallbackLookup=!0,K.fallbackNS.length){for(var J=0,L=K.fallbackNS.length;L>J;J++)if(o=B(K.fallbackNS[J]+K.nsseparator+a,b)){var M=o.indexOf(K.nsseparator)>-1?o.split(K.nsseparator)[1]:o,N=e.indexOf(K.nsseparator)>-1?e.split(K.nsseparator)[1]:e;if(M!==N)break}}else o=B(a,b);b.isFallbackLookup=!1}return o}function C(){var a,b=[];if("undefined"!=typeof window&&(!function(){for(var a=window.location.search.substring(1),c=a.split("&"),d=0;d0){var f=c[d].substring(0,e),g=c[d].substring(e+1);b[f]=g}}}(),b[K.detectLngQS]&&(a=b[K.detectLngQS])),!a&&"undefined"!=typeof document&&K.useCookie){var c=O.cookie.read(K.cookieName);c&&(a=c)}return!a&&"undefined"!=typeof document&&window.localstorage&&K.detectLngFromLocalStorage&&(a=window.localStorage.getItem("i18next_lng")),a||"undefined"==typeof navigator||(a=navigator.language?navigator.language:navigator.userLanguage),a||(a=K.fallbackLng[0]),a}Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>0&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&1/0!=d&&d!=-1/0&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=c;arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d))));for(var e=d>=0?Math.min(d,c-1):c-Math.abs(d);e>=0;e--)if(e in b&&b[e]===a)return e;return-1}),"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")});var D,E=void 0,F={},G={},H=0,I=[],J=!1;sync={load:function(a,b,c){b.useLocalStorage?sync._loadLocal(a,b,function(d,e){for(var f=[],g=0,h=a.length;h>g;g++)e[a[g]]||f.push(a[g]);f.length>0?sync._fetch(f,b,function(a,b){O.extend(e,b),sync._storeLocal(b),c(null,e)}):c(null,e)}):sync._fetch(a,b,function(a,b){c(null,b)})},_loadLocal:function(a,b,c){var d={},e=(new Date).getTime();if(window.localStorage){var f=a.length;O.each(a,function(a,g){var h=window.localStorage.getItem("res_"+g);h&&(h=JSON.parse(h),h.i18nStamp&&h.i18nStamp+b.localStorageExpirationTime>e&&(d[g]=h)),f--,0===f&&c(null,d)})}},_storeLocal:function(a){if(window.localStorage)for(var b in a)a[b].i18nStamp=(new Date).getTime(),window.localStorage.setItem("res_"+b,JSON.stringify(a[b]))},_fetch:function(a,b,c){var d=b.ns,e={};if(b.dynamicLoad){var f=function(a,b){c(null,b)};if("function"==typeof b.customLoad)b.customLoad(a,d.namespaces,b,f);else{var g=r(b.resGetPath,{lng:a.join("+"),ns:d.namespaces.join("+")});O.ajax({url:g,success:function(a){O.log("loaded: "+g),f(null,a)},error:function(a,b,c){O.log("failed loading: "+g),f("failed loading resource.json error: "+c)},dataType:"json",async:b.getAsync})}}else{var h,i=d.namespaces.length*a.length;O.each(d.namespaces,function(d,f){O.each(a,function(a,d){var g=function(a,b){a&&(h=h||[],h.push(a)),e[d]=e[d]||{},e[d][f]=b,i--,0===i&&c(h,e)};"function"==typeof b.customLoad?b.customLoad(d,f,b,g):sync._fetchOne(d,f,b,g)})})}},_fetchOne:function(a,b,c,d){var e=r(c.resGetPath,{lng:a,ns:b});O.ajax({url:e,success:function(a){O.log("loaded: "+e),d(null,a)},error:function(a,b,c){if(b&&200==b||a&&a.status&&200==a.status)O.error("There is a typo in: "+e);else if(b&&404==b||a&&a.status&&404==a.status)O.log("Does not exist: "+e);else{var f=b?b:a&&a.status?a.status:null;O.log(f+" when loading "+e)}d(c,{})},dataType:"json",async:c.getAsync})},postMissing:function(a,b,c,d,e){var f={};f[c]=d;var g=[];if("fallback"===K.sendMissingTo&&K.fallbackLng[0]!==!1)for(var h=0;hh;h++)g.push({lng:e[h],url:r(K.resPostPath,{lng:e[h],ns:b})});for(var j=0,k=g.length;k>j;j++){var l=g[j];O.ajax({url:l.url,type:K.sendType,data:f,success:function(){O.log("posted missing key '"+c+"' to: "+l.url);for(var a=c.split("."),e=0,f=G[l.lng][b];a[e];)f=f[a[e]]=e===a.length-1?d:f[a[e]]||{},e++},error:function(){O.log("failed posting missing key '"+c+"' to: "+l.url)},dataType:"json",async:K.postAsync})}}};var K={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:["dev"],fallbackNS:[],detectLngQS:"setLng",detectLngFromLocalStorage:!1,ns:"translation",fallbackOnNull:!0,fallbackOnEmpty:!1,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,indefiniteSuffix:"_indefinite",indefiniteNotFound:["indefinite_not_found",Math.random()].join(""),setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",cookieDomain:void 0,objectTreeKeyHandler:void 0,postProcess:void 0,parseMissingKey:void 0,missingKeyHandler:sync.postMissing,shortcutFunction:"sprintf"},L={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},M={create:function(a,b,c,d){var e;if(c){var f=new Date;f.setTime(f.getTime()+1e3*60*c),e="; expires="+f.toGMTString()}else e="";d=d?"domain="+d+";":"",document.cookie=a+"="+b+e+";"+d+"path=/"},read:function(a){for(var b=a+"=",c=document.cookie.split(";"),d=0;d-1?c.push(a):b("rejecting non-whitelisted language: "+a)};if("string"==typeof a&&a.indexOf("-")>-1){var f=a.split("-");a=K.lowerCaseLng?f[0].toLowerCase()+"-"+f[1].toLowerCase():f[0].toLowerCase()+"-"+f[1].toUpperCase(),"unspecific"!==K.load&&e(a),"current"!==K.load&&e(f[this.getCountyIndexOfLng(a)])}else e(a);for(var g=0;g1)}},af:{name:"Afrikaans",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ak:{name:"Akan",numbers:[1,2],plurals:function(a){return Number(a>1)}},am:{name:"Amharic",numbers:[1,2],plurals:function(a){return Number(a>1)}},an:{name:"Aragonese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ar:{name:"Arabic",numbers:[0,1,2,3,11,100],plurals:function(a){return Number(0===a?0:1==a?1:2==a?2:a%100>=3&&10>=a%100?3:a%100>=11?4:5)}},arn:{name:"Mapudungun",numbers:[1,2],plurals:function(a){return Number(a>1)}},ast:{name:"Asturian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ay:{name:"Aymará",numbers:[1],plurals:function(){return 0}},az:{name:"Azerbaijani",numbers:[1,2],plurals:function(a){return Number(1!=a)}},be:{name:"Belarusian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},bg:{name:"Bulgarian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},bn:{name:"Bengali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},bo:{name:"Tibetan",numbers:[1],plurals:function(){return 0}},br:{name:"Breton",numbers:[1,2],plurals:function(a){return Number(a>1)}},bs:{name:"Bosnian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},ca:{name:"Catalan",numbers:[1,2],plurals:function(a){return Number(1!=a)}},cgg:{name:"Chiga",numbers:[1],plurals:function(){return 0}},cs:{name:"Czech",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)}},csb:{name:"Kashubian",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},cy:{name:"Welsh",numbers:[1,2,3,8],plurals:function(a){return Number(1==a?0:2==a?1:8!=a&&11!=a?2:3)}},da:{name:"Danish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},de:{name:"German",numbers:[1,2],plurals:function(a){return Number(1!=a)}},dz:{name:"Dzongkha",numbers:[1],plurals:function(){return 0}},el:{name:"Greek",numbers:[1,2],plurals:function(a){return Number(1!=a)}},en:{name:"English",numbers:[1,2],plurals:function(a){return Number(1!=a)}},eo:{name:"Esperanto",numbers:[1,2],plurals:function(a){return Number(1!=a)}},es:{name:"Spanish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},es_ar:{name:"Argentinean Spanish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},et:{name:"Estonian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},eu:{name:"Basque",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fa:{name:"Persian",numbers:[1],plurals:function(){return 0}},fi:{name:"Finnish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fil:{name:"Filipino",numbers:[1,2],plurals:function(a){return Number(a>1)}},fo:{name:"Faroese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fr:{name:"French",numbers:[1,2],plurals:function(a){return Number(a>=2)}},fur:{name:"Friulian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fy:{name:"Frisian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ga:{name:"Irish",numbers:[1,2,3,7,11],plurals:function(a){return Number(1==a?0:2==a?1:7>a?2:11>a?3:4)}},gd:{name:"Scottish Gaelic",numbers:[1,2,3,20],plurals:function(a){return Number(1==a||11==a?0:2==a||12==a?1:a>2&&20>a?2:3)}},gl:{name:"Galician",numbers:[1,2],plurals:function(a){return Number(1!=a)}},gu:{name:"Gujarati",numbers:[1,2],plurals:function(a){return Number(1!=a)}},gun:{name:"Gun",numbers:[1,2],plurals:function(a){return Number(a>1)}},ha:{name:"Hausa",numbers:[1,2],plurals:function(a){return Number(1!=a)}},he:{name:"Hebrew",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hi:{name:"Hindi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hr:{name:"Croatian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},hu:{name:"Hungarian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hy:{name:"Armenian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ia:{name:"Interlingua",numbers:[1,2],plurals:function(a){return Number(1!=a)}},id:{name:"Indonesian",numbers:[1],plurals:function(){return 0}},is:{name:"Icelandic",numbers:[1,2],plurals:function(a){return Number(1!=a%10||11==a%100)}},it:{name:"Italian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ja:{name:"Japanese",numbers:[1],plurals:function(){return 0}},jbo:{name:"Lojban",numbers:[1],plurals:function(){return 0}},jv:{name:"Javanese",numbers:[0,1],plurals:function(a){return Number(0!==a)}},ka:{name:"Georgian",numbers:[1],plurals:function(){return 0}},kk:{name:"Kazakh",numbers:[1],plurals:function(){return 0}},km:{name:"Khmer",numbers:[1],plurals:function(){return 0}},kn:{name:"Kannada",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ko:{name:"Korean",numbers:[1],plurals:function(){return 0}},ku:{name:"Kurdish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},kw:{name:"Cornish",numbers:[1,2,3,4],plurals:function(a){return Number(1==a?0:2==a?1:3==a?2:3)}},ky:{name:"Kyrgyz",numbers:[1],plurals:function(){return 0}},lb:{name:"Letzeburgesch",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ln:{name:"Lingala",numbers:[1,2],plurals:function(a){return Number(a>1)}},lo:{name:"Lao",numbers:[1],plurals:function(){return 0}},lt:{name:"Lithuanian",numbers:[1,2,10],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&(10>a%100||a%100>=20)?1:2)}},lv:{name:"Latvian",numbers:[1,2,0],plurals:function(a){return Number(1==a%10&&11!=a%100?0:0!==a?1:2)}},mai:{name:"Maithili",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mfe:{name:"Mauritian Creole",numbers:[1,2],plurals:function(a){return Number(a>1)}},mg:{name:"Malagasy",numbers:[1,2],plurals:function(a){return Number(a>1)}},mi:{name:"Maori",numbers:[1,2],plurals:function(a){return Number(a>1)}},mk:{name:"Macedonian",numbers:[1,2],plurals:function(a){return Number(1==a||1==a%10?0:1)}},ml:{name:"Malayalam",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mn:{name:"Mongolian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mnk:{name:"Mandinka",numbers:[0,1,2],plurals:function(a){return Number(1==a?1:2)}},mr:{name:"Marathi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ms:{name:"Malay",numbers:[1],plurals:function(){return 0}},mt:{name:"Maltese",numbers:[1,2,11,20],plurals:function(a){return Number(1==a?0:0===a||a%100>1&&11>a%100?1:a%100>10&&20>a%100?2:3)}},nah:{name:"Nahuatl",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nap:{name:"Neapolitan",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nb:{name:"Norwegian Bokmal",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ne:{name:"Nepali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nl:{name:"Dutch",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nn:{name:"Norwegian Nynorsk",numbers:[1,2],plurals:function(a){return Number(1!=a)}},no:{name:"Norwegian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nso:{name:"Northern Sotho",numbers:[1,2],plurals:function(a){return Number(1!=a)}},oc:{name:"Occitan",numbers:[1,2],plurals:function(a){return Number(a>1)}},or:{name:"Oriya",numbers:[2,1],plurals:function(a){return Number(1!=a)}},pa:{name:"Punjabi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pap:{name:"Papiamento",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pl:{name:"Polish",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},pms:{name:"Piemontese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ps:{name:"Pashto",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pt:{name:"Portuguese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pt_br:{name:"Brazilian Portuguese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},rm:{name:"Romansh",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ro:{name:"Romanian",numbers:[1,2,20],plurals:function(a){return Number(1==a?0:0===a||a%100>0&&20>a%100?1:2)}},ru:{name:"Russian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},sah:{name:"Yakut",numbers:[1],plurals:function(){return 0}},sco:{name:"Scots",numbers:[1,2],plurals:function(a){return Number(1!=a)}},se:{name:"Northern Sami",numbers:[1,2],plurals:function(a){return Number(1!=a)}},si:{name:"Sinhala",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sk:{name:"Slovak",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)}},sl:{name:"Slovenian",numbers:[5,1,2,3],plurals:function(a){return Number(1==a%100?1:2==a%100?2:3==a%100||4==a%100?3:0)}},so:{name:"Somali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},son:{name:"Songhay",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sq:{name:"Albanian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sr:{name:"Serbian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},su:{name:"Sundanese",numbers:[1],plurals:function(){return 0}},sv:{name:"Swedish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sw:{name:"Swahili",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ta:{name:"Tamil",numbers:[1,2],plurals:function(a){return Number(1!=a)}},te:{name:"Telugu",numbers:[1,2],plurals:function(a){return Number(1!=a)}},tg:{name:"Tajik",numbers:[1,2],plurals:function(a){return Number(a>1)}},th:{name:"Thai",numbers:[1],plurals:function(){return 0}},ti:{name:"Tigrinya",numbers:[1,2],plurals:function(a){return Number(a>1)}},tk:{name:"Turkmen",numbers:[1,2],plurals:function(a){return Number(1!=a)}},tr:{name:"Turkish",numbers:[1,2],plurals:function(a){return Number(a>1)}},tt:{name:"Tatar",numbers:[1],plurals:function(){return 0}},ug:{name:"Uyghur",numbers:[1],plurals:function(){return 0}},uk:{name:"Ukrainian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},ur:{name:"Urdu",numbers:[1,2],plurals:function(a){return Number(1!=a)}},uz:{name:"Uzbek",numbers:[1,2],plurals:function(a){return Number(a>1)}},vi:{name:"Vietnamese",numbers:[1],plurals:function(){return 0}},wa:{name:"Walloon",numbers:[1,2],plurals:function(a){return Number(a>1)}},wo:{name:"Wolof",numbers:[1],plurals:function(){return 0}},yo:{name:"Yoruba",numbers:[1,2],plurals:function(a){return Number(1!=a)}},zh:{name:"Chinese",numbers:[1],plurals:function(){return 0}}},addRule:function(a,b){P.rules[a]=b},setCurrentLng:function(a){if(!P.currentRule||P.currentRule.lng!==a){var b=a.split("-");P.currentRule={lng:a,rule:P.rules[b[0]]}}},needsPlural:function(a,b){var c,d=a.split("-");return c=P.currentRule&&P.currentRule.lng===a?P.currentRule.rule:P.rules[d[O.getCountyIndexOfLng(a)]],c&&c.numbers.length<=1?!1:1!==this.get(a,b)},get:function(a,b){function c(b,c){var d;if(d=P.currentRule&&P.currentRule.lng===a?P.currentRule.rule:P.rules[b]){var e;e=d.noAbs?d.plurals(c):d.plurals(Math.abs(c));var f=d.numbers[e];return 2===d.numbers.length&&1===d.numbers[0]&&(2===f?f=-1:1===f&&(f=1)),f}return 1===c?"1":"-1"}var d=a.split("-");return c(d[O.getCountyIndexOfLng(a)],b)}},Q={},R=function(a,b){Q[a]=b +},S=function(){function a(a){return Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}function b(a,b){for(var c=[];b>0;c[--b]=a);return c.join("")}var c=function(){return c.cache.hasOwnProperty(arguments[0])||(c.cache[arguments[0]]=c.parse(arguments[0])),c.format.call(null,c.cache[arguments[0]],arguments)};return c.format=function(c,d){var e,f,g,h,i,j,k,l=1,m=c.length,n="",o=[];for(f=0;m>f;f++)if(n=a(c[f]),"string"===n)o.push(c[f]);else if("array"===n){if(h=c[f],h[2])for(e=d[l],g=0;g=0?"+"+e:e,j=h[4]?"0"==h[4]?"0":h[4].charAt(1):" ",k=h[6]-String(e).length,i=h[6]?b(j,k):"",o.push(h[5]?e+i:i+e)}return o.join("")},c.cache={},c.parse=function(a){for(var b=a,c=[],d=[],e=0;b;){if(null!==(c=/^[^\x25]+/.exec(b)))d.push(c[0]);else if(null!==(c=/^\x25{2}/.exec(b)))d.push("%");else{if(null===(c=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(b)))throw"[sprintf] huh?";if(c[2]){e|=1;var f=[],g=c[2],h=[];if(null===(h=/^([a-z_][a-z_\d]*)/i.exec(g)))throw"[sprintf] huh?";for(f.push(h[1]);""!==(g=g.substring(h[0].length));)if(null!==(h=/^\.([a-z_][a-z_\d]*)/i.exec(g)))f.push(h[1]);else{if(null===(h=/^\[(\d+)\]/.exec(g)))throw"[sprintf] huh?";f.push(h[1])}c[2]=f}else e|=2;if(3===e)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";d.push(c)}b=b.substring(c[0].length)}return d},c}(),T=function(a,b){return b.unshift(a),S.apply(null,b)};return R("sprintf",function(a,b,c){return c.sprintf?"[object Array]"===Object.prototype.toString.apply(c.sprintf)?T(a,c.sprintf):"object"==typeof c.sprintf?S(a,c.sprintf):a:a}),F.init=f,F.setLng=o,F.preload=g,F.addResourceBundle=h,F.addResource=j,F.addResources=k,F.removeResourceBundle=i,F.loadNamespace=m,F.loadNamespaces=n,F.setDefaultNamespace=l,F.t=x,F.translate=x,F.exists=w,F.detectLanguage=O.detectLanguage,F.pluralExtensions=P,F.sync=sync,F.functions=O,F.lng=p,F.addPostProcessor=R,F.options=K,F}); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd-1.7.4.zip b/libs/i18next/release/i18next.amd-1.7.4.zip new file mode 100644 index 00000000..de2d049d Binary files /dev/null and b/libs/i18next/release/i18next.amd-1.7.4.zip differ diff --git a/libs/i18next/release/i18next.amd-1.7.5.js b/libs/i18next/release/i18next.amd-1.7.5.js new file mode 100644 index 00000000..a72256a2 --- /dev/null +++ b/libs/i18next/release/i18next.amd-1.7.5.js @@ -0,0 +1,2099 @@ +// i18next, v1.7.5 +// Copyright (c)2014 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function (root, factory) { + if (typeof exports === 'object') { + + module.exports = factory(); + + } else if (typeof define === 'function' && define.amd) { + + define([], factory); + + } +}(this, function () { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + // Add string trim for IE8. + if (typeof String.prototype.trim !== 'function') { + String.prototype.trim = function() { + return this.replace(/^\s+|\s+$/g, ''); + } + } + + var $ = undefined + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = [] + , initialized = false + , sync = {}; + + sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + f.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + if ((status && status == 200) || (xhr && xhr.status && xhr.status == 200)) { + // file loaded but invalid json, stop waste time ! + f.error('There is a typo in: ' + url); + } else if ((status && status == 404) || (xhr && xhr.status && xhr.status == 404)) { + f.log('Does not exist: ' + url); + } else { + var theStatus = status ? status : ((xhr && xhr.status) ? xhr.status : null); + f.log(theStatus + ' when loading ' + url); + } + + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback' && o.fallbackLng[0] !== false) { + for (var i = 0; i < o.fallbackLng.length; i++) { + urls.push({lng: o.fallbackLng[i], url: applyReplacement(o.resPostPath, { lng: o.fallbackLng[i], ns: ns })}); + } + } else if (o.sendMissingTo === 'current' || (o.sendMissingTo === 'fallback' && o.fallbackLng[0] === false) ) { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + }, + + reload: reload + }; + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: ['dev'], + fallbackNS: [], + detectLngQS: 'setLng', + detectLngFromLocalStorage: false, + ns: 'translation', + fallbackOnNull: true, + fallbackOnEmpty: false, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + defaultVariables: false, + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + indefiniteSuffix: '_indefinite', + indefiniteNotFound: ['indefinite_not_found', Math.random()].join(''), + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + cookieDomain: undefined, + + objectTreeKeyHandler: undefined, + postProcess: undefined, + parseMissingKey: undefined, + missingKeyHandler: sync.postMissing, + + shortcutFunction: 'sprintf' // or: defaultValue + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _deepExtend(target, source) { + for (var prop in source) + if (prop in target) + _deepExtend(target[prop], source[prop]); + else + target[prop] = source[prop]; + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || Object.prototype.toString.apply(object) !== '[object Array]' || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + try { + return JSON.parse(data) + } catch (e) { + f.error('Can not parse JSON. URL: ' + url); + return {}; + } + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + // file: protocol always gives status code 0, so check for data + if (status === 200 || (status === 0 && data.text())) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes,domain) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + domain = (domain)? "domain="+domain+";" : ""; + document.cookie = name+"="+value+expires+";"+domain+"path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes,domain) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + deepExtend: _deepExtend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : (typeof document !== 'undefined' ? _ajax : function() {}), + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + error: function(str) { + if (typeof console !== "undefined") console.error(str); + }, + getCountyIndexOfLng: function(lng) { + var lng_index = 0; + if (lng === 'nb-NO' || lng === 'nn-NO' || lng === 'nb-no' || lng === 'nn-no') lng_index = 1; + return lng_index; + }, + toLanguages: function(lng) { + var log = this.log; + + function applyCase(l) { + var ret = l; + + if (typeof l === 'string' && l.indexOf('-') > -1) { + var parts = l.split('-'); + + ret = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } else { + ret = o.lowerCaseLng ? l.toLowerCase() : l; + } + + return ret; + } + + var languages = []; + var whitelist = o.lngWhitelist || false; + var addLanguage = function(language){ + //reject langs not whitelisted + if(!whitelist || whitelist.indexOf(language) > -1){ + languages.push(language); + }else{ + log('rejecting non-whitelisted language: ' + language); + } + }; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + if (o.load !== 'unspecific') addLanguage(applyCase(lng)); + if (o.load !== 'current') addLanguage(applyCase(parts[this.getCountyIndexOfLng(lng)])); + } else { + addLanguage(applyCase(lng)); + } + + for (var i = 0; i < o.fallbackLng.length; i++) { + if (languages.indexOf(o.fallbackLng[i]) === -1 && o.fallbackLng[i]) languages.push(applyCase(o.fallbackLng[i])); + } + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + }, + regexReplacementEscape: function(strOrFn) { + if (typeof strOrFn === 'string') { + return strOrFn.replace(/\$/g, "$$$$"); + } else { + return strOrFn; + } + }, + localStorage: { + setItem: function(key, value) { + if (window.localStorage) { + try { + window.localStorage.setItem(key, value); + } catch (e) { + f.log('failed to set value for key "' + key + '" to localStorage.'); + } + } + } + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + delete o.fixLng; /* passed in each time */ + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // fallback languages + if (typeof o.fallbackLng == 'string' || typeof o.fallbackLng == 'boolean') { + o.fallbackLng = [o.fallbackLng]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + if (o.useCookie && f.cookie.read(o.cookieName) !== currentLng){ //cookie is unset or invalid + f.cookie.create(o.cookieName, currentLng, o.cookieExpirationTime, o.cookieDomain); + } + if (o.detectLngFromLocalStorage && typeof document !== 'undefined' && window.localStorage) { + f.localStorage.setItem('i18next_lng', currentLng); + } + + var lngTranslate = translate; + if (options.fixLng) { + lngTranslate = function(key, options) { + options = options || {}; + options.lng = options.lng || lngTranslate.lng; + return translate(key, options); + }; + lngTranslate.lng = currentLng; + } + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + initialized = true; + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + initialized = true; + + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources, deep) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + if (deep) { + f.deepExtend(resStore[lng][ns], resources); + } else { + f.extend(resStore[lng][ns], resources); + } + } + + function hasResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + var res = resStore[lng][ns] || {}; + + var hasValues = false; + for(var prop in res) { + if (res.hasOwnProperty(prop)) { + hasValues = true; + } + } + + return hasValues; + } + + function removeResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = {}; + } + + function addResource(lng, ns, key, value) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + var keys = key.split(o.keyseparator); + var x = 0; + var node = resStore[lng][ns]; + var origRef = node; + + while (keys[x]) { + if (x == keys.length - 1) + node[keys[x]] = value; + else { + if (node[keys[x]] == null) + node[keys[x]] = {}; + + node = node[keys[x]]; + } + x++; + } + } + + function addResources(lng, ns, resources) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + for (var m in resources) { + if (typeof resources[m] === 'string') addResource(lng, ns, m, resources[m]); + } + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, options, cb) { + if (typeof options === 'function') { + cb = options; + options = {}; + } else if (!options) { + options = {}; + } + + options.lng = lng; + return init(options, cb); + } + + function lng() { + return currentLng; + } + + function reload(cb) { + resStore = {}; + setLng(currentLng, cb); + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else if (attr === 'prepend') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.prepend($.t(key, optionsToUse)); + } else if (attr === 'append') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.append($.t(key, optionsToUse)); + } else if (attr.indexOf("data-") === 0) { + var dataAttr = attr.substr(("data-").length); + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.data(dataAttr) }, options) : options; + var translated = $.t(key, optionsToUse); + //we change into the data cache + ele.data(dataAttr, translated); + //we change into the dom + ele.attr(attr, translated); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key && typeof key !== 'undefined' && key !== false) key = ele.text() || ele.val(); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + var hash = replacementHash.replace && typeof replacementHash.replace === 'object' ? replacementHash.replace : replacementHash; + f.each(hash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), f.regexReplacementEscape(value)); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(f.escape(value))); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(value)); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + if (index_of_end_of_closing <= index_of_opening) { + f.error('there is an missing closing in following translation value', translated); + return ''; + } + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, f.regexReplacementEscape(translated_token)); + } + return translated; + } + + function hasContext(options) { + return (options.context && (typeof options.context == 'string' || typeof options.context == 'number')); + } + + function needsPlural(options, lng) { + return (options.count !== undefined && typeof options.count != 'string'/* && pluralExtensions.needsPlural(lng, options.count)*/); + } + + function needsIndefiniteArticle(options) { + return (options.indefinite_article !== undefined && typeof options.indefinite_article != 'string' && options.indefinite_article); + } + + function exists(key, options) { + options = options || {}; + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + options = options || {}; + + if (!initialized) { + f.log('i18next not finished initialization. you might have called t function before loading resources finished.') + return options.defaultValue || ''; + }; + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _getDefaultValue(key, options) { + return (options.defaultValue !== undefined) ? options.defaultValue : key; + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(potentialKeys, options) { + if (options && typeof options !== 'object') { + if (o.shortcutFunction === 'sprintf') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else if (o.shortcutFunction === 'defaultValue') { + options = { + defaultValue: options + } + } + } else { + options = options || {}; + } + + if (typeof o.defaultVariables === 'object') { + options = f.extend({}, o.defaultVariables, options); + } + + if (potentialKeys === undefined || potentialKeys === null || potentialKeys === '') return ''; + + if (typeof potentialKeys === 'string') { + potentialKeys = [potentialKeys]; + } + + var key = potentialKeys[0]; + + if (potentialKeys.length > 1) { + for (var i = 0; i < potentialKeys.length; i++) { + key = potentialKeys[i]; + if (exists(key, options)) { + break; + } + } + } + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng, options.fallbackLng) : languages + , ns = options.ns || o.ns.defaultNs + , parts; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing && typeof o.missingKeyHandler === 'function') { + if (options.lng) { + o.missingKeyHandler(lngs[0], ns, key, notFound, lngs); + } else { + o.missingKeyHandler(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found !== undefined && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + // process notFound if function exists + var splitNotFound = notFound; + if (notFound.indexOf(o.nsseparator) > -1) { + parts = notFound.split(o.nsseparator); + splitNotFound = parts[1]; + } + if (splitNotFound === key && o.parseMissingKey) { + notFound = o.parseMissingKey(notFound); + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessor && postProcessors[postProcessor]) { + var val = _getDefaultValue(key, options); + found = postProcessors[postProcessor](val, key, options); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options) { + options = options || {}; + + var optionWithoutCount, translated + , notFound = _getDefaultValue(key, options) + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + // CI mode + if (lngs[0].toLowerCase() === 'cimode') return notFound; + + // passed in lng + if (options.lngs) lngs = options.lngs; + if (options.lng) { + lngs = f.toLanguages(options.lng, options.fallbackLng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options, lngs[0])) { + optionWithoutCount = f.extend({ lngs: [lngs[0]]}, options); + delete optionWithoutCount.count; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey; + if (!pluralExtensions.needsPlural(lngs[0], options.count)) { + pluralKey = ns + o.nsseparator + key; + } else { + pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(lngs[0], options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + } + + translated = translate(pluralKey, optionWithoutCount); + + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } else if (lngs.length > 1) { + // remove failed lng + var clone = lngs.slice(); + clone.shift(); + options = f.extend(options, { lngs: clone }); + // retry with fallbacks + translated = translate(ns + o.nsseparator + key, options); + if (translated != o.pluralNotFound) return translated; + } + } + + if (needsIndefiniteArticle(options)) { + var optionsWithoutIndef = f.extend({}, options); + delete optionsWithoutIndef.indefinite_article; + optionsWithoutIndef.defaultValue = o.indefiniteNotFound; + // If we don't have a count, we want the indefinite, if we do have a count, and needsPlural is false + var indefiniteKey = ns + o.nsseparator + key + (((options.count && !needsPlural(options, lngs[0])) || !options.count) ? o.indefiniteSuffix : ""); + translated = translate(indefiniteKey, optionsWithoutIndef); + if (translated != o.indefiniteNotFound) { + return translated; + } + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + var valueType = Object.prototype.toString.apply(value); + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (valueType === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + if (o.objectTreeKeyHandler && typeof o.objectTreeKeyHandler == 'function') { + value = o.objectTreeKeyHandler(key, value, l, ns, options); + } else { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned an object instead of string.'; + f.log(value); + } + } else if (valueType !== '[object Number]' && valueType !== '[object Function]' && valueType !== '[object RegExp]') { + var copy = (valueType === '[object Array]') ? [] : {}; // apply child translation on a copy + f.each(value, function(m) { + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + }); + value = copy; + } + } + + if (typeof value === 'string' && value.trim() === '' && o.fallbackOnEmpty === true) + value = undefined; + + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length > 0))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + options.isFallbackLookup = false; + } + + return found; + } + function detectLanguage() { + var detectedLng; + var whitelist = o.lngWhitelist || []; + var userLngChoices = []; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var params = query.split('&'); + for (var i=0; i 0) { + var key = params[i].substring(0,pos); + if (key == o.detectLngQS) { + userLngChoices.push(params[i].substring(pos+1)); + } + } + } + })(); + } + + // get from cookie + if (o.useCookie && typeof document !== 'undefined') { + var c = f.cookie.read(o.cookieName); + if (c) userLngChoices.push(c); + } + + // get from localStorage + if (o.detectLngFromLocalStorage && typeof window !== 'undefined' && window.localStorage) { + userLngChoices.push(window.localStorage.getItem('i18next_lng')); + } + + // get from navigator + if (typeof navigator !== 'undefined') { + if (navigator.languages) { // chrome only; not an array, so can't use .push.apply instead of iterating + for (var i=0;i -1) { + var parts = lng.split('-'); + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } + + if (whitelist.length === 0 || whitelist.indexOf(lng) > -1) { + detectedLng = lng; + break; + } + } + })(); + + //fallback + if (!detectedLng){ + detectedLng = o.fallbackLng[0]; + } + + return detectedLng; + } + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + + /* [code, name, numbers, pluralsType] */ + var _rules = [ + ["ach", "Acholi", [1,2], 1], + ["af", "Afrikaans",[1,2], 2], + ["ak", "Akan", [1,2], 1], + ["am", "Amharic", [1,2], 1], + ["an", "Aragonese",[1,2], 2], + ["ar", "Arabic", [0,1,2,3,11,100],5], + ["arn", "Mapudungun",[1,2], 1], + ["ast", "Asturian", [1,2], 2], + ["ay", "Aymará", [1], 3], + ["az", "Azerbaijani",[1,2],2], + ["be", "Belarusian",[1,2,5],4], + ["bg", "Bulgarian",[1,2], 2], + ["bn", "Bengali", [1,2], 2], + ["bo", "Tibetan", [1], 3], + ["br", "Breton", [1,2], 1], + ["bs", "Bosnian", [1,2,5],4], + ["ca", "Catalan", [1,2], 2], + ["cgg", "Chiga", [1], 3], + ["cs", "Czech", [1,2,5],6], + ["csb", "Kashubian",[1,2,5],7], + ["cy", "Welsh", [1,2,3,8],8], + ["da", "Danish", [1,2], 2], + ["de", "German", [1,2], 2], + ["dev", "Development Fallback", [1,2], 2], + ["dz", "Dzongkha", [1], 3], + ["el", "Greek", [1,2], 2], + ["en", "English", [1,2], 2], + ["eo", "Esperanto",[1,2], 2], + ["es", "Spanish", [1,2], 2], + ["es_ar","Argentinean Spanish", [1,2], 2], + ["et", "Estonian", [1,2], 2], + ["eu", "Basque", [1,2], 2], + ["fa", "Persian", [1], 3], + ["fi", "Finnish", [1,2], 2], + ["fil", "Filipino", [1,2], 1], + ["fo", "Faroese", [1,2], 2], + ["fr", "French", [1,2], 9], + ["fur", "Friulian", [1,2], 2], + ["fy", "Frisian", [1,2], 2], + ["ga", "Irish", [1,2,3,7,11],10], + ["gd", "Scottish Gaelic",[1,2,3,20],11], + ["gl", "Galician", [1,2], 2], + ["gu", "Gujarati", [1,2], 2], + ["gun", "Gun", [1,2], 1], + ["ha", "Hausa", [1,2], 2], + ["he", "Hebrew", [1,2], 2], + ["hi", "Hindi", [1,2], 2], + ["hr", "Croatian", [1,2,5],4], + ["hu", "Hungarian",[1,2], 2], + ["hy", "Armenian", [1,2], 2], + ["ia", "Interlingua",[1,2],2], + ["id", "Indonesian",[1], 3], + ["is", "Icelandic",[1,2], 12], + ["it", "Italian", [1,2], 2], + ["ja", "Japanese", [1], 3], + ["jbo", "Lojban", [1], 3], + ["jv", "Javanese", [0,1], 13], + ["ka", "Georgian", [1], 3], + ["kk", "Kazakh", [1], 3], + ["km", "Khmer", [1], 3], + ["kn", "Kannada", [1,2], 2], + ["ko", "Korean", [1], 3], + ["ku", "Kurdish", [1,2], 2], + ["kw", "Cornish", [1,2,3,4],14], + ["ky", "Kyrgyz", [1], 3], + ["lb", "Letzeburgesch",[1,2],2], + ["ln", "Lingala", [1,2], 1], + ["lo", "Lao", [1], 3], + ["lt", "Lithuanian",[1,2,10],15], + ["lv", "Latvian", [1,2,0],16], + ["mai", "Maithili", [1,2], 2], + ["mfe", "Mauritian Creole",[1,2],1], + ["mg", "Malagasy", [1,2], 1], + ["mi", "Maori", [1,2], 1], + ["mk", "Macedonian",[1,2],17], + ["ml", "Malayalam",[1,2], 2], + ["mn", "Mongolian",[1,2], 2], + ["mnk", "Mandinka", [0,1,2],18], + ["mr", "Marathi", [1,2], 2], + ["ms", "Malay", [1], 3], + ["mt", "Maltese", [1,2,11,20],19], + ["nah", "Nahuatl", [1,2], 2], + ["nap", "Neapolitan",[1,2], 2], + ["nb", "Norwegian Bokmal",[1,2],2], + ["ne", "Nepali", [1,2], 2], + ["nl", "Dutch", [1,2], 2], + ["nn", "Norwegian Nynorsk",[1,2],2], + ["no", "Norwegian",[1,2], 2], + ["nso", "Northern Sotho",[1,2],2], + ["oc", "Occitan", [1,2], 1], + ["or", "Oriya", [2,1], 2], + ["pa", "Punjabi", [1,2], 2], + ["pap", "Papiamento",[1,2], 2], + ["pl", "Polish", [1,2,5],7], + ["pms", "Piemontese",[1,2], 2], + ["ps", "Pashto", [1,2], 2], + ["pt", "Portuguese",[1,2], 2], + ["pt_br","Brazilian Portuguese",[1,2], 2], + ["rm", "Romansh", [1,2], 2], + ["ro", "Romanian", [1,2,20],20], + ["ru", "Russian", [1,2,5],4], + ["sah", "Yakut", [1], 3], + ["sco", "Scots", [1,2], 2], + ["se", "Northern Sami",[1,2], 2], + ["si", "Sinhala", [1,2], 2], + ["sk", "Slovak", [1,2,5],6], + ["sl", "Slovenian",[5,1,2,3],21], + ["so", "Somali", [1,2], 2], + ["son", "Songhay", [1,2], 2], + ["sq", "Albanian", [1,2], 2], + ["sr", "Serbian", [1,2,5],4], + ["su", "Sundanese",[1], 3], + ["sv", "Swedish", [1,2], 2], + ["sw", "Swahili", [1,2], 2], + ["ta", "Tamil", [1,2], 2], + ["te", "Telugu", [1,2], 2], + ["tg", "Tajik", [1,2], 1], + ["th", "Thai", [1], 3], + ["ti", "Tigrinya", [1,2], 1], + ["tk", "Turkmen", [1,2], 2], + ["tr", "Turkish", [1,2], 1], + ["tt", "Tatar", [1], 3], + ["ug", "Uyghur", [1], 3], + ["uk", "Ukrainian",[1,2,5],4], + ["ur", "Urdu", [1,2], 2], + ["uz", "Uzbek", [1,2], 1], + ["vi", "Vietnamese",[1], 3], + ["wa", "Walloon", [1,2], 1], + ["wo", "Wolof", [1], 3], + ["yo", "Yoruba", [1,2], 2], + ["zh", "Chinese", [1], 3] + ]; + + var _rulesPluralsTypes = { + 1: function(n) {return Number(n > 1);}, + 2: function(n) {return Number(n != 1);}, + 3: function(n) {return 0;}, + 4: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 5: function(n) {return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5);}, + 6: function(n) {return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2);}, + 7: function(n) {return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 8: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3);}, + 9: function(n) {return Number(n >= 2);}, + 10: function(n) {return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;}, + 11: function(n) {return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3);}, + 12: function(n) {return Number(n%10!=1 || n%100==11);}, + 13: function(n) {return Number(n !== 0);}, + 14: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3);}, + 15: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 16: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2);}, + 17: function(n) {return Number(n==1 || n%10==1 ? 0 : 1);}, + 18: function(n) {return Number(0 ? 0 : n==1 ? 1 : 2);}, + 19: function(n) {return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3);}, + 20: function(n) {return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2);}, + 21: function(n) {return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }; + + var pluralExtensions = { + + rules: (function () { + var l, rules = {}; + for (l=_rules.length; l-- ;) { + rules[_rules[l][0]] = { + name: _rules[l][1], + numbers: _rules[l][2], + plurals: _rulesPluralsTypes[_rules[l][3]] + } + } + return rules; + }()), + + // you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + needsPlural: function(lng, count) { + var parts = lng.split('-'); + + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[parts[f.getCountyIndexOfLng(lng)]]; + } + + if (ext && ext.numbers.length <= 1) { + return false; + } else { + return this.get(lng, count) !== 1; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i; + if (ext.noAbs) { + i = ext.plurals(c); + } else { + i = ext.plurals(Math.abs(c)); + } + + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[f.getCountyIndexOfLng(lng)], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.hasResourceBundle = hasResourceBundle; + i18n.addResource = addResource; + i18n.addResources = addResources; + i18n.removeResourceBundle = removeResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + + return i18n; + +})); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd-1.7.5.min.js b/libs/i18next/release/i18next.amd-1.7.5.min.js new file mode 100644 index 00000000..c6d32dbf --- /dev/null +++ b/libs/i18next/release/i18next.amd-1.7.5.min.js @@ -0,0 +1,5 @@ +// i18next, v1.7.5 +// Copyright (c)2014 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +!function(a,b){"object"==typeof exports?module.exports=b():"function"==typeof define&&define.amd&&define([],b)}(this,function(){function a(a,b){if(!b||"function"==typeof b)return a;for(var c in b)a[c]=b[c];return a}function b(a,c){for(var d in c)d in a?b(a[d],c[d]):a[d]=c[d];return a}function c(a,b,c){var d,e=0,f=a.length,g=void 0===f||"[object Array]"!==Object.prototype.toString.apply(a)||"function"==typeof a;if(c)if(g){for(d in a)if(b.apply(a[d],c)===!1)break}else for(;f>e&&b.apply(a[e++],c)!==!1;);else if(g){for(d in a)if(b.call(a[d],d,a[d])===!1)break}else for(;f>e&&b.call(a[e],e,a[e++])!==!1;);return a}function d(a){return"string"==typeof a?a.replace(/[&<>"'\/]/g,function(a){return O[a]}):a}function e(a){var b=function(a){if(window.XMLHttpRequest)return a(null,new XMLHttpRequest);if(window.ActiveXObject)try{return a(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(b){return a(null,new ActiveXObject("Microsoft.XMLHTTP"))}return a(new Error)},c=function(a){if("string"==typeof a)return a;var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")},d=function(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;cd?b+=String.fromCharCode(d):d>127&&2048>d?(b+=String.fromCharCode(192|d>>6),b+=String.fromCharCode(128|63&d)):(b+=String.fromCharCode(224|d>>12),b+=String.fromCharCode(128|63&d>>6),b+=String.fromCharCode(128|63&d))}return b},e=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";a=d(a);var c,e,f,g,h,i,j,k="",l=0;do c=a.charCodeAt(l++),e=a.charCodeAt(l++),f=a.charCodeAt(l++),g=c>>2,h=(3&c)<<4|e>>4,i=(15&e)<<2|f>>6,j=63&f,isNaN(e)?i=j=64:isNaN(f)&&(j=64),k+=b.charAt(g)+b.charAt(h)+b.charAt(i)+b.charAt(j),c=e=f="",g=h=i=j="";while(l1&&(d+=d.indexOf("?")>-1?"&"+k:"?"+k),e.jsonp){var l=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=d,l.appendChild(m),void 0}}b(function(b,c){if(b)return h(b);c.open(a,d,e.async);for(var f in j)j.hasOwnProperty(f)&&c.setRequestHeader(f,j[f]);c.onreadystatechange=function(){if(4===c.readyState){var a=c.responseText||"";if(!h)return;h(c.status,{text:function(){return a},json:function(){try{return JSON.parse(a)}catch(b){return R.error("Can not parse JSON. URL: "+d),{}}}})}},c.send(i)})},h={authBasic:function(a,b){g.headers.Authorization="Basic "+e(a+":"+b)},connect:function(a,b,c){return g("CONNECT",a,b,c)},del:function(a,b,c){return g("DELETE",a,b,c)},get:function(a,b,c){return g("GET",a,b,c)},head:function(a,b,c){return g("HEAD",a,b,c)},headers:function(a){g.headers=a||{}},isAllowed:function(a,b,c){this.options(a,function(a,d){c(-1!==d.text().indexOf(b))})},options:function(a,b,c){return g("OPTIONS",a,b,c)},patch:function(a,b,c){return g("PATCH",a,b,c)},post:function(a,b,c){return g("POST",a,b,c)},put:function(a,b,c){return g("PUT",a,b,c)},trace:function(a,b,c){return g("TRACE",a,b,c)}},i=a.type?a.type.toLowerCase():"get";h[i](a.url,a,function(b,c){200===b||0===b&&c.text()?a.success(c.json(),b,null):a.error(c.text(),b,null)})}function f(a,b){"function"==typeof a&&(b=a,a={}),a=a||{},R.extend(N,a),delete N.fixLng,"string"==typeof N.ns&&(N.ns={namespaces:[N.ns],defaultNs:N.ns}),"string"==typeof N.fallbackNS&&(N.fallbackNS=[N.fallbackNS]),("string"==typeof N.fallbackLng||"boolean"==typeof N.fallbackLng)&&(N.fallbackLng=[N.fallbackLng]),N.interpolationPrefixEscaped=R.regexEscape(N.interpolationPrefix),N.interpolationSuffixEscaped=R.regexEscape(N.interpolationSuffix),N.lng||(N.lng=R.detectLanguage()),K=R.toLanguages(N.lng),F=K[0],R.log("currentLng set to: "+F),N.useCookie&&R.cookie.read(N.cookieName)!==F&&R.cookie.create(N.cookieName,F,N.cookieExpirationTime,N.cookieDomain),N.detectLngFromLocalStorage&&"undefined"!=typeof document&&window.localStorage&&R.localStorage.setItem("i18next_lng",F);var c=z;a.fixLng&&(c=function(a,b){return b=b||{},b.lng=b.lng||c.lng,z(a,b)},c.lng=F),U.setCurrentLng(F),G&&N.setJqueryExt&&s();var d;if(G&&G.Deferred&&(d=G.Deferred()),!N.resStore){var e=R.toLanguages(N.lng);"string"==typeof N.preload&&(N.preload=[N.preload]);for(var f=0,g=N.preload.length;g>f;f++)for(var h=R.toLanguages(N.preload[f]),i=0,j=h.length;j>i;i++)e.indexOf(h[i])<0&&e.push(h[i]);return H.sync.load(e,N,function(a,e){I=e,L=!0,b&&b(c),d&&d.resolve(c)}),d?d.promise():void 0}return I=N.resStore,L=!0,b&&b(c),d&&d.resolve(c),d?d.promise():void 0}function g(a,b){"string"==typeof a&&(a=[a]);for(var c=0,d=a.length;d>c;c++)N.preload.indexOf(a[c])<0&&N.preload.push(a[c]);return f(b)}function h(a,b,c,d){"string"!=typeof b?(c=b,b=N.ns.defaultNs):N.ns.namespaces.indexOf(b)<0&&N.ns.namespaces.push(b),I[a]=I[a]||{},I[a][b]=I[a][b]||{},d?R.deepExtend(I[a][b],c):R.extend(I[a][b],c)}function i(a,b){"string"!=typeof b&&(b=N.ns.defaultNs),I[a]=I[a]||{};var c=I[a][b]||{},d=!1;for(var e in c)c.hasOwnProperty(e)&&(d=!0);return d}function j(a,b){"string"!=typeof b&&(b=N.ns.defaultNs),I[a]=I[a]||{},I[a][b]={}}function k(a,b,c,d){"string"!=typeof b?(resource=b,b=N.ns.defaultNs):N.ns.namespaces.indexOf(b)<0&&N.ns.namespaces.push(b),I[a]=I[a]||{},I[a][b]=I[a][b]||{};for(var e=c.split(N.keyseparator),f=0,g=I[a][b];e[f];)f==e.length-1?g[e[f]]=d:(null==g[e[f]]&&(g[e[f]]={}),g=g[e[f]]),f++}function l(a,b,c){"string"!=typeof b?(resource=b,b=N.ns.defaultNs):N.ns.namespaces.indexOf(b)<0&&N.ns.namespaces.push(b);for(var d in c)"string"==typeof c[d]&&k(a,b,d,c[d])}function m(a){N.ns.defaultNs=a}function n(a,b){o([a],b)}function o(a,b){var c={dynamicLoad:N.dynamicLoad,resGetPath:N.resGetPath,getAsync:N.getAsync,customLoad:N.customLoad,ns:{namespaces:a,defaultNs:""}},d=R.toLanguages(N.lng);"string"==typeof N.preload&&(N.preload=[N.preload]);for(var e=0,f=N.preload.length;f>e;e++)for(var g=R.toLanguages(N.preload[e]),h=0,i=g.length;i>h;h++)d.indexOf(g[h])<0&&d.push(g[h]);for(var j=[],k=0,l=d.length;l>k;k++){var m=!1,n=I[d[k]];if(n)for(var o=0,p=a.length;p>o;o++)n[a[o]]||(m=!0);else m=!0;m&&j.push(d[k])}j.length?H.sync._fetch(j,c,function(c,d){var e=a.length*j.length;R.each(a,function(a,c){N.ns.namespaces.indexOf(c)<0&&N.ns.namespaces.push(c),R.each(j,function(a,f){I[f]=I[f]||{},I[f][c]=d[f][c],e--,0===e&&b&&(N.useLocalStorage&&H.sync._storeLocal(I),b())})})}):b&&b()}function p(a,b,c){return"function"==typeof b?(c=b,b={}):b||(b={}),b.lng=a,f(b,c)}function q(){return F}function r(a){I={},p(F,a)}function s(){function a(a,b,c){if(0!==b.length){var d="text";if(0===b.indexOf("[")){var e=b.split("]");b=e[1],d=e[0].substr(1,e[0].length-1)}b.indexOf(";")===b.length-1&&(b=b.substr(0,b.length-2));var f;if("html"===d)f=N.defaultValueFromContent?G.extend({defaultValue:a.html()},c):c,a.html(G.t(b,f));else if("text"===d)f=N.defaultValueFromContent?G.extend({defaultValue:a.text()},c):c,a.text(G.t(b,f));else if("prepend"===d)f=N.defaultValueFromContent?G.extend({defaultValue:a.html()},c):c,a.prepend(G.t(b,f));else if("append"===d)f=N.defaultValueFromContent?G.extend({defaultValue:a.html()},c):c,a.append(G.t(b,f));else if(0===d.indexOf("data-")){var g=d.substr("data-".length);f=N.defaultValueFromContent?G.extend({defaultValue:a.data(g)},c):c;var h=G.t(b,f);a.data(g,h),a.attr(d,h)}else f=N.defaultValueFromContent?G.extend({defaultValue:a.attr(d)},c):c,a.attr(d,G.t(b,f))}}function b(b,c){var d=b.attr(N.selectorAttr);if(d||"undefined"==typeof d||d===!1||(d=b.text()||b.val()),d){var e=b,f=b.data("i18n-target");if(f&&(e=b.find(f)||b),c||N.useDataAttrOptions!==!0||(c=b.data("i18n-options")),c=c||{},d.indexOf(";")>=0){var g=d.split(";");G.each(g,function(b,d){""!==d&&a(e,d,c)})}else a(e,d,c);N.useDataAttrOptions===!0&&b.data("i18n-options",c)}}G.t=G.t||z,G.fn.i18n=function(a){return this.each(function(){b(G(this),a);var c=G(this).find("["+N.selectorAttr+"]");c.each(function(){b(G(this),a)})})}}function t(a,b,c,d){if(!a)return a;if(d=d||b,a.indexOf(d.interpolationPrefix||N.interpolationPrefix)<0)return a;var e=d.interpolationPrefix?R.regexEscape(d.interpolationPrefix):N.interpolationPrefixEscaped,f=d.interpolationSuffix?R.regexEscape(d.interpolationSuffix):N.interpolationSuffixEscaped,g="HTML"+f,h=b.replace&&"object"==typeof b.replace?b.replace:b;return R.each(h,function(b,h){var i=c?c+N.keyseparator+b:b;"object"==typeof h&&null!==h?a=t(a,h,i,d):d.escapeInterpolation||N.escapeInterpolation?(a=a.replace(new RegExp([e,i,g].join(""),"g"),R.regexReplacementEscape(h)),a=a.replace(new RegExp([e,i,f].join(""),"g"),R.regexReplacementEscape(R.escape(h)))):a=a.replace(new RegExp([e,i,f].join(""),"g"),R.regexReplacementEscape(h))}),a}function u(a,b){var c=",",d="{",e="}",f=R.extend({},b);for(delete f.postProcess;-1!=a.indexOf(N.reusePrefix)&&(J++,!(J>N.maxRecursion));){var g=a.lastIndexOf(N.reusePrefix),h=a.indexOf(N.reuseSuffix,g)+N.reuseSuffix.length,i=a.substring(g,h),j=i.replace(N.reusePrefix,"").replace(N.reuseSuffix,"");if(g>=h)return R.error("there is an missing closing in following translation value",a),"";if(-1!=j.indexOf(c)){var k=j.indexOf(c);if(-1!=j.indexOf(d,k)&&-1!=j.indexOf(e,k)){var l=j.indexOf(d,k),m=j.indexOf(e,l)+e.length;try{f=R.extend(f,JSON.parse(j.substring(l,m))),j=j.substring(0,k)}catch(n){}}}var o=C(j,f);a=a.replace(i,R.regexReplacementEscape(o))}return a}function v(a){return a.context&&("string"==typeof a.context||"number"==typeof a.context)}function w(a){return void 0!==a.count&&"string"!=typeof a.count}function x(a){return void 0!==a.indefinite_article&&"string"!=typeof a.indefinite_article&&a.indefinite_article}function y(a,b){b=b||{};var c=A(a,b),d=D(a,b);return void 0!==d||d===c}function z(a,b){return b=b||{},L?(J=0,C.apply(null,arguments)):(R.log("i18next not finished initialization. you might have called t function before loading resources finished."),b.defaultValue||"")}function A(a,b){return void 0!==b.defaultValue?b.defaultValue:a}function B(){for(var a=[],b=1;b1)for(var d=0;d-1&&(e=c.split(N.nsseparator),i=e[0],c=e[1]),void 0===g&&N.sendMissing&&"function"==typeof N.missingKeyHandler&&(b.lng?N.missingKeyHandler(h[0],i,c,f,h):N.missingKeyHandler(N.lng,i,c,f,h));var j=b.postProcess||N.postProcess;void 0!==g&&j&&V[j]&&(g=V[j](g,c,b));var k=f;if(f.indexOf(N.nsseparator)>-1&&(e=f.split(N.nsseparator),k=e[1]),k===c&&N.parseMissingKey&&(f=N.parseMissingKey(f)),void 0===g&&(f=t(f,b),f=u(f,b),j&&V[j])){var l=A(c,b);g=V[j](l,c,b)}return void 0!==g?g:f}function D(a,b){b=b||{};var c,d,e=A(a,b),f=K;if(!I)return e;if("cimode"===f[0].toLowerCase())return e;if(b.lngs&&(f=b.lngs),b.lng&&(f=R.toLanguages(b.lng,b.fallbackLng),!I[f[0]])){var g=N.getAsync;N.getAsync=!1,H.sync.load(f,N,function(a,b){R.extend(I,b),N.getAsync=g})}var h=b.ns||N.ns.defaultNs;if(a.indexOf(N.nsseparator)>-1){var i=a.split(N.nsseparator);h=i[0],a=i[1]}if(v(b)){c=R.extend({},b),delete c.context,c.defaultValue=N.contextNotFound;var j=h+N.nsseparator+a+"_"+b.context;if(d=z(j,c),d!=N.contextNotFound)return t(d,{context:b.context})}if(w(b,f[0])){c=R.extend({lngs:[f[0]]},b),delete c.count,c.defaultValue=N.pluralNotFound;var k;if(U.needsPlural(f[0],b.count)){k=h+N.nsseparator+a+N.pluralSuffix;var l=U.get(f[0],b.count);l>=0?k=k+"_"+l:1===l&&(k=h+N.nsseparator+a)}else k=h+N.nsseparator+a;if(d=z(k,c),d!=N.pluralNotFound)return t(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix});if(f.length>1){var m=f.slice();if(m.shift(),b=R.extend(b,{lngs:m}),d=z(h+N.nsseparator+a,b),d!=N.pluralNotFound)return d}}if(x(b)){var n=R.extend({},b);delete n.indefinite_article,n.defaultValue=N.indefiniteNotFound;var o=h+N.nsseparator+a+(b.count&&!w(b,f[0])||!b.count?N.indefiniteSuffix:"");if(d=z(o,n),d!=N.indefiniteNotFound)return d}for(var p,q=a.split(N.keyseparator),r=0,s=f.length;s>r&&void 0===p;r++){for(var y=f[r],B=0,E=I[y]&&I[y][h];q[B];)E=E&&E[q[B]],B++;if(void 0!==E){var F=Object.prototype.toString.apply(E);if("string"==typeof E)E=t(E,b),E=u(E,b);else if("[object Array]"!==F||N.returnObjectTrees||b.returnObjectTrees){if(null===E&&N.fallbackOnNull===!0)E=void 0;else if(null!==E)if(N.returnObjectTrees||b.returnObjectTrees){if("[object Number]"!==F&&"[object Function]"!==F&&"[object RegExp]"!==F){var G="[object Array]"===F?[]:{};R.each(E,function(c){G[c]=C(h+N.nsseparator+a+N.keyseparator+c,b)}),E=G}}else N.objectTreeKeyHandler&&"function"==typeof N.objectTreeKeyHandler?E=N.objectTreeKeyHandler(a,E,y,h,b):(E="key '"+h+":"+a+" ("+y+")' "+"returned an object instead of string.",R.log(E))}else E=E.join("\n"),E=t(E,b),E=u(E,b);"string"==typeof E&&""===E.trim()&&N.fallbackOnEmpty===!0&&(E=void 0),p=E}}if(void 0===p&&!b.isFallbackLookup&&(N.fallbackToDefaultNS===!0||N.fallbackNS&&N.fallbackNS.length>0)){if(b.isFallbackLookup=!0,N.fallbackNS.length){for(var J=0,L=N.fallbackNS.length;L>J;J++)if(p=D(N.fallbackNS[J]+N.nsseparator+a,b)){var M=p.indexOf(N.nsseparator)>-1?p.split(N.nsseparator)[1]:p,O=e.indexOf(N.nsseparator)>-1?e.split(N.nsseparator)[1]:e;if(M!==O)break}}else p=D(a,b);b.isFallbackLookup=!1}return p}function E(){var a,b=N.lngWhitelist||[],c=[];if("undefined"!=typeof window&&!function(){for(var a=window.location.search.substring(1),b=a.split("&"),d=0;d0){var f=b[d].substring(0,e);f==N.detectLngQS&&c.push(b[d].substring(e+1))}}}(),N.useCookie&&"undefined"!=typeof document){var d=R.cookie.read(N.cookieName);d&&c.push(d)}if(N.detectLngFromLocalStorage&&"undefined"!=typeof window&&window.localStorage&&c.push(window.localStorage.getItem("i18next_lng")),"undefined"!=typeof navigator){if(navigator.languages)for(var e=0;e-1){var f=e.split("-");e=N.lowerCaseLng?f[0].toLowerCase()+"-"+f[1].toLowerCase():f[0].toLowerCase()+"-"+f[1].toUpperCase()}if(0===b.length||b.indexOf(e)>-1){a=e;break}}}(),a||(a=N.fallbackLng[0]),a}Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>0&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&1/0!=d&&d!=-1/0&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=c;arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d))));for(var e=d>=0?Math.min(d,c-1):c-Math.abs(d);e>=0;e--)if(e in b&&b[e]===a)return e;return-1}),"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")});var F,G=void 0,H={},I={},J=0,K=[],L=!1,M={};M={load:function(a,b,c){b.useLocalStorage?M._loadLocal(a,b,function(d,e){for(var f=[],g=0,h=a.length;h>g;g++)e[a[g]]||f.push(a[g]);f.length>0?M._fetch(f,b,function(a,b){R.extend(e,b),M._storeLocal(b),c(null,e)}):c(null,e)}):M._fetch(a,b,function(a,b){c(null,b)})},_loadLocal:function(a,b,c){var d={},e=(new Date).getTime();if(window.localStorage){var f=a.length;R.each(a,function(a,g){var h=window.localStorage.getItem("res_"+g);h&&(h=JSON.parse(h),h.i18nStamp&&h.i18nStamp+b.localStorageExpirationTime>e&&(d[g]=h)),f--,0===f&&c(null,d)})}},_storeLocal:function(a){if(window.localStorage)for(var b in a)a[b].i18nStamp=(new Date).getTime(),R.localStorage.setItem("res_"+b,JSON.stringify(a[b]))},_fetch:function(a,b,c){var d=b.ns,e={};if(b.dynamicLoad){var f=function(a,b){c(null,b)};if("function"==typeof b.customLoad)b.customLoad(a,d.namespaces,b,f);else{var g=t(b.resGetPath,{lng:a.join("+"),ns:d.namespaces.join("+")});R.ajax({url:g,success:function(a){R.log("loaded: "+g),f(null,a)},error:function(a,b,c){R.log("failed loading: "+g),f("failed loading resource.json error: "+c)},dataType:"json",async:b.getAsync})}}else{var h,i=d.namespaces.length*a.length;R.each(d.namespaces,function(d,f){R.each(a,function(a,d){var g=function(a,b){a&&(h=h||[],h.push(a)),e[d]=e[d]||{},e[d][f]=b,i--,0===i&&c(h,e)};"function"==typeof b.customLoad?b.customLoad(d,f,b,g):M._fetchOne(d,f,b,g)})})}},_fetchOne:function(a,b,c,d){var e=t(c.resGetPath,{lng:a,ns:b});R.ajax({url:e,success:function(a){R.log("loaded: "+e),d(null,a)},error:function(a,b,c){if(b&&200==b||a&&a.status&&200==a.status)R.error("There is a typo in: "+e);else if(b&&404==b||a&&a.status&&404==a.status)R.log("Does not exist: "+e);else{var f=b?b:a&&a.status?a.status:null;R.log(f+" when loading "+e)}d(c,{})},dataType:"json",async:c.getAsync})},postMissing:function(a,b,c,d,e){var f={};f[c]=d;var g=[];if("fallback"===N.sendMissingTo&&N.fallbackLng[0]!==!1)for(var h=0;hh;h++)g.push({lng:e[h],url:t(N.resPostPath,{lng:e[h],ns:b})});for(var j=0,k=g.length;k>j;j++){var l=g[j];R.ajax({url:l.url,type:N.sendType,data:f,success:function(){R.log("posted missing key '"+c+"' to: "+l.url);for(var a=c.split("."),e=0,f=I[l.lng][b];a[e];)f=f[a[e]]=e===a.length-1?d:f[a[e]]||{},e++},error:function(){R.log("failed posting missing key '"+c+"' to: "+l.url)},dataType:"json",async:N.postAsync})}},reload:r};var N={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:["dev"],fallbackNS:[],detectLngQS:"setLng",detectLngFromLocalStorage:!1,ns:"translation",fallbackOnNull:!0,fallbackOnEmpty:!1,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",defaultVariables:!1,reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,indefiniteSuffix:"_indefinite",indefiniteNotFound:["indefinite_not_found",Math.random()].join(""),setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",cookieDomain:void 0,objectTreeKeyHandler:void 0,postProcess:void 0,parseMissingKey:void 0,missingKeyHandler:M.postMissing,shortcutFunction:"sprintf"},O={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},P={create:function(a,b,c,d){var e;if(c){var f=new Date;f.setTime(f.getTime()+1e3*60*c),e="; expires="+f.toGMTString()}else e="";d=d?"domain="+d+";":"",document.cookie=a+"="+b+e+";"+d+"path=/"},read:function(a){for(var b=a+"=",c=document.cookie.split(";"),d=0;d-1){var c=a.split("-");b=N.lowerCaseLng?c[0].toLowerCase()+"-"+c[1].toLowerCase():c[0].toLowerCase()+"-"+c[1].toUpperCase()}else b=N.lowerCaseLng?a.toLowerCase():a;return b}var c=this.log,d=[],e=N.lngWhitelist||!1,f=function(a){!e||e.indexOf(a)>-1?d.push(a):c("rejecting non-whitelisted language: "+a)};if("string"==typeof a&&a.indexOf("-")>-1){var g=a.split("-");"unspecific"!==N.load&&f(b(a)),"current"!==N.load&&f(b(g[this.getCountyIndexOfLng(a)]))}else f(b(a));for(var h=0;h1)},2:function(a){return Number(1!=a)},3:function(){return 0},4:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},5:function(a){return Number(0===a?0:1==a?1:2==a?2:a%100>=3&&10>=a%100?3:a%100>=11?4:5)},6:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)},7:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},8:function(a){return Number(1==a?0:2==a?1:8!=a&&11!=a?2:3)},9:function(a){return Number(a>=2)},10:function(a){return Number(1==a?0:2==a?1:7>a?2:11>a?3:4)},11:function(a){return Number(1==a||11==a?0:2==a||12==a?1:a>2&&20>a?2:3)},12:function(a){return Number(1!=a%10||11==a%100)},13:function(a){return Number(0!==a)},14:function(a){return Number(1==a?0:2==a?1:3==a?2:3)},15:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&(10>a%100||a%100>=20)?1:2)},16:function(a){return Number(1==a%10&&11!=a%100?0:0!==a?1:2)},17:function(a){return Number(1==a||1==a%10?0:1)},18:function(a){return Number(1==a?1:2)},19:function(a){return Number(1==a?0:0===a||a%100>1&&11>a%100?1:a%100>10&&20>a%100?2:3)},20:function(a){return Number(1==a?0:0===a||a%100>0&&20>a%100?1:2)},21:function(a){return Number(1==a%100?1:2==a%100?2:3==a%100||4==a%100?3:0)}},U={rules:function(){var a,b={};for(a=S.length;a--;)b[S[a][0]]={name:S[a][1],numbers:S[a][2],plurals:T[S[a][3]]};return b}(),addRule:function(a,b){U.rules[a]=b},setCurrentLng:function(a){if(!U.currentRule||U.currentRule.lng!==a){var b=a.split("-");U.currentRule={lng:a,rule:U.rules[b[0]]}}},needsPlural:function(a,b){var c,d=a.split("-");return c=U.currentRule&&U.currentRule.lng===a?U.currentRule.rule:U.rules[d[R.getCountyIndexOfLng(a)]],c&&c.numbers.length<=1?!1:1!==this.get(a,b)},get:function(a,b){function c(b,c){var d;if(d=U.currentRule&&U.currentRule.lng===a?U.currentRule.rule:U.rules[b]){var e;e=d.noAbs?d.plurals(c):d.plurals(Math.abs(c));var f=d.numbers[e];return 2===d.numbers.length&&1===d.numbers[0]&&(2===f?f=-1:1===f&&(f=1)),f}return 1===c?"1":"-1"}var d=a.split("-");return c(d[R.getCountyIndexOfLng(a)],b)}},V={},W=function(a,b){V[a]=b},X=function(){function a(a){return Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}function b(a,b){for(var c=[];b>0;c[--b]=a);return c.join("")}var c=function(){return c.cache.hasOwnProperty(arguments[0])||(c.cache[arguments[0]]=c.parse(arguments[0])),c.format.call(null,c.cache[arguments[0]],arguments)};return c.format=function(c,d){var e,f,g,h,i,j,k,l=1,m=c.length,n="",o=[];for(f=0;m>f;f++)if(n=a(c[f]),"string"===n)o.push(c[f]);else if("array"===n){if(h=c[f],h[2])for(e=d[l],g=0;g=0?"+"+e:e,j=h[4]?"0"==h[4]?"0":h[4].charAt(1):" ",k=h[6]-String(e).length,i=h[6]?b(j,k):"",o.push(h[5]?e+i:i+e)}return o.join("")},c.cache={},c.parse=function(a){for(var b=a,c=[],d=[],e=0;b;){if(null!==(c=/^[^\x25]+/.exec(b)))d.push(c[0]);else if(null!==(c=/^\x25{2}/.exec(b)))d.push("%");else{if(null===(c=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(b)))throw"[sprintf] huh?";if(c[2]){e|=1;var f=[],g=c[2],h=[];if(null===(h=/^([a-z_][a-z_\d]*)/i.exec(g)))throw"[sprintf] huh?";for(f.push(h[1]);""!==(g=g.substring(h[0].length));)if(null!==(h=/^\.([a-z_][a-z_\d]*)/i.exec(g)))f.push(h[1]);else{if(null===(h=/^\[(\d+)\]/.exec(g)))throw"[sprintf] huh?";f.push(h[1])}c[2]=f}else e|=2;if(3===e)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";d.push(c)}b=b.substring(c[0].length)}return d},c}(),Y=function(a,b){return b.unshift(a),X.apply(null,b)};return W("sprintf",function(a,b,c){return c.sprintf?"[object Array]"===Object.prototype.toString.apply(c.sprintf)?Y(a,c.sprintf):"object"==typeof c.sprintf?X(a,c.sprintf):a:a}),H.init=f,H.setLng=p,H.preload=g,H.addResourceBundle=h,H.hasResourceBundle=i,H.addResource=k,H.addResources=l,H.removeResourceBundle=j,H.loadNamespace=n,H.loadNamespaces=o,H.setDefaultNamespace=m,H.t=z,H.translate=z,H.exists=y,H.detectLanguage=R.detectLanguage,H.pluralExtensions=U,H.sync=M,H.functions=R,H.lng=q,H.addPostProcessor=W,H.options=N,H}); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd-1.7.5.zip b/libs/i18next/release/i18next.amd-1.7.5.zip new file mode 100644 index 00000000..48e71b5a Binary files /dev/null and b/libs/i18next/release/i18next.amd-1.7.5.zip differ diff --git a/libs/i18next/release/i18next.amd-1.7.7.js b/libs/i18next/release/i18next.amd-1.7.7.js new file mode 100644 index 00000000..79cbc0f2 --- /dev/null +++ b/libs/i18next/release/i18next.amd-1.7.7.js @@ -0,0 +1,2109 @@ +// i18next, v1.7.7 +// Copyright (c)2014 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function (root, factory) { + if (typeof exports === 'object') { + + module.exports = factory(); + + } else if (typeof define === 'function' && define.amd) { + + define([], factory); + + } +}(this, function () { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + // Add string trim for IE8. + if (typeof String.prototype.trim !== 'function') { + String.prototype.trim = function() { + return this.replace(/^\s+|\s+$/g, ''); + } + } + + var $ = undefined + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = [] + , initialized = false + , sync = {}; + + sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + f.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + if ((status && status == 200) || (xhr && xhr.status && xhr.status == 200)) { + // file loaded but invalid json, stop waste time ! + f.error('There is a typo in: ' + url); + } else if ((status && status == 404) || (xhr && xhr.status && xhr.status == 404)) { + f.log('Does not exist: ' + url); + } else { + var theStatus = status ? status : ((xhr && xhr.status) ? xhr.status : null); + f.log(theStatus + ' when loading ' + url); + } + + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback' && o.fallbackLng[0] !== false) { + for (var i = 0; i < o.fallbackLng.length; i++) { + urls.push({lng: o.fallbackLng[i], url: applyReplacement(o.resPostPath, { lng: o.fallbackLng[i], ns: ns })}); + } + } else if (o.sendMissingTo === 'current' || (o.sendMissingTo === 'fallback' && o.fallbackLng[0] === false) ) { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + }, + + reload: reload + }; + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: ['dev'], + fallbackNS: [], + detectLngQS: 'setLng', + detectLngFromLocalStorage: false, + ns: 'translation', + fallbackOnNull: true, + fallbackOnEmpty: false, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + defaultVariables: false, + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + indefiniteSuffix: '_indefinite', + indefiniteNotFound: ['indefinite_not_found', Math.random()].join(''), + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + cookieDomain: undefined, + + objectTreeKeyHandler: undefined, + postProcess: undefined, + parseMissingKey: undefined, + missingKeyHandler: sync.postMissing, + + shortcutFunction: 'sprintf' // or: defaultValue + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _deepExtend(target, source) { + for (var prop in source) + if (prop in target) + _deepExtend(target[prop], source[prop]); + else + target[prop] = source[prop]; + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || Object.prototype.toString.apply(object) !== '[object Array]' || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + try { + return JSON.parse(data) + } catch (e) { + f.error('Can not parse JSON. URL: ' + url); + return {}; + } + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + // file: protocol always gives status code 0, so check for data + if (status === 200 || (status === 0 && data.text())) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes,domain) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + domain = (domain)? "domain="+domain+";" : ""; + document.cookie = name+"="+value+expires+";"+domain+"path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes,domain) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + deepExtend: _deepExtend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : (typeof document !== 'undefined' ? _ajax : function() {}), + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + error: function(str) { + if (typeof console !== "undefined") console.error(str); + }, + getCountyIndexOfLng: function(lng) { + var lng_index = 0; + if (lng === 'nb-NO' || lng === 'nn-NO' || lng === 'nb-no' || lng === 'nn-no') lng_index = 1; + return lng_index; + }, + toLanguages: function(lng) { + var log = this.log; + + function applyCase(l) { + var ret = l; + + if (typeof l === 'string' && l.indexOf('-') > -1) { + var parts = l.split('-'); + + ret = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } else { + ret = o.lowerCaseLng ? l.toLowerCase() : l; + } + + return ret; + } + + var languages = []; + var whitelist = o.lngWhitelist || false; + var addLanguage = function(language){ + //reject langs not whitelisted + if(!whitelist || whitelist.indexOf(language) > -1){ + languages.push(language); + }else{ + log('rejecting non-whitelisted language: ' + language); + } + }; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + if (o.load !== 'unspecific') addLanguage(applyCase(lng)); + if (o.load !== 'current') addLanguage(applyCase(parts[this.getCountyIndexOfLng(lng)])); + } else { + addLanguage(applyCase(lng)); + } + + for (var i = 0; i < o.fallbackLng.length; i++) { + if (languages.indexOf(o.fallbackLng[i]) === -1 && o.fallbackLng[i]) languages.push(applyCase(o.fallbackLng[i])); + } + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + }, + regexReplacementEscape: function(strOrFn) { + if (typeof strOrFn === 'string') { + return strOrFn.replace(/\$/g, "$$$$"); + } else { + return strOrFn; + } + }, + localStorage: { + setItem: function(key, value) { + if (window.localStorage) { + try { + window.localStorage.setItem(key, value); + } catch (e) { + f.log('failed to set value for key "' + key + '" to localStorage.'); + } + } + } + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + delete o.fixLng; /* passed in each time */ + + // override functions: .log(), .detectLanguage(), etc + if (o.functions) { + delete o.functions; + f.extend(f, options.functions); + } + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // fallback languages + if (typeof o.fallbackLng == 'string' || typeof o.fallbackLng == 'boolean') { + o.fallbackLng = [o.fallbackLng]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + if (o.useCookie && f.cookie.read(o.cookieName) !== currentLng){ //cookie is unset or invalid + f.cookie.create(o.cookieName, currentLng, o.cookieExpirationTime, o.cookieDomain); + } + if (o.detectLngFromLocalStorage && typeof document !== 'undefined' && window.localStorage) { + f.localStorage.setItem('i18next_lng', currentLng); + } + + var lngTranslate = translate; + if (options.fixLng) { + lngTranslate = function(key, options) { + options = options || {}; + options.lng = options.lng || lngTranslate.lng; + return translate(key, options); + }; + lngTranslate.lng = currentLng; + } + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + initialized = true; + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + initialized = true; + + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources, deep) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + if (deep) { + f.deepExtend(resStore[lng][ns], resources); + } else { + f.extend(resStore[lng][ns], resources); + } + } + + function hasResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + var res = resStore[lng][ns] || {}; + + var hasValues = false; + for(var prop in res) { + if (res.hasOwnProperty(prop)) { + hasValues = true; + } + } + + return hasValues; + } + + function removeResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = {}; + } + + function addResource(lng, ns, key, value) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + var keys = key.split(o.keyseparator); + var x = 0; + var node = resStore[lng][ns]; + var origRef = node; + + while (keys[x]) { + if (x == keys.length - 1) + node[keys[x]] = value; + else { + if (node[keys[x]] == null) + node[keys[x]] = {}; + + node = node[keys[x]]; + } + x++; + } + } + + function addResources(lng, ns, resources) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + for (var m in resources) { + if (typeof resources[m] === 'string') addResource(lng, ns, m, resources[m]); + } + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, options, cb) { + if (typeof options === 'function') { + cb = options; + options = {}; + } else if (!options) { + options = {}; + } + + options.lng = lng; + return init(options, cb); + } + + function lng() { + return currentLng; + } + + function reload(cb) { + resStore = {}; + setLng(currentLng, cb); + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else if (attr === 'prepend') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.prepend($.t(key, optionsToUse)); + } else if (attr === 'append') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.append($.t(key, optionsToUse)); + } else if (attr.indexOf("data-") === 0) { + var dataAttr = attr.substr(("data-").length); + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.data(dataAttr) }, options) : options; + var translated = $.t(key, optionsToUse); + //we change into the data cache + ele.data(dataAttr, translated); + //we change into the dom + ele.attr(attr, translated); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key && typeof key !== 'undefined' && key !== false) key = ele.text() || ele.val(); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + var hash = replacementHash.replace && typeof replacementHash.replace === 'object' ? replacementHash.replace : replacementHash; + f.each(hash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), f.regexReplacementEscape(value)); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(f.escape(value))); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(value)); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + if (index_of_end_of_closing <= index_of_opening) { + f.error('there is an missing closing in following translation value', translated); + return ''; + } + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, f.regexReplacementEscape(translated_token)); + } + return translated; + } + + function hasContext(options) { + return (options.context && (typeof options.context == 'string' || typeof options.context == 'number')); + } + + function needsPlural(options, lng) { + return (options.count !== undefined && typeof options.count != 'string'/* && pluralExtensions.needsPlural(lng, options.count)*/); + } + + function needsIndefiniteArticle(options) { + return (options.indefinite_article !== undefined && typeof options.indefinite_article != 'string' && options.indefinite_article); + } + + function exists(key, options) { + options = options || {}; + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + options = options || {}; + + if (!initialized) { + f.log('i18next not finished initialization. you might have called t function before loading resources finished.') + return options.defaultValue || ''; + }; + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _getDefaultValue(key, options) { + return (options.defaultValue !== undefined) ? options.defaultValue : key; + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(potentialKeys, options) { + if (options && typeof options !== 'object') { + if (o.shortcutFunction === 'sprintf') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else if (o.shortcutFunction === 'defaultValue') { + options = { + defaultValue: options + } + } + } else { + options = options || {}; + } + + if (typeof o.defaultVariables === 'object') { + options = f.extend({}, o.defaultVariables, options); + } + + if (potentialKeys === undefined || potentialKeys === null || potentialKeys === '') return ''; + + if (typeof potentialKeys === 'string') { + potentialKeys = [potentialKeys]; + } + + var key = potentialKeys[0]; + + if (potentialKeys.length > 1) { + for (var i = 0; i < potentialKeys.length; i++) { + key = potentialKeys[i]; + if (exists(key, options)) { + break; + } + } + } + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng, options.fallbackLng) : languages + , ns = options.ns || o.ns.defaultNs + , parts; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing && typeof o.missingKeyHandler === 'function') { + if (options.lng) { + o.missingKeyHandler(lngs[0], ns, key, notFound, lngs); + } else { + o.missingKeyHandler(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found !== undefined && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + // process notFound if function exists + var splitNotFound = notFound; + if (notFound.indexOf(o.nsseparator) > -1) { + parts = notFound.split(o.nsseparator); + splitNotFound = parts[1]; + } + if (splitNotFound === key && o.parseMissingKey) { + notFound = o.parseMissingKey(notFound); + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessor && postProcessors[postProcessor]) { + var val = _getDefaultValue(key, options); + found = postProcessors[postProcessor](val, key, options); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options) { + options = options || {}; + + var optionWithoutCount, translated + , notFound = _getDefaultValue(key, options) + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + // CI mode + if (lngs[0].toLowerCase() === 'cimode') return notFound; + + // passed in lng + if (options.lngs) lngs = options.lngs; + if (options.lng) { + lngs = f.toLanguages(options.lng, options.fallbackLng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options, lngs[0])) { + optionWithoutCount = f.extend({ lngs: [lngs[0]]}, options); + delete optionWithoutCount.count; + delete optionWithoutCount.lng; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey; + if (!pluralExtensions.needsPlural(lngs[0], options.count)) { + pluralKey = ns + o.nsseparator + key; + } else { + pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(lngs[0], options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + } + + translated = translate(pluralKey, optionWithoutCount); + + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } else if (lngs.length > 1) { + // remove failed lng + var clone = lngs.slice(); + clone.shift(); + options = f.extend(options, { lngs: clone }); + delete options.lng; + // retry with fallbacks + translated = translate(ns + o.nsseparator + key, options); + if (translated != o.pluralNotFound) return translated; + } else { + return translated; + } + } + + if (needsIndefiniteArticle(options)) { + var optionsWithoutIndef = f.extend({}, options); + delete optionsWithoutIndef.indefinite_article; + optionsWithoutIndef.defaultValue = o.indefiniteNotFound; + // If we don't have a count, we want the indefinite, if we do have a count, and needsPlural is false + var indefiniteKey = ns + o.nsseparator + key + (((options.count && !needsPlural(options, lngs[0])) || !options.count) ? o.indefiniteSuffix : ""); + translated = translate(indefiniteKey, optionsWithoutIndef); + if (translated != o.indefiniteNotFound) { + return translated; + } + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + var valueType = Object.prototype.toString.apply(value); + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (valueType === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + if (o.objectTreeKeyHandler && typeof o.objectTreeKeyHandler == 'function') { + value = o.objectTreeKeyHandler(key, value, l, ns, options); + } else { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned an object instead of string.'; + f.log(value); + } + } else if (valueType !== '[object Number]' && valueType !== '[object Function]' && valueType !== '[object RegExp]') { + var copy = (valueType === '[object Array]') ? [] : {}; // apply child translation on a copy + f.each(value, function(m) { + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + }); + value = copy; + } + } + + if (typeof value === 'string' && value.trim() === '' && o.fallbackOnEmpty === true) + value = undefined; + + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length > 0))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found || (found==="" && o.fallbackOnEmpty === false)) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + options.isFallbackLookup = false; + } + + return found; + } + function detectLanguage() { + var detectedLng; + var whitelist = o.lngWhitelist || []; + var userLngChoices = []; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var params = query.split('&'); + for (var i=0; i 0) { + var key = params[i].substring(0,pos); + if (key == o.detectLngQS) { + userLngChoices.push(params[i].substring(pos+1)); + } + } + } + })(); + } + + // get from cookie + if (o.useCookie && typeof document !== 'undefined') { + var c = f.cookie.read(o.cookieName); + if (c) userLngChoices.push(c); + } + + // get from localStorage + if (o.detectLngFromLocalStorage && typeof window !== 'undefined' && window.localStorage) { + userLngChoices.push(window.localStorage.getItem('i18next_lng')); + } + + // get from navigator + if (typeof navigator !== 'undefined') { + if (navigator.languages) { // chrome only; not an array, so can't use .push.apply instead of iterating + for (var i=0;i -1) { + var parts = lng.split('-'); + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } + + if (whitelist.length === 0 || whitelist.indexOf(lng) > -1) { + detectedLng = lng; + break; + } + } + })(); + + //fallback + if (!detectedLng){ + detectedLng = o.fallbackLng[0]; + } + + return detectedLng; + } + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + + /* [code, name, numbers, pluralsType] */ + var _rules = [ + ["ach", "Acholi", [1,2], 1], + ["af", "Afrikaans",[1,2], 2], + ["ak", "Akan", [1,2], 1], + ["am", "Amharic", [1,2], 1], + ["an", "Aragonese",[1,2], 2], + ["ar", "Arabic", [0,1,2,3,11,100],5], + ["arn", "Mapudungun",[1,2], 1], + ["ast", "Asturian", [1,2], 2], + ["ay", "Aymará", [1], 3], + ["az", "Azerbaijani",[1,2],2], + ["be", "Belarusian",[1,2,5],4], + ["bg", "Bulgarian",[1,2], 2], + ["bn", "Bengali", [1,2], 2], + ["bo", "Tibetan", [1], 3], + ["br", "Breton", [1,2], 1], + ["bs", "Bosnian", [1,2,5],4], + ["ca", "Catalan", [1,2], 2], + ["cgg", "Chiga", [1], 3], + ["cs", "Czech", [1,2,5],6], + ["csb", "Kashubian",[1,2,5],7], + ["cy", "Welsh", [1,2,3,8],8], + ["da", "Danish", [1,2], 2], + ["de", "German", [1,2], 2], + ["dev", "Development Fallback", [1,2], 2], + ["dz", "Dzongkha", [1], 3], + ["el", "Greek", [1,2], 2], + ["en", "English", [1,2], 2], + ["eo", "Esperanto",[1,2], 2], + ["es", "Spanish", [1,2], 2], + ["es_ar","Argentinean Spanish", [1,2], 2], + ["et", "Estonian", [1,2], 2], + ["eu", "Basque", [1,2], 2], + ["fa", "Persian", [1], 3], + ["fi", "Finnish", [1,2], 2], + ["fil", "Filipino", [1,2], 1], + ["fo", "Faroese", [1,2], 2], + ["fr", "French", [1,2], 9], + ["fur", "Friulian", [1,2], 2], + ["fy", "Frisian", [1,2], 2], + ["ga", "Irish", [1,2,3,7,11],10], + ["gd", "Scottish Gaelic",[1,2,3,20],11], + ["gl", "Galician", [1,2], 2], + ["gu", "Gujarati", [1,2], 2], + ["gun", "Gun", [1,2], 1], + ["ha", "Hausa", [1,2], 2], + ["he", "Hebrew", [1,2], 2], + ["hi", "Hindi", [1,2], 2], + ["hr", "Croatian", [1,2,5],4], + ["hu", "Hungarian",[1,2], 2], + ["hy", "Armenian", [1,2], 2], + ["ia", "Interlingua",[1,2],2], + ["id", "Indonesian",[1], 3], + ["is", "Icelandic",[1,2], 12], + ["it", "Italian", [1,2], 2], + ["ja", "Japanese", [1], 3], + ["jbo", "Lojban", [1], 3], + ["jv", "Javanese", [0,1], 13], + ["ka", "Georgian", [1], 3], + ["kk", "Kazakh", [1], 3], + ["km", "Khmer", [1], 3], + ["kn", "Kannada", [1,2], 2], + ["ko", "Korean", [1], 3], + ["ku", "Kurdish", [1,2], 2], + ["kw", "Cornish", [1,2,3,4],14], + ["ky", "Kyrgyz", [1], 3], + ["lb", "Letzeburgesch",[1,2],2], + ["ln", "Lingala", [1,2], 1], + ["lo", "Lao", [1], 3], + ["lt", "Lithuanian",[1,2,10],15], + ["lv", "Latvian", [1,2,0],16], + ["mai", "Maithili", [1,2], 2], + ["mfe", "Mauritian Creole",[1,2],1], + ["mg", "Malagasy", [1,2], 1], + ["mi", "Maori", [1,2], 1], + ["mk", "Macedonian",[1,2],17], + ["ml", "Malayalam",[1,2], 2], + ["mn", "Mongolian",[1,2], 2], + ["mnk", "Mandinka", [0,1,2],18], + ["mr", "Marathi", [1,2], 2], + ["ms", "Malay", [1], 3], + ["mt", "Maltese", [1,2,11,20],19], + ["nah", "Nahuatl", [1,2], 2], + ["nap", "Neapolitan",[1,2], 2], + ["nb", "Norwegian Bokmal",[1,2],2], + ["ne", "Nepali", [1,2], 2], + ["nl", "Dutch", [1,2], 2], + ["nn", "Norwegian Nynorsk",[1,2],2], + ["no", "Norwegian",[1,2], 2], + ["nso", "Northern Sotho",[1,2],2], + ["oc", "Occitan", [1,2], 1], + ["or", "Oriya", [2,1], 2], + ["pa", "Punjabi", [1,2], 2], + ["pap", "Papiamento",[1,2], 2], + ["pl", "Polish", [1,2,5],7], + ["pms", "Piemontese",[1,2], 2], + ["ps", "Pashto", [1,2], 2], + ["pt", "Portuguese",[1,2], 2], + ["pt_br","Brazilian Portuguese",[1,2], 2], + ["rm", "Romansh", [1,2], 2], + ["ro", "Romanian", [1,2,20],20], + ["ru", "Russian", [1,2,5],4], + ["sah", "Yakut", [1], 3], + ["sco", "Scots", [1,2], 2], + ["se", "Northern Sami",[1,2], 2], + ["si", "Sinhala", [1,2], 2], + ["sk", "Slovak", [1,2,5],6], + ["sl", "Slovenian",[5,1,2,3],21], + ["so", "Somali", [1,2], 2], + ["son", "Songhay", [1,2], 2], + ["sq", "Albanian", [1,2], 2], + ["sr", "Serbian", [1,2,5],4], + ["su", "Sundanese",[1], 3], + ["sv", "Swedish", [1,2], 2], + ["sw", "Swahili", [1,2], 2], + ["ta", "Tamil", [1,2], 2], + ["te", "Telugu", [1,2], 2], + ["tg", "Tajik", [1,2], 1], + ["th", "Thai", [1], 3], + ["ti", "Tigrinya", [1,2], 1], + ["tk", "Turkmen", [1,2], 2], + ["tr", "Turkish", [1,2], 1], + ["tt", "Tatar", [1], 3], + ["ug", "Uyghur", [1], 3], + ["uk", "Ukrainian",[1,2,5],4], + ["ur", "Urdu", [1,2], 2], + ["uz", "Uzbek", [1,2], 1], + ["vi", "Vietnamese",[1], 3], + ["wa", "Walloon", [1,2], 1], + ["wo", "Wolof", [1], 3], + ["yo", "Yoruba", [1,2], 2], + ["zh", "Chinese", [1], 3] + ]; + + var _rulesPluralsTypes = { + 1: function(n) {return Number(n > 1);}, + 2: function(n) {return Number(n != 1);}, + 3: function(n) {return 0;}, + 4: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 5: function(n) {return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5);}, + 6: function(n) {return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2);}, + 7: function(n) {return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 8: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3);}, + 9: function(n) {return Number(n >= 2);}, + 10: function(n) {return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;}, + 11: function(n) {return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3);}, + 12: function(n) {return Number(n%10!=1 || n%100==11);}, + 13: function(n) {return Number(n !== 0);}, + 14: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3);}, + 15: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 16: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2);}, + 17: function(n) {return Number(n==1 || n%10==1 ? 0 : 1);}, + 18: function(n) {return Number(0 ? 0 : n==1 ? 1 : 2);}, + 19: function(n) {return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3);}, + 20: function(n) {return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2);}, + 21: function(n) {return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }; + + var pluralExtensions = { + + rules: (function () { + var l, rules = {}; + for (l=_rules.length; l-- ;) { + rules[_rules[l][0]] = { + name: _rules[l][1], + numbers: _rules[l][2], + plurals: _rulesPluralsTypes[_rules[l][3]] + } + } + return rules; + }()), + + // you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + needsPlural: function(lng, count) { + var parts = lng.split('-'); + + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[parts[f.getCountyIndexOfLng(lng)]]; + } + + if (ext && ext.numbers.length <= 1) { + return false; + } else { + return this.get(lng, count) !== 1; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i; + if (ext.noAbs) { + i = ext.plurals(c); + } else { + i = ext.plurals(Math.abs(c)); + } + + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[f.getCountyIndexOfLng(lng)], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.hasResourceBundle = hasResourceBundle; + i18n.addResource = addResource; + i18n.addResources = addResources; + i18n.removeResourceBundle = removeResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + + return i18n; + +})); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd-1.7.7.min.js b/libs/i18next/release/i18next.amd-1.7.7.min.js new file mode 100644 index 00000000..0a294726 --- /dev/null +++ b/libs/i18next/release/i18next.amd-1.7.7.min.js @@ -0,0 +1,5 @@ +// i18next, v1.7.7 +// Copyright (c)2014 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +!function(a,b){"object"==typeof exports?module.exports=b():"function"==typeof define&&define.amd&&define([],b)}(this,function(){function a(a,b){if(!b||"function"==typeof b)return a;for(var c in b)a[c]=b[c];return a}function b(a,c){for(var d in c)d in a?b(a[d],c[d]):a[d]=c[d];return a}function c(a,b,c){var d,e=0,f=a.length,g=void 0===f||"[object Array]"!==Object.prototype.toString.apply(a)||"function"==typeof a;if(c)if(g){for(d in a)if(b.apply(a[d],c)===!1)break}else for(;f>e&&b.apply(a[e++],c)!==!1;);else if(g){for(d in a)if(b.call(a[d],d,a[d])===!1)break}else for(;f>e&&b.call(a[e],e,a[e++])!==!1;);return a}function d(a){return"string"==typeof a?a.replace(/[&<>"'\/]/g,function(a){return O[a]}):a}function e(a){var b=function(a){if(window.XMLHttpRequest)return a(null,new XMLHttpRequest);if(window.ActiveXObject)try{return a(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(b){return a(null,new ActiveXObject("Microsoft.XMLHTTP"))}return a(new Error)},c=function(a){if("string"==typeof a)return a;var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")},d=function(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;cd?b+=String.fromCharCode(d):d>127&&2048>d?(b+=String.fromCharCode(192|d>>6),b+=String.fromCharCode(128|63&d)):(b+=String.fromCharCode(224|d>>12),b+=String.fromCharCode(128|63&d>>6),b+=String.fromCharCode(128|63&d))}return b},e=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";a=d(a);var c,e,f,g,h,i,j,k="",l=0;do c=a.charCodeAt(l++),e=a.charCodeAt(l++),f=a.charCodeAt(l++),g=c>>2,h=(3&c)<<4|e>>4,i=(15&e)<<2|f>>6,j=63&f,isNaN(e)?i=j=64:isNaN(f)&&(j=64),k+=b.charAt(g)+b.charAt(h)+b.charAt(i)+b.charAt(j),c=e=f="",g=h=i=j="";while(l1&&(d+=d.indexOf("?")>-1?"&"+k:"?"+k),e.jsonp){var l=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=d,l.appendChild(m),void 0}}b(function(b,c){if(b)return h(b);c.open(a,d,e.async);for(var f in j)j.hasOwnProperty(f)&&c.setRequestHeader(f,j[f]);c.onreadystatechange=function(){if(4===c.readyState){var a=c.responseText||"";if(!h)return;h(c.status,{text:function(){return a},json:function(){try{return JSON.parse(a)}catch(b){return R.error("Can not parse JSON. URL: "+d),{}}}})}},c.send(i)})},h={authBasic:function(a,b){g.headers.Authorization="Basic "+e(a+":"+b)},connect:function(a,b,c){return g("CONNECT",a,b,c)},del:function(a,b,c){return g("DELETE",a,b,c)},get:function(a,b,c){return g("GET",a,b,c)},head:function(a,b,c){return g("HEAD",a,b,c)},headers:function(a){g.headers=a||{}},isAllowed:function(a,b,c){this.options(a,function(a,d){c(-1!==d.text().indexOf(b))})},options:function(a,b,c){return g("OPTIONS",a,b,c)},patch:function(a,b,c){return g("PATCH",a,b,c)},post:function(a,b,c){return g("POST",a,b,c)},put:function(a,b,c){return g("PUT",a,b,c)},trace:function(a,b,c){return g("TRACE",a,b,c)}},i=a.type?a.type.toLowerCase():"get";h[i](a.url,a,function(b,c){200===b||0===b&&c.text()?a.success(c.json(),b,null):a.error(c.text(),b,null)})}function f(a,b){"function"==typeof a&&(b=a,a={}),a=a||{},R.extend(N,a),delete N.fixLng,N.functions&&(delete N.functions,R.extend(R,a.functions)),"string"==typeof N.ns&&(N.ns={namespaces:[N.ns],defaultNs:N.ns}),"string"==typeof N.fallbackNS&&(N.fallbackNS=[N.fallbackNS]),("string"==typeof N.fallbackLng||"boolean"==typeof N.fallbackLng)&&(N.fallbackLng=[N.fallbackLng]),N.interpolationPrefixEscaped=R.regexEscape(N.interpolationPrefix),N.interpolationSuffixEscaped=R.regexEscape(N.interpolationSuffix),N.lng||(N.lng=R.detectLanguage()),K=R.toLanguages(N.lng),F=K[0],R.log("currentLng set to: "+F),N.useCookie&&R.cookie.read(N.cookieName)!==F&&R.cookie.create(N.cookieName,F,N.cookieExpirationTime,N.cookieDomain),N.detectLngFromLocalStorage&&"undefined"!=typeof document&&window.localStorage&&R.localStorage.setItem("i18next_lng",F);var c=z;a.fixLng&&(c=function(a,b){return b=b||{},b.lng=b.lng||c.lng,z(a,b)},c.lng=F),U.setCurrentLng(F),G&&N.setJqueryExt&&s();var d;if(G&&G.Deferred&&(d=G.Deferred()),!N.resStore){var e=R.toLanguages(N.lng);"string"==typeof N.preload&&(N.preload=[N.preload]);for(var f=0,g=N.preload.length;g>f;f++)for(var h=R.toLanguages(N.preload[f]),i=0,j=h.length;j>i;i++)e.indexOf(h[i])<0&&e.push(h[i]);return H.sync.load(e,N,function(a,e){I=e,L=!0,b&&b(c),d&&d.resolve(c)}),d?d.promise():void 0}return I=N.resStore,L=!0,b&&b(c),d&&d.resolve(c),d?d.promise():void 0}function g(a,b){"string"==typeof a&&(a=[a]);for(var c=0,d=a.length;d>c;c++)N.preload.indexOf(a[c])<0&&N.preload.push(a[c]);return f(b)}function h(a,b,c,d){"string"!=typeof b?(c=b,b=N.ns.defaultNs):N.ns.namespaces.indexOf(b)<0&&N.ns.namespaces.push(b),I[a]=I[a]||{},I[a][b]=I[a][b]||{},d?R.deepExtend(I[a][b],c):R.extend(I[a][b],c)}function i(a,b){"string"!=typeof b&&(b=N.ns.defaultNs),I[a]=I[a]||{};var c=I[a][b]||{},d=!1;for(var e in c)c.hasOwnProperty(e)&&(d=!0);return d}function j(a,b){"string"!=typeof b&&(b=N.ns.defaultNs),I[a]=I[a]||{},I[a][b]={}}function k(a,b,c,d){"string"!=typeof b?(resource=b,b=N.ns.defaultNs):N.ns.namespaces.indexOf(b)<0&&N.ns.namespaces.push(b),I[a]=I[a]||{},I[a][b]=I[a][b]||{};for(var e=c.split(N.keyseparator),f=0,g=I[a][b];e[f];)f==e.length-1?g[e[f]]=d:(null==g[e[f]]&&(g[e[f]]={}),g=g[e[f]]),f++}function l(a,b,c){"string"!=typeof b?(resource=b,b=N.ns.defaultNs):N.ns.namespaces.indexOf(b)<0&&N.ns.namespaces.push(b);for(var d in c)"string"==typeof c[d]&&k(a,b,d,c[d])}function m(a){N.ns.defaultNs=a}function n(a,b){o([a],b)}function o(a,b){var c={dynamicLoad:N.dynamicLoad,resGetPath:N.resGetPath,getAsync:N.getAsync,customLoad:N.customLoad,ns:{namespaces:a,defaultNs:""}},d=R.toLanguages(N.lng);"string"==typeof N.preload&&(N.preload=[N.preload]);for(var e=0,f=N.preload.length;f>e;e++)for(var g=R.toLanguages(N.preload[e]),h=0,i=g.length;i>h;h++)d.indexOf(g[h])<0&&d.push(g[h]);for(var j=[],k=0,l=d.length;l>k;k++){var m=!1,n=I[d[k]];if(n)for(var o=0,p=a.length;p>o;o++)n[a[o]]||(m=!0);else m=!0;m&&j.push(d[k])}j.length?H.sync._fetch(j,c,function(c,d){var e=a.length*j.length;R.each(a,function(a,c){N.ns.namespaces.indexOf(c)<0&&N.ns.namespaces.push(c),R.each(j,function(a,f){I[f]=I[f]||{},I[f][c]=d[f][c],e--,0===e&&b&&(N.useLocalStorage&&H.sync._storeLocal(I),b())})})}):b&&b()}function p(a,b,c){return"function"==typeof b?(c=b,b={}):b||(b={}),b.lng=a,f(b,c)}function q(){return F}function r(a){I={},p(F,a)}function s(){function a(a,b,c){if(0!==b.length){var d="text";if(0===b.indexOf("[")){var e=b.split("]");b=e[1],d=e[0].substr(1,e[0].length-1)}b.indexOf(";")===b.length-1&&(b=b.substr(0,b.length-2));var f;if("html"===d)f=N.defaultValueFromContent?G.extend({defaultValue:a.html()},c):c,a.html(G.t(b,f));else if("text"===d)f=N.defaultValueFromContent?G.extend({defaultValue:a.text()},c):c,a.text(G.t(b,f));else if("prepend"===d)f=N.defaultValueFromContent?G.extend({defaultValue:a.html()},c):c,a.prepend(G.t(b,f));else if("append"===d)f=N.defaultValueFromContent?G.extend({defaultValue:a.html()},c):c,a.append(G.t(b,f));else if(0===d.indexOf("data-")){var g=d.substr("data-".length);f=N.defaultValueFromContent?G.extend({defaultValue:a.data(g)},c):c;var h=G.t(b,f);a.data(g,h),a.attr(d,h)}else f=N.defaultValueFromContent?G.extend({defaultValue:a.attr(d)},c):c,a.attr(d,G.t(b,f))}}function b(b,c){var d=b.attr(N.selectorAttr);if(d||"undefined"==typeof d||d===!1||(d=b.text()||b.val()),d){var e=b,f=b.data("i18n-target");if(f&&(e=b.find(f)||b),c||N.useDataAttrOptions!==!0||(c=b.data("i18n-options")),c=c||{},d.indexOf(";")>=0){var g=d.split(";");G.each(g,function(b,d){""!==d&&a(e,d,c)})}else a(e,d,c);N.useDataAttrOptions===!0&&b.data("i18n-options",c)}}G.t=G.t||z,G.fn.i18n=function(a){return this.each(function(){b(G(this),a);var c=G(this).find("["+N.selectorAttr+"]");c.each(function(){b(G(this),a)})})}}function t(a,b,c,d){if(!a)return a;if(d=d||b,a.indexOf(d.interpolationPrefix||N.interpolationPrefix)<0)return a;var e=d.interpolationPrefix?R.regexEscape(d.interpolationPrefix):N.interpolationPrefixEscaped,f=d.interpolationSuffix?R.regexEscape(d.interpolationSuffix):N.interpolationSuffixEscaped,g="HTML"+f,h=b.replace&&"object"==typeof b.replace?b.replace:b;return R.each(h,function(b,h){var i=c?c+N.keyseparator+b:b;"object"==typeof h&&null!==h?a=t(a,h,i,d):d.escapeInterpolation||N.escapeInterpolation?(a=a.replace(new RegExp([e,i,g].join(""),"g"),R.regexReplacementEscape(h)),a=a.replace(new RegExp([e,i,f].join(""),"g"),R.regexReplacementEscape(R.escape(h)))):a=a.replace(new RegExp([e,i,f].join(""),"g"),R.regexReplacementEscape(h))}),a}function u(a,b){var c=",",d="{",e="}",f=R.extend({},b);for(delete f.postProcess;-1!=a.indexOf(N.reusePrefix)&&(J++,!(J>N.maxRecursion));){var g=a.lastIndexOf(N.reusePrefix),h=a.indexOf(N.reuseSuffix,g)+N.reuseSuffix.length,i=a.substring(g,h),j=i.replace(N.reusePrefix,"").replace(N.reuseSuffix,"");if(g>=h)return R.error("there is an missing closing in following translation value",a),"";if(-1!=j.indexOf(c)){var k=j.indexOf(c);if(-1!=j.indexOf(d,k)&&-1!=j.indexOf(e,k)){var l=j.indexOf(d,k),m=j.indexOf(e,l)+e.length;try{f=R.extend(f,JSON.parse(j.substring(l,m))),j=j.substring(0,k)}catch(n){}}}var o=C(j,f);a=a.replace(i,R.regexReplacementEscape(o))}return a}function v(a){return a.context&&("string"==typeof a.context||"number"==typeof a.context)}function w(a){return void 0!==a.count&&"string"!=typeof a.count}function x(a){return void 0!==a.indefinite_article&&"string"!=typeof a.indefinite_article&&a.indefinite_article}function y(a,b){b=b||{};var c=A(a,b),d=D(a,b);return void 0!==d||d===c}function z(a,b){return b=b||{},L?(J=0,C.apply(null,arguments)):(R.log("i18next not finished initialization. you might have called t function before loading resources finished."),b.defaultValue||"")}function A(a,b){return void 0!==b.defaultValue?b.defaultValue:a}function B(){for(var a=[],b=1;b1)for(var d=0;d-1&&(e=c.split(N.nsseparator),i=e[0],c=e[1]),void 0===g&&N.sendMissing&&"function"==typeof N.missingKeyHandler&&(b.lng?N.missingKeyHandler(h[0],i,c,f,h):N.missingKeyHandler(N.lng,i,c,f,h));var j=b.postProcess||N.postProcess;void 0!==g&&j&&V[j]&&(g=V[j](g,c,b));var k=f;if(f.indexOf(N.nsseparator)>-1&&(e=f.split(N.nsseparator),k=e[1]),k===c&&N.parseMissingKey&&(f=N.parseMissingKey(f)),void 0===g&&(f=t(f,b),f=u(f,b),j&&V[j])){var l=A(c,b);g=V[j](l,c,b)}return void 0!==g?g:f}function D(a,b){b=b||{};var c,d,e=A(a,b),f=K;if(!I)return e;if("cimode"===f[0].toLowerCase())return e;if(b.lngs&&(f=b.lngs),b.lng&&(f=R.toLanguages(b.lng,b.fallbackLng),!I[f[0]])){var g=N.getAsync;N.getAsync=!1,H.sync.load(f,N,function(a,b){R.extend(I,b),N.getAsync=g})}var h=b.ns||N.ns.defaultNs;if(a.indexOf(N.nsseparator)>-1){var i=a.split(N.nsseparator);h=i[0],a=i[1]}if(v(b)){c=R.extend({},b),delete c.context,c.defaultValue=N.contextNotFound;var j=h+N.nsseparator+a+"_"+b.context;if(d=z(j,c),d!=N.contextNotFound)return t(d,{context:b.context})}if(w(b,f[0])){c=R.extend({lngs:[f[0]]},b),delete c.count,delete c.lng,c.defaultValue=N.pluralNotFound;var k;if(U.needsPlural(f[0],b.count)){k=h+N.nsseparator+a+N.pluralSuffix;var l=U.get(f[0],b.count);l>=0?k=k+"_"+l:1===l&&(k=h+N.nsseparator+a)}else k=h+N.nsseparator+a;if(d=z(k,c),d!=N.pluralNotFound)return t(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix});if(!(f.length>1))return d;var m=f.slice();if(m.shift(),b=R.extend(b,{lngs:m}),delete b.lng,d=z(h+N.nsseparator+a,b),d!=N.pluralNotFound)return d}if(x(b)){var n=R.extend({},b);delete n.indefinite_article,n.defaultValue=N.indefiniteNotFound;var o=h+N.nsseparator+a+(b.count&&!w(b,f[0])||!b.count?N.indefiniteSuffix:"");if(d=z(o,n),d!=N.indefiniteNotFound)return d}for(var p,q=a.split(N.keyseparator),r=0,s=f.length;s>r&&void 0===p;r++){for(var y=f[r],B=0,E=I[y]&&I[y][h];q[B];)E=E&&E[q[B]],B++;if(void 0!==E){var F=Object.prototype.toString.apply(E);if("string"==typeof E)E=t(E,b),E=u(E,b);else if("[object Array]"!==F||N.returnObjectTrees||b.returnObjectTrees){if(null===E&&N.fallbackOnNull===!0)E=void 0;else if(null!==E)if(N.returnObjectTrees||b.returnObjectTrees){if("[object Number]"!==F&&"[object Function]"!==F&&"[object RegExp]"!==F){var G="[object Array]"===F?[]:{};R.each(E,function(c){G[c]=C(h+N.nsseparator+a+N.keyseparator+c,b)}),E=G}}else N.objectTreeKeyHandler&&"function"==typeof N.objectTreeKeyHandler?E=N.objectTreeKeyHandler(a,E,y,h,b):(E="key '"+h+":"+a+" ("+y+")' "+"returned an object instead of string.",R.log(E))}else E=E.join("\n"),E=t(E,b),E=u(E,b);"string"==typeof E&&""===E.trim()&&N.fallbackOnEmpty===!0&&(E=void 0),p=E}}if(void 0===p&&!b.isFallbackLookup&&(N.fallbackToDefaultNS===!0||N.fallbackNS&&N.fallbackNS.length>0)){if(b.isFallbackLookup=!0,N.fallbackNS.length){for(var J=0,L=N.fallbackNS.length;L>J;J++)if(p=D(N.fallbackNS[J]+N.nsseparator+a,b),p||""===p&&N.fallbackOnEmpty===!1){var M=p.indexOf(N.nsseparator)>-1?p.split(N.nsseparator)[1]:p,O=e.indexOf(N.nsseparator)>-1?e.split(N.nsseparator)[1]:e;if(M!==O)break}}else p=D(a,b);b.isFallbackLookup=!1}return p}function E(){var a,b=N.lngWhitelist||[],c=[];if("undefined"!=typeof window&&!function(){for(var a=window.location.search.substring(1),b=a.split("&"),d=0;d0){var f=b[d].substring(0,e);f==N.detectLngQS&&c.push(b[d].substring(e+1))}}}(),N.useCookie&&"undefined"!=typeof document){var d=R.cookie.read(N.cookieName);d&&c.push(d)}if(N.detectLngFromLocalStorage&&"undefined"!=typeof window&&window.localStorage&&c.push(window.localStorage.getItem("i18next_lng")),"undefined"!=typeof navigator){if(navigator.languages)for(var e=0;e-1){var f=e.split("-");e=N.lowerCaseLng?f[0].toLowerCase()+"-"+f[1].toLowerCase():f[0].toLowerCase()+"-"+f[1].toUpperCase()}if(0===b.length||b.indexOf(e)>-1){a=e;break}}}(),a||(a=N.fallbackLng[0]),a}Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>0&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&1/0!=d&&d!=-1/0&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=c;arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d))));for(var e=d>=0?Math.min(d,c-1):c-Math.abs(d);e>=0;e--)if(e in b&&b[e]===a)return e;return-1}),"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")});var F,G=void 0,H={},I={},J=0,K=[],L=!1,M={};M={load:function(a,b,c){b.useLocalStorage?M._loadLocal(a,b,function(d,e){for(var f=[],g=0,h=a.length;h>g;g++)e[a[g]]||f.push(a[g]);f.length>0?M._fetch(f,b,function(a,b){R.extend(e,b),M._storeLocal(b),c(null,e)}):c(null,e)}):M._fetch(a,b,function(a,b){c(null,b)})},_loadLocal:function(a,b,c){var d={},e=(new Date).getTime();if(window.localStorage){var f=a.length;R.each(a,function(a,g){var h=window.localStorage.getItem("res_"+g);h&&(h=JSON.parse(h),h.i18nStamp&&h.i18nStamp+b.localStorageExpirationTime>e&&(d[g]=h)),f--,0===f&&c(null,d)})}},_storeLocal:function(a){if(window.localStorage)for(var b in a)a[b].i18nStamp=(new Date).getTime(),R.localStorage.setItem("res_"+b,JSON.stringify(a[b]))},_fetch:function(a,b,c){var d=b.ns,e={};if(b.dynamicLoad){var f=function(a,b){c(null,b)};if("function"==typeof b.customLoad)b.customLoad(a,d.namespaces,b,f);else{var g=t(b.resGetPath,{lng:a.join("+"),ns:d.namespaces.join("+")});R.ajax({url:g,success:function(a){R.log("loaded: "+g),f(null,a)},error:function(a,b,c){R.log("failed loading: "+g),f("failed loading resource.json error: "+c)},dataType:"json",async:b.getAsync})}}else{var h,i=d.namespaces.length*a.length;R.each(d.namespaces,function(d,f){R.each(a,function(a,d){var g=function(a,b){a&&(h=h||[],h.push(a)),e[d]=e[d]||{},e[d][f]=b,i--,0===i&&c(h,e)};"function"==typeof b.customLoad?b.customLoad(d,f,b,g):M._fetchOne(d,f,b,g)})})}},_fetchOne:function(a,b,c,d){var e=t(c.resGetPath,{lng:a,ns:b});R.ajax({url:e,success:function(a){R.log("loaded: "+e),d(null,a)},error:function(a,b,c){if(b&&200==b||a&&a.status&&200==a.status)R.error("There is a typo in: "+e);else if(b&&404==b||a&&a.status&&404==a.status)R.log("Does not exist: "+e);else{var f=b?b:a&&a.status?a.status:null;R.log(f+" when loading "+e)}d(c,{})},dataType:"json",async:c.getAsync})},postMissing:function(a,b,c,d,e){var f={};f[c]=d;var g=[];if("fallback"===N.sendMissingTo&&N.fallbackLng[0]!==!1)for(var h=0;hh;h++)g.push({lng:e[h],url:t(N.resPostPath,{lng:e[h],ns:b})});for(var j=0,k=g.length;k>j;j++){var l=g[j];R.ajax({url:l.url,type:N.sendType,data:f,success:function(){R.log("posted missing key '"+c+"' to: "+l.url);for(var a=c.split("."),e=0,f=I[l.lng][b];a[e];)f=f[a[e]]=e===a.length-1?d:f[a[e]]||{},e++},error:function(){R.log("failed posting missing key '"+c+"' to: "+l.url)},dataType:"json",async:N.postAsync})}},reload:r};var N={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:["dev"],fallbackNS:[],detectLngQS:"setLng",detectLngFromLocalStorage:!1,ns:"translation",fallbackOnNull:!0,fallbackOnEmpty:!1,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",defaultVariables:!1,reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,indefiniteSuffix:"_indefinite",indefiniteNotFound:["indefinite_not_found",Math.random()].join(""),setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",cookieDomain:void 0,objectTreeKeyHandler:void 0,postProcess:void 0,parseMissingKey:void 0,missingKeyHandler:M.postMissing,shortcutFunction:"sprintf"},O={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},P={create:function(a,b,c,d){var e;if(c){var f=new Date;f.setTime(f.getTime()+1e3*60*c),e="; expires="+f.toGMTString()}else e="";d=d?"domain="+d+";":"",document.cookie=a+"="+b+e+";"+d+"path=/"},read:function(a){for(var b=a+"=",c=document.cookie.split(";"),d=0;d-1){var c=a.split("-");b=N.lowerCaseLng?c[0].toLowerCase()+"-"+c[1].toLowerCase():c[0].toLowerCase()+"-"+c[1].toUpperCase()}else b=N.lowerCaseLng?a.toLowerCase():a;return b}var c=this.log,d=[],e=N.lngWhitelist||!1,f=function(a){!e||e.indexOf(a)>-1?d.push(a):c("rejecting non-whitelisted language: "+a)};if("string"==typeof a&&a.indexOf("-")>-1){var g=a.split("-");"unspecific"!==N.load&&f(b(a)),"current"!==N.load&&f(b(g[this.getCountyIndexOfLng(a)]))}else f(b(a));for(var h=0;h1)},2:function(a){return Number(1!=a)},3:function(){return 0},4:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},5:function(a){return Number(0===a?0:1==a?1:2==a?2:a%100>=3&&10>=a%100?3:a%100>=11?4:5)},6:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)},7:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},8:function(a){return Number(1==a?0:2==a?1:8!=a&&11!=a?2:3)},9:function(a){return Number(a>=2)},10:function(a){return Number(1==a?0:2==a?1:7>a?2:11>a?3:4)},11:function(a){return Number(1==a||11==a?0:2==a||12==a?1:a>2&&20>a?2:3)},12:function(a){return Number(1!=a%10||11==a%100)},13:function(a){return Number(0!==a)},14:function(a){return Number(1==a?0:2==a?1:3==a?2:3)},15:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&(10>a%100||a%100>=20)?1:2)},16:function(a){return Number(1==a%10&&11!=a%100?0:0!==a?1:2)},17:function(a){return Number(1==a||1==a%10?0:1)},18:function(a){return Number(1==a?1:2)},19:function(a){return Number(1==a?0:0===a||a%100>1&&11>a%100?1:a%100>10&&20>a%100?2:3)},20:function(a){return Number(1==a?0:0===a||a%100>0&&20>a%100?1:2)},21:function(a){return Number(1==a%100?1:2==a%100?2:3==a%100||4==a%100?3:0)}},U={rules:function(){var a,b={};for(a=S.length;a--;)b[S[a][0]]={name:S[a][1],numbers:S[a][2],plurals:T[S[a][3]]};return b}(),addRule:function(a,b){U.rules[a]=b},setCurrentLng:function(a){if(!U.currentRule||U.currentRule.lng!==a){var b=a.split("-");U.currentRule={lng:a,rule:U.rules[b[0]]}}},needsPlural:function(a,b){var c,d=a.split("-");return c=U.currentRule&&U.currentRule.lng===a?U.currentRule.rule:U.rules[d[R.getCountyIndexOfLng(a)]],c&&c.numbers.length<=1?!1:1!==this.get(a,b)},get:function(a,b){function c(b,c){var d;if(d=U.currentRule&&U.currentRule.lng===a?U.currentRule.rule:U.rules[b]){var e;e=d.noAbs?d.plurals(c):d.plurals(Math.abs(c));var f=d.numbers[e];return 2===d.numbers.length&&1===d.numbers[0]&&(2===f?f=-1:1===f&&(f=1)),f}return 1===c?"1":"-1"}var d=a.split("-");return c(d[R.getCountyIndexOfLng(a)],b)}},V={},W=function(a,b){V[a]=b},X=function(){function a(a){return Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}function b(a,b){for(var c=[];b>0;c[--b]=a);return c.join("")}var c=function(){return c.cache.hasOwnProperty(arguments[0])||(c.cache[arguments[0]]=c.parse(arguments[0])),c.format.call(null,c.cache[arguments[0]],arguments)};return c.format=function(c,d){var e,f,g,h,i,j,k,l=1,m=c.length,n="",o=[];for(f=0;m>f;f++)if(n=a(c[f]),"string"===n)o.push(c[f]);else if("array"===n){if(h=c[f],h[2])for(e=d[l],g=0;g=0?"+"+e:e,j=h[4]?"0"==h[4]?"0":h[4].charAt(1):" ",k=h[6]-String(e).length,i=h[6]?b(j,k):"",o.push(h[5]?e+i:i+e)}return o.join("")},c.cache={},c.parse=function(a){for(var b=a,c=[],d=[],e=0;b;){if(null!==(c=/^[^\x25]+/.exec(b)))d.push(c[0]);else if(null!==(c=/^\x25{2}/.exec(b)))d.push("%");else{if(null===(c=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(b)))throw"[sprintf] huh?";if(c[2]){e|=1;var f=[],g=c[2],h=[];if(null===(h=/^([a-z_][a-z_\d]*)/i.exec(g)))throw"[sprintf] huh?";for(f.push(h[1]);""!==(g=g.substring(h[0].length));)if(null!==(h=/^\.([a-z_][a-z_\d]*)/i.exec(g)))f.push(h[1]);else{if(null===(h=/^\[(\d+)\]/.exec(g)))throw"[sprintf] huh?";f.push(h[1])}c[2]=f}else e|=2;if(3===e)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";d.push(c)}b=b.substring(c[0].length)}return d},c}(),Y=function(a,b){return b.unshift(a),X.apply(null,b)};return W("sprintf",function(a,b,c){return c.sprintf?"[object Array]"===Object.prototype.toString.apply(c.sprintf)?Y(a,c.sprintf):"object"==typeof c.sprintf?X(a,c.sprintf):a:a}),H.init=f,H.setLng=p,H.preload=g,H.addResourceBundle=h,H.hasResourceBundle=i,H.addResource=k,H.addResources=l,H.removeResourceBundle=j,H.loadNamespace=n,H.loadNamespaces=o,H.setDefaultNamespace=m,H.t=z,H.translate=z,H.exists=y,H.detectLanguage=R.detectLanguage,H.pluralExtensions=U,H.sync=M,H.functions=R,H.lng=q,H.addPostProcessor=W,H.options=N,H}); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd-1.7.7.zip b/libs/i18next/release/i18next.amd-1.7.7.zip new file mode 100644 index 00000000..98bfb4f5 Binary files /dev/null and b/libs/i18next/release/i18next.amd-1.7.7.zip differ diff --git a/libs/i18next/release/i18next.amd-1.8.0.js b/libs/i18next/release/i18next.amd-1.8.0.js new file mode 100644 index 00000000..5a165677 --- /dev/null +++ b/libs/i18next/release/i18next.amd-1.8.0.js @@ -0,0 +1,2173 @@ +// i18next, v1.8.0 +// Copyright (c)2015 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function (root, factory) { + if (typeof exports === 'object') { + + module.exports = factory(); + + } else if (typeof define === 'function' && define.amd) { + + define([], factory); + + } +}(this, function () { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + // Add string trim for IE8. + if (typeof String.prototype.trim !== 'function') { + String.prototype.trim = function() { + return this.replace(/^\s+|\s+$/g, ''); + } + } + + var $ = undefined + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = [] + , initialized = false + , sync = {}; + + sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = f.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + f.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + if ((status && status == 200) || (xhr && xhr.status && xhr.status == 200)) { + // file loaded but invalid json, stop waste time ! + f.error('There is a typo in: ' + url); + } else if ((status && status == 404) || (xhr && xhr.status && xhr.status == 404)) { + f.log('Does not exist: ' + url); + } else { + var theStatus = status ? status : ((xhr && xhr.status) ? xhr.status : null); + f.log(theStatus + ' when loading ' + url); + } + + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback' && o.fallbackLng[0] !== false) { + for (var i = 0; i < o.fallbackLng.length; i++) { + urls.push({lng: o.fallbackLng[i], url: applyReplacement(o.resPostPath, { lng: o.fallbackLng[i], ns: ns })}); + } + } else if (o.sendMissingTo === 'current' || (o.sendMissingTo === 'fallback' && o.fallbackLng[0] === false) ) { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + }, + + reload: reload + }; + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: ['dev'], + fallbackNS: [], + detectLngQS: 'setLng', + detectLngFromLocalStorage: false, + ns: 'translation', + fallbackOnNull: true, + fallbackOnEmpty: false, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + defaultVariables: false, + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + indefiniteSuffix: '_indefinite', + indefiniteNotFound: ['indefinite_not_found', Math.random()].join(''), + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + cookieDomain: undefined, + + objectTreeKeyHandler: undefined, + postProcess: undefined, + parseMissingKey: undefined, + missingKeyHandler: sync.postMissing, + + shortcutFunction: 'sprintf' // or: defaultValue + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _deepExtend(target, source) { + for (var prop in source) + if (prop in target) + _deepExtend(target[prop], source[prop]); + else + target[prop] = source[prop]; + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || Object.prototype.toString.apply(object) !== '[object Array]' || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + try { + return JSON.parse(data) + } catch (e) { + f.error('Can not parse JSON. URL: ' + url); + return {}; + } + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + // file: protocol always gives status code 0, so check for data + if (status === 200 || (status === 0 && data.text())) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes,domain) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + domain = (domain)? "domain="+domain+";" : ""; + document.cookie = name+"="+value+expires+";"+domain+"path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes,domain) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + deepExtend: _deepExtend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : (typeof document !== 'undefined' ? _ajax : function() {}), + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + error: function(str) { + if (typeof console !== "undefined") console.error(str); + }, + getCountyIndexOfLng: function(lng) { + var lng_index = 0; + if (lng === 'nb-NO' || lng === 'nn-NO' || lng === 'nb-no' || lng === 'nn-no') lng_index = 1; + return lng_index; + }, + toLanguages: function(lng) { + var log = this.log; + + function applyCase(l) { + var ret = l; + + if (typeof l === 'string' && l.indexOf('-') > -1) { + var parts = l.split('-'); + + ret = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } else { + ret = o.lowerCaseLng ? l.toLowerCase() : l; + } + + return ret; + } + + var languages = []; + var whitelist = o.lngWhitelist || false; + var addLanguage = function(language){ + //reject langs not whitelisted + if(!whitelist || whitelist.indexOf(language) > -1){ + languages.push(language); + }else{ + log('rejecting non-whitelisted language: ' + language); + } + }; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + if (o.load !== 'unspecific') addLanguage(applyCase(lng)); + if (o.load !== 'current') addLanguage(applyCase(parts[this.getCountyIndexOfLng(lng)])); + } else { + addLanguage(applyCase(lng)); + } + + for (var i = 0; i < o.fallbackLng.length; i++) { + if (languages.indexOf(o.fallbackLng[i]) === -1 && o.fallbackLng[i]) languages.push(applyCase(o.fallbackLng[i])); + } + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + }, + regexReplacementEscape: function(strOrFn) { + if (typeof strOrFn === 'string') { + return strOrFn.replace(/\$/g, "$$$$"); + } else { + return strOrFn; + } + }, + localStorage: { + setItem: function(key, value) { + if (window.localStorage) { + try { + window.localStorage.setItem(key, value); + } catch (e) { + f.log('failed to set value for key "' + key + '" to localStorage.'); + } + } + }, + getItem: function(key, value) { + if (window.localStorage) { + try { + return window.localStorage.getItem(key, value); + } catch (e) { + f.log('failed to get value for key "' + key + '" from localStorage.'); + return undefined; + } + } + } + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + delete o.fixLng; /* passed in each time */ + + // override functions: .log(), .detectLanguage(), etc + if (o.functions) { + delete o.functions; + f.extend(f, options.functions); + } + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // fallback languages + if (typeof o.fallbackLng == 'string' || typeof o.fallbackLng == 'boolean') { + o.fallbackLng = [o.fallbackLng]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + if (o.useCookie && f.cookie.read(o.cookieName) !== currentLng){ //cookie is unset or invalid + f.cookie.create(o.cookieName, currentLng, o.cookieExpirationTime, o.cookieDomain); + } + if (o.detectLngFromLocalStorage && typeof document !== 'undefined' && window.localStorage) { + f.localStorage.setItem('i18next_lng', currentLng); + } + + var lngTranslate = translate; + if (options.fixLng) { + lngTranslate = function(key, options) { + options = options || {}; + options.lng = options.lng || lngTranslate.lng; + return translate(key, options); + }; + lngTranslate.lng = currentLng; + } + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + initialized = true; + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + initialized = true; + + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources, deep) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + if (deep) { + f.deepExtend(resStore[lng][ns], resources); + } else { + f.extend(resStore[lng][ns], resources); + } + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function hasResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + var res = resStore[lng][ns] || {}; + + var hasValues = false; + for(var prop in res) { + if (res.hasOwnProperty(prop)) { + hasValues = true; + } + } + + return hasValues; + } + + function getResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + return f.extend({}, resStore[lng][ns]); + } + + function removeResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = {}; + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function addResource(lng, ns, key, value) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + var keys = key.split(o.keyseparator); + var x = 0; + var node = resStore[lng][ns]; + var origRef = node; + + while (keys[x]) { + if (x == keys.length - 1) + node[keys[x]] = value; + else { + if (node[keys[x]] == null) + node[keys[x]] = {}; + + node = node[keys[x]]; + } + x++; + } + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function addResources(lng, ns, resources) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + for (var m in resources) { + if (typeof resources[m] === 'string') addResource(lng, ns, m, resources[m]); + } + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, options, cb) { + if (typeof options === 'function') { + cb = options; + options = {}; + } else if (!options) { + options = {}; + } + + options.lng = lng; + return init(options, cb); + } + + function lng() { + return currentLng; + } + + function reload(cb) { + resStore = {}; + setLng(currentLng, cb); + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else if (attr === 'prepend') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.prepend($.t(key, optionsToUse)); + } else if (attr === 'append') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.append($.t(key, optionsToUse)); + } else if (attr.indexOf("data-") === 0) { + var dataAttr = attr.substr(("data-").length); + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.data(dataAttr) }, options) : options; + var translated = $.t(key, optionsToUse); + //we change into the data cache + ele.data(dataAttr, translated); + //we change into the dom + ele.attr(attr, translated); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key && typeof key !== 'undefined' && key !== false) key = ele.text() || ele.val(); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + var hash = replacementHash.replace && typeof replacementHash.replace === 'object' ? replacementHash.replace : replacementHash; + f.each(hash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), f.regexReplacementEscape(value)); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(f.escape(value))); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(value)); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + if (index_of_end_of_closing <= index_of_opening) { + f.error('there is an missing closing in following translation value', translated); + return ''; + } + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, f.regexReplacementEscape(translated_token)); + } + return translated; + } + + function hasContext(options) { + return (options.context && (typeof options.context == 'string' || typeof options.context == 'number')); + } + + function needsPlural(options, lng) { + return (options.count !== undefined && typeof options.count != 'string'/* && pluralExtensions.needsPlural(lng, options.count)*/); + } + + function needsIndefiniteArticle(options) { + return (options.indefinite_article !== undefined && typeof options.indefinite_article != 'string' && options.indefinite_article); + } + + function exists(key, options) { + options = options || {}; + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + options = options || {}; + + if (!initialized) { + f.log('i18next not finished initialization. you might have called t function before loading resources finished.') + return options.defaultValue || ''; + }; + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _getDefaultValue(key, options) { + return (options.defaultValue !== undefined) ? options.defaultValue : key; + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(potentialKeys, options) { + if (options && typeof options !== 'object') { + if (o.shortcutFunction === 'sprintf') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else if (o.shortcutFunction === 'defaultValue') { + options = { + defaultValue: options + } + } + } else { + options = options || {}; + } + + if (typeof o.defaultVariables === 'object') { + options = f.extend({}, o.defaultVariables, options); + } + + if (potentialKeys === undefined || potentialKeys === null || potentialKeys === '') return ''; + + if (typeof potentialKeys === 'number') { + potentialKeys = String(potentialKeys); + } + + if (typeof potentialKeys === 'string') { + potentialKeys = [potentialKeys]; + } + + var key = potentialKeys[0]; + + if (potentialKeys.length > 1) { + for (var i = 0; i < potentialKeys.length; i++) { + key = potentialKeys[i]; + if (exists(key, options)) { + break; + } + } + } + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng, options.fallbackLng) : languages + , ns = options.ns || o.ns.defaultNs + , parts; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing && typeof o.missingKeyHandler === 'function') { + if (options.lng) { + o.missingKeyHandler(lngs[0], ns, key, notFound, lngs); + } else { + o.missingKeyHandler(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessorsToApply; + if (typeof o.postProcess === 'string' && o.postProcess !== '') { + postProcessorsToApply = [o.postProcess]; + } else if (typeof o.postProcess === 'array' || typeof o.postProcess === 'object') { + postProcessorsToApply = o.postProcess; + } else { + postProcessorsToApply = []; + } + + if (typeof options.postProcess === 'string' && options.postProcess !== '') { + postProcessorsToApply = postProcessorsToApply.concat([options.postProcess]); + } else if (typeof options.postProcess === 'array' || typeof options.postProcess === 'object') { + postProcessorsToApply = postProcessorsToApply.concat(options.postProcess); + } + + if (found !== undefined && postProcessorsToApply.length) { + postProcessorsToApply.forEach(function(postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + }); + } + + // process notFound if function exists + var splitNotFound = notFound; + if (notFound.indexOf(o.nsseparator) > -1) { + parts = notFound.split(o.nsseparator); + splitNotFound = parts[1]; + } + if (splitNotFound === key && o.parseMissingKey) { + notFound = o.parseMissingKey(notFound); + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessorsToApply.length) { + var val = _getDefaultValue(key, options); + postProcessorsToApply.forEach(function(postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](val, key, options); + } + }); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options) { + options = options || {}; + + var optionWithoutCount, translated + , notFound = _getDefaultValue(key, options) + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + // CI mode + if (lngs[0].toLowerCase() === 'cimode') return notFound; + + // passed in lng + if (options.lngs) lngs = options.lngs; + if (options.lng) { + lngs = f.toLanguages(options.lng, options.fallbackLng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options, lngs[0])) { + optionWithoutCount = f.extend({ lngs: [lngs[0]]}, options); + delete optionWithoutCount.count; + optionWithoutCount._origLng = optionWithoutCount._origLng || optionWithoutCount.lng || lngs[0]; + delete optionWithoutCount.lng; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey; + if (!pluralExtensions.needsPlural(lngs[0], options.count)) { + pluralKey = ns + o.nsseparator + key; + } else { + pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(lngs[0], options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + } + + translated = translate(pluralKey, optionWithoutCount); + + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } else if (lngs.length > 1) { + // remove failed lng + var clone = lngs.slice(); + clone.shift(); + options = f.extend(options, { lngs: clone }); + options._origLng = optionWithoutCount._origLng; + delete options.lng; + // retry with fallbacks + translated = translate(ns + o.nsseparator + key, options); + if (translated != o.pluralNotFound) return translated; + } else { + optionWithoutCount.lng = optionWithoutCount._origLng; + delete optionWithoutCount._origLng; + translated = translate(ns + o.nsseparator + key, optionWithoutCount); + + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); + } + } + + if (needsIndefiniteArticle(options)) { + var optionsWithoutIndef = f.extend({}, options); + delete optionsWithoutIndef.indefinite_article; + optionsWithoutIndef.defaultValue = o.indefiniteNotFound; + // If we don't have a count, we want the indefinite, if we do have a count, and needsPlural is false + var indefiniteKey = ns + o.nsseparator + key + (((options.count && !needsPlural(options, lngs[0])) || !options.count) ? o.indefiniteSuffix : ""); + translated = translate(indefiniteKey, optionsWithoutIndef); + if (translated != o.indefiniteNotFound) { + return translated; + } + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + var valueType = Object.prototype.toString.apply(value); + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (valueType === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + if (o.objectTreeKeyHandler && typeof o.objectTreeKeyHandler == 'function') { + value = o.objectTreeKeyHandler(key, value, l, ns, options); + } else { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned an object instead of string.'; + f.log(value); + } + } else if (valueType !== '[object Number]' && valueType !== '[object Function]' && valueType !== '[object RegExp]') { + var copy = (valueType === '[object Array]') ? [] : {}; // apply child translation on a copy + f.each(value, function(m) { + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + }); + value = copy; + } + } + + if (typeof value === 'string' && value.trim() === '' && o.fallbackOnEmpty === true) + value = undefined; + + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length > 0))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found || (found==="" && o.fallbackOnEmpty === false)) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + options.isFallbackLookup = false; + } + + return found; + } + function detectLanguage() { + var detectedLng; + var whitelist = o.lngWhitelist || []; + var userLngChoices = []; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var params = query.split('&'); + for (var i=0; i 0) { + var key = params[i].substring(0,pos); + if (key == o.detectLngQS) { + userLngChoices.push(params[i].substring(pos+1)); + } + } + } + })(); + } + + // get from cookie + if (o.useCookie && typeof document !== 'undefined') { + var c = f.cookie.read(o.cookieName); + if (c) userLngChoices.push(c); + } + + // get from localStorage + if (o.detectLngFromLocalStorage && typeof window !== 'undefined' && window.localStorage) { + userLngChoices.push(f.localStorage.getItem('i18next_lng')); + } + + // get from navigator + if (typeof navigator !== 'undefined') { + if (navigator.languages) { // chrome only; not an array, so can't use .push.apply instead of iterating + for (var i=0;i -1) { + var parts = lng.split('-'); + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } + + if (whitelist.length === 0 || whitelist.indexOf(lng) > -1) { + detectedLng = lng; + break; + } + } + })(); + + //fallback + if (!detectedLng){ + detectedLng = o.fallbackLng[0]; + } + + return detectedLng; + } + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + + /* [code, name, numbers, pluralsType] */ + var _rules = [ + ["ach", "Acholi", [1,2], 1], + ["af", "Afrikaans",[1,2], 2], + ["ak", "Akan", [1,2], 1], + ["am", "Amharic", [1,2], 1], + ["an", "Aragonese",[1,2], 2], + ["ar", "Arabic", [0,1,2,3,11,100],5], + ["arn", "Mapudungun",[1,2], 1], + ["ast", "Asturian", [1,2], 2], + ["ay", "Aymará", [1], 3], + ["az", "Azerbaijani",[1,2],2], + ["be", "Belarusian",[1,2,5],4], + ["bg", "Bulgarian",[1,2], 2], + ["bn", "Bengali", [1,2], 2], + ["bo", "Tibetan", [1], 3], + ["br", "Breton", [1,2], 1], + ["bs", "Bosnian", [1,2,5],4], + ["ca", "Catalan", [1,2], 2], + ["cgg", "Chiga", [1], 3], + ["cs", "Czech", [1,2,5],6], + ["csb", "Kashubian",[1,2,5],7], + ["cy", "Welsh", [1,2,3,8],8], + ["da", "Danish", [1,2], 2], + ["de", "German", [1,2], 2], + ["dev", "Development Fallback", [1,2], 2], + ["dz", "Dzongkha", [1], 3], + ["el", "Greek", [1,2], 2], + ["en", "English", [1,2], 2], + ["eo", "Esperanto",[1,2], 2], + ["es", "Spanish", [1,2], 2], + ["es_ar","Argentinean Spanish", [1,2], 2], + ["et", "Estonian", [1,2], 2], + ["eu", "Basque", [1,2], 2], + ["fa", "Persian", [1], 3], + ["fi", "Finnish", [1,2], 2], + ["fil", "Filipino", [1,2], 1], + ["fo", "Faroese", [1,2], 2], + ["fr", "French", [1,2], 9], + ["fur", "Friulian", [1,2], 2], + ["fy", "Frisian", [1,2], 2], + ["ga", "Irish", [1,2,3,7,11],10], + ["gd", "Scottish Gaelic",[1,2,3,20],11], + ["gl", "Galician", [1,2], 2], + ["gu", "Gujarati", [1,2], 2], + ["gun", "Gun", [1,2], 1], + ["ha", "Hausa", [1,2], 2], + ["he", "Hebrew", [1,2], 2], + ["hi", "Hindi", [1,2], 2], + ["hr", "Croatian", [1,2,5],4], + ["hu", "Hungarian",[1,2], 2], + ["hy", "Armenian", [1,2], 2], + ["ia", "Interlingua",[1,2],2], + ["id", "Indonesian",[1], 3], + ["is", "Icelandic",[1,2], 12], + ["it", "Italian", [1,2], 2], + ["ja", "Japanese", [1], 3], + ["jbo", "Lojban", [1], 3], + ["jv", "Javanese", [0,1], 13], + ["ka", "Georgian", [1], 3], + ["kk", "Kazakh", [1], 3], + ["km", "Khmer", [1], 3], + ["kn", "Kannada", [1,2], 2], + ["ko", "Korean", [1], 3], + ["ku", "Kurdish", [1,2], 2], + ["kw", "Cornish", [1,2,3,4],14], + ["ky", "Kyrgyz", [1], 3], + ["lb", "Letzeburgesch",[1,2],2], + ["ln", "Lingala", [1,2], 1], + ["lo", "Lao", [1], 3], + ["lt", "Lithuanian",[1,2,10],15], + ["lv", "Latvian", [1,2,0],16], + ["mai", "Maithili", [1,2], 2], + ["mfe", "Mauritian Creole",[1,2],1], + ["mg", "Malagasy", [1,2], 1], + ["mi", "Maori", [1,2], 1], + ["mk", "Macedonian",[1,2],17], + ["ml", "Malayalam",[1,2], 2], + ["mn", "Mongolian",[1,2], 2], + ["mnk", "Mandinka", [0,1,2],18], + ["mr", "Marathi", [1,2], 2], + ["ms", "Malay", [1], 3], + ["mt", "Maltese", [1,2,11,20],19], + ["nah", "Nahuatl", [1,2], 2], + ["nap", "Neapolitan",[1,2], 2], + ["nb", "Norwegian Bokmal",[1,2],2], + ["ne", "Nepali", [1,2], 2], + ["nl", "Dutch", [1,2], 2], + ["nn", "Norwegian Nynorsk",[1,2],2], + ["no", "Norwegian",[1,2], 2], + ["nso", "Northern Sotho",[1,2],2], + ["oc", "Occitan", [1,2], 1], + ["or", "Oriya", [2,1], 2], + ["pa", "Punjabi", [1,2], 2], + ["pap", "Papiamento",[1,2], 2], + ["pl", "Polish", [1,2,5],7], + ["pms", "Piemontese",[1,2], 2], + ["ps", "Pashto", [1,2], 2], + ["pt", "Portuguese",[1,2], 2], + ["pt_br","Brazilian Portuguese",[1,2], 2], + ["rm", "Romansh", [1,2], 2], + ["ro", "Romanian", [1,2,20],20], + ["ru", "Russian", [1,2,5],4], + ["sah", "Yakut", [1], 3], + ["sco", "Scots", [1,2], 2], + ["se", "Northern Sami",[1,2], 2], + ["si", "Sinhala", [1,2], 2], + ["sk", "Slovak", [1,2,5],6], + ["sl", "Slovenian",[5,1,2,3],21], + ["so", "Somali", [1,2], 2], + ["son", "Songhay", [1,2], 2], + ["sq", "Albanian", [1,2], 2], + ["sr", "Serbian", [1,2,5],4], + ["su", "Sundanese",[1], 3], + ["sv", "Swedish", [1,2], 2], + ["sw", "Swahili", [1,2], 2], + ["ta", "Tamil", [1,2], 2], + ["te", "Telugu", [1,2], 2], + ["tg", "Tajik", [1,2], 1], + ["th", "Thai", [1], 3], + ["ti", "Tigrinya", [1,2], 1], + ["tk", "Turkmen", [1,2], 2], + ["tr", "Turkish", [1,2], 1], + ["tt", "Tatar", [1], 3], + ["ug", "Uyghur", [1], 3], + ["uk", "Ukrainian",[1,2,5],4], + ["ur", "Urdu", [1,2], 2], + ["uz", "Uzbek", [1,2], 1], + ["vi", "Vietnamese",[1], 3], + ["wa", "Walloon", [1,2], 1], + ["wo", "Wolof", [1], 3], + ["yo", "Yoruba", [1,2], 2], + ["zh", "Chinese", [1], 3] + ]; + + var _rulesPluralsTypes = { + 1: function(n) {return Number(n > 1);}, + 2: function(n) {return Number(n != 1);}, + 3: function(n) {return 0;}, + 4: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 5: function(n) {return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5);}, + 6: function(n) {return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2);}, + 7: function(n) {return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 8: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3);}, + 9: function(n) {return Number(n >= 2);}, + 10: function(n) {return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;}, + 11: function(n) {return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3);}, + 12: function(n) {return Number(n%10!=1 || n%100==11);}, + 13: function(n) {return Number(n !== 0);}, + 14: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3);}, + 15: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 16: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2);}, + 17: function(n) {return Number(n==1 || n%10==1 ? 0 : 1);}, + 18: function(n) {return Number(0 ? 0 : n==1 ? 1 : 2);}, + 19: function(n) {return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3);}, + 20: function(n) {return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2);}, + 21: function(n) {return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }; + + var pluralExtensions = { + + rules: (function () { + var l, rules = {}; + for (l=_rules.length; l-- ;) { + rules[_rules[l][0]] = { + name: _rules[l][1], + numbers: _rules[l][2], + plurals: _rulesPluralsTypes[_rules[l][3]] + } + } + return rules; + }()), + + // you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + needsPlural: function(lng, count) { + var parts = lng.split('-'); + + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[parts[f.getCountyIndexOfLng(lng)]]; + } + + if (ext && ext.numbers.length <= 1) { + return false; + } else { + return this.get(lng, count) !== 1; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i; + if (ext.noAbs) { + i = ext.plurals(c); + } else { + i = ext.plurals(Math.abs(c)); + } + + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[f.getCountyIndexOfLng(lng)], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.hasResourceBundle = hasResourceBundle; + i18n.getResourceBundle = getResourceBundle; + i18n.addResource = addResource; + i18n.addResources = addResources; + i18n.removeResourceBundle = removeResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.applyReplacement = f.applyReplacement; + i18n.options = o; + + return i18n; + +})); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd-1.8.0.min.js b/libs/i18next/release/i18next.amd-1.8.0.min.js new file mode 100644 index 00000000..301ff3f5 --- /dev/null +++ b/libs/i18next/release/i18next.amd-1.8.0.min.js @@ -0,0 +1,5 @@ +// i18next, v1.8.0 +// Copyright (c)2015 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +!function(a,b){"object"==typeof exports?module.exports=b():"function"==typeof define&&define.amd&&define([],b)}(this,function(){function a(a,b){if(!b||"function"==typeof b)return a;for(var c in b)a[c]=b[c];return a}function b(a,c){for(var d in c)d in a?b(a[d],c[d]):a[d]=c[d];return a}function c(a,b,c){var d,e=0,f=a.length,g=void 0===f||"[object Array]"!==Object.prototype.toString.apply(a)||"function"==typeof a;if(c)if(g){for(d in a)if(b.apply(a[d],c)===!1)break}else for(;f>e&&b.apply(a[e++],c)!==!1;);else if(g){for(d in a)if(b.call(a[d],d,a[d])===!1)break}else for(;f>e&&b.call(a[e],e,a[e++])!==!1;);return a}function d(a){return"string"==typeof a?a.replace(/[&<>"'\/]/g,function(a){return P[a]}):a}function e(a){var b=function(a){if(window.XMLHttpRequest)return a(null,new XMLHttpRequest);if(window.ActiveXObject)try{return a(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(b){return a(null,new ActiveXObject("Microsoft.XMLHTTP"))}return a(new Error)},c=function(a){if("string"==typeof a)return a;var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")},d=function(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;cd?b+=String.fromCharCode(d):d>127&&2048>d?(b+=String.fromCharCode(d>>6|192),b+=String.fromCharCode(63&d|128)):(b+=String.fromCharCode(d>>12|224),b+=String.fromCharCode(d>>6&63|128),b+=String.fromCharCode(63&d|128))}return b},e=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";a=d(a);var c,e,f,g,h,i,j,k="",l=0;do c=a.charCodeAt(l++),e=a.charCodeAt(l++),f=a.charCodeAt(l++),g=c>>2,h=(3&c)<<4|e>>4,i=(15&e)<<2|f>>6,j=63&f,isNaN(e)?i=j=64:isNaN(f)&&(j=64),k+=b.charAt(g)+b.charAt(h)+b.charAt(i)+b.charAt(j),c=e=f="",g=h=i=j="";while(l1&&(d+=d.indexOf("?")>-1?"&"+k:"?"+k),e.jsonp){var l=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=d,void l.appendChild(m)}}b(function(b,c){if(b)return h(b);c.open(a,d,e.async);for(var f in j)j.hasOwnProperty(f)&&c.setRequestHeader(f,j[f]);c.onreadystatechange=function(){if(4===c.readyState){var a=c.responseText||"";if(!h)return;h(c.status,{text:function(){return a},json:function(){try{return JSON.parse(a)}catch(b){return S.error("Can not parse JSON. URL: "+d),{}}}})}},c.send(i)})},h={authBasic:function(a,b){g.headers.Authorization="Basic "+e(a+":"+b)},connect:function(a,b,c){return g("CONNECT",a,b,c)},del:function(a,b,c){return g("DELETE",a,b,c)},get:function(a,b,c){return g("GET",a,b,c)},head:function(a,b,c){return g("HEAD",a,b,c)},headers:function(a){g.headers=a||{}},isAllowed:function(a,b,c){this.options(a,function(a,d){c(-1!==d.text().indexOf(b))})},options:function(a,b,c){return g("OPTIONS",a,b,c)},patch:function(a,b,c){return g("PATCH",a,b,c)},post:function(a,b,c){return g("POST",a,b,c)},put:function(a,b,c){return g("PUT",a,b,c)},trace:function(a,b,c){return g("TRACE",a,b,c)}},i=a.type?a.type.toLowerCase():"get";h[i](a.url,a,function(b,c){200===b||0===b&&c.text()?a.success(c.json(),b,null):a.error(c.text(),b,null)})}function f(a,b){"function"==typeof a&&(b=a,a={}),a=a||{},S.extend(O,a),delete O.fixLng,O.functions&&(delete O.functions,S.extend(S,a.functions)),"string"==typeof O.ns&&(O.ns={namespaces:[O.ns],defaultNs:O.ns}),"string"==typeof O.fallbackNS&&(O.fallbackNS=[O.fallbackNS]),("string"==typeof O.fallbackLng||"boolean"==typeof O.fallbackLng)&&(O.fallbackLng=[O.fallbackLng]),O.interpolationPrefixEscaped=S.regexEscape(O.interpolationPrefix),O.interpolationSuffixEscaped=S.regexEscape(O.interpolationSuffix),O.lng||(O.lng=S.detectLanguage()),L=S.toLanguages(O.lng),G=L[0],S.log("currentLng set to: "+G),O.useCookie&&S.cookie.read(O.cookieName)!==G&&S.cookie.create(O.cookieName,G,O.cookieExpirationTime,O.cookieDomain),O.detectLngFromLocalStorage&&"undefined"!=typeof document&&window.localStorage&&S.localStorage.setItem("i18next_lng",G);var c=A;a.fixLng&&(c=function(a,b){return b=b||{},b.lng=b.lng||c.lng,A(a,b)},c.lng=G),V.setCurrentLng(G),H&&O.setJqueryExt&&t();var d;if(H&&H.Deferred&&(d=H.Deferred()),!O.resStore){var e=S.toLanguages(O.lng);"string"==typeof O.preload&&(O.preload=[O.preload]);for(var f=0,g=O.preload.length;g>f;f++)for(var h=S.toLanguages(O.preload[f]),i=0,j=h.length;j>i;i++)e.indexOf(h[i])<0&&e.push(h[i]);return I.sync.load(e,O,function(a,e){J=e,M=!0,b&&b(c),d&&d.resolve(c)}),d?d.promise():void 0}return J=O.resStore,M=!0,b&&b(c),d&&d.resolve(c),d?d.promise():void 0}function g(a,b){"string"==typeof a&&(a=[a]);for(var c=0,d=a.length;d>c;c++)O.preload.indexOf(a[c])<0&&O.preload.push(a[c]);return f(b)}function h(a,b,c,d){"string"!=typeof b?(c=b,b=O.ns.defaultNs):O.ns.namespaces.indexOf(b)<0&&O.ns.namespaces.push(b),J[a]=J[a]||{},J[a][b]=J[a][b]||{},d?S.deepExtend(J[a][b],c):S.extend(J[a][b],c),O.useLocalStorage&&N._storeLocal(J)}function i(a,b){"string"!=typeof b&&(b=O.ns.defaultNs),J[a]=J[a]||{};var c=J[a][b]||{},d=!1;for(var e in c)c.hasOwnProperty(e)&&(d=!0);return d}function j(a,b){return"string"!=typeof b&&(b=O.ns.defaultNs),J[a]=J[a]||{},S.extend({},J[a][b])}function k(a,b){"string"!=typeof b&&(b=O.ns.defaultNs),J[a]=J[a]||{},J[a][b]={},O.useLocalStorage&&N._storeLocal(J)}function l(a,b,c,d){"string"!=typeof b?(resource=b,b=O.ns.defaultNs):O.ns.namespaces.indexOf(b)<0&&O.ns.namespaces.push(b),J[a]=J[a]||{},J[a][b]=J[a][b]||{};for(var e=c.split(O.keyseparator),f=0,g=J[a][b];e[f];)f==e.length-1?g[e[f]]=d:(null==g[e[f]]&&(g[e[f]]={}),g=g[e[f]]),f++;O.useLocalStorage&&N._storeLocal(J)}function m(a,b,c){"string"!=typeof b?(resource=b,b=O.ns.defaultNs):O.ns.namespaces.indexOf(b)<0&&O.ns.namespaces.push(b);for(var d in c)"string"==typeof c[d]&&l(a,b,d,c[d])}function n(a){O.ns.defaultNs=a}function o(a,b){p([a],b)}function p(a,b){var c={dynamicLoad:O.dynamicLoad,resGetPath:O.resGetPath,getAsync:O.getAsync,customLoad:O.customLoad,ns:{namespaces:a,defaultNs:""}},d=S.toLanguages(O.lng);"string"==typeof O.preload&&(O.preload=[O.preload]);for(var e=0,f=O.preload.length;f>e;e++)for(var g=S.toLanguages(O.preload[e]),h=0,i=g.length;i>h;h++)d.indexOf(g[h])<0&&d.push(g[h]);for(var j=[],k=0,l=d.length;l>k;k++){var m=!1,n=J[d[k]];if(n)for(var o=0,p=a.length;p>o;o++)n[a[o]]||(m=!0);else m=!0;m&&j.push(d[k])}j.length?I.sync._fetch(j,c,function(c,d){var e=a.length*j.length;S.each(a,function(a,c){O.ns.namespaces.indexOf(c)<0&&O.ns.namespaces.push(c),S.each(j,function(a,f){J[f]=J[f]||{},J[f][c]=d[f][c],e--,0===e&&b&&(O.useLocalStorage&&I.sync._storeLocal(J),b())})})}):b&&b()}function q(a,b,c){return"function"==typeof b?(c=b,b={}):b||(b={}),b.lng=a,f(b,c)}function r(){return G}function s(a){J={},q(G,a)}function t(){function a(a,b,c){if(0!==b.length){var d="text";if(0===b.indexOf("[")){var e=b.split("]");b=e[1],d=e[0].substr(1,e[0].length-1)}b.indexOf(";")===b.length-1&&(b=b.substr(0,b.length-2));var f;if("html"===d)f=O.defaultValueFromContent?H.extend({defaultValue:a.html()},c):c,a.html(H.t(b,f));else if("text"===d)f=O.defaultValueFromContent?H.extend({defaultValue:a.text()},c):c,a.text(H.t(b,f));else if("prepend"===d)f=O.defaultValueFromContent?H.extend({defaultValue:a.html()},c):c,a.prepend(H.t(b,f));else if("append"===d)f=O.defaultValueFromContent?H.extend({defaultValue:a.html()},c):c,a.append(H.t(b,f));else if(0===d.indexOf("data-")){var g=d.substr("data-".length);f=O.defaultValueFromContent?H.extend({defaultValue:a.data(g)},c):c;var h=H.t(b,f);a.data(g,h),a.attr(d,h)}else f=O.defaultValueFromContent?H.extend({defaultValue:a.attr(d)},c):c,a.attr(d,H.t(b,f))}}function b(b,c){var d=b.attr(O.selectorAttr);if(d||"undefined"==typeof d||d===!1||(d=b.text()||b.val()),d){var e=b,f=b.data("i18n-target");if(f&&(e=b.find(f)||b),c||O.useDataAttrOptions!==!0||(c=b.data("i18n-options")),c=c||{},d.indexOf(";")>=0){var g=d.split(";");H.each(g,function(b,d){""!==d&&a(e,d,c)})}else a(e,d,c);O.useDataAttrOptions===!0&&b.data("i18n-options",c)}}H.t=H.t||A,H.fn.i18n=function(a){return this.each(function(){b(H(this),a);var c=H(this).find("["+O.selectorAttr+"]");c.each(function(){b(H(this),a)})})}}function u(a,b,c,d){if(!a)return a;if(d=d||b,a.indexOf(d.interpolationPrefix||O.interpolationPrefix)<0)return a;var e=d.interpolationPrefix?S.regexEscape(d.interpolationPrefix):O.interpolationPrefixEscaped,f=d.interpolationSuffix?S.regexEscape(d.interpolationSuffix):O.interpolationSuffixEscaped,g="HTML"+f,h=b.replace&&"object"==typeof b.replace?b.replace:b;return S.each(h,function(b,h){var i=c?c+O.keyseparator+b:b;"object"==typeof h&&null!==h?a=u(a,h,i,d):d.escapeInterpolation||O.escapeInterpolation?(a=a.replace(new RegExp([e,i,g].join(""),"g"),S.regexReplacementEscape(h)),a=a.replace(new RegExp([e,i,f].join(""),"g"),S.regexReplacementEscape(S.escape(h)))):a=a.replace(new RegExp([e,i,f].join(""),"g"),S.regexReplacementEscape(h))}),a}function v(a,b){var c=",",d="{",e="}",f=S.extend({},b);for(delete f.postProcess;-1!=a.indexOf(O.reusePrefix)&&(K++,!(K>O.maxRecursion));){var g=a.lastIndexOf(O.reusePrefix),h=a.indexOf(O.reuseSuffix,g)+O.reuseSuffix.length,i=a.substring(g,h),j=i.replace(O.reusePrefix,"").replace(O.reuseSuffix,"");if(g>=h)return S.error("there is an missing closing in following translation value",a),"";if(-1!=j.indexOf(c)){var k=j.indexOf(c);if(-1!=j.indexOf(d,k)&&-1!=j.indexOf(e,k)){var l=j.indexOf(d,k),m=j.indexOf(e,l)+e.length;try{f=S.extend(f,JSON.parse(j.substring(l,m))),j=j.substring(0,k)}catch(n){}}}var o=D(j,f);a=a.replace(i,S.regexReplacementEscape(o))}return a}function w(a){return a.context&&("string"==typeof a.context||"number"==typeof a.context)}function x(a){return void 0!==a.count&&"string"!=typeof a.count}function y(a){return void 0!==a.indefinite_article&&"string"!=typeof a.indefinite_article&&a.indefinite_article}function z(a,b){b=b||{};var c=B(a,b),d=E(a,b);return void 0!==d||d===c}function A(a,b){return b=b||{},M?(K=0,D.apply(null,arguments)):(S.log("i18next not finished initialization. you might have called t function before loading resources finished."),b.defaultValue||"")}function B(a,b){return void 0!==b.defaultValue?b.defaultValue:a}function C(){for(var a=[],b=1;b1)for(var d=0;d-1&&(e=c.split(O.nsseparator),i=e[0],c=e[1]),void 0===g&&O.sendMissing&&"function"==typeof O.missingKeyHandler&&(b.lng?O.missingKeyHandler(h[0],i,c,f,h):O.missingKeyHandler(O.lng,i,c,f,h));var j;j="string"==typeof O.postProcess&&""!==O.postProcess?[O.postProcess]:"array"==typeof O.postProcess||"object"==typeof O.postProcess?O.postProcess:[],"string"==typeof b.postProcess&&""!==b.postProcess?j=j.concat([b.postProcess]):("array"==typeof b.postProcess||"object"==typeof b.postProcess)&&(j=j.concat(b.postProcess)),void 0!==g&&j.length&&j.forEach(function(a){W[a]&&(g=W[a](g,c,b))});var k=f;if(f.indexOf(O.nsseparator)>-1&&(e=f.split(O.nsseparator),k=e[1]),k===c&&O.parseMissingKey&&(f=O.parseMissingKey(f)),void 0===g&&(f=u(f,b),f=v(f,b),j.length)){var l=B(c,b);j.forEach(function(a){W[a]&&(g=W[a](l,c,b))})}return void 0!==g?g:f}function E(a,b){b=b||{};var c,d,e=B(a,b),f=L;if(!J)return e;if("cimode"===f[0].toLowerCase())return e;if(b.lngs&&(f=b.lngs),b.lng&&(f=S.toLanguages(b.lng,b.fallbackLng),!J[f[0]])){var g=O.getAsync;O.getAsync=!1,I.sync.load(f,O,function(a,b){S.extend(J,b),O.getAsync=g})}var h=b.ns||O.ns.defaultNs;if(a.indexOf(O.nsseparator)>-1){var i=a.split(O.nsseparator);h=i[0],a=i[1]}if(w(b)){c=S.extend({},b),delete c.context,c.defaultValue=O.contextNotFound;var j=h+O.nsseparator+a+"_"+b.context;if(d=A(j,c),d!=O.contextNotFound)return u(d,{context:b.context})}if(x(b,f[0])){c=S.extend({lngs:[f[0]]},b),delete c.count,c._origLng=c._origLng||c.lng||f[0],delete c.lng,c.defaultValue=O.pluralNotFound;var k;if(V.needsPlural(f[0],b.count)){k=h+O.nsseparator+a+O.pluralSuffix;var l=V.get(f[0],b.count);l>=0?k=k+"_"+l:1===l&&(k=h+O.nsseparator+a)}else k=h+O.nsseparator+a;if(d=A(k,c),d!=O.pluralNotFound)return u(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix});if(!(f.length>1))return c.lng=c._origLng,delete c._origLng,d=A(h+O.nsseparator+a,c),u(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix});var m=f.slice();if(m.shift(),b=S.extend(b,{lngs:m}),b._origLng=c._origLng,delete b.lng,d=A(h+O.nsseparator+a,b),d!=O.pluralNotFound)return d}if(y(b)){var n=S.extend({},b);delete n.indefinite_article,n.defaultValue=O.indefiniteNotFound;var o=h+O.nsseparator+a+(b.count&&!x(b,f[0])||!b.count?O.indefiniteSuffix:"");if(d=A(o,n),d!=O.indefiniteNotFound)return d}for(var p,q=a.split(O.keyseparator),r=0,s=f.length;s>r&&void 0===p;r++){for(var t=f[r],z=0,C=J[t]&&J[t][h];q[z];)C=C&&C[q[z]],z++;if(void 0!==C){var F=Object.prototype.toString.apply(C);if("string"==typeof C)C=u(C,b),C=v(C,b);else if("[object Array]"!==F||O.returnObjectTrees||b.returnObjectTrees){if(null===C&&O.fallbackOnNull===!0)C=void 0;else if(null!==C)if(O.returnObjectTrees||b.returnObjectTrees){if("[object Number]"!==F&&"[object Function]"!==F&&"[object RegExp]"!==F){var G="[object Array]"===F?[]:{};S.each(C,function(c){G[c]=D(h+O.nsseparator+a+O.keyseparator+c,b)}),C=G}}else O.objectTreeKeyHandler&&"function"==typeof O.objectTreeKeyHandler?C=O.objectTreeKeyHandler(a,C,t,h,b):(C="key '"+h+":"+a+" ("+t+")' returned an object instead of string.",S.log(C))}else C=C.join("\n"),C=u(C,b),C=v(C,b);"string"==typeof C&&""===C.trim()&&O.fallbackOnEmpty===!0&&(C=void 0),p=C}}if(void 0===p&&!b.isFallbackLookup&&(O.fallbackToDefaultNS===!0||O.fallbackNS&&O.fallbackNS.length>0)){if(b.isFallbackLookup=!0,O.fallbackNS.length){for(var H=0,K=O.fallbackNS.length;K>H;H++)if(p=E(O.fallbackNS[H]+O.nsseparator+a,b),p||""===p&&O.fallbackOnEmpty===!1){var M=p.indexOf(O.nsseparator)>-1?p.split(O.nsseparator)[1]:p,N=e.indexOf(O.nsseparator)>-1?e.split(O.nsseparator)[1]:e;if(M!==N)break}}else p=E(a,b);b.isFallbackLookup=!1}return p}function F(){var a,b=O.lngWhitelist||[],c=[];if("undefined"!=typeof window&&!function(){for(var a=window.location.search.substring(1),b=a.split("&"),d=0;d0){var f=b[d].substring(0,e);f==O.detectLngQS&&c.push(b[d].substring(e+1))}}}(),O.useCookie&&"undefined"!=typeof document){var d=S.cookie.read(O.cookieName);d&&c.push(d)}if(O.detectLngFromLocalStorage&&"undefined"!=typeof window&&window.localStorage&&c.push(S.localStorage.getItem("i18next_lng")),"undefined"!=typeof navigator){if(navigator.languages)for(var e=0;e-1){var f=e.split("-");e=O.lowerCaseLng?f[0].toLowerCase()+"-"+f[1].toLowerCase():f[0].toLowerCase()+"-"+f[1].toUpperCase()}if(0===b.length||b.indexOf(e)>-1){a=e;break}}}(),a||(a=O.fallbackLng[0]),a}Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>0&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=c;arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d))));for(var e=d>=0?Math.min(d,c-1):c-Math.abs(d);e>=0;e--)if(e in b&&b[e]===a)return e;return-1}),"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")});var G,H=void 0,I={},J={},K=0,L=[],M=!1,N={};N={load:function(a,b,c){b.useLocalStorage?N._loadLocal(a,b,function(d,e){for(var f=[],g=0,h=a.length;h>g;g++)e[a[g]]||f.push(a[g]);f.length>0?N._fetch(f,b,function(a,b){S.extend(e,b),N._storeLocal(b),c(null,e)}):c(null,e)}):N._fetch(a,b,function(a,b){c(null,b)})},_loadLocal:function(a,b,c){var d={},e=(new Date).getTime();if(window.localStorage){var f=a.length;S.each(a,function(a,g){var h=S.localStorage.getItem("res_"+g);h&&(h=JSON.parse(h),h.i18nStamp&&h.i18nStamp+b.localStorageExpirationTime>e&&(d[g]=h)),f--,0===f&&c(null,d)})}},_storeLocal:function(a){if(window.localStorage)for(var b in a)a[b].i18nStamp=(new Date).getTime(),S.localStorage.setItem("res_"+b,JSON.stringify(a[b]))},_fetch:function(a,b,c){var d=b.ns,e={};if(b.dynamicLoad){var f=function(a,b){c(null,b)};if("function"==typeof b.customLoad)b.customLoad(a,d.namespaces,b,f);else{var g=u(b.resGetPath,{lng:a.join("+"),ns:d.namespaces.join("+")});S.ajax({url:g,success:function(a){S.log("loaded: "+g),f(null,a)},error:function(a,b,c){S.log("failed loading: "+g),f("failed loading resource.json error: "+c)},dataType:"json",async:b.getAsync})}}else{var h,i=d.namespaces.length*a.length;S.each(d.namespaces,function(d,f){S.each(a,function(a,d){var g=function(a,b){a&&(h=h||[],h.push(a)),e[d]=e[d]||{},e[d][f]=b,i--,0===i&&c(h,e)};"function"==typeof b.customLoad?b.customLoad(d,f,b,g):N._fetchOne(d,f,b,g)})})}},_fetchOne:function(a,b,c,d){var e=u(c.resGetPath,{lng:a,ns:b});S.ajax({url:e,success:function(a){S.log("loaded: "+e),d(null,a)},error:function(a,b,c){if(b&&200==b||a&&a.status&&200==a.status)S.error("There is a typo in: "+e);else if(b&&404==b||a&&a.status&&404==a.status)S.log("Does not exist: "+e);else{var f=b?b:a&&a.status?a.status:null;S.log(f+" when loading "+e)}d(c,{})},dataType:"json",async:c.getAsync})},postMissing:function(a,b,c,d,e){var f={};f[c]=d;var g=[];if("fallback"===O.sendMissingTo&&O.fallbackLng[0]!==!1)for(var h=0;hh;h++)g.push({lng:e[h],url:u(O.resPostPath,{lng:e[h],ns:b})});for(var j=0,k=g.length;k>j;j++){var l=g[j];S.ajax({url:l.url,type:O.sendType,data:f,success:function(){S.log("posted missing key '"+c+"' to: "+l.url);for(var a=c.split("."),e=0,f=J[l.lng][b];a[e];)f=f[a[e]]=e===a.length-1?d:f[a[e]]||{},e++},error:function(){S.log("failed posting missing key '"+c+"' to: "+l.url)},dataType:"json",async:O.postAsync})}},reload:s};var O={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:["dev"],fallbackNS:[],detectLngQS:"setLng",detectLngFromLocalStorage:!1,ns:"translation",fallbackOnNull:!0,fallbackOnEmpty:!1,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",defaultVariables:!1,reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,indefiniteSuffix:"_indefinite",indefiniteNotFound:["indefinite_not_found",Math.random()].join(""),setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",cookieDomain:void 0,objectTreeKeyHandler:void 0,postProcess:void 0,parseMissingKey:void 0,missingKeyHandler:N.postMissing,shortcutFunction:"sprintf"},P={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},Q={create:function(a,b,c,d){var e;if(c){var f=new Date;f.setTime(f.getTime()+60*c*1e3),e="; expires="+f.toGMTString()}else e="";d=d?"domain="+d+";":"",document.cookie=a+"="+b+e+";"+d+"path=/"},read:function(a){for(var b=a+"=",c=document.cookie.split(";"),d=0;d-1){var c=a.split("-");b=O.lowerCaseLng?c[0].toLowerCase()+"-"+c[1].toLowerCase():c[0].toLowerCase()+"-"+c[1].toUpperCase()}else b=O.lowerCaseLng?a.toLowerCase():a;return b}var c=this.log,d=[],e=O.lngWhitelist||!1,f=function(a){!e||e.indexOf(a)>-1?d.push(a):c("rejecting non-whitelisted language: "+a)};if("string"==typeof a&&a.indexOf("-")>-1){var g=a.split("-");"unspecific"!==O.load&&f(b(a)),"current"!==O.load&&f(b(g[this.getCountyIndexOfLng(a)]))}else f(b(a));for(var h=0;h1)},2:function(a){return Number(1!=a)},3:function(){return 0},4:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},5:function(a){return Number(0===a?0:1==a?1:2==a?2:a%100>=3&&10>=a%100?3:a%100>=11?4:5)},6:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)},7:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},8:function(a){return Number(1==a?0:2==a?1:8!=a&&11!=a?2:3)},9:function(a){return Number(a>=2)},10:function(a){return Number(1==a?0:2==a?1:7>a?2:11>a?3:4)},11:function(a){return Number(1==a||11==a?0:2==a||12==a?1:a>2&&20>a?2:3)},12:function(a){return Number(a%10!=1||a%100==11)},13:function(a){return Number(0!==a)},14:function(a){return Number(1==a?0:2==a?1:3==a?2:3)},15:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&(10>a%100||a%100>=20)?1:2)},16:function(a){return Number(a%10==1&&a%100!=11?0:0!==a?1:2)},17:function(a){return Number(1==a||a%10==1?0:1)},18:function(a){return Number(1==a?1:2)},19:function(a){return Number(1==a?0:0===a||a%100>1&&11>a%100?1:a%100>10&&20>a%100?2:3)},20:function(a){return Number(1==a?0:0===a||a%100>0&&20>a%100?1:2)},21:function(a){return Number(a%100==1?1:a%100==2?2:a%100==3||a%100==4?3:0)}},V={rules:function(){var a,b={};for(a=T.length;a--;)b[T[a][0]]={name:T[a][1],numbers:T[a][2],plurals:U[T[a][3]]};return b}(),addRule:function(a,b){V.rules[a]=b},setCurrentLng:function(a){if(!V.currentRule||V.currentRule.lng!==a){var b=a.split("-");V.currentRule={lng:a,rule:V.rules[b[0]]}}},needsPlural:function(a,b){var c,d=a.split("-");return c=V.currentRule&&V.currentRule.lng===a?V.currentRule.rule:V.rules[d[S.getCountyIndexOfLng(a)]],c&&c.numbers.length<=1?!1:1!==this.get(a,b)},get:function(a,b){function c(b,c){var d;if(d=V.currentRule&&V.currentRule.lng===a?V.currentRule.rule:V.rules[b]){var e;e=d.plurals(d.noAbs?c:Math.abs(c));var f=d.numbers[e];return 2===d.numbers.length&&1===d.numbers[0]&&(2===f?f=-1:1===f&&(f=1)),f}return 1===c?"1":"-1"}var d=a.split("-");return c(d[S.getCountyIndexOfLng(a)],b)}},W={},X=function(a,b){W[a]=b},Y=function(){function a(a){return Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}function b(a,b){for(var c=[];b>0;c[--b]=a);return c.join("")}var c=function(){return c.cache.hasOwnProperty(arguments[0])||(c.cache[arguments[0]]=c.parse(arguments[0])),c.format.call(null,c.cache[arguments[0]],arguments)};return c.format=function(c,d){var e,f,g,h,i,j,k,l=1,m=c.length,n="",o=[];for(f=0;m>f;f++)if(n=a(c[f]),"string"===n)o.push(c[f]);else if("array"===n){if(h=c[f],h[2])for(e=d[l],g=0;g=0?"+"+e:e,j=h[4]?"0"==h[4]?"0":h[4].charAt(1):" ",k=h[6]-String(e).length,i=h[6]?b(j,k):"",o.push(h[5]?e+i:i+e)}return o.join("")},c.cache={},c.parse=function(a){for(var b=a,c=[],d=[],e=0;b;){if(null!==(c=/^[^\x25]+/.exec(b)))d.push(c[0]);else if(null!==(c=/^\x25{2}/.exec(b)))d.push("%");else{if(null===(c=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(b)))throw"[sprintf] huh?";if(c[2]){e|=1;var f=[],g=c[2],h=[];if(null===(h=/^([a-z_][a-z_\d]*)/i.exec(g)))throw"[sprintf] huh?";for(f.push(h[1]);""!==(g=g.substring(h[0].length));)if(null!==(h=/^\.([a-z_][a-z_\d]*)/i.exec(g)))f.push(h[1]);else{if(null===(h=/^\[(\d+)\]/.exec(g)))throw"[sprintf] huh?";f.push(h[1])}c[2]=f}else e|=2;if(3===e)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";d.push(c)}b=b.substring(c[0].length)}return d},c}(),Z=function(a,b){return b.unshift(a),Y.apply(null,b)};return X("sprintf",function(a,b,c){return c.sprintf?"[object Array]"===Object.prototype.toString.apply(c.sprintf)?Z(a,c.sprintf):"object"==typeof c.sprintf?Y(a,c.sprintf):a:a}),I.init=f,I.setLng=q,I.preload=g,I.addResourceBundle=h,I.hasResourceBundle=i,I.getResourceBundle=j,I.addResource=l,I.addResources=m,I.removeResourceBundle=k,I.loadNamespace=o,I.loadNamespaces=p,I.setDefaultNamespace=n,I.t=A,I.translate=A,I.exists=z,I.detectLanguage=S.detectLanguage,I.pluralExtensions=V,I.sync=N,I.functions=S,I.lng=r,I.addPostProcessor=X,I.applyReplacement=S.applyReplacement,I.options=O,I}); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd-1.8.0.zip b/libs/i18next/release/i18next.amd-1.8.0.zip new file mode 100644 index 00000000..66ce5f94 Binary files /dev/null and b/libs/i18next/release/i18next.amd-1.8.0.zip differ diff --git a/libs/i18next/release/i18next.amd-1.8.1.js b/libs/i18next/release/i18next.amd-1.8.1.js new file mode 100644 index 00000000..9d95640b --- /dev/null +++ b/libs/i18next/release/i18next.amd-1.8.1.js @@ -0,0 +1,2173 @@ +// i18next, v1.8.1 +// Copyright (c)2015 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function (root, factory) { + if (typeof exports === 'object') { + + module.exports = factory(); + + } else if (typeof define === 'function' && define.amd) { + + define([], factory); + + } +}(this, function () { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + // Add string trim for IE8. + if (typeof String.prototype.trim !== 'function') { + String.prototype.trim = function() { + return this.replace(/^\s+|\s+$/g, ''); + } + } + + var $ = undefined + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = [] + , initialized = false + , sync = {}; + + sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = f.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + f.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + if ((status && status == 200) || (xhr && xhr.status && xhr.status == 200)) { + // file loaded but invalid json, stop waste time ! + f.error('There is a typo in: ' + url); + } else if ((status && status == 404) || (xhr && xhr.status && xhr.status == 404)) { + f.log('Does not exist: ' + url); + } else { + var theStatus = status ? status : ((xhr && xhr.status) ? xhr.status : null); + f.log(theStatus + ' when loading ' + url); + } + + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback' && o.fallbackLng[0] !== false) { + for (var i = 0; i < o.fallbackLng.length; i++) { + urls.push({lng: o.fallbackLng[i], url: applyReplacement(o.resPostPath, { lng: o.fallbackLng[i], ns: ns })}); + } + } else if (o.sendMissingTo === 'current' || (o.sendMissingTo === 'fallback' && o.fallbackLng[0] === false) ) { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + }, + + reload: reload + }; + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: ['dev'], + fallbackNS: [], + detectLngQS: 'setLng', + detectLngFromLocalStorage: false, + ns: 'translation', + fallbackOnNull: true, + fallbackOnEmpty: false, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + defaultVariables: false, + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + indefiniteSuffix: '_indefinite', + indefiniteNotFound: ['indefinite_not_found', Math.random()].join(''), + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + cookieDomain: undefined, + + objectTreeKeyHandler: undefined, + postProcess: undefined, + parseMissingKey: undefined, + missingKeyHandler: sync.postMissing, + + shortcutFunction: 'sprintf' // or: defaultValue + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _deepExtend(target, source) { + for (var prop in source) + if (prop in target) + _deepExtend(target[prop], source[prop]); + else + target[prop] = source[prop]; + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || Object.prototype.toString.apply(object) !== '[object Array]' || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + try { + return JSON.parse(data) + } catch (e) { + f.error('Can not parse JSON. URL: ' + url); + return {}; + } + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + // file: protocol always gives status code 0, so check for data + if (status === 200 || (status === 0 && data.text())) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes,domain) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + domain = (domain)? "domain="+domain+";" : ""; + document.cookie = name+"="+value+expires+";"+domain+"path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes,domain) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + deepExtend: _deepExtend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : (typeof document !== 'undefined' ? _ajax : function() {}), + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + error: function(str) { + if (typeof console !== "undefined") console.error(str); + }, + getCountyIndexOfLng: function(lng) { + var lng_index = 0; + if (lng === 'nb-NO' || lng === 'nn-NO' || lng === 'nb-no' || lng === 'nn-no') lng_index = 1; + return lng_index; + }, + toLanguages: function(lng) { + var log = this.log; + + function applyCase(l) { + var ret = l; + + if (typeof l === 'string' && l.indexOf('-') > -1) { + var parts = l.split('-'); + + ret = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } else { + ret = o.lowerCaseLng ? l.toLowerCase() : l; + } + + return ret; + } + + var languages = []; + var whitelist = o.lngWhitelist || false; + var addLanguage = function(language){ + //reject langs not whitelisted + if(!whitelist || whitelist.indexOf(language) > -1){ + languages.push(language); + }else{ + log('rejecting non-whitelisted language: ' + language); + } + }; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + if (o.load !== 'unspecific') addLanguage(applyCase(lng)); + if (o.load !== 'current') addLanguage(applyCase(parts[this.getCountyIndexOfLng(lng)])); + } else { + addLanguage(applyCase(lng)); + } + + for (var i = 0; i < o.fallbackLng.length; i++) { + if (languages.indexOf(o.fallbackLng[i]) === -1 && o.fallbackLng[i]) languages.push(applyCase(o.fallbackLng[i])); + } + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + }, + regexReplacementEscape: function(strOrFn) { + if (typeof strOrFn === 'string') { + return strOrFn.replace(/\$/g, "$$$$"); + } else { + return strOrFn; + } + }, + localStorage: { + setItem: function(key, value) { + if (window.localStorage) { + try { + window.localStorage.setItem(key, value); + } catch (e) { + f.log('failed to set value for key "' + key + '" to localStorage.'); + } + } + }, + getItem: function(key, value) { + if (window.localStorage) { + try { + return window.localStorage.getItem(key, value); + } catch (e) { + f.log('failed to get value for key "' + key + '" from localStorage.'); + return undefined; + } + } + } + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + delete o.fixLng; /* passed in each time */ + + // override functions: .log(), .detectLanguage(), etc + if (o.functions) { + delete o.functions; + f.extend(f, options.functions); + } + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // fallback languages + if (typeof o.fallbackLng == 'string' || typeof o.fallbackLng == 'boolean') { + o.fallbackLng = [o.fallbackLng]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + if (o.useCookie && f.cookie.read(o.cookieName) !== currentLng){ //cookie is unset or invalid + f.cookie.create(o.cookieName, currentLng, o.cookieExpirationTime, o.cookieDomain); + } + if (o.detectLngFromLocalStorage && typeof document !== 'undefined' && window.localStorage) { + f.localStorage.setItem('i18next_lng', currentLng); + } + + var lngTranslate = translate; + if (options.fixLng) { + lngTranslate = function(key, options) { + options = options || {}; + options.lng = options.lng || lngTranslate.lng; + return translate(key, options); + }; + lngTranslate.lng = currentLng; + } + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + initialized = true; + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + initialized = true; + + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources, deep) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + if (deep) { + f.deepExtend(resStore[lng][ns], resources); + } else { + f.extend(resStore[lng][ns], resources); + } + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function hasResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + var res = resStore[lng][ns] || {}; + + var hasValues = false; + for(var prop in res) { + if (res.hasOwnProperty(prop)) { + hasValues = true; + } + } + + return hasValues; + } + + function getResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + return f.extend({}, resStore[lng][ns]); + } + + function removeResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = {}; + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function addResource(lng, ns, key, value) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + var keys = key.split(o.keyseparator); + var x = 0; + var node = resStore[lng][ns]; + var origRef = node; + + while (keys[x]) { + if (x == keys.length - 1) + node[keys[x]] = value; + else { + if (node[keys[x]] == null) + node[keys[x]] = {}; + + node = node[keys[x]]; + } + x++; + } + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function addResources(lng, ns, resources) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + for (var m in resources) { + if (typeof resources[m] === 'string') addResource(lng, ns, m, resources[m]); + } + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, options, cb) { + if (typeof options === 'function') { + cb = options; + options = {}; + } else if (!options) { + options = {}; + } + + options.lng = lng; + return init(options, cb); + } + + function lng() { + return currentLng; + } + + function reload(cb) { + resStore = {}; + setLng(currentLng, cb); + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else if (attr === 'prepend') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.prepend($.t(key, optionsToUse)); + } else if (attr === 'append') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.append($.t(key, optionsToUse)); + } else if (attr.indexOf("data-") === 0) { + var dataAttr = attr.substr(("data-").length); + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.data(dataAttr) }, options) : options; + var translated = $.t(key, optionsToUse); + //we change into the data cache + ele.data(dataAttr, translated); + //we change into the dom + ele.attr(attr, translated); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key && typeof key !== 'undefined' && key !== false) key = ele.text() || ele.val(); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + var hash = replacementHash.replace && typeof replacementHash.replace === 'object' ? replacementHash.replace : replacementHash; + f.each(hash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), f.regexReplacementEscape(value)); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(f.escape(value))); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(value)); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + if (index_of_end_of_closing <= index_of_opening) { + f.error('there is an missing closing in following translation value', translated); + return ''; + } + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, f.regexReplacementEscape(translated_token)); + } + return translated; + } + + function hasContext(options) { + return (options.context && (typeof options.context == 'string' || typeof options.context == 'number')); + } + + function needsPlural(options, lng) { + return (options.count !== undefined && typeof options.count != 'string'/* && pluralExtensions.needsPlural(lng, options.count)*/); + } + + function needsIndefiniteArticle(options) { + return (options.indefinite_article !== undefined && typeof options.indefinite_article != 'string' && options.indefinite_article); + } + + function exists(key, options) { + options = options || {}; + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + options = options || {}; + + if (!initialized) { + f.log('i18next not finished initialization. you might have called t function before loading resources finished.') + return options.defaultValue || ''; + }; + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _getDefaultValue(key, options) { + return (options.defaultValue !== undefined) ? options.defaultValue : key; + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(potentialKeys, options) { + if (options && typeof options !== 'object') { + if (o.shortcutFunction === 'sprintf') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else if (o.shortcutFunction === 'defaultValue') { + options = { + defaultValue: options + } + } + } else { + options = options || {}; + } + + if (typeof o.defaultVariables === 'object') { + options = f.extend({}, o.defaultVariables, options); + } + + if (potentialKeys === undefined || potentialKeys === null || potentialKeys === '') return ''; + + if (typeof potentialKeys === 'number') { + potentialKeys = String(potentialKeys); + } + + if (typeof potentialKeys === 'string') { + potentialKeys = [potentialKeys]; + } + + var key = potentialKeys[0]; + + if (potentialKeys.length > 1) { + for (var i = 0; i < potentialKeys.length; i++) { + key = potentialKeys[i]; + if (exists(key, options)) { + break; + } + } + } + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng, options.fallbackLng) : languages + , ns = options.ns || o.ns.defaultNs + , parts; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing && typeof o.missingKeyHandler === 'function') { + if (options.lng) { + o.missingKeyHandler(lngs[0], ns, key, notFound, lngs); + } else { + o.missingKeyHandler(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessorsToApply; + if (typeof o.postProcess === 'string' && o.postProcess !== '') { + postProcessorsToApply = [o.postProcess]; + } else if (typeof o.postProcess === 'array' || typeof o.postProcess === 'object') { + postProcessorsToApply = o.postProcess; + } else { + postProcessorsToApply = []; + } + + if (typeof options.postProcess === 'string' && options.postProcess !== '') { + postProcessorsToApply = postProcessorsToApply.concat([options.postProcess]); + } else if (typeof options.postProcess === 'array' || typeof options.postProcess === 'object') { + postProcessorsToApply = postProcessorsToApply.concat(options.postProcess); + } + + if (found !== undefined && postProcessorsToApply.length) { + postProcessorsToApply.forEach(function(postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + }); + } + + // process notFound if function exists + var splitNotFound = notFound; + if (notFound.indexOf(o.nsseparator) > -1) { + parts = notFound.split(o.nsseparator); + splitNotFound = parts[1]; + } + if (splitNotFound === key && o.parseMissingKey) { + notFound = o.parseMissingKey(notFound); + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessorsToApply.length) { + var val = _getDefaultValue(key, options); + postProcessorsToApply.forEach(function(postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](val, key, options); + } + }); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options) { + options = options || {}; + + var optionWithoutCount, translated + , notFound = _getDefaultValue(key, options) + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + // CI mode + if (lngs[0].toLowerCase() === 'cimode') return notFound; + + // passed in lng + if (options.lngs) lngs = options.lngs; + if (options.lng) { + lngs = f.toLanguages(options.lng, options.fallbackLng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options, lngs[0])) { + optionWithoutCount = f.extend({ lngs: [lngs[0]]}, options); + delete optionWithoutCount.count; + optionWithoutCount._origLng = optionWithoutCount._origLng || optionWithoutCount.lng || lngs[0]; + delete optionWithoutCount.lng; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey; + if (!pluralExtensions.needsPlural(lngs[0], options.count)) { + pluralKey = ns + o.nsseparator + key; + } else { + pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(lngs[0], options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + } + + translated = translate(pluralKey, optionWithoutCount); + + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } else if (lngs.length > 1) { + // remove failed lng + var clone = lngs.slice(); + clone.shift(); + options = f.extend(options, { lngs: clone }); + options._origLng = optionWithoutCount._origLng; + delete options.lng; + // retry with fallbacks + translated = translate(ns + o.nsseparator + key, options); + if (translated != o.pluralNotFound) return translated; + } else { + optionWithoutCount.lng = optionWithoutCount._origLng; + delete optionWithoutCount._origLng; + translated = translate(ns + o.nsseparator + key, optionWithoutCount); + + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); + } + } + + if (needsIndefiniteArticle(options)) { + var optionsWithoutIndef = f.extend({}, options); + delete optionsWithoutIndef.indefinite_article; + optionsWithoutIndef.defaultValue = o.indefiniteNotFound; + // If we don't have a count, we want the indefinite, if we do have a count, and needsPlural is false + var indefiniteKey = ns + o.nsseparator + key + (((options.count && !needsPlural(options, lngs[0])) || !options.count) ? o.indefiniteSuffix : ""); + translated = translate(indefiniteKey, optionsWithoutIndef); + if (translated != o.indefiniteNotFound) { + return translated; + } + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + var valueType = Object.prototype.toString.apply(value); + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (valueType === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + if (o.objectTreeKeyHandler && typeof o.objectTreeKeyHandler == 'function') { + value = o.objectTreeKeyHandler(key, value, l, ns, options); + } else { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned an object instead of string.'; + f.log(value); + } + } else if (valueType !== '[object Number]' && valueType !== '[object Function]' && valueType !== '[object RegExp]') { + var copy = (valueType === '[object Array]') ? [] : {}; // apply child translation on a copy + f.each(value, function(m) { + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + }); + value = copy; + } + } + + if (typeof value === 'string' && value.trim() === '' && o.fallbackOnEmpty === true) + value = undefined; + + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length > 0))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found || (found==="" && o.fallbackOnEmpty === false)) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + options.isFallbackLookup = false; + } + + return found; + } + function detectLanguage() { + var detectedLng; + var whitelist = o.lngWhitelist || []; + var userLngChoices = []; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var params = query.split('&'); + for (var i=0; i 0) { + var key = params[i].substring(0,pos); + if (key == o.detectLngQS) { + userLngChoices.push(params[i].substring(pos+1)); + } + } + } + })(); + } + + // get from cookie + if (o.useCookie && typeof document !== 'undefined') { + var c = f.cookie.read(o.cookieName); + if (c) userLngChoices.push(c); + } + + // get from localStorage + if (o.detectLngFromLocalStorage && typeof window !== 'undefined' && window.localStorage) { + userLngChoices.push(f.localStorage.getItem('i18next_lng')); + } + + // get from navigator + if (typeof navigator !== 'undefined') { + if (navigator.languages) { // chrome only; not an array, so can't use .push.apply instead of iterating + for (var i=0;i -1) { + var parts = lng.split('-'); + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } + + if (whitelist.length === 0 || whitelist.indexOf(lng) > -1) { + detectedLng = lng; + break; + } + } + })(); + + //fallback + if (!detectedLng){ + detectedLng = o.fallbackLng[0]; + } + + return detectedLng; + } + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + + /* [code, name, numbers, pluralsType] */ + var _rules = [ + ["ach", "Acholi", [1,2], 1], + ["af", "Afrikaans",[1,2], 2], + ["ak", "Akan", [1,2], 1], + ["am", "Amharic", [1,2], 1], + ["an", "Aragonese",[1,2], 2], + ["ar", "Arabic", [0,1,2,3,11,100],5], + ["arn", "Mapudungun",[1,2], 1], + ["ast", "Asturian", [1,2], 2], + ["ay", "Aymará", [1], 3], + ["az", "Azerbaijani",[1,2],2], + ["be", "Belarusian",[1,2,5],4], + ["bg", "Bulgarian",[1,2], 2], + ["bn", "Bengali", [1,2], 2], + ["bo", "Tibetan", [1], 3], + ["br", "Breton", [1,2], 1], + ["bs", "Bosnian", [1,2,5],4], + ["ca", "Catalan", [1,2], 2], + ["cgg", "Chiga", [1], 3], + ["cs", "Czech", [1,2,5],6], + ["csb", "Kashubian",[1,2,5],7], + ["cy", "Welsh", [1,2,3,8],8], + ["da", "Danish", [1,2], 2], + ["de", "German", [1,2], 2], + ["dev", "Development Fallback", [1,2], 2], + ["dz", "Dzongkha", [1], 3], + ["el", "Greek", [1,2], 2], + ["en", "English", [1,2], 2], + ["eo", "Esperanto",[1,2], 2], + ["es", "Spanish", [1,2], 2], + ["es_ar","Argentinean Spanish", [1,2], 2], + ["et", "Estonian", [1,2], 2], + ["eu", "Basque", [1,2], 2], + ["fa", "Persian", [1], 3], + ["fi", "Finnish", [1,2], 2], + ["fil", "Filipino", [1,2], 1], + ["fo", "Faroese", [1,2], 2], + ["fr", "French", [1,2], 9], + ["fur", "Friulian", [1,2], 2], + ["fy", "Frisian", [1,2], 2], + ["ga", "Irish", [1,2,3,7,11],10], + ["gd", "Scottish Gaelic",[1,2,3,20],11], + ["gl", "Galician", [1,2], 2], + ["gu", "Gujarati", [1,2], 2], + ["gun", "Gun", [1,2], 1], + ["ha", "Hausa", [1,2], 2], + ["he", "Hebrew", [1,2], 2], + ["hi", "Hindi", [1,2], 2], + ["hr", "Croatian", [1,2,5],4], + ["hu", "Hungarian",[1,2], 2], + ["hy", "Armenian", [1,2], 2], + ["ia", "Interlingua",[1,2],2], + ["id", "Indonesian",[1], 3], + ["is", "Icelandic",[1,2], 12], + ["it", "Italian", [1,2], 2], + ["ja", "Japanese", [1], 3], + ["jbo", "Lojban", [1], 3], + ["jv", "Javanese", [0,1], 13], + ["ka", "Georgian", [1], 3], + ["kk", "Kazakh", [1], 3], + ["km", "Khmer", [1], 3], + ["kn", "Kannada", [1,2], 2], + ["ko", "Korean", [1], 3], + ["ku", "Kurdish", [1,2], 2], + ["kw", "Cornish", [1,2,3,4],14], + ["ky", "Kyrgyz", [1], 3], + ["lb", "Letzeburgesch",[1,2],2], + ["ln", "Lingala", [1,2], 1], + ["lo", "Lao", [1], 3], + ["lt", "Lithuanian",[1,2,10],15], + ["lv", "Latvian", [1,2,0],16], + ["mai", "Maithili", [1,2], 2], + ["mfe", "Mauritian Creole",[1,2],1], + ["mg", "Malagasy", [1,2], 1], + ["mi", "Maori", [1,2], 1], + ["mk", "Macedonian",[1,2],17], + ["ml", "Malayalam",[1,2], 2], + ["mn", "Mongolian",[1,2], 2], + ["mnk", "Mandinka", [0,1,2],18], + ["mr", "Marathi", [1,2], 2], + ["ms", "Malay", [1], 3], + ["mt", "Maltese", [1,2,11,20],19], + ["nah", "Nahuatl", [1,2], 2], + ["nap", "Neapolitan",[1,2], 2], + ["nb", "Norwegian Bokmal",[1,2],2], + ["ne", "Nepali", [1,2], 2], + ["nl", "Dutch", [1,2], 2], + ["nn", "Norwegian Nynorsk",[1,2],2], + ["no", "Norwegian",[1,2], 2], + ["nso", "Northern Sotho",[1,2],2], + ["oc", "Occitan", [1,2], 1], + ["or", "Oriya", [2,1], 2], + ["pa", "Punjabi", [1,2], 2], + ["pap", "Papiamento",[1,2], 2], + ["pl", "Polish", [1,2,5],7], + ["pms", "Piemontese",[1,2], 2], + ["ps", "Pashto", [1,2], 2], + ["pt", "Portuguese",[1,2], 2], + ["pt_br","Brazilian Portuguese",[1,2], 2], + ["rm", "Romansh", [1,2], 2], + ["ro", "Romanian", [1,2,20],20], + ["ru", "Russian", [1,2,5],4], + ["sah", "Yakut", [1], 3], + ["sco", "Scots", [1,2], 2], + ["se", "Northern Sami",[1,2], 2], + ["si", "Sinhala", [1,2], 2], + ["sk", "Slovak", [1,2,5],6], + ["sl", "Slovenian",[5,1,2,3],21], + ["so", "Somali", [1,2], 2], + ["son", "Songhay", [1,2], 2], + ["sq", "Albanian", [1,2], 2], + ["sr", "Serbian", [1,2,5],4], + ["su", "Sundanese",[1], 3], + ["sv", "Swedish", [1,2], 2], + ["sw", "Swahili", [1,2], 2], + ["ta", "Tamil", [1,2], 2], + ["te", "Telugu", [1,2], 2], + ["tg", "Tajik", [1,2], 1], + ["th", "Thai", [1], 3], + ["ti", "Tigrinya", [1,2], 1], + ["tk", "Turkmen", [1,2], 2], + ["tr", "Turkish", [1,2], 1], + ["tt", "Tatar", [1], 3], + ["ug", "Uyghur", [1], 3], + ["uk", "Ukrainian",[1,2,5],4], + ["ur", "Urdu", [1,2], 2], + ["uz", "Uzbek", [1,2], 1], + ["vi", "Vietnamese",[1], 3], + ["wa", "Walloon", [1,2], 1], + ["wo", "Wolof", [1], 3], + ["yo", "Yoruba", [1,2], 2], + ["zh", "Chinese", [1], 3] + ]; + + var _rulesPluralsTypes = { + 1: function(n) {return Number(n > 1);}, + 2: function(n) {return Number(n != 1);}, + 3: function(n) {return 0;}, + 4: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 5: function(n) {return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5);}, + 6: function(n) {return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2);}, + 7: function(n) {return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 8: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3);}, + 9: function(n) {return Number(n >= 2);}, + 10: function(n) {return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;}, + 11: function(n) {return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3);}, + 12: function(n) {return Number(n%10!=1 || n%100==11);}, + 13: function(n) {return Number(n !== 0);}, + 14: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3);}, + 15: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 16: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2);}, + 17: function(n) {return Number(n==1 || n%10==1 ? 0 : 1);}, + 18: function(n) {return Number(0 ? 0 : n==1 ? 1 : 2);}, + 19: function(n) {return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3);}, + 20: function(n) {return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2);}, + 21: function(n) {return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }; + + var pluralExtensions = { + + rules: (function () { + var l, rules = {}; + for (l=_rules.length; l-- ;) { + rules[_rules[l][0]] = { + name: _rules[l][1], + numbers: _rules[l][2], + plurals: _rulesPluralsTypes[_rules[l][3]] + } + } + return rules; + }()), + + // you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + needsPlural: function(lng, count) { + var parts = lng.split('-'); + + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[parts[f.getCountyIndexOfLng(lng)]]; + } + + if (ext && ext.numbers.length <= 1) { + return false; + } else { + return this.get(lng, count) !== 1; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i; + if (ext.noAbs) { + i = ext.plurals(c); + } else { + i = ext.plurals(Math.abs(c)); + } + + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[f.getCountyIndexOfLng(lng)], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.hasResourceBundle = hasResourceBundle; + i18n.getResourceBundle = getResourceBundle; + i18n.addResource = addResource; + i18n.addResources = addResources; + i18n.removeResourceBundle = removeResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.applyReplacement = f.applyReplacement; + i18n.options = o; + + return i18n; + +})); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd-1.8.1.min.js b/libs/i18next/release/i18next.amd-1.8.1.min.js new file mode 100644 index 00000000..80e09ba4 --- /dev/null +++ b/libs/i18next/release/i18next.amd-1.8.1.min.js @@ -0,0 +1,5 @@ +// i18next, v1.8.1 +// Copyright (c)2015 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +!function(a,b){"object"==typeof exports?module.exports=b():"function"==typeof define&&define.amd&&define([],b)}(this,function(){function a(a,b){if(!b||"function"==typeof b)return a;for(var c in b)a[c]=b[c];return a}function b(a,c){for(var d in c)d in a?b(a[d],c[d]):a[d]=c[d];return a}function c(a,b,c){var d,e=0,f=a.length,g=void 0===f||"[object Array]"!==Object.prototype.toString.apply(a)||"function"==typeof a;if(c)if(g){for(d in a)if(b.apply(a[d],c)===!1)break}else for(;f>e&&b.apply(a[e++],c)!==!1;);else if(g){for(d in a)if(b.call(a[d],d,a[d])===!1)break}else for(;f>e&&b.call(a[e],e,a[e++])!==!1;);return a}function d(a){return"string"==typeof a?a.replace(/[&<>"'\/]/g,function(a){return P[a]}):a}function e(a){var b=function(a){if(window.XMLHttpRequest)return a(null,new XMLHttpRequest);if(window.ActiveXObject)try{return a(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(b){return a(null,new ActiveXObject("Microsoft.XMLHTTP"))}return a(new Error)},c=function(a){if("string"==typeof a)return a;var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")},d=function(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;cd?b+=String.fromCharCode(d):d>127&&2048>d?(b+=String.fromCharCode(d>>6|192),b+=String.fromCharCode(63&d|128)):(b+=String.fromCharCode(d>>12|224),b+=String.fromCharCode(d>>6&63|128),b+=String.fromCharCode(63&d|128))}return b},e=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";a=d(a);var c,e,f,g,h,i,j,k="",l=0;do c=a.charCodeAt(l++),e=a.charCodeAt(l++),f=a.charCodeAt(l++),g=c>>2,h=(3&c)<<4|e>>4,i=(15&e)<<2|f>>6,j=63&f,isNaN(e)?i=j=64:isNaN(f)&&(j=64),k+=b.charAt(g)+b.charAt(h)+b.charAt(i)+b.charAt(j),c=e=f="",g=h=i=j="";while(l1&&(d+=d.indexOf("?")>-1?"&"+k:"?"+k),e.jsonp){var l=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=d,void l.appendChild(m)}}b(function(b,c){if(b)return h(b);c.open(a,d,e.async);for(var f in j)j.hasOwnProperty(f)&&c.setRequestHeader(f,j[f]);c.onreadystatechange=function(){if(4===c.readyState){var a=c.responseText||"";if(!h)return;h(c.status,{text:function(){return a},json:function(){try{return JSON.parse(a)}catch(b){return S.error("Can not parse JSON. URL: "+d),{}}}})}},c.send(i)})},h={authBasic:function(a,b){g.headers.Authorization="Basic "+e(a+":"+b)},connect:function(a,b,c){return g("CONNECT",a,b,c)},del:function(a,b,c){return g("DELETE",a,b,c)},get:function(a,b,c){return g("GET",a,b,c)},head:function(a,b,c){return g("HEAD",a,b,c)},headers:function(a){g.headers=a||{}},isAllowed:function(a,b,c){this.options(a,function(a,d){c(-1!==d.text().indexOf(b))})},options:function(a,b,c){return g("OPTIONS",a,b,c)},patch:function(a,b,c){return g("PATCH",a,b,c)},post:function(a,b,c){return g("POST",a,b,c)},put:function(a,b,c){return g("PUT",a,b,c)},trace:function(a,b,c){return g("TRACE",a,b,c)}},i=a.type?a.type.toLowerCase():"get";h[i](a.url,a,function(b,c){200===b||0===b&&c.text()?a.success(c.json(),b,null):a.error(c.text(),b,null)})}function f(a,b){"function"==typeof a&&(b=a,a={}),a=a||{},S.extend(O,a),delete O.fixLng,O.functions&&(delete O.functions,S.extend(S,a.functions)),"string"==typeof O.ns&&(O.ns={namespaces:[O.ns],defaultNs:O.ns}),"string"==typeof O.fallbackNS&&(O.fallbackNS=[O.fallbackNS]),("string"==typeof O.fallbackLng||"boolean"==typeof O.fallbackLng)&&(O.fallbackLng=[O.fallbackLng]),O.interpolationPrefixEscaped=S.regexEscape(O.interpolationPrefix),O.interpolationSuffixEscaped=S.regexEscape(O.interpolationSuffix),O.lng||(O.lng=S.detectLanguage()),L=S.toLanguages(O.lng),G=L[0],S.log("currentLng set to: "+G),O.useCookie&&S.cookie.read(O.cookieName)!==G&&S.cookie.create(O.cookieName,G,O.cookieExpirationTime,O.cookieDomain),O.detectLngFromLocalStorage&&"undefined"!=typeof document&&window.localStorage&&S.localStorage.setItem("i18next_lng",G);var c=A;a.fixLng&&(c=function(a,b){return b=b||{},b.lng=b.lng||c.lng,A(a,b)},c.lng=G),V.setCurrentLng(G),H&&O.setJqueryExt&&t();var d;if(H&&H.Deferred&&(d=H.Deferred()),!O.resStore){var e=S.toLanguages(O.lng);"string"==typeof O.preload&&(O.preload=[O.preload]);for(var f=0,g=O.preload.length;g>f;f++)for(var h=S.toLanguages(O.preload[f]),i=0,j=h.length;j>i;i++)e.indexOf(h[i])<0&&e.push(h[i]);return I.sync.load(e,O,function(a,e){J=e,M=!0,b&&b(c),d&&d.resolve(c)}),d?d.promise():void 0}return J=O.resStore,M=!0,b&&b(c),d&&d.resolve(c),d?d.promise():void 0}function g(a,b){"string"==typeof a&&(a=[a]);for(var c=0,d=a.length;d>c;c++)O.preload.indexOf(a[c])<0&&O.preload.push(a[c]);return f(b)}function h(a,b,c,d){"string"!=typeof b?(c=b,b=O.ns.defaultNs):O.ns.namespaces.indexOf(b)<0&&O.ns.namespaces.push(b),J[a]=J[a]||{},J[a][b]=J[a][b]||{},d?S.deepExtend(J[a][b],c):S.extend(J[a][b],c),O.useLocalStorage&&N._storeLocal(J)}function i(a,b){"string"!=typeof b&&(b=O.ns.defaultNs),J[a]=J[a]||{};var c=J[a][b]||{},d=!1;for(var e in c)c.hasOwnProperty(e)&&(d=!0);return d}function j(a,b){return"string"!=typeof b&&(b=O.ns.defaultNs),J[a]=J[a]||{},S.extend({},J[a][b])}function k(a,b){"string"!=typeof b&&(b=O.ns.defaultNs),J[a]=J[a]||{},J[a][b]={},O.useLocalStorage&&N._storeLocal(J)}function l(a,b,c,d){"string"!=typeof b?(resource=b,b=O.ns.defaultNs):O.ns.namespaces.indexOf(b)<0&&O.ns.namespaces.push(b),J[a]=J[a]||{},J[a][b]=J[a][b]||{};for(var e=c.split(O.keyseparator),f=0,g=J[a][b];e[f];)f==e.length-1?g[e[f]]=d:(null==g[e[f]]&&(g[e[f]]={}),g=g[e[f]]),f++;O.useLocalStorage&&N._storeLocal(J)}function m(a,b,c){"string"!=typeof b?(resource=b,b=O.ns.defaultNs):O.ns.namespaces.indexOf(b)<0&&O.ns.namespaces.push(b);for(var d in c)"string"==typeof c[d]&&l(a,b,d,c[d])}function n(a){O.ns.defaultNs=a}function o(a,b){p([a],b)}function p(a,b){var c={dynamicLoad:O.dynamicLoad,resGetPath:O.resGetPath,getAsync:O.getAsync,customLoad:O.customLoad,ns:{namespaces:a,defaultNs:""}},d=S.toLanguages(O.lng);"string"==typeof O.preload&&(O.preload=[O.preload]);for(var e=0,f=O.preload.length;f>e;e++)for(var g=S.toLanguages(O.preload[e]),h=0,i=g.length;i>h;h++)d.indexOf(g[h])<0&&d.push(g[h]);for(var j=[],k=0,l=d.length;l>k;k++){var m=!1,n=J[d[k]];if(n)for(var o=0,p=a.length;p>o;o++)n[a[o]]||(m=!0);else m=!0;m&&j.push(d[k])}j.length?I.sync._fetch(j,c,function(c,d){var e=a.length*j.length;S.each(a,function(a,c){O.ns.namespaces.indexOf(c)<0&&O.ns.namespaces.push(c),S.each(j,function(a,f){J[f]=J[f]||{},J[f][c]=d[f][c],e--,0===e&&b&&(O.useLocalStorage&&I.sync._storeLocal(J),b())})})}):b&&b()}function q(a,b,c){return"function"==typeof b?(c=b,b={}):b||(b={}),b.lng=a,f(b,c)}function r(){return G}function s(a){J={},q(G,a)}function t(){function a(a,b,c){if(0!==b.length){var d="text";if(0===b.indexOf("[")){var e=b.split("]");b=e[1],d=e[0].substr(1,e[0].length-1)}b.indexOf(";")===b.length-1&&(b=b.substr(0,b.length-2));var f;if("html"===d)f=O.defaultValueFromContent?H.extend({defaultValue:a.html()},c):c,a.html(H.t(b,f));else if("text"===d)f=O.defaultValueFromContent?H.extend({defaultValue:a.text()},c):c,a.text(H.t(b,f));else if("prepend"===d)f=O.defaultValueFromContent?H.extend({defaultValue:a.html()},c):c,a.prepend(H.t(b,f));else if("append"===d)f=O.defaultValueFromContent?H.extend({defaultValue:a.html()},c):c,a.append(H.t(b,f));else if(0===d.indexOf("data-")){var g=d.substr("data-".length);f=O.defaultValueFromContent?H.extend({defaultValue:a.data(g)},c):c;var h=H.t(b,f);a.data(g,h),a.attr(d,h)}else f=O.defaultValueFromContent?H.extend({defaultValue:a.attr(d)},c):c,a.attr(d,H.t(b,f))}}function b(b,c){var d=b.attr(O.selectorAttr);if(d||"undefined"==typeof d||d===!1||(d=b.text()||b.val()),d){var e=b,f=b.data("i18n-target");if(f&&(e=b.find(f)||b),c||O.useDataAttrOptions!==!0||(c=b.data("i18n-options")),c=c||{},d.indexOf(";")>=0){var g=d.split(";");H.each(g,function(b,d){""!==d&&a(e,d,c)})}else a(e,d,c);O.useDataAttrOptions===!0&&b.data("i18n-options",c)}}H.t=H.t||A,H.fn.i18n=function(a){return this.each(function(){b(H(this),a);var c=H(this).find("["+O.selectorAttr+"]");c.each(function(){b(H(this),a)})})}}function u(a,b,c,d){if(!a)return a;if(d=d||b,a.indexOf(d.interpolationPrefix||O.interpolationPrefix)<0)return a;var e=d.interpolationPrefix?S.regexEscape(d.interpolationPrefix):O.interpolationPrefixEscaped,f=d.interpolationSuffix?S.regexEscape(d.interpolationSuffix):O.interpolationSuffixEscaped,g="HTML"+f,h=b.replace&&"object"==typeof b.replace?b.replace:b;return S.each(h,function(b,h){var i=c?c+O.keyseparator+b:b;"object"==typeof h&&null!==h?a=u(a,h,i,d):d.escapeInterpolation||O.escapeInterpolation?(a=a.replace(new RegExp([e,i,g].join(""),"g"),S.regexReplacementEscape(h)),a=a.replace(new RegExp([e,i,f].join(""),"g"),S.regexReplacementEscape(S.escape(h)))):a=a.replace(new RegExp([e,i,f].join(""),"g"),S.regexReplacementEscape(h))}),a}function v(a,b){var c=",",d="{",e="}",f=S.extend({},b);for(delete f.postProcess;-1!=a.indexOf(O.reusePrefix)&&(K++,!(K>O.maxRecursion));){var g=a.lastIndexOf(O.reusePrefix),h=a.indexOf(O.reuseSuffix,g)+O.reuseSuffix.length,i=a.substring(g,h),j=i.replace(O.reusePrefix,"").replace(O.reuseSuffix,"");if(g>=h)return S.error("there is an missing closing in following translation value",a),"";if(-1!=j.indexOf(c)){var k=j.indexOf(c);if(-1!=j.indexOf(d,k)&&-1!=j.indexOf(e,k)){var l=j.indexOf(d,k),m=j.indexOf(e,l)+e.length;try{f=S.extend(f,JSON.parse(j.substring(l,m))),j=j.substring(0,k)}catch(n){}}}var o=D(j,f);a=a.replace(i,S.regexReplacementEscape(o))}return a}function w(a){return a.context&&("string"==typeof a.context||"number"==typeof a.context)}function x(a){return void 0!==a.count&&"string"!=typeof a.count}function y(a){return void 0!==a.indefinite_article&&"string"!=typeof a.indefinite_article&&a.indefinite_article}function z(a,b){b=b||{};var c=B(a,b),d=E(a,b);return void 0!==d||d===c}function A(a,b){return b=b||{},M?(K=0,D.apply(null,arguments)):(S.log("i18next not finished initialization. you might have called t function before loading resources finished."),b.defaultValue||"")}function B(a,b){return void 0!==b.defaultValue?b.defaultValue:a}function C(){for(var a=[],b=1;b1)for(var d=0;d-1&&(e=c.split(O.nsseparator),i=e[0],c=e[1]),void 0===g&&O.sendMissing&&"function"==typeof O.missingKeyHandler&&(b.lng?O.missingKeyHandler(h[0],i,c,f,h):O.missingKeyHandler(O.lng,i,c,f,h));var j;j="string"==typeof O.postProcess&&""!==O.postProcess?[O.postProcess]:"array"==typeof O.postProcess||"object"==typeof O.postProcess?O.postProcess:[],"string"==typeof b.postProcess&&""!==b.postProcess?j=j.concat([b.postProcess]):("array"==typeof b.postProcess||"object"==typeof b.postProcess)&&(j=j.concat(b.postProcess)),void 0!==g&&j.length&&j.forEach(function(a){W[a]&&(g=W[a](g,c,b))});var k=f;if(f.indexOf(O.nsseparator)>-1&&(e=f.split(O.nsseparator),k=e[1]),k===c&&O.parseMissingKey&&(f=O.parseMissingKey(f)),void 0===g&&(f=u(f,b),f=v(f,b),j.length)){var l=B(c,b);j.forEach(function(a){W[a]&&(g=W[a](l,c,b))})}return void 0!==g?g:f}function E(a,b){b=b||{};var c,d,e=B(a,b),f=L;if(!J)return e;if("cimode"===f[0].toLowerCase())return e;if(b.lngs&&(f=b.lngs),b.lng&&(f=S.toLanguages(b.lng,b.fallbackLng),!J[f[0]])){var g=O.getAsync;O.getAsync=!1,I.sync.load(f,O,function(a,b){S.extend(J,b),O.getAsync=g})}var h=b.ns||O.ns.defaultNs;if(a.indexOf(O.nsseparator)>-1){var i=a.split(O.nsseparator);h=i[0],a=i[1]}if(w(b)){c=S.extend({},b),delete c.context,c.defaultValue=O.contextNotFound;var j=h+O.nsseparator+a+"_"+b.context;if(d=A(j,c),d!=O.contextNotFound)return u(d,{context:b.context})}if(x(b,f[0])){c=S.extend({lngs:[f[0]]},b),delete c.count,c._origLng=c._origLng||c.lng||f[0],delete c.lng,c.defaultValue=O.pluralNotFound;var k;if(V.needsPlural(f[0],b.count)){k=h+O.nsseparator+a+O.pluralSuffix;var l=V.get(f[0],b.count);l>=0?k=k+"_"+l:1===l&&(k=h+O.nsseparator+a)}else k=h+O.nsseparator+a;if(d=A(k,c),d!=O.pluralNotFound)return u(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix});if(!(f.length>1))return c.lng=c._origLng,delete c._origLng,d=A(h+O.nsseparator+a,c),u(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix});var m=f.slice();if(m.shift(),b=S.extend(b,{lngs:m}),b._origLng=c._origLng,delete b.lng,d=A(h+O.nsseparator+a,b),d!=O.pluralNotFound)return d}if(y(b)){var n=S.extend({},b);delete n.indefinite_article,n.defaultValue=O.indefiniteNotFound;var o=h+O.nsseparator+a+(b.count&&!x(b,f[0])||!b.count?O.indefiniteSuffix:"");if(d=A(o,n),d!=O.indefiniteNotFound)return d}for(var p,q=a.split(O.keyseparator),r=0,s=f.length;s>r&&void 0===p;r++){for(var t=f[r],z=0,C=J[t]&&J[t][h];q[z];)C=C&&C[q[z]],z++;if(void 0!==C){var F=Object.prototype.toString.apply(C);if("string"==typeof C)C=u(C,b),C=v(C,b);else if("[object Array]"!==F||O.returnObjectTrees||b.returnObjectTrees){if(null===C&&O.fallbackOnNull===!0)C=void 0;else if(null!==C)if(O.returnObjectTrees||b.returnObjectTrees){if("[object Number]"!==F&&"[object Function]"!==F&&"[object RegExp]"!==F){var G="[object Array]"===F?[]:{};S.each(C,function(c){G[c]=D(h+O.nsseparator+a+O.keyseparator+c,b)}),C=G}}else O.objectTreeKeyHandler&&"function"==typeof O.objectTreeKeyHandler?C=O.objectTreeKeyHandler(a,C,t,h,b):(C="key '"+h+":"+a+" ("+t+")' returned an object instead of string.",S.log(C))}else C=C.join("\n"),C=u(C,b),C=v(C,b);"string"==typeof C&&""===C.trim()&&O.fallbackOnEmpty===!0&&(C=void 0),p=C}}if(void 0===p&&!b.isFallbackLookup&&(O.fallbackToDefaultNS===!0||O.fallbackNS&&O.fallbackNS.length>0)){if(b.isFallbackLookup=!0,O.fallbackNS.length){for(var H=0,K=O.fallbackNS.length;K>H;H++)if(p=E(O.fallbackNS[H]+O.nsseparator+a,b),p||""===p&&O.fallbackOnEmpty===!1){var M=p.indexOf(O.nsseparator)>-1?p.split(O.nsseparator)[1]:p,N=e.indexOf(O.nsseparator)>-1?e.split(O.nsseparator)[1]:e;if(M!==N)break}}else p=E(a,b);b.isFallbackLookup=!1}return p}function F(){var a,b=O.lngWhitelist||[],c=[];if("undefined"!=typeof window&&!function(){for(var a=window.location.search.substring(1),b=a.split("&"),d=0;d0){var f=b[d].substring(0,e);f==O.detectLngQS&&c.push(b[d].substring(e+1))}}}(),O.useCookie&&"undefined"!=typeof document){var d=S.cookie.read(O.cookieName);d&&c.push(d)}if(O.detectLngFromLocalStorage&&"undefined"!=typeof window&&window.localStorage&&c.push(S.localStorage.getItem("i18next_lng")),"undefined"!=typeof navigator){if(navigator.languages)for(var e=0;e-1){var f=e.split("-");e=O.lowerCaseLng?f[0].toLowerCase()+"-"+f[1].toLowerCase():f[0].toLowerCase()+"-"+f[1].toUpperCase()}if(0===b.length||b.indexOf(e)>-1){a=e;break}}}(),a||(a=O.fallbackLng[0]),a}Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>0&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=c;arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d))));for(var e=d>=0?Math.min(d,c-1):c-Math.abs(d);e>=0;e--)if(e in b&&b[e]===a)return e;return-1}),"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")});var G,H=void 0,I={},J={},K=0,L=[],M=!1,N={};N={load:function(a,b,c){b.useLocalStorage?N._loadLocal(a,b,function(d,e){for(var f=[],g=0,h=a.length;h>g;g++)e[a[g]]||f.push(a[g]);f.length>0?N._fetch(f,b,function(a,b){S.extend(e,b),N._storeLocal(b),c(null,e)}):c(null,e)}):N._fetch(a,b,function(a,b){c(null,b)})},_loadLocal:function(a,b,c){var d={},e=(new Date).getTime();if(window.localStorage){var f=a.length;S.each(a,function(a,g){var h=S.localStorage.getItem("res_"+g);h&&(h=JSON.parse(h),h.i18nStamp&&h.i18nStamp+b.localStorageExpirationTime>e&&(d[g]=h)),f--,0===f&&c(null,d)})}},_storeLocal:function(a){if(window.localStorage)for(var b in a)a[b].i18nStamp=(new Date).getTime(),S.localStorage.setItem("res_"+b,JSON.stringify(a[b]))},_fetch:function(a,b,c){var d=b.ns,e={};if(b.dynamicLoad){var f=function(a,b){c(null,b)};if("function"==typeof b.customLoad)b.customLoad(a,d.namespaces,b,f);else{var g=u(b.resGetPath,{lng:a.join("+"),ns:d.namespaces.join("+")});S.ajax({url:g,success:function(a){S.log("loaded: "+g),f(null,a)},error:function(a,b,c){S.log("failed loading: "+g),f("failed loading resource.json error: "+c)},dataType:"json",async:b.getAsync})}}else{var h,i=d.namespaces.length*a.length;S.each(d.namespaces,function(d,f){S.each(a,function(a,d){var g=function(a,b){a&&(h=h||[],h.push(a)),e[d]=e[d]||{},e[d][f]=b,i--,0===i&&c(h,e)};"function"==typeof b.customLoad?b.customLoad(d,f,b,g):N._fetchOne(d,f,b,g)})})}},_fetchOne:function(a,b,c,d){var e=u(c.resGetPath,{lng:a,ns:b});S.ajax({url:e,success:function(a){S.log("loaded: "+e),d(null,a)},error:function(a,b,c){if(b&&200==b||a&&a.status&&200==a.status)S.error("There is a typo in: "+e);else if(b&&404==b||a&&a.status&&404==a.status)S.log("Does not exist: "+e);else{var f=b?b:a&&a.status?a.status:null;S.log(f+" when loading "+e)}d(c,{})},dataType:"json",async:c.getAsync})},postMissing:function(a,b,c,d,e){var f={};f[c]=d;var g=[];if("fallback"===O.sendMissingTo&&O.fallbackLng[0]!==!1)for(var h=0;hh;h++)g.push({lng:e[h],url:u(O.resPostPath,{lng:e[h],ns:b})});for(var j=0,k=g.length;k>j;j++){var l=g[j];S.ajax({url:l.url,type:O.sendType,data:f,success:function(){S.log("posted missing key '"+c+"' to: "+l.url);for(var a=c.split("."),e=0,f=J[l.lng][b];a[e];)f=f[a[e]]=e===a.length-1?d:f[a[e]]||{},e++},error:function(){S.log("failed posting missing key '"+c+"' to: "+l.url)},dataType:"json",async:O.postAsync})}},reload:s};var O={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:["dev"],fallbackNS:[],detectLngQS:"setLng",detectLngFromLocalStorage:!1,ns:"translation",fallbackOnNull:!0,fallbackOnEmpty:!1,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",defaultVariables:!1,reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,indefiniteSuffix:"_indefinite",indefiniteNotFound:["indefinite_not_found",Math.random()].join(""),setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",cookieDomain:void 0,objectTreeKeyHandler:void 0,postProcess:void 0,parseMissingKey:void 0,missingKeyHandler:N.postMissing,shortcutFunction:"sprintf"},P={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},Q={create:function(a,b,c,d){var e;if(c){var f=new Date;f.setTime(f.getTime()+60*c*1e3),e="; expires="+f.toGMTString()}else e="";d=d?"domain="+d+";":"",document.cookie=a+"="+b+e+";"+d+"path=/"},read:function(a){for(var b=a+"=",c=document.cookie.split(";"),d=0;d-1){var c=a.split("-");b=O.lowerCaseLng?c[0].toLowerCase()+"-"+c[1].toLowerCase():c[0].toLowerCase()+"-"+c[1].toUpperCase()}else b=O.lowerCaseLng?a.toLowerCase():a;return b}var c=this.log,d=[],e=O.lngWhitelist||!1,f=function(a){!e||e.indexOf(a)>-1?d.push(a):c("rejecting non-whitelisted language: "+a)};if("string"==typeof a&&a.indexOf("-")>-1){var g=a.split("-");"unspecific"!==O.load&&f(b(a)),"current"!==O.load&&f(b(g[this.getCountyIndexOfLng(a)]))}else f(b(a));for(var h=0;h1)},2:function(a){return Number(1!=a)},3:function(){return 0},4:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},5:function(a){return Number(0===a?0:1==a?1:2==a?2:a%100>=3&&10>=a%100?3:a%100>=11?4:5)},6:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)},7:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},8:function(a){return Number(1==a?0:2==a?1:8!=a&&11!=a?2:3)},9:function(a){return Number(a>=2)},10:function(a){return Number(1==a?0:2==a?1:7>a?2:11>a?3:4)},11:function(a){return Number(1==a||11==a?0:2==a||12==a?1:a>2&&20>a?2:3)},12:function(a){return Number(a%10!=1||a%100==11)},13:function(a){return Number(0!==a)},14:function(a){return Number(1==a?0:2==a?1:3==a?2:3)},15:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&(10>a%100||a%100>=20)?1:2)},16:function(a){return Number(a%10==1&&a%100!=11?0:0!==a?1:2)},17:function(a){return Number(1==a||a%10==1?0:1)},18:function(a){return Number(1==a?1:2)},19:function(a){return Number(1==a?0:0===a||a%100>1&&11>a%100?1:a%100>10&&20>a%100?2:3)},20:function(a){return Number(1==a?0:0===a||a%100>0&&20>a%100?1:2)},21:function(a){return Number(a%100==1?1:a%100==2?2:a%100==3||a%100==4?3:0)}},V={rules:function(){var a,b={};for(a=T.length;a--;)b[T[a][0]]={name:T[a][1],numbers:T[a][2],plurals:U[T[a][3]]};return b}(),addRule:function(a,b){V.rules[a]=b},setCurrentLng:function(a){if(!V.currentRule||V.currentRule.lng!==a){var b=a.split("-");V.currentRule={lng:a,rule:V.rules[b[0]]}}},needsPlural:function(a,b){var c,d=a.split("-");return c=V.currentRule&&V.currentRule.lng===a?V.currentRule.rule:V.rules[d[S.getCountyIndexOfLng(a)]],c&&c.numbers.length<=1?!1:1!==this.get(a,b)},get:function(a,b){function c(b,c){var d;if(d=V.currentRule&&V.currentRule.lng===a?V.currentRule.rule:V.rules[b]){var e;e=d.plurals(d.noAbs?c:Math.abs(c));var f=d.numbers[e];return 2===d.numbers.length&&1===d.numbers[0]&&(2===f?f=-1:1===f&&(f=1)),f}return 1===c?"1":"-1"}var d=a.split("-");return c(d[S.getCountyIndexOfLng(a)],b)}},W={},X=function(a,b){W[a]=b},Y=function(){function a(a){return Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}function b(a,b){for(var c=[];b>0;c[--b]=a);return c.join("")}var c=function(){return c.cache.hasOwnProperty(arguments[0])||(c.cache[arguments[0]]=c.parse(arguments[0])),c.format.call(null,c.cache[arguments[0]],arguments)};return c.format=function(c,d){var e,f,g,h,i,j,k,l=1,m=c.length,n="",o=[];for(f=0;m>f;f++)if(n=a(c[f]),"string"===n)o.push(c[f]);else if("array"===n){if(h=c[f],h[2])for(e=d[l],g=0;g=0?"+"+e:e,j=h[4]?"0"==h[4]?"0":h[4].charAt(1):" ",k=h[6]-String(e).length,i=h[6]?b(j,k):"",o.push(h[5]?e+i:i+e)}return o.join("")},c.cache={},c.parse=function(a){for(var b=a,c=[],d=[],e=0;b;){if(null!==(c=/^[^\x25]+/.exec(b)))d.push(c[0]);else if(null!==(c=/^\x25{2}/.exec(b)))d.push("%");else{if(null===(c=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(b)))throw"[sprintf] huh?";if(c[2]){e|=1;var f=[],g=c[2],h=[];if(null===(h=/^([a-z_][a-z_\d]*)/i.exec(g)))throw"[sprintf] huh?";for(f.push(h[1]);""!==(g=g.substring(h[0].length));)if(null!==(h=/^\.([a-z_][a-z_\d]*)/i.exec(g)))f.push(h[1]);else{if(null===(h=/^\[(\d+)\]/.exec(g)))throw"[sprintf] huh?";f.push(h[1])}c[2]=f}else e|=2;if(3===e)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";d.push(c)}b=b.substring(c[0].length)}return d},c}(),Z=function(a,b){return b.unshift(a),Y.apply(null,b)};return X("sprintf",function(a,b,c){return c.sprintf?"[object Array]"===Object.prototype.toString.apply(c.sprintf)?Z(a,c.sprintf):"object"==typeof c.sprintf?Y(a,c.sprintf):a:a}),I.init=f,I.setLng=q,I.preload=g,I.addResourceBundle=h,I.hasResourceBundle=i,I.getResourceBundle=j,I.addResource=l,I.addResources=m,I.removeResourceBundle=k,I.loadNamespace=o,I.loadNamespaces=p,I.setDefaultNamespace=n,I.t=A,I.translate=A,I.exists=z,I.detectLanguage=S.detectLanguage,I.pluralExtensions=V,I.sync=N,I.functions=S,I.lng=r,I.addPostProcessor=X,I.applyReplacement=S.applyReplacement,I.options=O,I}); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd-1.8.1.zip b/libs/i18next/release/i18next.amd-1.8.1.zip new file mode 100644 index 00000000..ba6a891d Binary files /dev/null and b/libs/i18next/release/i18next.amd-1.8.1.zip differ diff --git a/libs/i18next/release/i18next.amd-1.8.2.js b/libs/i18next/release/i18next.amd-1.8.2.js new file mode 100644 index 00000000..a71b1ce5 --- /dev/null +++ b/libs/i18next/release/i18next.amd-1.8.2.js @@ -0,0 +1,2176 @@ +// i18next, v1.8.2 +// Copyright (c)2015 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function (root, factory) { + if (typeof exports === 'object') { + + module.exports = factory(); + + } else if (typeof define === 'function' && define.amd) { + + define([], factory); + + } +}(this, function () { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + // Add string trim for IE8. + if (typeof String.prototype.trim !== 'function') { + String.prototype.trim = function() { + return this.replace(/^\s+|\s+$/g, ''); + } + } + + var $ = undefined + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = [] + , initialized = false + , sync = {}; + + sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = f.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + f.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + if ((status && status == 200) || (xhr && xhr.status && xhr.status == 200)) { + // file loaded but invalid json, stop waste time ! + f.error('There is a typo in: ' + url); + } else if ((status && status == 404) || (xhr && xhr.status && xhr.status == 404)) { + f.log('Does not exist: ' + url); + } else { + var theStatus = status ? status : ((xhr && xhr.status) ? xhr.status : null); + f.log(theStatus + ' when loading ' + url); + } + + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback' && o.fallbackLng[0] !== false) { + for (var i = 0; i < o.fallbackLng.length; i++) { + urls.push({lng: o.fallbackLng[i], url: applyReplacement(o.resPostPath, { lng: o.fallbackLng[i], ns: ns })}); + } + } else if (o.sendMissingTo === 'current' || (o.sendMissingTo === 'fallback' && o.fallbackLng[0] === false) ) { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + }, + + reload: reload + }; + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: ['dev'], + fallbackNS: [], + detectLngQS: 'setLng', + detectLngFromLocalStorage: false, + ns: { + namespaces: ['translation'], + defaultNs: 'translation' + }, + fallbackOnNull: true, + fallbackOnEmpty: false, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + defaultVariables: false, + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + indefiniteSuffix: '_indefinite', + indefiniteNotFound: ['indefinite_not_found', Math.random()].join(''), + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + cookieDomain: undefined, + + objectTreeKeyHandler: undefined, + postProcess: undefined, + parseMissingKey: undefined, + missingKeyHandler: sync.postMissing, + + shortcutFunction: 'sprintf' // or: defaultValue + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _deepExtend(target, source) { + for (var prop in source) + if (prop in target) + _deepExtend(target[prop], source[prop]); + else + target[prop] = source[prop]; + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || Object.prototype.toString.apply(object) !== '[object Array]' || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + try { + return JSON.parse(data) + } catch (e) { + f.error('Can not parse JSON. URL: ' + url); + return {}; + } + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + // file: protocol always gives status code 0, so check for data + if (status === 200 || (status === 0 && data.text())) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes,domain) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + domain = (domain)? "domain="+domain+";" : ""; + document.cookie = name+"="+value+expires+";"+domain+"path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes,domain) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + deepExtend: _deepExtend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : (typeof document !== 'undefined' ? _ajax : function() {}), + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + error: function(str) { + if (typeof console !== "undefined") console.error(str); + }, + getCountyIndexOfLng: function(lng) { + var lng_index = 0; + if (lng === 'nb-NO' || lng === 'nn-NO' || lng === 'nb-no' || lng === 'nn-no') lng_index = 1; + return lng_index; + }, + toLanguages: function(lng) { + var log = this.log; + + function applyCase(l) { + var ret = l; + + if (typeof l === 'string' && l.indexOf('-') > -1) { + var parts = l.split('-'); + + ret = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } else { + ret = o.lowerCaseLng ? l.toLowerCase() : l; + } + + return ret; + } + + var languages = []; + var whitelist = o.lngWhitelist || false; + var addLanguage = function(language){ + //reject langs not whitelisted + if(!whitelist || whitelist.indexOf(language) > -1){ + languages.push(language); + }else{ + log('rejecting non-whitelisted language: ' + language); + } + }; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + if (o.load !== 'unspecific') addLanguage(applyCase(lng)); + if (o.load !== 'current') addLanguage(applyCase(parts[this.getCountyIndexOfLng(lng)])); + } else { + addLanguage(applyCase(lng)); + } + + for (var i = 0; i < o.fallbackLng.length; i++) { + if (languages.indexOf(o.fallbackLng[i]) === -1 && o.fallbackLng[i]) languages.push(applyCase(o.fallbackLng[i])); + } + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + }, + regexReplacementEscape: function(strOrFn) { + if (typeof strOrFn === 'string') { + return strOrFn.replace(/\$/g, "$$$$"); + } else { + return strOrFn; + } + }, + localStorage: { + setItem: function(key, value) { + if (window.localStorage) { + try { + window.localStorage.setItem(key, value); + } catch (e) { + f.log('failed to set value for key "' + key + '" to localStorage.'); + } + } + }, + getItem: function(key, value) { + if (window.localStorage) { + try { + return window.localStorage.getItem(key, value); + } catch (e) { + f.log('failed to get value for key "' + key + '" from localStorage.'); + return undefined; + } + } + } + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + delete o.fixLng; /* passed in each time */ + + // override functions: .log(), .detectLanguage(), etc + if (o.functions) { + delete o.functions; + f.extend(f, options.functions); + } + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // fallback languages + if (typeof o.fallbackLng == 'string' || typeof o.fallbackLng == 'boolean') { + o.fallbackLng = [o.fallbackLng]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + if (o.useCookie && f.cookie.read(o.cookieName) !== currentLng){ //cookie is unset or invalid + f.cookie.create(o.cookieName, currentLng, o.cookieExpirationTime, o.cookieDomain); + } + if (o.detectLngFromLocalStorage && typeof document !== 'undefined' && window.localStorage) { + f.localStorage.setItem('i18next_lng', currentLng); + } + + var lngTranslate = translate; + if (options.fixLng) { + lngTranslate = function(key, options) { + options = options || {}; + options.lng = options.lng || lngTranslate.lng; + return translate(key, options); + }; + lngTranslate.lng = currentLng; + } + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + initialized = true; + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + initialized = true; + + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources, deep) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + if (deep) { + f.deepExtend(resStore[lng][ns], resources); + } else { + f.extend(resStore[lng][ns], resources); + } + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function hasResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + var res = resStore[lng][ns] || {}; + + var hasValues = false; + for(var prop in res) { + if (res.hasOwnProperty(prop)) { + hasValues = true; + } + } + + return hasValues; + } + + function getResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + return f.extend({}, resStore[lng][ns]); + } + + function removeResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = {}; + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function addResource(lng, ns, key, value) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + var keys = key.split(o.keyseparator); + var x = 0; + var node = resStore[lng][ns]; + var origRef = node; + + while (keys[x]) { + if (x == keys.length - 1) + node[keys[x]] = value; + else { + if (node[keys[x]] == null) + node[keys[x]] = {}; + + node = node[keys[x]]; + } + x++; + } + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function addResources(lng, ns, resources) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + for (var m in resources) { + if (typeof resources[m] === 'string') addResource(lng, ns, m, resources[m]); + } + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, options, cb) { + if (typeof options === 'function') { + cb = options; + options = {}; + } else if (!options) { + options = {}; + } + + options.lng = lng; + return init(options, cb); + } + + function lng() { + return currentLng; + } + + function reload(cb) { + resStore = {}; + setLng(currentLng, cb); + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else if (attr === 'prepend') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.prepend($.t(key, optionsToUse)); + } else if (attr === 'append') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.append($.t(key, optionsToUse)); + } else if (attr.indexOf("data-") === 0) { + var dataAttr = attr.substr(("data-").length); + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.data(dataAttr) }, options) : options; + var translated = $.t(key, optionsToUse); + //we change into the data cache + ele.data(dataAttr, translated); + //we change into the dom + ele.attr(attr, translated); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key && typeof key !== 'undefined' && key !== false) key = ele.text() || ele.val(); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + var hash = replacementHash.replace && typeof replacementHash.replace === 'object' ? replacementHash.replace : replacementHash; + f.each(hash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), f.regexReplacementEscape(value)); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(f.escape(value))); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(value)); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + if (index_of_end_of_closing <= index_of_opening) { + f.error('there is an missing closing in following translation value', translated); + return ''; + } + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, f.regexReplacementEscape(translated_token)); + } + return translated; + } + + function hasContext(options) { + return (options.context && (typeof options.context == 'string' || typeof options.context == 'number')); + } + + function needsPlural(options, lng) { + return (options.count !== undefined && typeof options.count != 'string'/* && pluralExtensions.needsPlural(lng, options.count)*/); + } + + function needsIndefiniteArticle(options) { + return (options.indefinite_article !== undefined && typeof options.indefinite_article != 'string' && options.indefinite_article); + } + + function exists(key, options) { + options = options || {}; + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + options = options || {}; + + if (!initialized) { + f.log('i18next not finished initialization. you might have called t function before loading resources finished.') + return options.defaultValue || ''; + }; + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _getDefaultValue(key, options) { + return (options.defaultValue !== undefined) ? options.defaultValue : key; + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(potentialKeys, options) { + if (options && typeof options !== 'object') { + if (o.shortcutFunction === 'sprintf') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else if (o.shortcutFunction === 'defaultValue') { + options = { + defaultValue: options + } + } + } else { + options = options || {}; + } + + if (typeof o.defaultVariables === 'object') { + options = f.extend({}, o.defaultVariables, options); + } + + if (potentialKeys === undefined || potentialKeys === null || potentialKeys === '') return ''; + + if (typeof potentialKeys === 'number') { + potentialKeys = String(potentialKeys); + } + + if (typeof potentialKeys === 'string') { + potentialKeys = [potentialKeys]; + } + + var key = potentialKeys[0]; + + if (potentialKeys.length > 1) { + for (var i = 0; i < potentialKeys.length; i++) { + key = potentialKeys[i]; + if (exists(key, options)) { + break; + } + } + } + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng, options.fallbackLng) : languages + , ns = options.ns || o.ns.defaultNs + , parts; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing && typeof o.missingKeyHandler === 'function') { + if (options.lng) { + o.missingKeyHandler(lngs[0], ns, key, notFound, lngs); + } else { + o.missingKeyHandler(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessorsToApply; + if (typeof o.postProcess === 'string' && o.postProcess !== '') { + postProcessorsToApply = [o.postProcess]; + } else if (typeof o.postProcess === 'array' || typeof o.postProcess === 'object') { + postProcessorsToApply = o.postProcess; + } else { + postProcessorsToApply = []; + } + + if (typeof options.postProcess === 'string' && options.postProcess !== '') { + postProcessorsToApply = postProcessorsToApply.concat([options.postProcess]); + } else if (typeof options.postProcess === 'array' || typeof options.postProcess === 'object') { + postProcessorsToApply = postProcessorsToApply.concat(options.postProcess); + } + + if (found !== undefined && postProcessorsToApply.length) { + postProcessorsToApply.forEach(function(postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + }); + } + + // process notFound if function exists + var splitNotFound = notFound; + if (notFound.indexOf(o.nsseparator) > -1) { + parts = notFound.split(o.nsseparator); + splitNotFound = parts[1]; + } + if (splitNotFound === key && o.parseMissingKey) { + notFound = o.parseMissingKey(notFound); + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessorsToApply.length) { + var val = _getDefaultValue(key, options); + postProcessorsToApply.forEach(function(postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](val, key, options); + } + }); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options) { + options = options || {}; + + var optionWithoutCount, translated + , notFound = _getDefaultValue(key, options) + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + // CI mode + if (lngs[0].toLowerCase() === 'cimode') return notFound; + + // passed in lng + if (options.lngs) lngs = options.lngs; + if (options.lng) { + lngs = f.toLanguages(options.lng, options.fallbackLng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options, lngs[0])) { + optionWithoutCount = f.extend({ lngs: [lngs[0]]}, options); + delete optionWithoutCount.count; + optionWithoutCount._origLng = optionWithoutCount._origLng || optionWithoutCount.lng || lngs[0]; + delete optionWithoutCount.lng; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey; + if (!pluralExtensions.needsPlural(lngs[0], options.count)) { + pluralKey = ns + o.nsseparator + key; + } else { + pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(lngs[0], options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + } + + translated = translate(pluralKey, optionWithoutCount); + + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } else if (lngs.length > 1) { + // remove failed lng + var clone = lngs.slice(); + clone.shift(); + options = f.extend(options, { lngs: clone }); + options._origLng = optionWithoutCount._origLng; + delete options.lng; + // retry with fallbacks + translated = translate(ns + o.nsseparator + key, options); + if (translated != o.pluralNotFound) return translated; + } else { + optionWithoutCount.lng = optionWithoutCount._origLng; + delete optionWithoutCount._origLng; + translated = translate(ns + o.nsseparator + key, optionWithoutCount); + + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); + } + } + + if (needsIndefiniteArticle(options)) { + var optionsWithoutIndef = f.extend({}, options); + delete optionsWithoutIndef.indefinite_article; + optionsWithoutIndef.defaultValue = o.indefiniteNotFound; + // If we don't have a count, we want the indefinite, if we do have a count, and needsPlural is false + var indefiniteKey = ns + o.nsseparator + key + (((options.count && !needsPlural(options, lngs[0])) || !options.count) ? o.indefiniteSuffix : ""); + translated = translate(indefiniteKey, optionsWithoutIndef); + if (translated != o.indefiniteNotFound) { + return translated; + } + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + var valueType = Object.prototype.toString.apply(value); + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (valueType === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + if (o.objectTreeKeyHandler && typeof o.objectTreeKeyHandler == 'function') { + value = o.objectTreeKeyHandler(key, value, l, ns, options); + } else { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned an object instead of string.'; + f.log(value); + } + } else if (valueType !== '[object Number]' && valueType !== '[object Function]' && valueType !== '[object RegExp]') { + var copy = (valueType === '[object Array]') ? [] : {}; // apply child translation on a copy + f.each(value, function(m) { + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + }); + value = copy; + } + } + + if (typeof value === 'string' && value.trim() === '' && o.fallbackOnEmpty === true) + value = undefined; + + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length > 0))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found || (found==="" && o.fallbackOnEmpty === false)) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + options.isFallbackLookup = false; + } + + return found; + } + function detectLanguage() { + var detectedLng; + var whitelist = o.lngWhitelist || []; + var userLngChoices = []; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var params = query.split('&'); + for (var i=0; i 0) { + var key = params[i].substring(0,pos); + if (key == o.detectLngQS) { + userLngChoices.push(params[i].substring(pos+1)); + } + } + } + })(); + } + + // get from cookie + if (o.useCookie && typeof document !== 'undefined') { + var c = f.cookie.read(o.cookieName); + if (c) userLngChoices.push(c); + } + + // get from localStorage + if (o.detectLngFromLocalStorage && typeof window !== 'undefined' && window.localStorage) { + userLngChoices.push(f.localStorage.getItem('i18next_lng')); + } + + // get from navigator + if (typeof navigator !== 'undefined') { + if (navigator.languages) { // chrome only; not an array, so can't use .push.apply instead of iterating + for (var i=0;i -1) { + var parts = lng.split('-'); + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } + + if (whitelist.length === 0 || whitelist.indexOf(lng) > -1) { + detectedLng = lng; + break; + } + } + })(); + + //fallback + if (!detectedLng){ + detectedLng = o.fallbackLng[0]; + } + + return detectedLng; + } + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + + /* [code, name, numbers, pluralsType] */ + var _rules = [ + ["ach", "Acholi", [1,2], 1], + ["af", "Afrikaans",[1,2], 2], + ["ak", "Akan", [1,2], 1], + ["am", "Amharic", [1,2], 1], + ["an", "Aragonese",[1,2], 2], + ["ar", "Arabic", [0,1,2,3,11,100],5], + ["arn", "Mapudungun",[1,2], 1], + ["ast", "Asturian", [1,2], 2], + ["ay", "Aymará", [1], 3], + ["az", "Azerbaijani",[1,2],2], + ["be", "Belarusian",[1,2,5],4], + ["bg", "Bulgarian",[1,2], 2], + ["bn", "Bengali", [1,2], 2], + ["bo", "Tibetan", [1], 3], + ["br", "Breton", [1,2], 1], + ["bs", "Bosnian", [1,2,5],4], + ["ca", "Catalan", [1,2], 2], + ["cgg", "Chiga", [1], 3], + ["cs", "Czech", [1,2,5],6], + ["csb", "Kashubian",[1,2,5],7], + ["cy", "Welsh", [1,2,3,8],8], + ["da", "Danish", [1,2], 2], + ["de", "German", [1,2], 2], + ["dev", "Development Fallback", [1,2], 2], + ["dz", "Dzongkha", [1], 3], + ["el", "Greek", [1,2], 2], + ["en", "English", [1,2], 2], + ["eo", "Esperanto",[1,2], 2], + ["es", "Spanish", [1,2], 2], + ["es_ar","Argentinean Spanish", [1,2], 2], + ["et", "Estonian", [1,2], 2], + ["eu", "Basque", [1,2], 2], + ["fa", "Persian", [1], 3], + ["fi", "Finnish", [1,2], 2], + ["fil", "Filipino", [1,2], 1], + ["fo", "Faroese", [1,2], 2], + ["fr", "French", [1,2], 9], + ["fur", "Friulian", [1,2], 2], + ["fy", "Frisian", [1,2], 2], + ["ga", "Irish", [1,2,3,7,11],10], + ["gd", "Scottish Gaelic",[1,2,3,20],11], + ["gl", "Galician", [1,2], 2], + ["gu", "Gujarati", [1,2], 2], + ["gun", "Gun", [1,2], 1], + ["ha", "Hausa", [1,2], 2], + ["he", "Hebrew", [1,2], 2], + ["hi", "Hindi", [1,2], 2], + ["hr", "Croatian", [1,2,5],4], + ["hu", "Hungarian",[1,2], 2], + ["hy", "Armenian", [1,2], 2], + ["ia", "Interlingua",[1,2],2], + ["id", "Indonesian",[1], 3], + ["is", "Icelandic",[1,2], 12], + ["it", "Italian", [1,2], 2], + ["ja", "Japanese", [1], 3], + ["jbo", "Lojban", [1], 3], + ["jv", "Javanese", [0,1], 13], + ["ka", "Georgian", [1], 3], + ["kk", "Kazakh", [1], 3], + ["km", "Khmer", [1], 3], + ["kn", "Kannada", [1,2], 2], + ["ko", "Korean", [1], 3], + ["ku", "Kurdish", [1,2], 2], + ["kw", "Cornish", [1,2,3,4],14], + ["ky", "Kyrgyz", [1], 3], + ["lb", "Letzeburgesch",[1,2],2], + ["ln", "Lingala", [1,2], 1], + ["lo", "Lao", [1], 3], + ["lt", "Lithuanian",[1,2,10],15], + ["lv", "Latvian", [1,2,0],16], + ["mai", "Maithili", [1,2], 2], + ["mfe", "Mauritian Creole",[1,2],1], + ["mg", "Malagasy", [1,2], 1], + ["mi", "Maori", [1,2], 1], + ["mk", "Macedonian",[1,2],17], + ["ml", "Malayalam",[1,2], 2], + ["mn", "Mongolian",[1,2], 2], + ["mnk", "Mandinka", [0,1,2],18], + ["mr", "Marathi", [1,2], 2], + ["ms", "Malay", [1], 3], + ["mt", "Maltese", [1,2,11,20],19], + ["nah", "Nahuatl", [1,2], 2], + ["nap", "Neapolitan",[1,2], 2], + ["nb", "Norwegian Bokmal",[1,2],2], + ["ne", "Nepali", [1,2], 2], + ["nl", "Dutch", [1,2], 2], + ["nn", "Norwegian Nynorsk",[1,2],2], + ["no", "Norwegian",[1,2], 2], + ["nso", "Northern Sotho",[1,2],2], + ["oc", "Occitan", [1,2], 1], + ["or", "Oriya", [2,1], 2], + ["pa", "Punjabi", [1,2], 2], + ["pap", "Papiamento",[1,2], 2], + ["pl", "Polish", [1,2,5],7], + ["pms", "Piemontese",[1,2], 2], + ["ps", "Pashto", [1,2], 2], + ["pt", "Portuguese",[1,2], 2], + ["pt_br","Brazilian Portuguese",[1,2], 2], + ["rm", "Romansh", [1,2], 2], + ["ro", "Romanian", [1,2,20],20], + ["ru", "Russian", [1,2,5],4], + ["sah", "Yakut", [1], 3], + ["sco", "Scots", [1,2], 2], + ["se", "Northern Sami",[1,2], 2], + ["si", "Sinhala", [1,2], 2], + ["sk", "Slovak", [1,2,5],6], + ["sl", "Slovenian",[5,1,2,3],21], + ["so", "Somali", [1,2], 2], + ["son", "Songhay", [1,2], 2], + ["sq", "Albanian", [1,2], 2], + ["sr", "Serbian", [1,2,5],4], + ["su", "Sundanese",[1], 3], + ["sv", "Swedish", [1,2], 2], + ["sw", "Swahili", [1,2], 2], + ["ta", "Tamil", [1,2], 2], + ["te", "Telugu", [1,2], 2], + ["tg", "Tajik", [1,2], 1], + ["th", "Thai", [1], 3], + ["ti", "Tigrinya", [1,2], 1], + ["tk", "Turkmen", [1,2], 2], + ["tr", "Turkish", [1,2], 1], + ["tt", "Tatar", [1], 3], + ["ug", "Uyghur", [1], 3], + ["uk", "Ukrainian",[1,2,5],4], + ["ur", "Urdu", [1,2], 2], + ["uz", "Uzbek", [1,2], 1], + ["vi", "Vietnamese",[1], 3], + ["wa", "Walloon", [1,2], 1], + ["wo", "Wolof", [1], 3], + ["yo", "Yoruba", [1,2], 2], + ["zh", "Chinese", [1], 3] + ]; + + var _rulesPluralsTypes = { + 1: function(n) {return Number(n > 1);}, + 2: function(n) {return Number(n != 1);}, + 3: function(n) {return 0;}, + 4: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 5: function(n) {return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5);}, + 6: function(n) {return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2);}, + 7: function(n) {return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 8: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3);}, + 9: function(n) {return Number(n >= 2);}, + 10: function(n) {return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;}, + 11: function(n) {return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3);}, + 12: function(n) {return Number(n%10!=1 || n%100==11);}, + 13: function(n) {return Number(n !== 0);}, + 14: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3);}, + 15: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 16: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2);}, + 17: function(n) {return Number(n==1 || n%10==1 ? 0 : 1);}, + 18: function(n) {return Number(0 ? 0 : n==1 ? 1 : 2);}, + 19: function(n) {return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3);}, + 20: function(n) {return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2);}, + 21: function(n) {return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }; + + var pluralExtensions = { + + rules: (function () { + var l, rules = {}; + for (l=_rules.length; l-- ;) { + rules[_rules[l][0]] = { + name: _rules[l][1], + numbers: _rules[l][2], + plurals: _rulesPluralsTypes[_rules[l][3]] + } + } + return rules; + }()), + + // you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + needsPlural: function(lng, count) { + var parts = lng.split('-'); + + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[parts[f.getCountyIndexOfLng(lng)]]; + } + + if (ext && ext.numbers.length <= 1) { + return false; + } else { + return this.get(lng, count) !== 1; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i; + if (ext.noAbs) { + i = ext.plurals(c); + } else { + i = ext.plurals(Math.abs(c)); + } + + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[f.getCountyIndexOfLng(lng)], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.hasResourceBundle = hasResourceBundle; + i18n.getResourceBundle = getResourceBundle; + i18n.addResource = addResource; + i18n.addResources = addResources; + i18n.removeResourceBundle = removeResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.applyReplacement = f.applyReplacement; + i18n.options = o; + + return i18n; + +})); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd-1.8.2.min.js b/libs/i18next/release/i18next.amd-1.8.2.min.js new file mode 100644 index 00000000..e91e2051 --- /dev/null +++ b/libs/i18next/release/i18next.amd-1.8.2.min.js @@ -0,0 +1,5 @@ +// i18next, v1.8.2 +// Copyright (c)2015 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +!function(a,b){"object"==typeof exports?module.exports=b():"function"==typeof define&&define.amd&&define([],b)}(this,function(){function a(a,b){if(!b||"function"==typeof b)return a;for(var c in b)a[c]=b[c];return a}function b(a,c){for(var d in c)d in a?b(a[d],c[d]):a[d]=c[d];return a}function c(a,b,c){var d,e=0,f=a.length,g=void 0===f||"[object Array]"!==Object.prototype.toString.apply(a)||"function"==typeof a;if(c)if(g){for(d in a)if(b.apply(a[d],c)===!1)break}else for(;f>e&&b.apply(a[e++],c)!==!1;);else if(g){for(d in a)if(b.call(a[d],d,a[d])===!1)break}else for(;f>e&&b.call(a[e],e,a[e++])!==!1;);return a}function d(a){return"string"==typeof a?a.replace(/[&<>"'\/]/g,function(a){return P[a]}):a}function e(a){var b=function(a){if(window.XMLHttpRequest)return a(null,new XMLHttpRequest);if(window.ActiveXObject)try{return a(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(b){return a(null,new ActiveXObject("Microsoft.XMLHTTP"))}return a(new Error)},c=function(a){if("string"==typeof a)return a;var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")},d=function(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;cd?b+=String.fromCharCode(d):d>127&&2048>d?(b+=String.fromCharCode(d>>6|192),b+=String.fromCharCode(63&d|128)):(b+=String.fromCharCode(d>>12|224),b+=String.fromCharCode(d>>6&63|128),b+=String.fromCharCode(63&d|128))}return b},e=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";a=d(a);var c,e,f,g,h,i,j,k="",l=0;do c=a.charCodeAt(l++),e=a.charCodeAt(l++),f=a.charCodeAt(l++),g=c>>2,h=(3&c)<<4|e>>4,i=(15&e)<<2|f>>6,j=63&f,isNaN(e)?i=j=64:isNaN(f)&&(j=64),k+=b.charAt(g)+b.charAt(h)+b.charAt(i)+b.charAt(j),c=e=f="",g=h=i=j="";while(l1&&(d+=d.indexOf("?")>-1?"&"+k:"?"+k),e.jsonp){var l=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=d,void l.appendChild(m)}}b(function(b,c){if(b)return h(b);c.open(a,d,e.async);for(var f in j)j.hasOwnProperty(f)&&c.setRequestHeader(f,j[f]);c.onreadystatechange=function(){if(4===c.readyState){var a=c.responseText||"";if(!h)return;h(c.status,{text:function(){return a},json:function(){try{return JSON.parse(a)}catch(b){return S.error("Can not parse JSON. URL: "+d),{}}}})}},c.send(i)})},h={authBasic:function(a,b){g.headers.Authorization="Basic "+e(a+":"+b)},connect:function(a,b,c){return g("CONNECT",a,b,c)},del:function(a,b,c){return g("DELETE",a,b,c)},get:function(a,b,c){return g("GET",a,b,c)},head:function(a,b,c){return g("HEAD",a,b,c)},headers:function(a){g.headers=a||{}},isAllowed:function(a,b,c){this.options(a,function(a,d){c(-1!==d.text().indexOf(b))})},options:function(a,b,c){return g("OPTIONS",a,b,c)},patch:function(a,b,c){return g("PATCH",a,b,c)},post:function(a,b,c){return g("POST",a,b,c)},put:function(a,b,c){return g("PUT",a,b,c)},trace:function(a,b,c){return g("TRACE",a,b,c)}},i=a.type?a.type.toLowerCase():"get";h[i](a.url,a,function(b,c){200===b||0===b&&c.text()?a.success(c.json(),b,null):a.error(c.text(),b,null)})}function f(a,b){"function"==typeof a&&(b=a,a={}),a=a||{},S.extend(O,a),delete O.fixLng,O.functions&&(delete O.functions,S.extend(S,a.functions)),"string"==typeof O.ns&&(O.ns={namespaces:[O.ns],defaultNs:O.ns}),"string"==typeof O.fallbackNS&&(O.fallbackNS=[O.fallbackNS]),("string"==typeof O.fallbackLng||"boolean"==typeof O.fallbackLng)&&(O.fallbackLng=[O.fallbackLng]),O.interpolationPrefixEscaped=S.regexEscape(O.interpolationPrefix),O.interpolationSuffixEscaped=S.regexEscape(O.interpolationSuffix),O.lng||(O.lng=S.detectLanguage()),L=S.toLanguages(O.lng),G=L[0],S.log("currentLng set to: "+G),O.useCookie&&S.cookie.read(O.cookieName)!==G&&S.cookie.create(O.cookieName,G,O.cookieExpirationTime,O.cookieDomain),O.detectLngFromLocalStorage&&"undefined"!=typeof document&&window.localStorage&&S.localStorage.setItem("i18next_lng",G);var c=A;a.fixLng&&(c=function(a,b){return b=b||{},b.lng=b.lng||c.lng,A(a,b)},c.lng=G),V.setCurrentLng(G),H&&O.setJqueryExt&&t();var d;if(H&&H.Deferred&&(d=H.Deferred()),!O.resStore){var e=S.toLanguages(O.lng);"string"==typeof O.preload&&(O.preload=[O.preload]);for(var f=0,g=O.preload.length;g>f;f++)for(var h=S.toLanguages(O.preload[f]),i=0,j=h.length;j>i;i++)e.indexOf(h[i])<0&&e.push(h[i]);return I.sync.load(e,O,function(a,e){J=e,M=!0,b&&b(c),d&&d.resolve(c)}),d?d.promise():void 0}return J=O.resStore,M=!0,b&&b(c),d&&d.resolve(c),d?d.promise():void 0}function g(a,b){"string"==typeof a&&(a=[a]);for(var c=0,d=a.length;d>c;c++)O.preload.indexOf(a[c])<0&&O.preload.push(a[c]);return f(b)}function h(a,b,c,d){"string"!=typeof b?(c=b,b=O.ns.defaultNs):O.ns.namespaces.indexOf(b)<0&&O.ns.namespaces.push(b),J[a]=J[a]||{},J[a][b]=J[a][b]||{},d?S.deepExtend(J[a][b],c):S.extend(J[a][b],c),O.useLocalStorage&&N._storeLocal(J)}function i(a,b){"string"!=typeof b&&(b=O.ns.defaultNs),J[a]=J[a]||{};var c=J[a][b]||{},d=!1;for(var e in c)c.hasOwnProperty(e)&&(d=!0);return d}function j(a,b){return"string"!=typeof b&&(b=O.ns.defaultNs),J[a]=J[a]||{},S.extend({},J[a][b])}function k(a,b){"string"!=typeof b&&(b=O.ns.defaultNs),J[a]=J[a]||{},J[a][b]={},O.useLocalStorage&&N._storeLocal(J)}function l(a,b,c,d){"string"!=typeof b?(resource=b,b=O.ns.defaultNs):O.ns.namespaces.indexOf(b)<0&&O.ns.namespaces.push(b),J[a]=J[a]||{},J[a][b]=J[a][b]||{};for(var e=c.split(O.keyseparator),f=0,g=J[a][b];e[f];)f==e.length-1?g[e[f]]=d:(null==g[e[f]]&&(g[e[f]]={}),g=g[e[f]]),f++;O.useLocalStorage&&N._storeLocal(J)}function m(a,b,c){"string"!=typeof b?(resource=b,b=O.ns.defaultNs):O.ns.namespaces.indexOf(b)<0&&O.ns.namespaces.push(b);for(var d in c)"string"==typeof c[d]&&l(a,b,d,c[d])}function n(a){O.ns.defaultNs=a}function o(a,b){p([a],b)}function p(a,b){var c={dynamicLoad:O.dynamicLoad,resGetPath:O.resGetPath,getAsync:O.getAsync,customLoad:O.customLoad,ns:{namespaces:a,defaultNs:""}},d=S.toLanguages(O.lng);"string"==typeof O.preload&&(O.preload=[O.preload]);for(var e=0,f=O.preload.length;f>e;e++)for(var g=S.toLanguages(O.preload[e]),h=0,i=g.length;i>h;h++)d.indexOf(g[h])<0&&d.push(g[h]);for(var j=[],k=0,l=d.length;l>k;k++){var m=!1,n=J[d[k]];if(n)for(var o=0,p=a.length;p>o;o++)n[a[o]]||(m=!0);else m=!0;m&&j.push(d[k])}j.length?I.sync._fetch(j,c,function(c,d){var e=a.length*j.length;S.each(a,function(a,c){O.ns.namespaces.indexOf(c)<0&&O.ns.namespaces.push(c),S.each(j,function(a,f){J[f]=J[f]||{},J[f][c]=d[f][c],e--,0===e&&b&&(O.useLocalStorage&&I.sync._storeLocal(J),b())})})}):b&&b()}function q(a,b,c){return"function"==typeof b?(c=b,b={}):b||(b={}),b.lng=a,f(b,c)}function r(){return G}function s(a){J={},q(G,a)}function t(){function a(a,b,c){if(0!==b.length){var d="text";if(0===b.indexOf("[")){var e=b.split("]");b=e[1],d=e[0].substr(1,e[0].length-1)}b.indexOf(";")===b.length-1&&(b=b.substr(0,b.length-2));var f;if("html"===d)f=O.defaultValueFromContent?H.extend({defaultValue:a.html()},c):c,a.html(H.t(b,f));else if("text"===d)f=O.defaultValueFromContent?H.extend({defaultValue:a.text()},c):c,a.text(H.t(b,f));else if("prepend"===d)f=O.defaultValueFromContent?H.extend({defaultValue:a.html()},c):c,a.prepend(H.t(b,f));else if("append"===d)f=O.defaultValueFromContent?H.extend({defaultValue:a.html()},c):c,a.append(H.t(b,f));else if(0===d.indexOf("data-")){var g=d.substr("data-".length);f=O.defaultValueFromContent?H.extend({defaultValue:a.data(g)},c):c;var h=H.t(b,f);a.data(g,h),a.attr(d,h)}else f=O.defaultValueFromContent?H.extend({defaultValue:a.attr(d)},c):c,a.attr(d,H.t(b,f))}}function b(b,c){var d=b.attr(O.selectorAttr);if(d||"undefined"==typeof d||d===!1||(d=b.text()||b.val()),d){var e=b,f=b.data("i18n-target");if(f&&(e=b.find(f)||b),c||O.useDataAttrOptions!==!0||(c=b.data("i18n-options")),c=c||{},d.indexOf(";")>=0){var g=d.split(";");H.each(g,function(b,d){""!==d&&a(e,d,c)})}else a(e,d,c);O.useDataAttrOptions===!0&&b.data("i18n-options",c)}}H.t=H.t||A,H.fn.i18n=function(a){return this.each(function(){b(H(this),a);var c=H(this).find("["+O.selectorAttr+"]");c.each(function(){b(H(this),a)})})}}function u(a,b,c,d){if(!a)return a;if(d=d||b,a.indexOf(d.interpolationPrefix||O.interpolationPrefix)<0)return a;var e=d.interpolationPrefix?S.regexEscape(d.interpolationPrefix):O.interpolationPrefixEscaped,f=d.interpolationSuffix?S.regexEscape(d.interpolationSuffix):O.interpolationSuffixEscaped,g="HTML"+f,h=b.replace&&"object"==typeof b.replace?b.replace:b;return S.each(h,function(b,h){var i=c?c+O.keyseparator+b:b;"object"==typeof h&&null!==h?a=u(a,h,i,d):d.escapeInterpolation||O.escapeInterpolation?(a=a.replace(new RegExp([e,i,g].join(""),"g"),S.regexReplacementEscape(h)),a=a.replace(new RegExp([e,i,f].join(""),"g"),S.regexReplacementEscape(S.escape(h)))):a=a.replace(new RegExp([e,i,f].join(""),"g"),S.regexReplacementEscape(h))}),a}function v(a,b){var c=",",d="{",e="}",f=S.extend({},b);for(delete f.postProcess;-1!=a.indexOf(O.reusePrefix)&&(K++,!(K>O.maxRecursion));){var g=a.lastIndexOf(O.reusePrefix),h=a.indexOf(O.reuseSuffix,g)+O.reuseSuffix.length,i=a.substring(g,h),j=i.replace(O.reusePrefix,"").replace(O.reuseSuffix,"");if(g>=h)return S.error("there is an missing closing in following translation value",a),"";if(-1!=j.indexOf(c)){var k=j.indexOf(c);if(-1!=j.indexOf(d,k)&&-1!=j.indexOf(e,k)){var l=j.indexOf(d,k),m=j.indexOf(e,l)+e.length;try{f=S.extend(f,JSON.parse(j.substring(l,m))),j=j.substring(0,k)}catch(n){}}}var o=D(j,f);a=a.replace(i,S.regexReplacementEscape(o))}return a}function w(a){return a.context&&("string"==typeof a.context||"number"==typeof a.context)}function x(a){return void 0!==a.count&&"string"!=typeof a.count}function y(a){return void 0!==a.indefinite_article&&"string"!=typeof a.indefinite_article&&a.indefinite_article}function z(a,b){b=b||{};var c=B(a,b),d=E(a,b);return void 0!==d||d===c}function A(a,b){return b=b||{},M?(K=0,D.apply(null,arguments)):(S.log("i18next not finished initialization. you might have called t function before loading resources finished."),b.defaultValue||"")}function B(a,b){return void 0!==b.defaultValue?b.defaultValue:a}function C(){for(var a=[],b=1;b1)for(var d=0;d-1&&(e=c.split(O.nsseparator),i=e[0],c=e[1]),void 0===g&&O.sendMissing&&"function"==typeof O.missingKeyHandler&&(b.lng?O.missingKeyHandler(h[0],i,c,f,h):O.missingKeyHandler(O.lng,i,c,f,h));var j;j="string"==typeof O.postProcess&&""!==O.postProcess?[O.postProcess]:"array"==typeof O.postProcess||"object"==typeof O.postProcess?O.postProcess:[],"string"==typeof b.postProcess&&""!==b.postProcess?j=j.concat([b.postProcess]):("array"==typeof b.postProcess||"object"==typeof b.postProcess)&&(j=j.concat(b.postProcess)),void 0!==g&&j.length&&j.forEach(function(a){W[a]&&(g=W[a](g,c,b))});var k=f;if(f.indexOf(O.nsseparator)>-1&&(e=f.split(O.nsseparator),k=e[1]),k===c&&O.parseMissingKey&&(f=O.parseMissingKey(f)),void 0===g&&(f=u(f,b),f=v(f,b),j.length)){var l=B(c,b);j.forEach(function(a){W[a]&&(g=W[a](l,c,b))})}return void 0!==g?g:f}function E(a,b){b=b||{};var c,d,e=B(a,b),f=L;if(!J)return e;if("cimode"===f[0].toLowerCase())return e;if(b.lngs&&(f=b.lngs),b.lng&&(f=S.toLanguages(b.lng,b.fallbackLng),!J[f[0]])){var g=O.getAsync;O.getAsync=!1,I.sync.load(f,O,function(a,b){S.extend(J,b),O.getAsync=g})}var h=b.ns||O.ns.defaultNs;if(a.indexOf(O.nsseparator)>-1){var i=a.split(O.nsseparator);h=i[0],a=i[1]}if(w(b)){c=S.extend({},b),delete c.context,c.defaultValue=O.contextNotFound;var j=h+O.nsseparator+a+"_"+b.context;if(d=A(j,c),d!=O.contextNotFound)return u(d,{context:b.context})}if(x(b,f[0])){c=S.extend({lngs:[f[0]]},b),delete c.count,c._origLng=c._origLng||c.lng||f[0],delete c.lng,c.defaultValue=O.pluralNotFound;var k;if(V.needsPlural(f[0],b.count)){k=h+O.nsseparator+a+O.pluralSuffix;var l=V.get(f[0],b.count);l>=0?k=k+"_"+l:1===l&&(k=h+O.nsseparator+a)}else k=h+O.nsseparator+a;if(d=A(k,c),d!=O.pluralNotFound)return u(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix});if(!(f.length>1))return c.lng=c._origLng,delete c._origLng,d=A(h+O.nsseparator+a,c),u(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix});var m=f.slice();if(m.shift(),b=S.extend(b,{lngs:m}),b._origLng=c._origLng,delete b.lng,d=A(h+O.nsseparator+a,b),d!=O.pluralNotFound)return d}if(y(b)){var n=S.extend({},b);delete n.indefinite_article,n.defaultValue=O.indefiniteNotFound;var o=h+O.nsseparator+a+(b.count&&!x(b,f[0])||!b.count?O.indefiniteSuffix:"");if(d=A(o,n),d!=O.indefiniteNotFound)return d}for(var p,q=a.split(O.keyseparator),r=0,s=f.length;s>r&&void 0===p;r++){for(var t=f[r],z=0,C=J[t]&&J[t][h];q[z];)C=C&&C[q[z]],z++;if(void 0!==C){var F=Object.prototype.toString.apply(C);if("string"==typeof C)C=u(C,b),C=v(C,b);else if("[object Array]"!==F||O.returnObjectTrees||b.returnObjectTrees){if(null===C&&O.fallbackOnNull===!0)C=void 0;else if(null!==C)if(O.returnObjectTrees||b.returnObjectTrees){if("[object Number]"!==F&&"[object Function]"!==F&&"[object RegExp]"!==F){var G="[object Array]"===F?[]:{};S.each(C,function(c){G[c]=D(h+O.nsseparator+a+O.keyseparator+c,b)}),C=G}}else O.objectTreeKeyHandler&&"function"==typeof O.objectTreeKeyHandler?C=O.objectTreeKeyHandler(a,C,t,h,b):(C="key '"+h+":"+a+" ("+t+")' returned an object instead of string.",S.log(C))}else C=C.join("\n"),C=u(C,b),C=v(C,b);"string"==typeof C&&""===C.trim()&&O.fallbackOnEmpty===!0&&(C=void 0),p=C}}if(void 0===p&&!b.isFallbackLookup&&(O.fallbackToDefaultNS===!0||O.fallbackNS&&O.fallbackNS.length>0)){if(b.isFallbackLookup=!0,O.fallbackNS.length){for(var H=0,K=O.fallbackNS.length;K>H;H++)if(p=E(O.fallbackNS[H]+O.nsseparator+a,b),p||""===p&&O.fallbackOnEmpty===!1){var M=p.indexOf(O.nsseparator)>-1?p.split(O.nsseparator)[1]:p,N=e.indexOf(O.nsseparator)>-1?e.split(O.nsseparator)[1]:e;if(M!==N)break}}else p=E(a,b);b.isFallbackLookup=!1}return p}function F(){var a,b=O.lngWhitelist||[],c=[];if("undefined"!=typeof window&&!function(){for(var a=window.location.search.substring(1),b=a.split("&"),d=0;d0){var f=b[d].substring(0,e);f==O.detectLngQS&&c.push(b[d].substring(e+1))}}}(),O.useCookie&&"undefined"!=typeof document){var d=S.cookie.read(O.cookieName);d&&c.push(d)}if(O.detectLngFromLocalStorage&&"undefined"!=typeof window&&window.localStorage&&c.push(S.localStorage.getItem("i18next_lng")),"undefined"!=typeof navigator){if(navigator.languages)for(var e=0;e-1){var f=e.split("-");e=O.lowerCaseLng?f[0].toLowerCase()+"-"+f[1].toLowerCase():f[0].toLowerCase()+"-"+f[1].toUpperCase()}if(0===b.length||b.indexOf(e)>-1){a=e;break}}}(),a||(a=O.fallbackLng[0]),a}Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>0&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=c;arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d))));for(var e=d>=0?Math.min(d,c-1):c-Math.abs(d);e>=0;e--)if(e in b&&b[e]===a)return e;return-1}),"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")});var G,H=void 0,I={},J={},K=0,L=[],M=!1,N={};N={load:function(a,b,c){b.useLocalStorage?N._loadLocal(a,b,function(d,e){for(var f=[],g=0,h=a.length;h>g;g++)e[a[g]]||f.push(a[g]);f.length>0?N._fetch(f,b,function(a,b){S.extend(e,b),N._storeLocal(b),c(null,e)}):c(null,e)}):N._fetch(a,b,function(a,b){c(null,b)})},_loadLocal:function(a,b,c){var d={},e=(new Date).getTime();if(window.localStorage){var f=a.length;S.each(a,function(a,g){var h=S.localStorage.getItem("res_"+g);h&&(h=JSON.parse(h),h.i18nStamp&&h.i18nStamp+b.localStorageExpirationTime>e&&(d[g]=h)),f--,0===f&&c(null,d)})}},_storeLocal:function(a){if(window.localStorage)for(var b in a)a[b].i18nStamp=(new Date).getTime(),S.localStorage.setItem("res_"+b,JSON.stringify(a[b]))},_fetch:function(a,b,c){var d=b.ns,e={};if(b.dynamicLoad){var f=function(a,b){c(null,b)};if("function"==typeof b.customLoad)b.customLoad(a,d.namespaces,b,f);else{var g=u(b.resGetPath,{lng:a.join("+"),ns:d.namespaces.join("+")});S.ajax({url:g,success:function(a){S.log("loaded: "+g),f(null,a)},error:function(a,b,c){S.log("failed loading: "+g),f("failed loading resource.json error: "+c)},dataType:"json",async:b.getAsync})}}else{var h,i=d.namespaces.length*a.length;S.each(d.namespaces,function(d,f){S.each(a,function(a,d){var g=function(a,b){a&&(h=h||[],h.push(a)),e[d]=e[d]||{},e[d][f]=b,i--,0===i&&c(h,e)};"function"==typeof b.customLoad?b.customLoad(d,f,b,g):N._fetchOne(d,f,b,g)})})}},_fetchOne:function(a,b,c,d){var e=u(c.resGetPath,{lng:a,ns:b});S.ajax({url:e,success:function(a){S.log("loaded: "+e),d(null,a)},error:function(a,b,c){if(b&&200==b||a&&a.status&&200==a.status)S.error("There is a typo in: "+e);else if(b&&404==b||a&&a.status&&404==a.status)S.log("Does not exist: "+e);else{var f=b?b:a&&a.status?a.status:null;S.log(f+" when loading "+e)}d(c,{})},dataType:"json",async:c.getAsync})},postMissing:function(a,b,c,d,e){var f={};f[c]=d;var g=[];if("fallback"===O.sendMissingTo&&O.fallbackLng[0]!==!1)for(var h=0;hh;h++)g.push({lng:e[h],url:u(O.resPostPath,{lng:e[h],ns:b})});for(var j=0,k=g.length;k>j;j++){var l=g[j];S.ajax({url:l.url,type:O.sendType,data:f,success:function(){S.log("posted missing key '"+c+"' to: "+l.url);for(var a=c.split("."),e=0,f=J[l.lng][b];a[e];)f=f[a[e]]=e===a.length-1?d:f[a[e]]||{},e++},error:function(){S.log("failed posting missing key '"+c+"' to: "+l.url)},dataType:"json",async:O.postAsync})}},reload:s};var O={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:["dev"],fallbackNS:[],detectLngQS:"setLng",detectLngFromLocalStorage:!1,ns:{namespaces:["translation"],defaultNs:"translation"},fallbackOnNull:!0,fallbackOnEmpty:!1,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",defaultVariables:!1,reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,indefiniteSuffix:"_indefinite",indefiniteNotFound:["indefinite_not_found",Math.random()].join(""),setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",cookieDomain:void 0,objectTreeKeyHandler:void 0,postProcess:void 0,parseMissingKey:void 0,missingKeyHandler:N.postMissing,shortcutFunction:"sprintf"},P={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},Q={create:function(a,b,c,d){var e;if(c){var f=new Date;f.setTime(f.getTime()+60*c*1e3),e="; expires="+f.toGMTString()}else e="";d=d?"domain="+d+";":"",document.cookie=a+"="+b+e+";"+d+"path=/"},read:function(a){for(var b=a+"=",c=document.cookie.split(";"),d=0;d-1){var c=a.split("-");b=O.lowerCaseLng?c[0].toLowerCase()+"-"+c[1].toLowerCase():c[0].toLowerCase()+"-"+c[1].toUpperCase()}else b=O.lowerCaseLng?a.toLowerCase():a;return b}var c=this.log,d=[],e=O.lngWhitelist||!1,f=function(a){!e||e.indexOf(a)>-1?d.push(a):c("rejecting non-whitelisted language: "+a)};if("string"==typeof a&&a.indexOf("-")>-1){var g=a.split("-");"unspecific"!==O.load&&f(b(a)),"current"!==O.load&&f(b(g[this.getCountyIndexOfLng(a)]))}else f(b(a));for(var h=0;h1)},2:function(a){return Number(1!=a)},3:function(){return 0},4:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},5:function(a){return Number(0===a?0:1==a?1:2==a?2:a%100>=3&&10>=a%100?3:a%100>=11?4:5)},6:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)},7:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},8:function(a){return Number(1==a?0:2==a?1:8!=a&&11!=a?2:3)},9:function(a){return Number(a>=2)},10:function(a){return Number(1==a?0:2==a?1:7>a?2:11>a?3:4)},11:function(a){return Number(1==a||11==a?0:2==a||12==a?1:a>2&&20>a?2:3)},12:function(a){return Number(a%10!=1||a%100==11)},13:function(a){return Number(0!==a)},14:function(a){return Number(1==a?0:2==a?1:3==a?2:3)},15:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&(10>a%100||a%100>=20)?1:2)},16:function(a){return Number(a%10==1&&a%100!=11?0:0!==a?1:2)},17:function(a){return Number(1==a||a%10==1?0:1)},18:function(a){return Number(1==a?1:2)},19:function(a){return Number(1==a?0:0===a||a%100>1&&11>a%100?1:a%100>10&&20>a%100?2:3)},20:function(a){return Number(1==a?0:0===a||a%100>0&&20>a%100?1:2)},21:function(a){return Number(a%100==1?1:a%100==2?2:a%100==3||a%100==4?3:0)}},V={rules:function(){var a,b={};for(a=T.length;a--;)b[T[a][0]]={name:T[a][1],numbers:T[a][2],plurals:U[T[a][3]]};return b}(),addRule:function(a,b){V.rules[a]=b},setCurrentLng:function(a){if(!V.currentRule||V.currentRule.lng!==a){var b=a.split("-");V.currentRule={lng:a,rule:V.rules[b[0]]}}},needsPlural:function(a,b){var c,d=a.split("-");return c=V.currentRule&&V.currentRule.lng===a?V.currentRule.rule:V.rules[d[S.getCountyIndexOfLng(a)]],c&&c.numbers.length<=1?!1:1!==this.get(a,b)},get:function(a,b){function c(b,c){var d;if(d=V.currentRule&&V.currentRule.lng===a?V.currentRule.rule:V.rules[b]){var e;e=d.plurals(d.noAbs?c:Math.abs(c));var f=d.numbers[e];return 2===d.numbers.length&&1===d.numbers[0]&&(2===f?f=-1:1===f&&(f=1)),f}return 1===c?"1":"-1"}var d=a.split("-");return c(d[S.getCountyIndexOfLng(a)],b)}},W={},X=function(a,b){W[a]=b},Y=function(){function a(a){return Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}function b(a,b){for(var c=[];b>0;c[--b]=a);return c.join("")}var c=function(){return c.cache.hasOwnProperty(arguments[0])||(c.cache[arguments[0]]=c.parse(arguments[0])),c.format.call(null,c.cache[arguments[0]],arguments)};return c.format=function(c,d){var e,f,g,h,i,j,k,l=1,m=c.length,n="",o=[];for(f=0;m>f;f++)if(n=a(c[f]),"string"===n)o.push(c[f]);else if("array"===n){if(h=c[f],h[2])for(e=d[l],g=0;g=0?"+"+e:e,j=h[4]?"0"==h[4]?"0":h[4].charAt(1):" ",k=h[6]-String(e).length,i=h[6]?b(j,k):"",o.push(h[5]?e+i:i+e)}return o.join("")},c.cache={},c.parse=function(a){for(var b=a,c=[],d=[],e=0;b;){if(null!==(c=/^[^\x25]+/.exec(b)))d.push(c[0]);else if(null!==(c=/^\x25{2}/.exec(b)))d.push("%");else{if(null===(c=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(b)))throw"[sprintf] huh?";if(c[2]){e|=1;var f=[],g=c[2],h=[];if(null===(h=/^([a-z_][a-z_\d]*)/i.exec(g)))throw"[sprintf] huh?";for(f.push(h[1]);""!==(g=g.substring(h[0].length));)if(null!==(h=/^\.([a-z_][a-z_\d]*)/i.exec(g)))f.push(h[1]);else{if(null===(h=/^\[(\d+)\]/.exec(g)))throw"[sprintf] huh?";f.push(h[1])}c[2]=f}else e|=2;if(3===e)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";d.push(c)}b=b.substring(c[0].length)}return d},c}(),Z=function(a,b){return b.unshift(a),Y.apply(null,b)};return X("sprintf",function(a,b,c){return c.sprintf?"[object Array]"===Object.prototype.toString.apply(c.sprintf)?Z(a,c.sprintf):"object"==typeof c.sprintf?Y(a,c.sprintf):a:a}),I.init=f,I.setLng=q,I.preload=g,I.addResourceBundle=h,I.hasResourceBundle=i,I.getResourceBundle=j,I.addResource=l,I.addResources=m,I.removeResourceBundle=k,I.loadNamespace=o,I.loadNamespaces=p,I.setDefaultNamespace=n,I.t=A,I.translate=A,I.exists=z,I.detectLanguage=S.detectLanguage,I.pluralExtensions=V,I.sync=N,I.functions=S,I.lng=r,I.addPostProcessor=X,I.applyReplacement=S.applyReplacement,I.options=O,I}); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd-1.8.2.zip b/libs/i18next/release/i18next.amd-1.8.2.zip new file mode 100644 index 00000000..b9666ee6 Binary files /dev/null and b/libs/i18next/release/i18next.amd-1.8.2.zip differ diff --git a/libs/i18next/release/i18next.amd-latest.js b/libs/i18next/release/i18next.amd-latest.js new file mode 100644 index 00000000..a71b1ce5 --- /dev/null +++ b/libs/i18next/release/i18next.amd-latest.js @@ -0,0 +1,2176 @@ +// i18next, v1.8.2 +// Copyright (c)2015 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function (root, factory) { + if (typeof exports === 'object') { + + module.exports = factory(); + + } else if (typeof define === 'function' && define.amd) { + + define([], factory); + + } +}(this, function () { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + // Add string trim for IE8. + if (typeof String.prototype.trim !== 'function') { + String.prototype.trim = function() { + return this.replace(/^\s+|\s+$/g, ''); + } + } + + var $ = undefined + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = [] + , initialized = false + , sync = {}; + + sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = f.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + f.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + if ((status && status == 200) || (xhr && xhr.status && xhr.status == 200)) { + // file loaded but invalid json, stop waste time ! + f.error('There is a typo in: ' + url); + } else if ((status && status == 404) || (xhr && xhr.status && xhr.status == 404)) { + f.log('Does not exist: ' + url); + } else { + var theStatus = status ? status : ((xhr && xhr.status) ? xhr.status : null); + f.log(theStatus + ' when loading ' + url); + } + + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback' && o.fallbackLng[0] !== false) { + for (var i = 0; i < o.fallbackLng.length; i++) { + urls.push({lng: o.fallbackLng[i], url: applyReplacement(o.resPostPath, { lng: o.fallbackLng[i], ns: ns })}); + } + } else if (o.sendMissingTo === 'current' || (o.sendMissingTo === 'fallback' && o.fallbackLng[0] === false) ) { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + }, + + reload: reload + }; + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: ['dev'], + fallbackNS: [], + detectLngQS: 'setLng', + detectLngFromLocalStorage: false, + ns: { + namespaces: ['translation'], + defaultNs: 'translation' + }, + fallbackOnNull: true, + fallbackOnEmpty: false, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + defaultVariables: false, + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + indefiniteSuffix: '_indefinite', + indefiniteNotFound: ['indefinite_not_found', Math.random()].join(''), + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + cookieDomain: undefined, + + objectTreeKeyHandler: undefined, + postProcess: undefined, + parseMissingKey: undefined, + missingKeyHandler: sync.postMissing, + + shortcutFunction: 'sprintf' // or: defaultValue + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _deepExtend(target, source) { + for (var prop in source) + if (prop in target) + _deepExtend(target[prop], source[prop]); + else + target[prop] = source[prop]; + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || Object.prototype.toString.apply(object) !== '[object Array]' || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + try { + return JSON.parse(data) + } catch (e) { + f.error('Can not parse JSON. URL: ' + url); + return {}; + } + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + // file: protocol always gives status code 0, so check for data + if (status === 200 || (status === 0 && data.text())) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes,domain) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + domain = (domain)? "domain="+domain+";" : ""; + document.cookie = name+"="+value+expires+";"+domain+"path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes,domain) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + deepExtend: _deepExtend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : (typeof document !== 'undefined' ? _ajax : function() {}), + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + error: function(str) { + if (typeof console !== "undefined") console.error(str); + }, + getCountyIndexOfLng: function(lng) { + var lng_index = 0; + if (lng === 'nb-NO' || lng === 'nn-NO' || lng === 'nb-no' || lng === 'nn-no') lng_index = 1; + return lng_index; + }, + toLanguages: function(lng) { + var log = this.log; + + function applyCase(l) { + var ret = l; + + if (typeof l === 'string' && l.indexOf('-') > -1) { + var parts = l.split('-'); + + ret = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } else { + ret = o.lowerCaseLng ? l.toLowerCase() : l; + } + + return ret; + } + + var languages = []; + var whitelist = o.lngWhitelist || false; + var addLanguage = function(language){ + //reject langs not whitelisted + if(!whitelist || whitelist.indexOf(language) > -1){ + languages.push(language); + }else{ + log('rejecting non-whitelisted language: ' + language); + } + }; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + if (o.load !== 'unspecific') addLanguage(applyCase(lng)); + if (o.load !== 'current') addLanguage(applyCase(parts[this.getCountyIndexOfLng(lng)])); + } else { + addLanguage(applyCase(lng)); + } + + for (var i = 0; i < o.fallbackLng.length; i++) { + if (languages.indexOf(o.fallbackLng[i]) === -1 && o.fallbackLng[i]) languages.push(applyCase(o.fallbackLng[i])); + } + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + }, + regexReplacementEscape: function(strOrFn) { + if (typeof strOrFn === 'string') { + return strOrFn.replace(/\$/g, "$$$$"); + } else { + return strOrFn; + } + }, + localStorage: { + setItem: function(key, value) { + if (window.localStorage) { + try { + window.localStorage.setItem(key, value); + } catch (e) { + f.log('failed to set value for key "' + key + '" to localStorage.'); + } + } + }, + getItem: function(key, value) { + if (window.localStorage) { + try { + return window.localStorage.getItem(key, value); + } catch (e) { + f.log('failed to get value for key "' + key + '" from localStorage.'); + return undefined; + } + } + } + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + delete o.fixLng; /* passed in each time */ + + // override functions: .log(), .detectLanguage(), etc + if (o.functions) { + delete o.functions; + f.extend(f, options.functions); + } + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // fallback languages + if (typeof o.fallbackLng == 'string' || typeof o.fallbackLng == 'boolean') { + o.fallbackLng = [o.fallbackLng]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + if (o.useCookie && f.cookie.read(o.cookieName) !== currentLng){ //cookie is unset or invalid + f.cookie.create(o.cookieName, currentLng, o.cookieExpirationTime, o.cookieDomain); + } + if (o.detectLngFromLocalStorage && typeof document !== 'undefined' && window.localStorage) { + f.localStorage.setItem('i18next_lng', currentLng); + } + + var lngTranslate = translate; + if (options.fixLng) { + lngTranslate = function(key, options) { + options = options || {}; + options.lng = options.lng || lngTranslate.lng; + return translate(key, options); + }; + lngTranslate.lng = currentLng; + } + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + initialized = true; + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + initialized = true; + + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources, deep) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + if (deep) { + f.deepExtend(resStore[lng][ns], resources); + } else { + f.extend(resStore[lng][ns], resources); + } + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function hasResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + var res = resStore[lng][ns] || {}; + + var hasValues = false; + for(var prop in res) { + if (res.hasOwnProperty(prop)) { + hasValues = true; + } + } + + return hasValues; + } + + function getResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + return f.extend({}, resStore[lng][ns]); + } + + function removeResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = {}; + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function addResource(lng, ns, key, value) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + var keys = key.split(o.keyseparator); + var x = 0; + var node = resStore[lng][ns]; + var origRef = node; + + while (keys[x]) { + if (x == keys.length - 1) + node[keys[x]] = value; + else { + if (node[keys[x]] == null) + node[keys[x]] = {}; + + node = node[keys[x]]; + } + x++; + } + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function addResources(lng, ns, resources) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + for (var m in resources) { + if (typeof resources[m] === 'string') addResource(lng, ns, m, resources[m]); + } + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, options, cb) { + if (typeof options === 'function') { + cb = options; + options = {}; + } else if (!options) { + options = {}; + } + + options.lng = lng; + return init(options, cb); + } + + function lng() { + return currentLng; + } + + function reload(cb) { + resStore = {}; + setLng(currentLng, cb); + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else if (attr === 'prepend') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.prepend($.t(key, optionsToUse)); + } else if (attr === 'append') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.append($.t(key, optionsToUse)); + } else if (attr.indexOf("data-") === 0) { + var dataAttr = attr.substr(("data-").length); + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.data(dataAttr) }, options) : options; + var translated = $.t(key, optionsToUse); + //we change into the data cache + ele.data(dataAttr, translated); + //we change into the dom + ele.attr(attr, translated); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key && typeof key !== 'undefined' && key !== false) key = ele.text() || ele.val(); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + var hash = replacementHash.replace && typeof replacementHash.replace === 'object' ? replacementHash.replace : replacementHash; + f.each(hash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), f.regexReplacementEscape(value)); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(f.escape(value))); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(value)); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + if (index_of_end_of_closing <= index_of_opening) { + f.error('there is an missing closing in following translation value', translated); + return ''; + } + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, f.regexReplacementEscape(translated_token)); + } + return translated; + } + + function hasContext(options) { + return (options.context && (typeof options.context == 'string' || typeof options.context == 'number')); + } + + function needsPlural(options, lng) { + return (options.count !== undefined && typeof options.count != 'string'/* && pluralExtensions.needsPlural(lng, options.count)*/); + } + + function needsIndefiniteArticle(options) { + return (options.indefinite_article !== undefined && typeof options.indefinite_article != 'string' && options.indefinite_article); + } + + function exists(key, options) { + options = options || {}; + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + options = options || {}; + + if (!initialized) { + f.log('i18next not finished initialization. you might have called t function before loading resources finished.') + return options.defaultValue || ''; + }; + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _getDefaultValue(key, options) { + return (options.defaultValue !== undefined) ? options.defaultValue : key; + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(potentialKeys, options) { + if (options && typeof options !== 'object') { + if (o.shortcutFunction === 'sprintf') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else if (o.shortcutFunction === 'defaultValue') { + options = { + defaultValue: options + } + } + } else { + options = options || {}; + } + + if (typeof o.defaultVariables === 'object') { + options = f.extend({}, o.defaultVariables, options); + } + + if (potentialKeys === undefined || potentialKeys === null || potentialKeys === '') return ''; + + if (typeof potentialKeys === 'number') { + potentialKeys = String(potentialKeys); + } + + if (typeof potentialKeys === 'string') { + potentialKeys = [potentialKeys]; + } + + var key = potentialKeys[0]; + + if (potentialKeys.length > 1) { + for (var i = 0; i < potentialKeys.length; i++) { + key = potentialKeys[i]; + if (exists(key, options)) { + break; + } + } + } + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng, options.fallbackLng) : languages + , ns = options.ns || o.ns.defaultNs + , parts; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing && typeof o.missingKeyHandler === 'function') { + if (options.lng) { + o.missingKeyHandler(lngs[0], ns, key, notFound, lngs); + } else { + o.missingKeyHandler(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessorsToApply; + if (typeof o.postProcess === 'string' && o.postProcess !== '') { + postProcessorsToApply = [o.postProcess]; + } else if (typeof o.postProcess === 'array' || typeof o.postProcess === 'object') { + postProcessorsToApply = o.postProcess; + } else { + postProcessorsToApply = []; + } + + if (typeof options.postProcess === 'string' && options.postProcess !== '') { + postProcessorsToApply = postProcessorsToApply.concat([options.postProcess]); + } else if (typeof options.postProcess === 'array' || typeof options.postProcess === 'object') { + postProcessorsToApply = postProcessorsToApply.concat(options.postProcess); + } + + if (found !== undefined && postProcessorsToApply.length) { + postProcessorsToApply.forEach(function(postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + }); + } + + // process notFound if function exists + var splitNotFound = notFound; + if (notFound.indexOf(o.nsseparator) > -1) { + parts = notFound.split(o.nsseparator); + splitNotFound = parts[1]; + } + if (splitNotFound === key && o.parseMissingKey) { + notFound = o.parseMissingKey(notFound); + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessorsToApply.length) { + var val = _getDefaultValue(key, options); + postProcessorsToApply.forEach(function(postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](val, key, options); + } + }); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options) { + options = options || {}; + + var optionWithoutCount, translated + , notFound = _getDefaultValue(key, options) + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + // CI mode + if (lngs[0].toLowerCase() === 'cimode') return notFound; + + // passed in lng + if (options.lngs) lngs = options.lngs; + if (options.lng) { + lngs = f.toLanguages(options.lng, options.fallbackLng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options, lngs[0])) { + optionWithoutCount = f.extend({ lngs: [lngs[0]]}, options); + delete optionWithoutCount.count; + optionWithoutCount._origLng = optionWithoutCount._origLng || optionWithoutCount.lng || lngs[0]; + delete optionWithoutCount.lng; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey; + if (!pluralExtensions.needsPlural(lngs[0], options.count)) { + pluralKey = ns + o.nsseparator + key; + } else { + pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(lngs[0], options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + } + + translated = translate(pluralKey, optionWithoutCount); + + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } else if (lngs.length > 1) { + // remove failed lng + var clone = lngs.slice(); + clone.shift(); + options = f.extend(options, { lngs: clone }); + options._origLng = optionWithoutCount._origLng; + delete options.lng; + // retry with fallbacks + translated = translate(ns + o.nsseparator + key, options); + if (translated != o.pluralNotFound) return translated; + } else { + optionWithoutCount.lng = optionWithoutCount._origLng; + delete optionWithoutCount._origLng; + translated = translate(ns + o.nsseparator + key, optionWithoutCount); + + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); + } + } + + if (needsIndefiniteArticle(options)) { + var optionsWithoutIndef = f.extend({}, options); + delete optionsWithoutIndef.indefinite_article; + optionsWithoutIndef.defaultValue = o.indefiniteNotFound; + // If we don't have a count, we want the indefinite, if we do have a count, and needsPlural is false + var indefiniteKey = ns + o.nsseparator + key + (((options.count && !needsPlural(options, lngs[0])) || !options.count) ? o.indefiniteSuffix : ""); + translated = translate(indefiniteKey, optionsWithoutIndef); + if (translated != o.indefiniteNotFound) { + return translated; + } + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + var valueType = Object.prototype.toString.apply(value); + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (valueType === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + if (o.objectTreeKeyHandler && typeof o.objectTreeKeyHandler == 'function') { + value = o.objectTreeKeyHandler(key, value, l, ns, options); + } else { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned an object instead of string.'; + f.log(value); + } + } else if (valueType !== '[object Number]' && valueType !== '[object Function]' && valueType !== '[object RegExp]') { + var copy = (valueType === '[object Array]') ? [] : {}; // apply child translation on a copy + f.each(value, function(m) { + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + }); + value = copy; + } + } + + if (typeof value === 'string' && value.trim() === '' && o.fallbackOnEmpty === true) + value = undefined; + + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length > 0))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found || (found==="" && o.fallbackOnEmpty === false)) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + options.isFallbackLookup = false; + } + + return found; + } + function detectLanguage() { + var detectedLng; + var whitelist = o.lngWhitelist || []; + var userLngChoices = []; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var params = query.split('&'); + for (var i=0; i 0) { + var key = params[i].substring(0,pos); + if (key == o.detectLngQS) { + userLngChoices.push(params[i].substring(pos+1)); + } + } + } + })(); + } + + // get from cookie + if (o.useCookie && typeof document !== 'undefined') { + var c = f.cookie.read(o.cookieName); + if (c) userLngChoices.push(c); + } + + // get from localStorage + if (o.detectLngFromLocalStorage && typeof window !== 'undefined' && window.localStorage) { + userLngChoices.push(f.localStorage.getItem('i18next_lng')); + } + + // get from navigator + if (typeof navigator !== 'undefined') { + if (navigator.languages) { // chrome only; not an array, so can't use .push.apply instead of iterating + for (var i=0;i -1) { + var parts = lng.split('-'); + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } + + if (whitelist.length === 0 || whitelist.indexOf(lng) > -1) { + detectedLng = lng; + break; + } + } + })(); + + //fallback + if (!detectedLng){ + detectedLng = o.fallbackLng[0]; + } + + return detectedLng; + } + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + + /* [code, name, numbers, pluralsType] */ + var _rules = [ + ["ach", "Acholi", [1,2], 1], + ["af", "Afrikaans",[1,2], 2], + ["ak", "Akan", [1,2], 1], + ["am", "Amharic", [1,2], 1], + ["an", "Aragonese",[1,2], 2], + ["ar", "Arabic", [0,1,2,3,11,100],5], + ["arn", "Mapudungun",[1,2], 1], + ["ast", "Asturian", [1,2], 2], + ["ay", "Aymará", [1], 3], + ["az", "Azerbaijani",[1,2],2], + ["be", "Belarusian",[1,2,5],4], + ["bg", "Bulgarian",[1,2], 2], + ["bn", "Bengali", [1,2], 2], + ["bo", "Tibetan", [1], 3], + ["br", "Breton", [1,2], 1], + ["bs", "Bosnian", [1,2,5],4], + ["ca", "Catalan", [1,2], 2], + ["cgg", "Chiga", [1], 3], + ["cs", "Czech", [1,2,5],6], + ["csb", "Kashubian",[1,2,5],7], + ["cy", "Welsh", [1,2,3,8],8], + ["da", "Danish", [1,2], 2], + ["de", "German", [1,2], 2], + ["dev", "Development Fallback", [1,2], 2], + ["dz", "Dzongkha", [1], 3], + ["el", "Greek", [1,2], 2], + ["en", "English", [1,2], 2], + ["eo", "Esperanto",[1,2], 2], + ["es", "Spanish", [1,2], 2], + ["es_ar","Argentinean Spanish", [1,2], 2], + ["et", "Estonian", [1,2], 2], + ["eu", "Basque", [1,2], 2], + ["fa", "Persian", [1], 3], + ["fi", "Finnish", [1,2], 2], + ["fil", "Filipino", [1,2], 1], + ["fo", "Faroese", [1,2], 2], + ["fr", "French", [1,2], 9], + ["fur", "Friulian", [1,2], 2], + ["fy", "Frisian", [1,2], 2], + ["ga", "Irish", [1,2,3,7,11],10], + ["gd", "Scottish Gaelic",[1,2,3,20],11], + ["gl", "Galician", [1,2], 2], + ["gu", "Gujarati", [1,2], 2], + ["gun", "Gun", [1,2], 1], + ["ha", "Hausa", [1,2], 2], + ["he", "Hebrew", [1,2], 2], + ["hi", "Hindi", [1,2], 2], + ["hr", "Croatian", [1,2,5],4], + ["hu", "Hungarian",[1,2], 2], + ["hy", "Armenian", [1,2], 2], + ["ia", "Interlingua",[1,2],2], + ["id", "Indonesian",[1], 3], + ["is", "Icelandic",[1,2], 12], + ["it", "Italian", [1,2], 2], + ["ja", "Japanese", [1], 3], + ["jbo", "Lojban", [1], 3], + ["jv", "Javanese", [0,1], 13], + ["ka", "Georgian", [1], 3], + ["kk", "Kazakh", [1], 3], + ["km", "Khmer", [1], 3], + ["kn", "Kannada", [1,2], 2], + ["ko", "Korean", [1], 3], + ["ku", "Kurdish", [1,2], 2], + ["kw", "Cornish", [1,2,3,4],14], + ["ky", "Kyrgyz", [1], 3], + ["lb", "Letzeburgesch",[1,2],2], + ["ln", "Lingala", [1,2], 1], + ["lo", "Lao", [1], 3], + ["lt", "Lithuanian",[1,2,10],15], + ["lv", "Latvian", [1,2,0],16], + ["mai", "Maithili", [1,2], 2], + ["mfe", "Mauritian Creole",[1,2],1], + ["mg", "Malagasy", [1,2], 1], + ["mi", "Maori", [1,2], 1], + ["mk", "Macedonian",[1,2],17], + ["ml", "Malayalam",[1,2], 2], + ["mn", "Mongolian",[1,2], 2], + ["mnk", "Mandinka", [0,1,2],18], + ["mr", "Marathi", [1,2], 2], + ["ms", "Malay", [1], 3], + ["mt", "Maltese", [1,2,11,20],19], + ["nah", "Nahuatl", [1,2], 2], + ["nap", "Neapolitan",[1,2], 2], + ["nb", "Norwegian Bokmal",[1,2],2], + ["ne", "Nepali", [1,2], 2], + ["nl", "Dutch", [1,2], 2], + ["nn", "Norwegian Nynorsk",[1,2],2], + ["no", "Norwegian",[1,2], 2], + ["nso", "Northern Sotho",[1,2],2], + ["oc", "Occitan", [1,2], 1], + ["or", "Oriya", [2,1], 2], + ["pa", "Punjabi", [1,2], 2], + ["pap", "Papiamento",[1,2], 2], + ["pl", "Polish", [1,2,5],7], + ["pms", "Piemontese",[1,2], 2], + ["ps", "Pashto", [1,2], 2], + ["pt", "Portuguese",[1,2], 2], + ["pt_br","Brazilian Portuguese",[1,2], 2], + ["rm", "Romansh", [1,2], 2], + ["ro", "Romanian", [1,2,20],20], + ["ru", "Russian", [1,2,5],4], + ["sah", "Yakut", [1], 3], + ["sco", "Scots", [1,2], 2], + ["se", "Northern Sami",[1,2], 2], + ["si", "Sinhala", [1,2], 2], + ["sk", "Slovak", [1,2,5],6], + ["sl", "Slovenian",[5,1,2,3],21], + ["so", "Somali", [1,2], 2], + ["son", "Songhay", [1,2], 2], + ["sq", "Albanian", [1,2], 2], + ["sr", "Serbian", [1,2,5],4], + ["su", "Sundanese",[1], 3], + ["sv", "Swedish", [1,2], 2], + ["sw", "Swahili", [1,2], 2], + ["ta", "Tamil", [1,2], 2], + ["te", "Telugu", [1,2], 2], + ["tg", "Tajik", [1,2], 1], + ["th", "Thai", [1], 3], + ["ti", "Tigrinya", [1,2], 1], + ["tk", "Turkmen", [1,2], 2], + ["tr", "Turkish", [1,2], 1], + ["tt", "Tatar", [1], 3], + ["ug", "Uyghur", [1], 3], + ["uk", "Ukrainian",[1,2,5],4], + ["ur", "Urdu", [1,2], 2], + ["uz", "Uzbek", [1,2], 1], + ["vi", "Vietnamese",[1], 3], + ["wa", "Walloon", [1,2], 1], + ["wo", "Wolof", [1], 3], + ["yo", "Yoruba", [1,2], 2], + ["zh", "Chinese", [1], 3] + ]; + + var _rulesPluralsTypes = { + 1: function(n) {return Number(n > 1);}, + 2: function(n) {return Number(n != 1);}, + 3: function(n) {return 0;}, + 4: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 5: function(n) {return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5);}, + 6: function(n) {return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2);}, + 7: function(n) {return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 8: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3);}, + 9: function(n) {return Number(n >= 2);}, + 10: function(n) {return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;}, + 11: function(n) {return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3);}, + 12: function(n) {return Number(n%10!=1 || n%100==11);}, + 13: function(n) {return Number(n !== 0);}, + 14: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3);}, + 15: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 16: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2);}, + 17: function(n) {return Number(n==1 || n%10==1 ? 0 : 1);}, + 18: function(n) {return Number(0 ? 0 : n==1 ? 1 : 2);}, + 19: function(n) {return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3);}, + 20: function(n) {return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2);}, + 21: function(n) {return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }; + + var pluralExtensions = { + + rules: (function () { + var l, rules = {}; + for (l=_rules.length; l-- ;) { + rules[_rules[l][0]] = { + name: _rules[l][1], + numbers: _rules[l][2], + plurals: _rulesPluralsTypes[_rules[l][3]] + } + } + return rules; + }()), + + // you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + needsPlural: function(lng, count) { + var parts = lng.split('-'); + + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[parts[f.getCountyIndexOfLng(lng)]]; + } + + if (ext && ext.numbers.length <= 1) { + return false; + } else { + return this.get(lng, count) !== 1; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i; + if (ext.noAbs) { + i = ext.plurals(c); + } else { + i = ext.plurals(Math.abs(c)); + } + + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[f.getCountyIndexOfLng(lng)], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.hasResourceBundle = hasResourceBundle; + i18n.getResourceBundle = getResourceBundle; + i18n.addResource = addResource; + i18n.addResources = addResources; + i18n.removeResourceBundle = removeResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.applyReplacement = f.applyReplacement; + i18n.options = o; + + return i18n; + +})); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd-latest.min.js b/libs/i18next/release/i18next.amd-latest.min.js new file mode 100644 index 00000000..e91e2051 --- /dev/null +++ b/libs/i18next/release/i18next.amd-latest.min.js @@ -0,0 +1,5 @@ +// i18next, v1.8.2 +// Copyright (c)2015 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +!function(a,b){"object"==typeof exports?module.exports=b():"function"==typeof define&&define.amd&&define([],b)}(this,function(){function a(a,b){if(!b||"function"==typeof b)return a;for(var c in b)a[c]=b[c];return a}function b(a,c){for(var d in c)d in a?b(a[d],c[d]):a[d]=c[d];return a}function c(a,b,c){var d,e=0,f=a.length,g=void 0===f||"[object Array]"!==Object.prototype.toString.apply(a)||"function"==typeof a;if(c)if(g){for(d in a)if(b.apply(a[d],c)===!1)break}else for(;f>e&&b.apply(a[e++],c)!==!1;);else if(g){for(d in a)if(b.call(a[d],d,a[d])===!1)break}else for(;f>e&&b.call(a[e],e,a[e++])!==!1;);return a}function d(a){return"string"==typeof a?a.replace(/[&<>"'\/]/g,function(a){return P[a]}):a}function e(a){var b=function(a){if(window.XMLHttpRequest)return a(null,new XMLHttpRequest);if(window.ActiveXObject)try{return a(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(b){return a(null,new ActiveXObject("Microsoft.XMLHTTP"))}return a(new Error)},c=function(a){if("string"==typeof a)return a;var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")},d=function(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;cd?b+=String.fromCharCode(d):d>127&&2048>d?(b+=String.fromCharCode(d>>6|192),b+=String.fromCharCode(63&d|128)):(b+=String.fromCharCode(d>>12|224),b+=String.fromCharCode(d>>6&63|128),b+=String.fromCharCode(63&d|128))}return b},e=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";a=d(a);var c,e,f,g,h,i,j,k="",l=0;do c=a.charCodeAt(l++),e=a.charCodeAt(l++),f=a.charCodeAt(l++),g=c>>2,h=(3&c)<<4|e>>4,i=(15&e)<<2|f>>6,j=63&f,isNaN(e)?i=j=64:isNaN(f)&&(j=64),k+=b.charAt(g)+b.charAt(h)+b.charAt(i)+b.charAt(j),c=e=f="",g=h=i=j="";while(l1&&(d+=d.indexOf("?")>-1?"&"+k:"?"+k),e.jsonp){var l=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=d,void l.appendChild(m)}}b(function(b,c){if(b)return h(b);c.open(a,d,e.async);for(var f in j)j.hasOwnProperty(f)&&c.setRequestHeader(f,j[f]);c.onreadystatechange=function(){if(4===c.readyState){var a=c.responseText||"";if(!h)return;h(c.status,{text:function(){return a},json:function(){try{return JSON.parse(a)}catch(b){return S.error("Can not parse JSON. URL: "+d),{}}}})}},c.send(i)})},h={authBasic:function(a,b){g.headers.Authorization="Basic "+e(a+":"+b)},connect:function(a,b,c){return g("CONNECT",a,b,c)},del:function(a,b,c){return g("DELETE",a,b,c)},get:function(a,b,c){return g("GET",a,b,c)},head:function(a,b,c){return g("HEAD",a,b,c)},headers:function(a){g.headers=a||{}},isAllowed:function(a,b,c){this.options(a,function(a,d){c(-1!==d.text().indexOf(b))})},options:function(a,b,c){return g("OPTIONS",a,b,c)},patch:function(a,b,c){return g("PATCH",a,b,c)},post:function(a,b,c){return g("POST",a,b,c)},put:function(a,b,c){return g("PUT",a,b,c)},trace:function(a,b,c){return g("TRACE",a,b,c)}},i=a.type?a.type.toLowerCase():"get";h[i](a.url,a,function(b,c){200===b||0===b&&c.text()?a.success(c.json(),b,null):a.error(c.text(),b,null)})}function f(a,b){"function"==typeof a&&(b=a,a={}),a=a||{},S.extend(O,a),delete O.fixLng,O.functions&&(delete O.functions,S.extend(S,a.functions)),"string"==typeof O.ns&&(O.ns={namespaces:[O.ns],defaultNs:O.ns}),"string"==typeof O.fallbackNS&&(O.fallbackNS=[O.fallbackNS]),("string"==typeof O.fallbackLng||"boolean"==typeof O.fallbackLng)&&(O.fallbackLng=[O.fallbackLng]),O.interpolationPrefixEscaped=S.regexEscape(O.interpolationPrefix),O.interpolationSuffixEscaped=S.regexEscape(O.interpolationSuffix),O.lng||(O.lng=S.detectLanguage()),L=S.toLanguages(O.lng),G=L[0],S.log("currentLng set to: "+G),O.useCookie&&S.cookie.read(O.cookieName)!==G&&S.cookie.create(O.cookieName,G,O.cookieExpirationTime,O.cookieDomain),O.detectLngFromLocalStorage&&"undefined"!=typeof document&&window.localStorage&&S.localStorage.setItem("i18next_lng",G);var c=A;a.fixLng&&(c=function(a,b){return b=b||{},b.lng=b.lng||c.lng,A(a,b)},c.lng=G),V.setCurrentLng(G),H&&O.setJqueryExt&&t();var d;if(H&&H.Deferred&&(d=H.Deferred()),!O.resStore){var e=S.toLanguages(O.lng);"string"==typeof O.preload&&(O.preload=[O.preload]);for(var f=0,g=O.preload.length;g>f;f++)for(var h=S.toLanguages(O.preload[f]),i=0,j=h.length;j>i;i++)e.indexOf(h[i])<0&&e.push(h[i]);return I.sync.load(e,O,function(a,e){J=e,M=!0,b&&b(c),d&&d.resolve(c)}),d?d.promise():void 0}return J=O.resStore,M=!0,b&&b(c),d&&d.resolve(c),d?d.promise():void 0}function g(a,b){"string"==typeof a&&(a=[a]);for(var c=0,d=a.length;d>c;c++)O.preload.indexOf(a[c])<0&&O.preload.push(a[c]);return f(b)}function h(a,b,c,d){"string"!=typeof b?(c=b,b=O.ns.defaultNs):O.ns.namespaces.indexOf(b)<0&&O.ns.namespaces.push(b),J[a]=J[a]||{},J[a][b]=J[a][b]||{},d?S.deepExtend(J[a][b],c):S.extend(J[a][b],c),O.useLocalStorage&&N._storeLocal(J)}function i(a,b){"string"!=typeof b&&(b=O.ns.defaultNs),J[a]=J[a]||{};var c=J[a][b]||{},d=!1;for(var e in c)c.hasOwnProperty(e)&&(d=!0);return d}function j(a,b){return"string"!=typeof b&&(b=O.ns.defaultNs),J[a]=J[a]||{},S.extend({},J[a][b])}function k(a,b){"string"!=typeof b&&(b=O.ns.defaultNs),J[a]=J[a]||{},J[a][b]={},O.useLocalStorage&&N._storeLocal(J)}function l(a,b,c,d){"string"!=typeof b?(resource=b,b=O.ns.defaultNs):O.ns.namespaces.indexOf(b)<0&&O.ns.namespaces.push(b),J[a]=J[a]||{},J[a][b]=J[a][b]||{};for(var e=c.split(O.keyseparator),f=0,g=J[a][b];e[f];)f==e.length-1?g[e[f]]=d:(null==g[e[f]]&&(g[e[f]]={}),g=g[e[f]]),f++;O.useLocalStorage&&N._storeLocal(J)}function m(a,b,c){"string"!=typeof b?(resource=b,b=O.ns.defaultNs):O.ns.namespaces.indexOf(b)<0&&O.ns.namespaces.push(b);for(var d in c)"string"==typeof c[d]&&l(a,b,d,c[d])}function n(a){O.ns.defaultNs=a}function o(a,b){p([a],b)}function p(a,b){var c={dynamicLoad:O.dynamicLoad,resGetPath:O.resGetPath,getAsync:O.getAsync,customLoad:O.customLoad,ns:{namespaces:a,defaultNs:""}},d=S.toLanguages(O.lng);"string"==typeof O.preload&&(O.preload=[O.preload]);for(var e=0,f=O.preload.length;f>e;e++)for(var g=S.toLanguages(O.preload[e]),h=0,i=g.length;i>h;h++)d.indexOf(g[h])<0&&d.push(g[h]);for(var j=[],k=0,l=d.length;l>k;k++){var m=!1,n=J[d[k]];if(n)for(var o=0,p=a.length;p>o;o++)n[a[o]]||(m=!0);else m=!0;m&&j.push(d[k])}j.length?I.sync._fetch(j,c,function(c,d){var e=a.length*j.length;S.each(a,function(a,c){O.ns.namespaces.indexOf(c)<0&&O.ns.namespaces.push(c),S.each(j,function(a,f){J[f]=J[f]||{},J[f][c]=d[f][c],e--,0===e&&b&&(O.useLocalStorage&&I.sync._storeLocal(J),b())})})}):b&&b()}function q(a,b,c){return"function"==typeof b?(c=b,b={}):b||(b={}),b.lng=a,f(b,c)}function r(){return G}function s(a){J={},q(G,a)}function t(){function a(a,b,c){if(0!==b.length){var d="text";if(0===b.indexOf("[")){var e=b.split("]");b=e[1],d=e[0].substr(1,e[0].length-1)}b.indexOf(";")===b.length-1&&(b=b.substr(0,b.length-2));var f;if("html"===d)f=O.defaultValueFromContent?H.extend({defaultValue:a.html()},c):c,a.html(H.t(b,f));else if("text"===d)f=O.defaultValueFromContent?H.extend({defaultValue:a.text()},c):c,a.text(H.t(b,f));else if("prepend"===d)f=O.defaultValueFromContent?H.extend({defaultValue:a.html()},c):c,a.prepend(H.t(b,f));else if("append"===d)f=O.defaultValueFromContent?H.extend({defaultValue:a.html()},c):c,a.append(H.t(b,f));else if(0===d.indexOf("data-")){var g=d.substr("data-".length);f=O.defaultValueFromContent?H.extend({defaultValue:a.data(g)},c):c;var h=H.t(b,f);a.data(g,h),a.attr(d,h)}else f=O.defaultValueFromContent?H.extend({defaultValue:a.attr(d)},c):c,a.attr(d,H.t(b,f))}}function b(b,c){var d=b.attr(O.selectorAttr);if(d||"undefined"==typeof d||d===!1||(d=b.text()||b.val()),d){var e=b,f=b.data("i18n-target");if(f&&(e=b.find(f)||b),c||O.useDataAttrOptions!==!0||(c=b.data("i18n-options")),c=c||{},d.indexOf(";")>=0){var g=d.split(";");H.each(g,function(b,d){""!==d&&a(e,d,c)})}else a(e,d,c);O.useDataAttrOptions===!0&&b.data("i18n-options",c)}}H.t=H.t||A,H.fn.i18n=function(a){return this.each(function(){b(H(this),a);var c=H(this).find("["+O.selectorAttr+"]");c.each(function(){b(H(this),a)})})}}function u(a,b,c,d){if(!a)return a;if(d=d||b,a.indexOf(d.interpolationPrefix||O.interpolationPrefix)<0)return a;var e=d.interpolationPrefix?S.regexEscape(d.interpolationPrefix):O.interpolationPrefixEscaped,f=d.interpolationSuffix?S.regexEscape(d.interpolationSuffix):O.interpolationSuffixEscaped,g="HTML"+f,h=b.replace&&"object"==typeof b.replace?b.replace:b;return S.each(h,function(b,h){var i=c?c+O.keyseparator+b:b;"object"==typeof h&&null!==h?a=u(a,h,i,d):d.escapeInterpolation||O.escapeInterpolation?(a=a.replace(new RegExp([e,i,g].join(""),"g"),S.regexReplacementEscape(h)),a=a.replace(new RegExp([e,i,f].join(""),"g"),S.regexReplacementEscape(S.escape(h)))):a=a.replace(new RegExp([e,i,f].join(""),"g"),S.regexReplacementEscape(h))}),a}function v(a,b){var c=",",d="{",e="}",f=S.extend({},b);for(delete f.postProcess;-1!=a.indexOf(O.reusePrefix)&&(K++,!(K>O.maxRecursion));){var g=a.lastIndexOf(O.reusePrefix),h=a.indexOf(O.reuseSuffix,g)+O.reuseSuffix.length,i=a.substring(g,h),j=i.replace(O.reusePrefix,"").replace(O.reuseSuffix,"");if(g>=h)return S.error("there is an missing closing in following translation value",a),"";if(-1!=j.indexOf(c)){var k=j.indexOf(c);if(-1!=j.indexOf(d,k)&&-1!=j.indexOf(e,k)){var l=j.indexOf(d,k),m=j.indexOf(e,l)+e.length;try{f=S.extend(f,JSON.parse(j.substring(l,m))),j=j.substring(0,k)}catch(n){}}}var o=D(j,f);a=a.replace(i,S.regexReplacementEscape(o))}return a}function w(a){return a.context&&("string"==typeof a.context||"number"==typeof a.context)}function x(a){return void 0!==a.count&&"string"!=typeof a.count}function y(a){return void 0!==a.indefinite_article&&"string"!=typeof a.indefinite_article&&a.indefinite_article}function z(a,b){b=b||{};var c=B(a,b),d=E(a,b);return void 0!==d||d===c}function A(a,b){return b=b||{},M?(K=0,D.apply(null,arguments)):(S.log("i18next not finished initialization. you might have called t function before loading resources finished."),b.defaultValue||"")}function B(a,b){return void 0!==b.defaultValue?b.defaultValue:a}function C(){for(var a=[],b=1;b1)for(var d=0;d-1&&(e=c.split(O.nsseparator),i=e[0],c=e[1]),void 0===g&&O.sendMissing&&"function"==typeof O.missingKeyHandler&&(b.lng?O.missingKeyHandler(h[0],i,c,f,h):O.missingKeyHandler(O.lng,i,c,f,h));var j;j="string"==typeof O.postProcess&&""!==O.postProcess?[O.postProcess]:"array"==typeof O.postProcess||"object"==typeof O.postProcess?O.postProcess:[],"string"==typeof b.postProcess&&""!==b.postProcess?j=j.concat([b.postProcess]):("array"==typeof b.postProcess||"object"==typeof b.postProcess)&&(j=j.concat(b.postProcess)),void 0!==g&&j.length&&j.forEach(function(a){W[a]&&(g=W[a](g,c,b))});var k=f;if(f.indexOf(O.nsseparator)>-1&&(e=f.split(O.nsseparator),k=e[1]),k===c&&O.parseMissingKey&&(f=O.parseMissingKey(f)),void 0===g&&(f=u(f,b),f=v(f,b),j.length)){var l=B(c,b);j.forEach(function(a){W[a]&&(g=W[a](l,c,b))})}return void 0!==g?g:f}function E(a,b){b=b||{};var c,d,e=B(a,b),f=L;if(!J)return e;if("cimode"===f[0].toLowerCase())return e;if(b.lngs&&(f=b.lngs),b.lng&&(f=S.toLanguages(b.lng,b.fallbackLng),!J[f[0]])){var g=O.getAsync;O.getAsync=!1,I.sync.load(f,O,function(a,b){S.extend(J,b),O.getAsync=g})}var h=b.ns||O.ns.defaultNs;if(a.indexOf(O.nsseparator)>-1){var i=a.split(O.nsseparator);h=i[0],a=i[1]}if(w(b)){c=S.extend({},b),delete c.context,c.defaultValue=O.contextNotFound;var j=h+O.nsseparator+a+"_"+b.context;if(d=A(j,c),d!=O.contextNotFound)return u(d,{context:b.context})}if(x(b,f[0])){c=S.extend({lngs:[f[0]]},b),delete c.count,c._origLng=c._origLng||c.lng||f[0],delete c.lng,c.defaultValue=O.pluralNotFound;var k;if(V.needsPlural(f[0],b.count)){k=h+O.nsseparator+a+O.pluralSuffix;var l=V.get(f[0],b.count);l>=0?k=k+"_"+l:1===l&&(k=h+O.nsseparator+a)}else k=h+O.nsseparator+a;if(d=A(k,c),d!=O.pluralNotFound)return u(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix});if(!(f.length>1))return c.lng=c._origLng,delete c._origLng,d=A(h+O.nsseparator+a,c),u(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix});var m=f.slice();if(m.shift(),b=S.extend(b,{lngs:m}),b._origLng=c._origLng,delete b.lng,d=A(h+O.nsseparator+a,b),d!=O.pluralNotFound)return d}if(y(b)){var n=S.extend({},b);delete n.indefinite_article,n.defaultValue=O.indefiniteNotFound;var o=h+O.nsseparator+a+(b.count&&!x(b,f[0])||!b.count?O.indefiniteSuffix:"");if(d=A(o,n),d!=O.indefiniteNotFound)return d}for(var p,q=a.split(O.keyseparator),r=0,s=f.length;s>r&&void 0===p;r++){for(var t=f[r],z=0,C=J[t]&&J[t][h];q[z];)C=C&&C[q[z]],z++;if(void 0!==C){var F=Object.prototype.toString.apply(C);if("string"==typeof C)C=u(C,b),C=v(C,b);else if("[object Array]"!==F||O.returnObjectTrees||b.returnObjectTrees){if(null===C&&O.fallbackOnNull===!0)C=void 0;else if(null!==C)if(O.returnObjectTrees||b.returnObjectTrees){if("[object Number]"!==F&&"[object Function]"!==F&&"[object RegExp]"!==F){var G="[object Array]"===F?[]:{};S.each(C,function(c){G[c]=D(h+O.nsseparator+a+O.keyseparator+c,b)}),C=G}}else O.objectTreeKeyHandler&&"function"==typeof O.objectTreeKeyHandler?C=O.objectTreeKeyHandler(a,C,t,h,b):(C="key '"+h+":"+a+" ("+t+")' returned an object instead of string.",S.log(C))}else C=C.join("\n"),C=u(C,b),C=v(C,b);"string"==typeof C&&""===C.trim()&&O.fallbackOnEmpty===!0&&(C=void 0),p=C}}if(void 0===p&&!b.isFallbackLookup&&(O.fallbackToDefaultNS===!0||O.fallbackNS&&O.fallbackNS.length>0)){if(b.isFallbackLookup=!0,O.fallbackNS.length){for(var H=0,K=O.fallbackNS.length;K>H;H++)if(p=E(O.fallbackNS[H]+O.nsseparator+a,b),p||""===p&&O.fallbackOnEmpty===!1){var M=p.indexOf(O.nsseparator)>-1?p.split(O.nsseparator)[1]:p,N=e.indexOf(O.nsseparator)>-1?e.split(O.nsseparator)[1]:e;if(M!==N)break}}else p=E(a,b);b.isFallbackLookup=!1}return p}function F(){var a,b=O.lngWhitelist||[],c=[];if("undefined"!=typeof window&&!function(){for(var a=window.location.search.substring(1),b=a.split("&"),d=0;d0){var f=b[d].substring(0,e);f==O.detectLngQS&&c.push(b[d].substring(e+1))}}}(),O.useCookie&&"undefined"!=typeof document){var d=S.cookie.read(O.cookieName);d&&c.push(d)}if(O.detectLngFromLocalStorage&&"undefined"!=typeof window&&window.localStorage&&c.push(S.localStorage.getItem("i18next_lng")),"undefined"!=typeof navigator){if(navigator.languages)for(var e=0;e-1){var f=e.split("-");e=O.lowerCaseLng?f[0].toLowerCase()+"-"+f[1].toLowerCase():f[0].toLowerCase()+"-"+f[1].toUpperCase()}if(0===b.length||b.indexOf(e)>-1){a=e;break}}}(),a||(a=O.fallbackLng[0]),a}Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>0&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=c;arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d))));for(var e=d>=0?Math.min(d,c-1):c-Math.abs(d);e>=0;e--)if(e in b&&b[e]===a)return e;return-1}),"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")});var G,H=void 0,I={},J={},K=0,L=[],M=!1,N={};N={load:function(a,b,c){b.useLocalStorage?N._loadLocal(a,b,function(d,e){for(var f=[],g=0,h=a.length;h>g;g++)e[a[g]]||f.push(a[g]);f.length>0?N._fetch(f,b,function(a,b){S.extend(e,b),N._storeLocal(b),c(null,e)}):c(null,e)}):N._fetch(a,b,function(a,b){c(null,b)})},_loadLocal:function(a,b,c){var d={},e=(new Date).getTime();if(window.localStorage){var f=a.length;S.each(a,function(a,g){var h=S.localStorage.getItem("res_"+g);h&&(h=JSON.parse(h),h.i18nStamp&&h.i18nStamp+b.localStorageExpirationTime>e&&(d[g]=h)),f--,0===f&&c(null,d)})}},_storeLocal:function(a){if(window.localStorage)for(var b in a)a[b].i18nStamp=(new Date).getTime(),S.localStorage.setItem("res_"+b,JSON.stringify(a[b]))},_fetch:function(a,b,c){var d=b.ns,e={};if(b.dynamicLoad){var f=function(a,b){c(null,b)};if("function"==typeof b.customLoad)b.customLoad(a,d.namespaces,b,f);else{var g=u(b.resGetPath,{lng:a.join("+"),ns:d.namespaces.join("+")});S.ajax({url:g,success:function(a){S.log("loaded: "+g),f(null,a)},error:function(a,b,c){S.log("failed loading: "+g),f("failed loading resource.json error: "+c)},dataType:"json",async:b.getAsync})}}else{var h,i=d.namespaces.length*a.length;S.each(d.namespaces,function(d,f){S.each(a,function(a,d){var g=function(a,b){a&&(h=h||[],h.push(a)),e[d]=e[d]||{},e[d][f]=b,i--,0===i&&c(h,e)};"function"==typeof b.customLoad?b.customLoad(d,f,b,g):N._fetchOne(d,f,b,g)})})}},_fetchOne:function(a,b,c,d){var e=u(c.resGetPath,{lng:a,ns:b});S.ajax({url:e,success:function(a){S.log("loaded: "+e),d(null,a)},error:function(a,b,c){if(b&&200==b||a&&a.status&&200==a.status)S.error("There is a typo in: "+e);else if(b&&404==b||a&&a.status&&404==a.status)S.log("Does not exist: "+e);else{var f=b?b:a&&a.status?a.status:null;S.log(f+" when loading "+e)}d(c,{})},dataType:"json",async:c.getAsync})},postMissing:function(a,b,c,d,e){var f={};f[c]=d;var g=[];if("fallback"===O.sendMissingTo&&O.fallbackLng[0]!==!1)for(var h=0;hh;h++)g.push({lng:e[h],url:u(O.resPostPath,{lng:e[h],ns:b})});for(var j=0,k=g.length;k>j;j++){var l=g[j];S.ajax({url:l.url,type:O.sendType,data:f,success:function(){S.log("posted missing key '"+c+"' to: "+l.url);for(var a=c.split("."),e=0,f=J[l.lng][b];a[e];)f=f[a[e]]=e===a.length-1?d:f[a[e]]||{},e++},error:function(){S.log("failed posting missing key '"+c+"' to: "+l.url)},dataType:"json",async:O.postAsync})}},reload:s};var O={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:["dev"],fallbackNS:[],detectLngQS:"setLng",detectLngFromLocalStorage:!1,ns:{namespaces:["translation"],defaultNs:"translation"},fallbackOnNull:!0,fallbackOnEmpty:!1,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",defaultVariables:!1,reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,indefiniteSuffix:"_indefinite",indefiniteNotFound:["indefinite_not_found",Math.random()].join(""),setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",cookieDomain:void 0,objectTreeKeyHandler:void 0,postProcess:void 0,parseMissingKey:void 0,missingKeyHandler:N.postMissing,shortcutFunction:"sprintf"},P={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},Q={create:function(a,b,c,d){var e;if(c){var f=new Date;f.setTime(f.getTime()+60*c*1e3),e="; expires="+f.toGMTString()}else e="";d=d?"domain="+d+";":"",document.cookie=a+"="+b+e+";"+d+"path=/"},read:function(a){for(var b=a+"=",c=document.cookie.split(";"),d=0;d-1){var c=a.split("-");b=O.lowerCaseLng?c[0].toLowerCase()+"-"+c[1].toLowerCase():c[0].toLowerCase()+"-"+c[1].toUpperCase()}else b=O.lowerCaseLng?a.toLowerCase():a;return b}var c=this.log,d=[],e=O.lngWhitelist||!1,f=function(a){!e||e.indexOf(a)>-1?d.push(a):c("rejecting non-whitelisted language: "+a)};if("string"==typeof a&&a.indexOf("-")>-1){var g=a.split("-");"unspecific"!==O.load&&f(b(a)),"current"!==O.load&&f(b(g[this.getCountyIndexOfLng(a)]))}else f(b(a));for(var h=0;h1)},2:function(a){return Number(1!=a)},3:function(){return 0},4:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},5:function(a){return Number(0===a?0:1==a?1:2==a?2:a%100>=3&&10>=a%100?3:a%100>=11?4:5)},6:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)},7:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},8:function(a){return Number(1==a?0:2==a?1:8!=a&&11!=a?2:3)},9:function(a){return Number(a>=2)},10:function(a){return Number(1==a?0:2==a?1:7>a?2:11>a?3:4)},11:function(a){return Number(1==a||11==a?0:2==a||12==a?1:a>2&&20>a?2:3)},12:function(a){return Number(a%10!=1||a%100==11)},13:function(a){return Number(0!==a)},14:function(a){return Number(1==a?0:2==a?1:3==a?2:3)},15:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&(10>a%100||a%100>=20)?1:2)},16:function(a){return Number(a%10==1&&a%100!=11?0:0!==a?1:2)},17:function(a){return Number(1==a||a%10==1?0:1)},18:function(a){return Number(1==a?1:2)},19:function(a){return Number(1==a?0:0===a||a%100>1&&11>a%100?1:a%100>10&&20>a%100?2:3)},20:function(a){return Number(1==a?0:0===a||a%100>0&&20>a%100?1:2)},21:function(a){return Number(a%100==1?1:a%100==2?2:a%100==3||a%100==4?3:0)}},V={rules:function(){var a,b={};for(a=T.length;a--;)b[T[a][0]]={name:T[a][1],numbers:T[a][2],plurals:U[T[a][3]]};return b}(),addRule:function(a,b){V.rules[a]=b},setCurrentLng:function(a){if(!V.currentRule||V.currentRule.lng!==a){var b=a.split("-");V.currentRule={lng:a,rule:V.rules[b[0]]}}},needsPlural:function(a,b){var c,d=a.split("-");return c=V.currentRule&&V.currentRule.lng===a?V.currentRule.rule:V.rules[d[S.getCountyIndexOfLng(a)]],c&&c.numbers.length<=1?!1:1!==this.get(a,b)},get:function(a,b){function c(b,c){var d;if(d=V.currentRule&&V.currentRule.lng===a?V.currentRule.rule:V.rules[b]){var e;e=d.plurals(d.noAbs?c:Math.abs(c));var f=d.numbers[e];return 2===d.numbers.length&&1===d.numbers[0]&&(2===f?f=-1:1===f&&(f=1)),f}return 1===c?"1":"-1"}var d=a.split("-");return c(d[S.getCountyIndexOfLng(a)],b)}},W={},X=function(a,b){W[a]=b},Y=function(){function a(a){return Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}function b(a,b){for(var c=[];b>0;c[--b]=a);return c.join("")}var c=function(){return c.cache.hasOwnProperty(arguments[0])||(c.cache[arguments[0]]=c.parse(arguments[0])),c.format.call(null,c.cache[arguments[0]],arguments)};return c.format=function(c,d){var e,f,g,h,i,j,k,l=1,m=c.length,n="",o=[];for(f=0;m>f;f++)if(n=a(c[f]),"string"===n)o.push(c[f]);else if("array"===n){if(h=c[f],h[2])for(e=d[l],g=0;g=0?"+"+e:e,j=h[4]?"0"==h[4]?"0":h[4].charAt(1):" ",k=h[6]-String(e).length,i=h[6]?b(j,k):"",o.push(h[5]?e+i:i+e)}return o.join("")},c.cache={},c.parse=function(a){for(var b=a,c=[],d=[],e=0;b;){if(null!==(c=/^[^\x25]+/.exec(b)))d.push(c[0]);else if(null!==(c=/^\x25{2}/.exec(b)))d.push("%");else{if(null===(c=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(b)))throw"[sprintf] huh?";if(c[2]){e|=1;var f=[],g=c[2],h=[];if(null===(h=/^([a-z_][a-z_\d]*)/i.exec(g)))throw"[sprintf] huh?";for(f.push(h[1]);""!==(g=g.substring(h[0].length));)if(null!==(h=/^\.([a-z_][a-z_\d]*)/i.exec(g)))f.push(h[1]);else{if(null===(h=/^\[(\d+)\]/.exec(g)))throw"[sprintf] huh?";f.push(h[1])}c[2]=f}else e|=2;if(3===e)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";d.push(c)}b=b.substring(c[0].length)}return d},c}(),Z=function(a,b){return b.unshift(a),Y.apply(null,b)};return X("sprintf",function(a,b,c){return c.sprintf?"[object Array]"===Object.prototype.toString.apply(c.sprintf)?Z(a,c.sprintf):"object"==typeof c.sprintf?Y(a,c.sprintf):a:a}),I.init=f,I.setLng=q,I.preload=g,I.addResourceBundle=h,I.hasResourceBundle=i,I.getResourceBundle=j,I.addResource=l,I.addResources=m,I.removeResourceBundle=k,I.loadNamespace=o,I.loadNamespaces=p,I.setDefaultNamespace=n,I.t=A,I.translate=A,I.exists=z,I.detectLanguage=S.detectLanguage,I.pluralExtensions=V,I.sync=N,I.functions=S,I.lng=r,I.addPostProcessor=X,I.applyReplacement=S.applyReplacement,I.options=O,I}); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd.withJQuery-1.5.10.js b/libs/i18next/release/i18next.amd.withJQuery-1.5.10.js new file mode 100644 index 00000000..c5ced850 --- /dev/null +++ b/libs/i18next/release/i18next.amd.withJQuery-1.5.10.js @@ -0,0 +1,2370 @@ +// i18next, v1.5.10 +// Copyright (c)2012 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function (root, factory) { + if (typeof exports === 'object') { + + var jquery = require('jquery'); + + module.exports = factory(jquery); + + } else if (typeof define === 'function' && define.amd) { + + define(['jquery'], factory); + + } +}(this, function ($) { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + var i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = []; + + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: 'dev', + detectLngQS: 'setLng', + ns: 'translation', + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + + postProcess: undefined + }; + + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = '?' + queryString.join('&'); + url += queryString !== '?' ? queryString : ''; + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + return JSON.parse(data); + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, {async: options.async}, function (status, data) { + if (status === 200) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + document.cookie = name+"="+value+expires+"; path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : _ajax, + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + toLanguages: function(lng) { + var languages = []; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + + if (o.load !== 'unspecific') languages.push(lng); + if (o.load !== 'current') languages.push(parts[0]); + } else { + languages.push(lng); + } + + if (languages.indexOf(o.fallbackLng) === -1 && o.fallbackLng) languages.push(o.fallbackLng); + + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + if (o.lng) { + // set cookie with lng set (as detectLanguage will set cookie on need) + if (o.useCookie) f.cookie.create(o.cookieName, o.lng, o.cookieExpirationTime); + } else { + o.lng = o.fallbackLng; + if (o.useCookie) f.cookie.remove(o.cookieName); + } + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + if (cb) cb(translate); + if (deferred) deferred.resolve(); + return deferred; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + + if (cb) cb(translate); + if (deferred) deferred.resolve(); + }); + + return deferred; + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, cb) { + return init({lng: lng}, cb); + } + + function lng() { + return currentLng; + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } + else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key) return; + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') <= key.length-1) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + parse(ele, k, options); + }); + + } else { + parse(ele, k, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + + function applyReplacement(str, replacementHash, nestedKey) { + if (str.indexOf(o.interpolationPrefix) < 0) return str; + + f.each(replacementHash, function(key, value) { + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nestedKey ? nestedKey + '.' + key : key); + } else { + str = str.replace(new RegExp([o.interpolationPrefixEscaped, nestedKey ? nestedKey + '.' + key : key, o.interpolationSuffixEscaped].join(''), 'g'), value); + } + }); + return str; + } + + function applyReuse(translated, options){ + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.indexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_sans_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + var translated_token = _translate(token_sans_symbols, opts); + translated = translated.replace(token, translated_token); + } + return translated; + } + + function hasContext(options) { + return (options.context && typeof options.context == 'string'); + } + + function needsPlural(options) { + return (options.count !== undefined && typeof options.count != 'string' && options.count !== 1); + } + + function translate(key, options){ + replacementCounter = 0; + return _translate(key, options); + } + + function _translate(key, options){ + options = options || {}; + + if (!resStore) { return notfound; } // no resStore to translate from + + var optionWithoutCount, translated + , notfound = options.defaultValue || key + , lngs = languages; + + if (options.lng) { + lngs = f.toLanguages(options.lng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + ':' + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.count; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey = ns + ':' + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(currentLng, options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + ':' + key; // singular + } + + translated = translate(pluralKey, optionWithoutCount); + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { count: options.count }); // apply replacement for count only + } // else continue translation with original/singular key + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (Object.prototype.toString.apply(value) === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned a object instead of string.'; + f.log(value); + } else { + for (var m in value) { + // apply translation on childs + value[m] = _translate(ns + ':' + key + '.' + m, options); + } + } + } + found = value; + } + } + + if (found === undefined && o.sendMissing) { + if (options.lng) { + sync.postMissing(options.lng, ns, key, notfound, lngs); + } else { + sync.postMissing(o.lng, ns, key, notfound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found !== undefined && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + if (found === undefined) { + notfound = applyReplacement(notfound, options); + notfound = applyReuse(notfound, options); + } + + return (found !== undefined) ? found : notfound; + } + + function detectLanguage() { + var detectedLng; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var parms = query.split('&'); + for (var i=0; i 0) { + var key = parms[i].substring(0,pos); + var val = parms[i].substring(pos+1); + qsParm[key] = val; + } + } + })(); + if (qsParm[o.detectLngQS]) { + detectedLng = qsParm[o.detectLngQS]; + } + } + + // get from cookie + if (!detectedLng && typeof document !== 'undefined' && o.useCookie ) { + var c = f.cookie.read(o.cookieName); + if (c) detectedLng = c; + } + + // get from navigator + if (!detectedLng && typeof navigator !== 'undefined') { + detectedLng = (navigator.language) ? navigator.language : navigator.userLanguage; + } + + return detectedLng; + } + var sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + window.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + cb(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + cb('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback') { + urls.push({lng: o.fallbackLng, url: applyReplacement(o.resPostPath, { lng: o.fallbackLng, ns: ns })}); + } else if (o.sendMissingTo === 'current') { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + resStore[item.lng][ns][key] = defaultValue; + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + } + }; + + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + var pluralExtensions = { + + rules: { + "ach": { + "name": "Acholi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "af": { + "name": "Afrikaans", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ak": { + "name": "Akan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "am": { + "name": "Amharic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "an": { + "name": "Aragonese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ar": { + "name": "Arabic", + "numbers": [ + 0, + 1, + 2, + 3, + 11, + 100 + ], + "plurals": function(n) { return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5); } + }, + "arn": { + "name": "Mapudungun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ast": { + "name": "Asturian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ay": { + "name": "Aymar\u00e1", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "az": { + "name": "Azerbaijani", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "be": { + "name": "Belarusian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "bg": { + "name": "Bulgarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bn": { + "name": "Bengali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bo": { + "name": "Tibetan", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "br": { + "name": "Breton", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "bs": { + "name": "Bosnian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ca": { + "name": "Catalan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "cgg": { + "name": "Chiga", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "cs": { + "name": "Czech", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "csb": { + "name": "Kashubian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "cy": { + "name": "Welsh", + "numbers": [ + 1, + 2, + 3, + 8 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3); } + }, + "da": { + "name": "Danish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "de": { + "name": "German", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "dz": { + "name": "Dzongkha", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "el": { + "name": "Greek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "en": { + "name": "English", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eo": { + "name": "Esperanto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es": { + "name": "Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es_ar": { + "name": "Argentinean Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "et": { + "name": "Estonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eu": { + "name": "Basque", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fa": { + "name": "Persian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "fi": { + "name": "Finnish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fil": { + "name": "Filipino", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fo": { + "name": "Faroese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fr": { + "name": "French", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fur": { + "name": "Friulian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fy": { + "name": "Frisian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ga": { + "name": "Irish", + "numbers": [ + 1, + 2, + 3, + 7, + 11 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;} + }, + "gd": { + "name": "Scottish Gaelic", + "numbers": [ + 1, + 2, + 3, + 20 + ], + "plurals": function(n) { return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3); } + }, + "gl": { + "name": "Galician", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gu": { + "name": "Gujarati", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gun": { + "name": "Gun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ha": { + "name": "Hausa", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "he": { + "name": "Hebrew", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hi": { + "name": "Hindi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hr": { + "name": "Croatian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "hu": { + "name": "Hungarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hy": { + "name": "Armenian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ia": { + "name": "Interlingua", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "id": { + "name": "Indonesian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "is": { + "name": "Icelandic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n%10!=1 || n%100==11); } + }, + "it": { + "name": "Italian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ja": { + "name": "Japanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jbo": { + "name": "Lojban", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jv": { + "name": "Javanese", + "numbers": [ + 0, + 1 + ], + "plurals": function(n) { return Number(n !== 0); } + }, + "ka": { + "name": "Georgian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kk": { + "name": "Kazakh", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "km": { + "name": "Khmer", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kn": { + "name": "Kannada", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ko": { + "name": "Korean", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ku": { + "name": "Kurdish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "kw": { + "name": "Cornish", + "numbers": [ + 1, + 2, + 3, + 4 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3); } + }, + "ky": { + "name": "Kyrgyz", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lb": { + "name": "Letzeburgesch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ln": { + "name": "Lingala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "lo": { + "name": "Lao", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lt": { + "name": "Lithuanian", + "numbers": [ + 1, + 2, + 10 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "lv": { + "name": "Latvian", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2); } + }, + "mai": { + "name": "Maithili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mfe": { + "name": "Mauritian Creole", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mg": { + "name": "Malagasy", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mi": { + "name": "Maori", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mk": { + "name": "Macedonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 || n%10==1 ? 0 : 1); } + }, + "ml": { + "name": "Malayalam", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mn": { + "name": "Mongolian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mnk": { + "name": "Mandinka", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(0 ? 0 : n==1 ? 1 : 2); } + }, + "mr": { + "name": "Marathi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ms": { + "name": "Malay", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "mt": { + "name": "Maltese", + "numbers": [ + 1, + 2, + 11, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3); } + }, + "nah": { + "name": "Nahuatl", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nap": { + "name": "Neapolitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nb": { + "name": "Norwegian Bokmal", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ne": { + "name": "Nepali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nl": { + "name": "Dutch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nn": { + "name": "Norwegian Nynorsk", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "no": { + "name": "Norwegian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nso": { + "name": "Northern Sotho", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "oc": { + "name": "Occitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "or": { + "name": "Oriya", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pa": { + "name": "Punjabi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pap": { + "name": "Papiamento", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pl": { + "name": "Polish", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "pms": { + "name": "Piemontese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ps": { + "name": "Pashto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt": { + "name": "Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt_br": { + "name": "Brazilian Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "rm": { + "name": "Romansh", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ro": { + "name": "Romanian", + "numbers": [ + 1, + 2, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2); } + }, + "ru": { + "name": "Russian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "sah": { + "name": "Yakut", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sco": { + "name": "Scots", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "se": { + "name": "Northern Sami", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "si": { + "name": "Sinhala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sk": { + "name": "Slovak", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "sl": { + "name": "Slovenian", + "numbers": [ + 5, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }, + "so": { + "name": "Somali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "son": { + "name": "Songhay", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sq": { + "name": "Albanian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sr": { + "name": "Serbian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "su": { + "name": "Sundanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sv": { + "name": "Swedish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sw": { + "name": "Swahili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ta": { + "name": "Tamil", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "te": { + "name": "Telugu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tg": { + "name": "Tajik", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "th": { + "name": "Thai", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ti": { + "name": "Tigrinya", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tk": { + "name": "Turkmen", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tr": { + "name": "Turkish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tt": { + "name": "Tatar", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ug": { + "name": "Uyghur", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "uk": { + "name": "Ukrainian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ur": { + "name": "Urdu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "uz": { + "name": "Uzbek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "vi": { + "name": "Vietnamese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "wa": { + "name": "Walloon", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "wo": { + "name": "Wolof", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "yo": { + "name": "Yoruba", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "zh": { + "name": "Chinese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + } + }, + + // for demonstration only sl and ar is added but you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i = ext.plurals(c); + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[0], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + + $.i18n = i18n; + $.t = i18n.t; + + return i18n; + +})); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd.withJQuery-1.5.6.js b/libs/i18next/release/i18next.amd.withJQuery-1.5.6.js new file mode 100644 index 00000000..91e03782 --- /dev/null +++ b/libs/i18next/release/i18next.amd.withJQuery-1.5.6.js @@ -0,0 +1,2274 @@ +// i18next, v1.5.6 +// Copyright (c)2012 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function (root, factory) { + if (typeof exports === 'object') { + + var jquery = require('jquery'); + + module.exports = factory(jquery); + + } else if (typeof define === 'function' && define.amd) { + + define(['jquery'], factory); + + } +}(this, function ($) { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + var i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = []; + + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: 'dev', + ns: 'translation', + nsseparator: ':', + keyseparator: '.', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + + setJqueryExt: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + + postProcess: undefined + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = '?' + queryString.join('&'); + url += queryString !== '?' ? queryString : ''; + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + return JSON.parse(data); + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.sendType ? options.sendType.toLowerCase() : 'get'; + + http[methode](options.url, {async: options.async}, function (status, data) { + if (status === 200) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + document.cookie = name+"="+value+expires+"; path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : _ajax, + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + log: function(str) { + if (o.debug) console.log(str); + }, + toLanguages: function(lng) { + var languages = []; + if (lng.indexOf('-') === 2 && lng.length === 5) { + var parts = lng.split('-'); + + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + + if (o.load !== 'unspecific') languages.push(lng); + if (o.load !== 'current') languages.push(lng.substr(0, 2)); + } else { + languages.push(lng); + } + + if (languages.indexOf(o.fallbackLng) === -1 && o.fallbackLng) languages.push(o.fallbackLng); + + return languages; + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + if (!o.lng) o.lng = f.detectLanguage(); + if (o.lng) { + // set cookie with lng set (as detectLanguage will set cookie on need) + f.cookie.create('i18next', o.lng, o.cookieExpirationTime); + } else { + o.lng = o.fallbackLng; + f.cookie.remove('i18next'); + } + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + if (cb) cb(translate); + if (deferred) deferred.resolve(); + return deferred; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + + if (cb) cb(translate); + if (deferred) deferred.resolve(); + }); + + return deferred; + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function setLng(lng, cb) { + return init({lng: lng}, cb); + } + + function lng() { + return currentLng; + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = $.extend({ defaultValue: ele.html() }, options); + ele.html($.t(key, optionsToUse)); + } + else if (attr === 'text') { + optionsToUse = $.extend({ defaultValue: ele.text() }, options); + ele.text($.t(key, optionsToUse)); + } else { + optionsToUse = $.extend({ defaultValue: ele.attr(attr) }, options); + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr('data-i18n'); + if (!key) return; + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') <= key.length-1) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + parse(ele, k, options); + }); + + } else { + parse(ele, k, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[data-i18n]'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey) { + if (str.indexOf(o.interpolationPrefix) < 0) return str; + + f.each(replacementHash, function(key, value) { + if (typeof value === 'object') { + str = applyReplacement(str, value, key); + } else { + str = str.replace(new RegExp([o.interpolationPrefix, nestedKey ? nestedKey + '.' + key : key, o.interpolationSuffix].join(''), 'g'), value); + } + }); + return str; + } + + function applyReuse(translated, options){ + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.indexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_sans_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + var translated_token = _translate(token_sans_symbols, opts); + translated = translated.replace(token, translated_token); + } + return translated; + } + + function hasContext(options) { + return (options.context && typeof options.context == 'string'); + } + + function needsPlural(options) { + return (options.count !== undefined && typeof options.count != 'string' && options.count !== 1); + } + + function translate(key, options){ + replacementCounter = 0; + return _translate(key, options); + } + + function _translate(key, options){ + options = options || {}; + + var optionsSansCount, translated + , notfound = options.defaultValue || key + , lngs = languages; + + if (options.lng) { + lngs = f.toLanguages(options.lng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + if (!resStore) { return notfound; } // no resStore to translate from + + var ns = o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionsSansCount = f.extend({}, options); + delete optionsSansCount.context; + optionsSansCount.defaultValue = o.contextNotFound; + + var contextKey = ns + ':' + key + '_' + options.context; + + translated = translate(contextKey, optionsSansCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options)) { + optionsSansCount = f.extend({}, options); + delete optionsSansCount.count; + optionsSansCount.defaultValue = o.pluralNotFound; + + var pluralKey = ns + ':' + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(currentLng, options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + ':' + key; // singular + } + + translated = translate(pluralKey, optionsSansCount); + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { count: options.count }); // apply replacement for count only + } // else continue translation with original/singular key + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value) { + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (Object.prototype.toString.apply(value) === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned a object instead of string.'; + f.log(value); + } else { + for (var m in value) { + // apply translation on childs + value[m] = _translate(key + '.' + m, options); + } + } + } + found = value; + } + } + + if (!found && o.sendMissing) { + if (options.lng) { + sync.postMissing(options.lng, ns, key, notfound, lngs); + } else { + sync.postMissing(o.lng, ns, key, notfound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + if (!found) { + notfound = applyReplacement(notfound, options); + notfound = applyReuse(notfound, options); + } + + return (found) ? found : notfound; + } + function detectLanguage() { + var detectedLng; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var parms = query.split('&'); + for (var i=0; i 0) { + var key = parms[i].substring(0,pos); + var val = parms[i].substring(pos+1); + qsParm[key] = val; + } + } + })(); + if (qsParm.setLng) { + detectedLng = qsParm.setLng; + } + } + + // get from cookie + if (!detectedLng && typeof document !== 'undefined') { + var c = f.cookie.read('i18next'); + if (c) detectedLng = c; + } + + // get from navigator + if (!detectedLng && typeof navigator !== 'undefined') { + detectedLng = (navigator.language) ? navigator.language : navigator.userLanguage; + } + + return detectedLng; + } + var sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched){ + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + window.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + sync._fetchOne(lngValue, nsValue, options, function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }); + }); + }); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + cb(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + cb('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback') { + urls.push({lng: o.fallbackLng, url: applyReplacement(o.resPostPath, { lng: o.fallbackLng, ns: ns })}); + } else if (o.sendMissingTo === 'current') { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + resStore[item.lng][ns][key] = defaultValue; + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + } + }; + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + var pluralExtensions = { + + rules: { + "ach": { + "name": "Acholi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "af": { + "name": "Afrikaans", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ak": { + "name": "Akan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "am": { + "name": "Amharic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "an": { + "name": "Aragonese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ar": { + "name": "Arabic", + "numbers": [ + 0, + 1, + 2, + 3, + 11, + 100 + ], + "plurals": function(n) { return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5); } + }, + "arn": { + "name": "Mapudungun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ast": { + "name": "Asturian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ay": { + "name": "Aymar\u00e1", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "az": { + "name": "Azerbaijani", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "be": { + "name": "Belarusian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "bg": { + "name": "Bulgarian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bn": { + "name": "Bengali", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bo": { + "name": "Tibetan", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "br": { + "name": "Breton", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "bs": { + "name": "Bosnian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ca": { + "name": "Catalan", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "cgg": { + "name": "Chiga", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "cs": { + "name": "Czech", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "csb": { + "name": "Kashubian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "cy": { + "name": "Welsh", + "numbers": [ + 3, + 1, + 2, + 8 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3); } + }, + "da": { + "name": "Danish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "de": { + "name": "German", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "dz": { + "name": "Dzongkha", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "el": { + "name": "Greek", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "en": { + "name": "English", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eo": { + "name": "Esperanto", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es": { + "name": "Spanish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es_ar": { + "name": "Argentinean Spanish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "et": { + "name": "Estonian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eu": { + "name": "Basque", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fa": { + "name": "Persian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "fi": { + "name": "Finnish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fil": { + "name": "Filipino", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fo": { + "name": "Faroese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fr": { + "name": "French", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fur": { + "name": "Friulian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fy": { + "name": "Frisian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ga": { + "name": "Irish", + "numbers": [ + 3, + 1, + 2, + 7, + 11 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;} + }, + "gd": { + "name": "Scottish Gaelic", + "numbers": [ + 20, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3); } + }, + "gl": { + "name": "Galician", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gu": { + "name": "Gujarati", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gun": { + "name": "Gun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ha": { + "name": "Hausa", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "he": { + "name": "Hebrew", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hi": { + "name": "Hindi", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hr": { + "name": "Croatian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "hu": { + "name": "Hungarian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hy": { + "name": "Armenian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ia": { + "name": "Interlingua", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "id": { + "name": "Indonesian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "is": { + "name": "Icelandic", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n%10!=1 || n%100==11); } + }, + "it": { + "name": "Italian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ja": { + "name": "Japanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jbo": { + "name": "Lojban", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jv": { + "name": "Javanese", + "numbers": [ + 0, + 1 + ], + "plurals": function(n) { return Number(n !== 0); } + }, + "ka": { + "name": "Georgian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kk": { + "name": "Kazakh", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "km": { + "name": "Khmer", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kn": { + "name": "Kannada", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ko": { + "name": "Korean", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ku": { + "name": "Kurdish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "kw": { + "name": "Cornish", + "numbers": [ + 4, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3); } + }, + "ky": { + "name": "Kyrgyz", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lb": { + "name": "Letzeburgesch", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ln": { + "name": "Lingala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "lo": { + "name": "Lao", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lt": { + "name": "Lithuanian", + "numbers": [ + 10, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "lv": { + "name": "Latvian", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2); } + }, + "mai": { + "name": "Maithili", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mfe": { + "name": "Mauritian Creole", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mg": { + "name": "Malagasy", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mi": { + "name": "Maori", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mk": { + "name": "Macedonian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n==1 || n%10==1 ? 0 : 1); } + }, + "ml": { + "name": "Malayalam", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mn": { + "name": "Mongolian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mnk": { + "name": "Mandinka", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(0 ? 0 : n==1 ? 1 : 2); } + }, + "mr": { + "name": "Marathi", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ms": { + "name": "Malay", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "mt": { + "name": "Maltese", + "numbers": [ + 2, + 1, + 11, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3); } + }, + "nah": { + "name": "Nahuatl", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nap": { + "name": "Neapolitan", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nb": { + "name": "Norwegian Bokmal", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ne": { + "name": "Nepali", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nl": { + "name": "Dutch", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nn": { + "name": "Norwegian Nynorsk", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "no": { + "name": "Norwegian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nso": { + "name": "Northern Sotho", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "oc": { + "name": "Occitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "or": { + "name": "Oriya", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pa": { + "name": "Punjabi", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pap": { + "name": "Papiamento", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pl": { + "name": "Polish", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "pms": { + "name": "Piemontese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ps": { + "name": "Pashto", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt": { + "name": "Portuguese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt_br": { + "name": "Brazilian Portuguese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "rm": { + "name": "Romansh", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ro": { + "name": "Romanian", + "numbers": [ + 2, + 1, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2); } + }, + "ru": { + "name": "Russian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "sah": { + "name": "Yakut", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sco": { + "name": "Scots", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "se": { + "name": "Northern Sami", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "si": { + "name": "Sinhala", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sk": { + "name": "Slovak", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "sl": { + "name": "Slovenian", + "numbers": [ + 5, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }, + "so": { + "name": "Somali", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "son": { + "name": "Songhay", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sq": { + "name": "Albanian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sr": { + "name": "Serbian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "su": { + "name": "Sundanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sv": { + "name": "Swedish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sw": { + "name": "Swahili", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ta": { + "name": "Tamil", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "te": { + "name": "Telugu", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tg": { + "name": "Tajik", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "th": { + "name": "Thai", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ti": { + "name": "Tigrinya", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tk": { + "name": "Turkmen", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tr": { + "name": "Turkish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tt": { + "name": "Tatar", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ug": { + "name": "Uyghur", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "uk": { + "name": "Ukrainian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ur": { + "name": "Urdu", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "uz": { + "name": "Uzbek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "vi": { + "name": "Vietnamese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "wa": { + "name": "Walloon", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "wo": { + "name": "Wolof", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "yo": { + "name": "Yoruba", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "zh": { + "name": "Chinese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + } + }, + + // for demonstration only sl and ar is added but you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i = ext.plurals(c); + var number = ext.numbers[i]; + if (ext.numbers.length === 2) { + if (number === 2) { + number = 1; + } else if (number === 1) { + number = -1; + } + } //console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[0], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.t = translate; + i18n.translate = translate; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + + $.i18n = i18n; + $.t = i18n.t; + + return i18n; + +})); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd.withJQuery-1.5.7.js b/libs/i18next/release/i18next.amd.withJQuery-1.5.7.js new file mode 100644 index 00000000..a42b0fc9 --- /dev/null +++ b/libs/i18next/release/i18next.amd.withJQuery-1.5.7.js @@ -0,0 +1,2276 @@ +// i18next, v1.5.7 +// Copyright (c)2012 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function (root, factory) { + if (typeof exports === 'object') { + + var jquery = require('jquery'); + + module.exports = factory(jquery); + + } else if (typeof define === 'function' && define.amd) { + + define(['jquery'], factory); + + } +}(this, function ($) { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + var i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = []; + + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: 'dev', + detectLngQS: 'setLng', + ns: 'translation', + nsseparator: ':', + keyseparator: '.', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + + setJqueryExt: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + + postProcess: undefined + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = '?' + queryString.join('&'); + url += queryString !== '?' ? queryString : ''; + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + return JSON.parse(data); + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.sendType ? options.sendType.toLowerCase() : 'get'; + + http[methode](options.url, {async: options.async}, function (status, data) { + if (status === 200) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + document.cookie = name+"="+value+expires+"; path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : _ajax, + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + log: function(str) { + if (o.debug) console.log(str); + }, + toLanguages: function(lng) { + var languages = []; + if (lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + + if (o.load !== 'unspecific') languages.push(lng); + if (o.load !== 'current') languages.push(parts[0]); + } else { + languages.push(lng); + } + + if (languages.indexOf(o.fallbackLng) === -1 && o.fallbackLng) languages.push(o.fallbackLng); + + return languages; + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + if (!o.lng) o.lng = f.detectLanguage(); + if (o.lng) { + // set cookie with lng set (as detectLanguage will set cookie on need) + f.cookie.create('i18next', o.lng, o.cookieExpirationTime); + } else { + o.lng = o.fallbackLng; + f.cookie.remove('i18next'); + } + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + if (cb) cb(translate); + if (deferred) deferred.resolve(); + return deferred; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + + if (cb) cb(translate); + if (deferred) deferred.resolve(); + }); + + return deferred; + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function setLng(lng, cb) { + return init({lng: lng}, cb); + } + + function lng() { + return currentLng; + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = $.extend({ defaultValue: ele.html() }, options); + ele.html($.t(key, optionsToUse)); + } + else if (attr === 'text') { + optionsToUse = $.extend({ defaultValue: ele.text() }, options); + ele.text($.t(key, optionsToUse)); + } else { + optionsToUse = $.extend({ defaultValue: ele.attr(attr) }, options); + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr('data-i18n'); + if (!key) return; + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') <= key.length-1) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + parse(ele, k, options); + }); + + } else { + parse(ele, k, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[data-i18n]'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey) { + if (str.indexOf(o.interpolationPrefix) < 0) return str; + + f.each(replacementHash, function(key, value) { + if (typeof value === 'object') { + str = applyReplacement(str, value, nestedKey ? nestedKey + '.' + key : key); + } else { + str = str.replace(new RegExp([o.interpolationPrefix, nestedKey ? nestedKey + '.' + key : key, o.interpolationSuffix].join(''), 'g'), value); + } + }); + return str; + } + + function applyReuse(translated, options){ + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.indexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_sans_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + var translated_token = _translate(token_sans_symbols, opts); + translated = translated.replace(token, translated_token); + } + return translated; + } + + function hasContext(options) { + return (options.context && typeof options.context == 'string'); + } + + function needsPlural(options) { + return (options.count !== undefined && typeof options.count != 'string' && options.count !== 1); + } + + function translate(key, options){ + replacementCounter = 0; + return _translate(key, options); + } + + function _translate(key, options){ + options = options || {}; + + var optionsSansCount, translated + , notfound = options.defaultValue || key + , lngs = languages; + + if (options.lng) { + lngs = f.toLanguages(options.lng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + if (!resStore) { return notfound; } // no resStore to translate from + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionsSansCount = f.extend({}, options); + delete optionsSansCount.context; + optionsSansCount.defaultValue = o.contextNotFound; + + var contextKey = ns + ':' + key + '_' + options.context; + + translated = translate(contextKey, optionsSansCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options)) { + optionsSansCount = f.extend({}, options); + delete optionsSansCount.count; + optionsSansCount.defaultValue = o.pluralNotFound; + + var pluralKey = ns + ':' + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(currentLng, options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + ':' + key; // singular + } + + translated = translate(pluralKey, optionsSansCount); + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { count: options.count }); // apply replacement for count only + } // else continue translation with original/singular key + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value) { + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (Object.prototype.toString.apply(value) === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned a object instead of string.'; + f.log(value); + } else { + for (var m in value) { + // apply translation on childs + value[m] = _translate(key + '.' + m, options); + } + } + } + found = value; + } + } + + if (!found && o.sendMissing) { + if (options.lng) { + sync.postMissing(options.lng, ns, key, notfound, lngs); + } else { + sync.postMissing(o.lng, ns, key, notfound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + if (!found) { + notfound = applyReplacement(notfound, options); + notfound = applyReuse(notfound, options); + } + + return (found) ? found : notfound; + } + + function detectLanguage() { + var detectedLng; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var parms = query.split('&'); + for (var i=0; i 0) { + var key = parms[i].substring(0,pos); + var val = parms[i].substring(pos+1); + qsParm[key] = val; + } + } + })(); + if (qsParm[o.detectLngQS]) { + detectedLng = qsParm[o.detectLngQS]; + } + } + + // get from cookie + if (!detectedLng && typeof document !== 'undefined') { + var c = f.cookie.read('i18next'); + if (c) detectedLng = c; + } + + // get from navigator + if (!detectedLng && typeof navigator !== 'undefined') { + detectedLng = (navigator.language) ? navigator.language : navigator.userLanguage; + } + + return detectedLng; + } + var sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched){ + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + window.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + sync._fetchOne(lngValue, nsValue, options, function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }); + }); + }); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + cb(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + cb('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback') { + urls.push({lng: o.fallbackLng, url: applyReplacement(o.resPostPath, { lng: o.fallbackLng, ns: ns })}); + } else if (o.sendMissingTo === 'current') { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + resStore[item.lng][ns][key] = defaultValue; + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + } + }; + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + var pluralExtensions = { + + rules: { + "ach": { + "name": "Acholi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "af": { + "name": "Afrikaans", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ak": { + "name": "Akan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "am": { + "name": "Amharic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "an": { + "name": "Aragonese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ar": { + "name": "Arabic", + "numbers": [ + 0, + 1, + 2, + 3, + 11, + 100 + ], + "plurals": function(n) { return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5); } + }, + "arn": { + "name": "Mapudungun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ast": { + "name": "Asturian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ay": { + "name": "Aymar\u00e1", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "az": { + "name": "Azerbaijani", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "be": { + "name": "Belarusian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "bg": { + "name": "Bulgarian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bn": { + "name": "Bengali", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bo": { + "name": "Tibetan", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "br": { + "name": "Breton", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "bs": { + "name": "Bosnian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ca": { + "name": "Catalan", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "cgg": { + "name": "Chiga", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "cs": { + "name": "Czech", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "csb": { + "name": "Kashubian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "cy": { + "name": "Welsh", + "numbers": [ + 3, + 1, + 2, + 8 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3); } + }, + "da": { + "name": "Danish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "de": { + "name": "German", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "dz": { + "name": "Dzongkha", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "el": { + "name": "Greek", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "en": { + "name": "English", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eo": { + "name": "Esperanto", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es": { + "name": "Spanish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es_ar": { + "name": "Argentinean Spanish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "et": { + "name": "Estonian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eu": { + "name": "Basque", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fa": { + "name": "Persian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "fi": { + "name": "Finnish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fil": { + "name": "Filipino", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fo": { + "name": "Faroese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fr": { + "name": "French", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fur": { + "name": "Friulian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fy": { + "name": "Frisian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ga": { + "name": "Irish", + "numbers": [ + 3, + 1, + 2, + 7, + 11 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;} + }, + "gd": { + "name": "Scottish Gaelic", + "numbers": [ + 20, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3); } + }, + "gl": { + "name": "Galician", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gu": { + "name": "Gujarati", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gun": { + "name": "Gun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ha": { + "name": "Hausa", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "he": { + "name": "Hebrew", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hi": { + "name": "Hindi", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hr": { + "name": "Croatian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "hu": { + "name": "Hungarian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hy": { + "name": "Armenian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ia": { + "name": "Interlingua", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "id": { + "name": "Indonesian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "is": { + "name": "Icelandic", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n%10!=1 || n%100==11); } + }, + "it": { + "name": "Italian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ja": { + "name": "Japanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jbo": { + "name": "Lojban", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jv": { + "name": "Javanese", + "numbers": [ + 0, + 1 + ], + "plurals": function(n) { return Number(n !== 0); } + }, + "ka": { + "name": "Georgian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kk": { + "name": "Kazakh", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "km": { + "name": "Khmer", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kn": { + "name": "Kannada", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ko": { + "name": "Korean", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ku": { + "name": "Kurdish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "kw": { + "name": "Cornish", + "numbers": [ + 4, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3); } + }, + "ky": { + "name": "Kyrgyz", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lb": { + "name": "Letzeburgesch", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ln": { + "name": "Lingala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "lo": { + "name": "Lao", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lt": { + "name": "Lithuanian", + "numbers": [ + 10, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "lv": { + "name": "Latvian", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2); } + }, + "mai": { + "name": "Maithili", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mfe": { + "name": "Mauritian Creole", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mg": { + "name": "Malagasy", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mi": { + "name": "Maori", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mk": { + "name": "Macedonian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n==1 || n%10==1 ? 0 : 1); } + }, + "ml": { + "name": "Malayalam", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mn": { + "name": "Mongolian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mnk": { + "name": "Mandinka", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(0 ? 0 : n==1 ? 1 : 2); } + }, + "mr": { + "name": "Marathi", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ms": { + "name": "Malay", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "mt": { + "name": "Maltese", + "numbers": [ + 2, + 1, + 11, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3); } + }, + "nah": { + "name": "Nahuatl", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nap": { + "name": "Neapolitan", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nb": { + "name": "Norwegian Bokmal", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ne": { + "name": "Nepali", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nl": { + "name": "Dutch", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nn": { + "name": "Norwegian Nynorsk", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "no": { + "name": "Norwegian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nso": { + "name": "Northern Sotho", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "oc": { + "name": "Occitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "or": { + "name": "Oriya", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pa": { + "name": "Punjabi", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pap": { + "name": "Papiamento", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pl": { + "name": "Polish", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "pms": { + "name": "Piemontese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ps": { + "name": "Pashto", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt": { + "name": "Portuguese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt_br": { + "name": "Brazilian Portuguese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "rm": { + "name": "Romansh", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ro": { + "name": "Romanian", + "numbers": [ + 2, + 1, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2); } + }, + "ru": { + "name": "Russian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "sah": { + "name": "Yakut", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sco": { + "name": "Scots", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "se": { + "name": "Northern Sami", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "si": { + "name": "Sinhala", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sk": { + "name": "Slovak", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "sl": { + "name": "Slovenian", + "numbers": [ + 5, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }, + "so": { + "name": "Somali", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "son": { + "name": "Songhay", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sq": { + "name": "Albanian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sr": { + "name": "Serbian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "su": { + "name": "Sundanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sv": { + "name": "Swedish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sw": { + "name": "Swahili", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ta": { + "name": "Tamil", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "te": { + "name": "Telugu", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tg": { + "name": "Tajik", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "th": { + "name": "Thai", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ti": { + "name": "Tigrinya", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tk": { + "name": "Turkmen", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tr": { + "name": "Turkish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tt": { + "name": "Tatar", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ug": { + "name": "Uyghur", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "uk": { + "name": "Ukrainian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ur": { + "name": "Urdu", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "uz": { + "name": "Uzbek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "vi": { + "name": "Vietnamese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "wa": { + "name": "Walloon", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "wo": { + "name": "Wolof", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "yo": { + "name": "Yoruba", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "zh": { + "name": "Chinese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + } + }, + + // for demonstration only sl and ar is added but you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i = ext.plurals(c); + var number = ext.numbers[i]; + if (ext.numbers.length === 2) { + if (number === 2) { + number = 1; + } else if (number === 1) { + number = -1; + } + } //console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[0], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.t = translate; + i18n.translate = translate; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + + $.i18n = i18n; + $.t = i18n.t; + + return i18n; + +})); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd.withJQuery-1.5.8.js b/libs/i18next/release/i18next.amd.withJQuery-1.5.8.js new file mode 100644 index 00000000..ecf6ed31 --- /dev/null +++ b/libs/i18next/release/i18next.amd.withJQuery-1.5.8.js @@ -0,0 +1,2288 @@ +// i18next, v1.5.8 +// Copyright (c)2012 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function (root, factory) { + if (typeof exports === 'object') { + + var jquery = require('jquery'); + + module.exports = factory(jquery); + + } else if (typeof define === 'function' && define.amd) { + + define(['jquery'], factory); + + } +}(this, function ($) { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + var i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = []; + + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: 'dev', + detectLngQS: 'setLng', + ns: 'translation', + nsseparator: ':', + keyseparator: '.', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + + setJqueryExt: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + + postProcess: undefined + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = '?' + queryString.join('&'); + url += queryString !== '?' ? queryString : ''; + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + return JSON.parse(data); + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, {async: options.async}, function (status, data) { + if (status === 200) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + document.cookie = name+"="+value+expires+"; path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : _ajax, + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + log: function(str) { + if (o.debug) console.log(str); + }, + toLanguages: function(lng) { + var languages = []; + if (lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + + if (o.load !== 'unspecific') languages.push(lng); + if (o.load !== 'current') languages.push(parts[0]); + } else { + languages.push(lng); + } + + if (languages.indexOf(o.fallbackLng) === -1 && o.fallbackLng) languages.push(o.fallbackLng); + + return languages; + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + if (!o.lng) o.lng = f.detectLanguage(); + if (o.lng) { + // set cookie with lng set (as detectLanguage will set cookie on need) + if (o.useCookie) f.cookie.create('i18next', o.lng, o.cookieExpirationTime); + } else { + o.lng = o.fallbackLng; + if (o.useCookie) f.cookie.remove('i18next'); + } + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + if (cb) cb(translate); + if (deferred) deferred.resolve(); + return deferred; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + + if (cb) cb(translate); + if (deferred) deferred.resolve(); + }); + + return deferred; + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function setLng(lng, cb) { + return init({lng: lng}, cb); + } + + function lng() { + return currentLng; + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = $.extend({ defaultValue: ele.html() }, options); + ele.html($.t(key, optionsToUse)); + } + else if (attr === 'text') { + optionsToUse = $.extend({ defaultValue: ele.text() }, options); + ele.text($.t(key, optionsToUse)); + } else { + optionsToUse = $.extend({ defaultValue: ele.attr(attr) }, options); + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr('data-i18n'); + if (!key) return; + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') <= key.length-1) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + parse(ele, k, options); + }); + + } else { + parse(ele, k, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[data-i18n]'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey) { + if (str.indexOf(o.interpolationPrefix) < 0) return str; + + f.each(replacementHash, function(key, value) { + if (typeof value === 'object') { + str = applyReplacement(str, value, nestedKey ? nestedKey + '.' + key : key); + } else { + str = str.replace(new RegExp([o.interpolationPrefix, nestedKey ? nestedKey + '.' + key : key, o.interpolationSuffix].join(''), 'g'), value); + } + }); + return str; + } + + function applyReuse(translated, options){ + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.indexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_sans_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + var translated_token = _translate(token_sans_symbols, opts); + translated = translated.replace(token, translated_token); + } + return translated; + } + + function hasContext(options) { + return (options.context && typeof options.context == 'string'); + } + + function needsPlural(options) { + return (options.count !== undefined && typeof options.count != 'string' && options.count !== 1); + } + + function translate(key, options){ + replacementCounter = 0; + return _translate(key, options); + } + + function _translate(key, options){ + options = options || {}; + + var optionWithoutCount, translated + , notfound = options.defaultValue || key + , lngs = languages; + + if (options.lng) { + lngs = f.toLanguages(options.lng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + if (!resStore) { return notfound; } // no resStore to translate from + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + ':' + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.count; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey = ns + ':' + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(currentLng, options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + ':' + key; // singular + } + + translated = translate(pluralKey, optionWithoutCount); + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { count: options.count }); // apply replacement for count only + } // else continue translation with original/singular key + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (Object.prototype.toString.apply(value) === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned a object instead of string.'; + f.log(value); + } else { + for (var m in value) { + // apply translation on childs + value[m] = _translate(ns + ':' + key + '.' + m, options); + } + } + } + found = value; + } + } + + if (found === undefined && o.sendMissing) { + if (options.lng) { + sync.postMissing(options.lng, ns, key, notfound, lngs); + } else { + sync.postMissing(o.lng, ns, key, notfound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found !== undefined && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + if (found === undefined) { + notfound = applyReplacement(notfound, options); + notfound = applyReuse(notfound, options); + } + + return (found !== undefined) ? found : notfound; + } + + function detectLanguage() { + var detectedLng; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var parms = query.split('&'); + for (var i=0; i 0) { + var key = parms[i].substring(0,pos); + var val = parms[i].substring(pos+1); + qsParm[key] = val; + } + } + })(); + if (qsParm[o.detectLngQS]) { + detectedLng = qsParm[o.detectLngQS]; + } + } + + // get from cookie + if (!detectedLng && typeof document !== 'undefined' && o.useCookie ) { + var c = f.cookie.read('i18next'); + if (c) detectedLng = c; + } + + // get from navigator + if (!detectedLng && typeof navigator !== 'undefined') { + detectedLng = (navigator.language) ? navigator.language : navigator.userLanguage; + } + + return detectedLng; + } + var sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched){ + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + window.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + sync._fetchOne(lngValue, nsValue, options, function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }); + }); + }); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + cb(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + cb('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback') { + urls.push({lng: o.fallbackLng, url: applyReplacement(o.resPostPath, { lng: o.fallbackLng, ns: ns })}); + } else if (o.sendMissingTo === 'current') { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + resStore[item.lng][ns][key] = defaultValue; + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + } + }; + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + var pluralExtensions = { + + rules: { + "ach": { + "name": "Acholi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "af": { + "name": "Afrikaans", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ak": { + "name": "Akan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "am": { + "name": "Amharic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "an": { + "name": "Aragonese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ar": { + "name": "Arabic", + "numbers": [ + 0, + 1, + 2, + 3, + 11, + 100 + ], + "plurals": function(n) { return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5); } + }, + "arn": { + "name": "Mapudungun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ast": { + "name": "Asturian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ay": { + "name": "Aymar\u00e1", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "az": { + "name": "Azerbaijani", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "be": { + "name": "Belarusian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "bg": { + "name": "Bulgarian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bn": { + "name": "Bengali", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bo": { + "name": "Tibetan", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "br": { + "name": "Breton", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "bs": { + "name": "Bosnian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ca": { + "name": "Catalan", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "cgg": { + "name": "Chiga", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "cs": { + "name": "Czech", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "csb": { + "name": "Kashubian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "cy": { + "name": "Welsh", + "numbers": [ + 3, + 1, + 2, + 8 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3); } + }, + "da": { + "name": "Danish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "de": { + "name": "German", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "dz": { + "name": "Dzongkha", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "el": { + "name": "Greek", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "en": { + "name": "English", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eo": { + "name": "Esperanto", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es": { + "name": "Spanish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es_ar": { + "name": "Argentinean Spanish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "et": { + "name": "Estonian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eu": { + "name": "Basque", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fa": { + "name": "Persian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "fi": { + "name": "Finnish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fil": { + "name": "Filipino", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fo": { + "name": "Faroese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fr": { + "name": "French", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fur": { + "name": "Friulian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fy": { + "name": "Frisian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ga": { + "name": "Irish", + "numbers": [ + 3, + 1, + 2, + 7, + 11 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;} + }, + "gd": { + "name": "Scottish Gaelic", + "numbers": [ + 20, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3); } + }, + "gl": { + "name": "Galician", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gu": { + "name": "Gujarati", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gun": { + "name": "Gun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ha": { + "name": "Hausa", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "he": { + "name": "Hebrew", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hi": { + "name": "Hindi", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hr": { + "name": "Croatian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "hu": { + "name": "Hungarian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hy": { + "name": "Armenian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ia": { + "name": "Interlingua", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "id": { + "name": "Indonesian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "is": { + "name": "Icelandic", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n%10!=1 || n%100==11); } + }, + "it": { + "name": "Italian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ja": { + "name": "Japanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jbo": { + "name": "Lojban", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jv": { + "name": "Javanese", + "numbers": [ + 0, + 1 + ], + "plurals": function(n) { return Number(n !== 0); } + }, + "ka": { + "name": "Georgian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kk": { + "name": "Kazakh", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "km": { + "name": "Khmer", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kn": { + "name": "Kannada", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ko": { + "name": "Korean", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ku": { + "name": "Kurdish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "kw": { + "name": "Cornish", + "numbers": [ + 4, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3); } + }, + "ky": { + "name": "Kyrgyz", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lb": { + "name": "Letzeburgesch", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ln": { + "name": "Lingala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "lo": { + "name": "Lao", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lt": { + "name": "Lithuanian", + "numbers": [ + 10, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "lv": { + "name": "Latvian", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2); } + }, + "mai": { + "name": "Maithili", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mfe": { + "name": "Mauritian Creole", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mg": { + "name": "Malagasy", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mi": { + "name": "Maori", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mk": { + "name": "Macedonian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n==1 || n%10==1 ? 0 : 1); } + }, + "ml": { + "name": "Malayalam", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mn": { + "name": "Mongolian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mnk": { + "name": "Mandinka", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(0 ? 0 : n==1 ? 1 : 2); } + }, + "mr": { + "name": "Marathi", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ms": { + "name": "Malay", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "mt": { + "name": "Maltese", + "numbers": [ + 2, + 1, + 11, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3); } + }, + "nah": { + "name": "Nahuatl", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nap": { + "name": "Neapolitan", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nb": { + "name": "Norwegian Bokmal", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ne": { + "name": "Nepali", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nl": { + "name": "Dutch", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nn": { + "name": "Norwegian Nynorsk", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "no": { + "name": "Norwegian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nso": { + "name": "Northern Sotho", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "oc": { + "name": "Occitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "or": { + "name": "Oriya", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pa": { + "name": "Punjabi", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pap": { + "name": "Papiamento", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pl": { + "name": "Polish", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "pms": { + "name": "Piemontese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ps": { + "name": "Pashto", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt": { + "name": "Portuguese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt_br": { + "name": "Brazilian Portuguese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "rm": { + "name": "Romansh", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ro": { + "name": "Romanian", + "numbers": [ + 2, + 1, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2); } + }, + "ru": { + "name": "Russian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "sah": { + "name": "Yakut", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sco": { + "name": "Scots", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "se": { + "name": "Northern Sami", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "si": { + "name": "Sinhala", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sk": { + "name": "Slovak", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "sl": { + "name": "Slovenian", + "numbers": [ + 5, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }, + "so": { + "name": "Somali", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "son": { + "name": "Songhay", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sq": { + "name": "Albanian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sr": { + "name": "Serbian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "su": { + "name": "Sundanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sv": { + "name": "Swedish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sw": { + "name": "Swahili", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ta": { + "name": "Tamil", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "te": { + "name": "Telugu", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tg": { + "name": "Tajik", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "th": { + "name": "Thai", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ti": { + "name": "Tigrinya", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tk": { + "name": "Turkmen", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tr": { + "name": "Turkish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tt": { + "name": "Tatar", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ug": { + "name": "Uyghur", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "uk": { + "name": "Ukrainian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ur": { + "name": "Urdu", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "uz": { + "name": "Uzbek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "vi": { + "name": "Vietnamese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "wa": { + "name": "Walloon", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "wo": { + "name": "Wolof", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "yo": { + "name": "Yoruba", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "zh": { + "name": "Chinese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + } + }, + + // for demonstration only sl and ar is added but you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i = ext.plurals(c); + var number = ext.numbers[i]; + if (ext.numbers.length === 2) { + // germanic like en + if (ext.numbers[0] === 2) { + if (number === 2) { + number = 1; // singular + } else if (number === 1) { + number = -1; // regular plural + } + } + // romanic like fr + else if (ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + } + } //console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[0], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.t = translate; + i18n.translate = translate; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + + $.i18n = i18n; + $.t = i18n.t; + + return i18n; + +})); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd.withJQuery-1.5.9.js b/libs/i18next/release/i18next.amd.withJQuery-1.5.9.js new file mode 100644 index 00000000..3eab21b1 --- /dev/null +++ b/libs/i18next/release/i18next.amd.withJQuery-1.5.9.js @@ -0,0 +1,2363 @@ +// i18next, v1.5.9 +// Copyright (c)2012 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function (root, factory) { + if (typeof exports === 'object') { + + var jquery = require('jquery'); + + module.exports = factory(jquery); + + } else if (typeof define === 'function' && define.amd) { + + define(['jquery'], factory); + + } +}(this, function ($) { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + var i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = []; + + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: 'dev', + detectLngQS: 'setLng', + ns: 'translation', + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + + postProcess: undefined + }; + + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = '?' + queryString.join('&'); + url += queryString !== '?' ? queryString : ''; + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + return JSON.parse(data); + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, {async: options.async}, function (status, data) { + if (status === 200) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + document.cookie = name+"="+value+expires+"; path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : _ajax, + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + toLanguages: function(lng) { + var languages = []; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + + if (o.load !== 'unspecific') languages.push(lng); + if (o.load !== 'current') languages.push(parts[0]); + } else { + languages.push(lng); + } + + if (languages.indexOf(o.fallbackLng) === -1 && o.fallbackLng) languages.push(o.fallbackLng); + + return languages; + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + if (!o.lng) o.lng = f.detectLanguage(); + if (o.lng) { + // set cookie with lng set (as detectLanguage will set cookie on need) + if (o.useCookie) f.cookie.create(o.cookieName, o.lng, o.cookieExpirationTime); + } else { + o.lng = o.fallbackLng; + if (o.useCookie) f.cookie.remove(o.cookieName); + } + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + if (cb) cb(translate); + if (deferred) deferred.resolve(); + return deferred; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + + if (cb) cb(translate); + if (deferred) deferred.resolve(); + }); + + return deferred; + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, cb) { + return init({lng: lng}, cb); + } + + function lng() { + return currentLng; + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } + else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key) return; + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') <= key.length-1) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + parse(ele, k, options); + }); + + } else { + parse(ele, k, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + + function applyReplacement(str, replacementHash, nestedKey) { + if (str.indexOf(o.interpolationPrefix) < 0) return str; + + f.each(replacementHash, function(key, value) { + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nestedKey ? nestedKey + '.' + key : key); + } else { + str = str.replace(new RegExp([o.interpolationPrefix, nestedKey ? nestedKey + '.' + key : key, o.interpolationSuffix].join(''), 'g'), value); + } + }); + return str; + } + + function applyReuse(translated, options){ + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.indexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_sans_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + var translated_token = _translate(token_sans_symbols, opts); + translated = translated.replace(token, translated_token); + } + return translated; + } + + function hasContext(options) { + return (options.context && typeof options.context == 'string'); + } + + function needsPlural(options) { + return (options.count !== undefined && typeof options.count != 'string' && options.count !== 1); + } + + function translate(key, options){ + replacementCounter = 0; + return _translate(key, options); + } + + function _translate(key, options){ + options = options || {}; + + if (!resStore) { return notfound; } // no resStore to translate from + + var optionWithoutCount, translated + , notfound = options.defaultValue || key + , lngs = languages; + + if (options.lng) { + lngs = f.toLanguages(options.lng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + ':' + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.count; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey = ns + ':' + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(currentLng, options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + ':' + key; // singular + } + + translated = translate(pluralKey, optionWithoutCount); + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { count: options.count }); // apply replacement for count only + } // else continue translation with original/singular key + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (Object.prototype.toString.apply(value) === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned a object instead of string.'; + f.log(value); + } else { + for (var m in value) { + // apply translation on childs + value[m] = _translate(ns + ':' + key + '.' + m, options); + } + } + } + found = value; + } + } + + if (found === undefined && o.sendMissing) { + if (options.lng) { + sync.postMissing(options.lng, ns, key, notfound, lngs); + } else { + sync.postMissing(o.lng, ns, key, notfound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found !== undefined && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + if (found === undefined) { + notfound = applyReplacement(notfound, options); + notfound = applyReuse(notfound, options); + } + + return (found !== undefined) ? found : notfound; + } + + function detectLanguage() { + var detectedLng; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var parms = query.split('&'); + for (var i=0; i 0) { + var key = parms[i].substring(0,pos); + var val = parms[i].substring(pos+1); + qsParm[key] = val; + } + } + })(); + if (qsParm[o.detectLngQS]) { + detectedLng = qsParm[o.detectLngQS]; + } + } + + // get from cookie + if (!detectedLng && typeof document !== 'undefined' && o.useCookie ) { + var c = f.cookie.read(o.cookieName); + if (c) detectedLng = c; + } + + // get from navigator + if (!detectedLng && typeof navigator !== 'undefined') { + detectedLng = (navigator.language) ? navigator.language : navigator.userLanguage; + } + + return detectedLng; + } + var sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + window.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + sync._fetchOne(lngValue, nsValue, options, function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }); + }); + }); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + cb(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + cb('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback') { + urls.push({lng: o.fallbackLng, url: applyReplacement(o.resPostPath, { lng: o.fallbackLng, ns: ns })}); + } else if (o.sendMissingTo === 'current') { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + resStore[item.lng][ns][key] = defaultValue; + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + } + }; + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + var pluralExtensions = { + + rules: { + "ach": { + "name": "Acholi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "af": { + "name": "Afrikaans", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ak": { + "name": "Akan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "am": { + "name": "Amharic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "an": { + "name": "Aragonese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ar": { + "name": "Arabic", + "numbers": [ + 0, + 1, + 2, + 3, + 11, + 100 + ], + "plurals": function(n) { return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5); } + }, + "arn": { + "name": "Mapudungun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ast": { + "name": "Asturian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ay": { + "name": "Aymar\u00e1", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "az": { + "name": "Azerbaijani", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "be": { + "name": "Belarusian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "bg": { + "name": "Bulgarian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bn": { + "name": "Bengali", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bo": { + "name": "Tibetan", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "br": { + "name": "Breton", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "bs": { + "name": "Bosnian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ca": { + "name": "Catalan", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "cgg": { + "name": "Chiga", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "cs": { + "name": "Czech", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "csb": { + "name": "Kashubian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "cy": { + "name": "Welsh", + "numbers": [ + 3, + 1, + 2, + 8 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3); } + }, + "da": { + "name": "Danish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "de": { + "name": "German", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "dz": { + "name": "Dzongkha", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "el": { + "name": "Greek", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "en": { + "name": "English", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eo": { + "name": "Esperanto", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es": { + "name": "Spanish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es_ar": { + "name": "Argentinean Spanish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "et": { + "name": "Estonian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eu": { + "name": "Basque", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fa": { + "name": "Persian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "fi": { + "name": "Finnish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fil": { + "name": "Filipino", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fo": { + "name": "Faroese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fr": { + "name": "French", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fur": { + "name": "Friulian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fy": { + "name": "Frisian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ga": { + "name": "Irish", + "numbers": [ + 3, + 1, + 2, + 7, + 11 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;} + }, + "gd": { + "name": "Scottish Gaelic", + "numbers": [ + 20, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3); } + }, + "gl": { + "name": "Galician", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gu": { + "name": "Gujarati", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gun": { + "name": "Gun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ha": { + "name": "Hausa", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "he": { + "name": "Hebrew", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hi": { + "name": "Hindi", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hr": { + "name": "Croatian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "hu": { + "name": "Hungarian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hy": { + "name": "Armenian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ia": { + "name": "Interlingua", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "id": { + "name": "Indonesian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "is": { + "name": "Icelandic", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n%10!=1 || n%100==11); } + }, + "it": { + "name": "Italian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ja": { + "name": "Japanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jbo": { + "name": "Lojban", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jv": { + "name": "Javanese", + "numbers": [ + 0, + 1 + ], + "plurals": function(n) { return Number(n !== 0); } + }, + "ka": { + "name": "Georgian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kk": { + "name": "Kazakh", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "km": { + "name": "Khmer", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kn": { + "name": "Kannada", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ko": { + "name": "Korean", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ku": { + "name": "Kurdish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "kw": { + "name": "Cornish", + "numbers": [ + 4, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3); } + }, + "ky": { + "name": "Kyrgyz", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lb": { + "name": "Letzeburgesch", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ln": { + "name": "Lingala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "lo": { + "name": "Lao", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lt": { + "name": "Lithuanian", + "numbers": [ + 10, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "lv": { + "name": "Latvian", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2); } + }, + "mai": { + "name": "Maithili", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mfe": { + "name": "Mauritian Creole", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mg": { + "name": "Malagasy", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mi": { + "name": "Maori", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mk": { + "name": "Macedonian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n==1 || n%10==1 ? 0 : 1); } + }, + "ml": { + "name": "Malayalam", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mn": { + "name": "Mongolian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mnk": { + "name": "Mandinka", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(0 ? 0 : n==1 ? 1 : 2); } + }, + "mr": { + "name": "Marathi", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ms": { + "name": "Malay", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "mt": { + "name": "Maltese", + "numbers": [ + 2, + 1, + 11, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3); } + }, + "nah": { + "name": "Nahuatl", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nap": { + "name": "Neapolitan", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nb": { + "name": "Norwegian Bokmal", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ne": { + "name": "Nepali", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nl": { + "name": "Dutch", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nn": { + "name": "Norwegian Nynorsk", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "no": { + "name": "Norwegian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nso": { + "name": "Northern Sotho", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "oc": { + "name": "Occitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "or": { + "name": "Oriya", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pa": { + "name": "Punjabi", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pap": { + "name": "Papiamento", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pl": { + "name": "Polish", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "pms": { + "name": "Piemontese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ps": { + "name": "Pashto", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt": { + "name": "Portuguese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt_br": { + "name": "Brazilian Portuguese", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "rm": { + "name": "Romansh", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ro": { + "name": "Romanian", + "numbers": [ + 2, + 1, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2); } + }, + "ru": { + "name": "Russian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "sah": { + "name": "Yakut", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sco": { + "name": "Scots", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "se": { + "name": "Northern Sami", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "si": { + "name": "Sinhala", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sk": { + "name": "Slovak", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "sl": { + "name": "Slovenian", + "numbers": [ + 5, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }, + "so": { + "name": "Somali", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "son": { + "name": "Songhay", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sq": { + "name": "Albanian", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sr": { + "name": "Serbian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "su": { + "name": "Sundanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sv": { + "name": "Swedish", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sw": { + "name": "Swahili", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ta": { + "name": "Tamil", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "te": { + "name": "Telugu", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tg": { + "name": "Tajik", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "th": { + "name": "Thai", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ti": { + "name": "Tigrinya", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tk": { + "name": "Turkmen", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tr": { + "name": "Turkish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tt": { + "name": "Tatar", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ug": { + "name": "Uyghur", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "uk": { + "name": "Ukrainian", + "numbers": [ + 5, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ur": { + "name": "Urdu", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "uz": { + "name": "Uzbek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "vi": { + "name": "Vietnamese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "wa": { + "name": "Walloon", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "wo": { + "name": "Wolof", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "yo": { + "name": "Yoruba", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "zh": { + "name": "Chinese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + } + }, + + // for demonstration only sl and ar is added but you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i = ext.plurals(c); + var number = ext.numbers[i]; + if (ext.numbers.length === 2) { + // germanic like en + if (ext.numbers[0] === 2) { + if (number === 2) { + number = 1; // singular + } else if (number === 1) { + number = -1; // regular plural + } + } + // romanic like fr + else if (ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + } + } //console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[0], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + + $.i18n = i18n; + $.t = i18n.t; + + return i18n; + +})); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd.withJQuery-1.6.0.js b/libs/i18next/release/i18next.amd.withJQuery-1.6.0.js new file mode 100644 index 00000000..1a7f95d5 --- /dev/null +++ b/libs/i18next/release/i18next.amd.withJQuery-1.6.0.js @@ -0,0 +1,2438 @@ +// i18next, v1.6.0 +// Copyright (c)2013 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function (root, factory) { + if (typeof exports === 'object') { + + var jquery = require('jquery'); + + module.exports = factory(jquery); + + } else if (typeof define === 'function' && define.amd) { + + define(['jquery'], factory); + + } +}(this, function ($) { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + var i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = []; + + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: 'dev', + detectLngQS: 'setLng', + ns: 'translation', + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + + postProcess: undefined + }; + + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + return JSON.parse(data); + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + if (status === 200) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + document.cookie = name+"="+value+expires+"; path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : _ajax, + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + toLanguages: function(lng) { + var languages = []; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + + if (o.load !== 'unspecific') languages.push(lng); + if (o.load !== 'current') languages.push(parts[0]); + } else { + languages.push(lng); + } + + if (languages.indexOf(o.fallbackLng) === -1 && o.fallbackLng) languages.push(o.fallbackLng); + + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + if (o.lng) { + // set cookie with lng set (as detectLanguage will set cookie on need) + if (o.useCookie) f.cookie.create(o.cookieName, o.lng, o.cookieExpirationTime); + } else { + o.lng = o.fallbackLng; + if (o.useCookie) f.cookie.remove(o.cookieName); + } + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + if (cb) cb(translate); + if (deferred) deferred.resolve(); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + + if (cb) cb(translate); + if (deferred) deferred.resolve(); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + f.extend(resStore[lng][ns], resources); + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, cb) { + return init({lng: lng}, cb); + } + + function lng() { + return currentLng; + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } + else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') <= key.length-1) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + parse(target, k, options); + }); + + } else { + parse(target, k, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + + function applyReplacement(str, replacementHash, nestedKey, options) { + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped; + + f.each(replacementHash, function(key, value) { + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nestedKey ? nestedKey + o.keyseparator + key : key, options); + } else { + str = str.replace(new RegExp([prefix, nestedKey ? nestedKey + o.keyseparator + key : key, suffix].join(''), 'g'), value); + } + }); + return str; + } + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.indexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, translated_token); + } + return translated; + } + + function hasContext(options) { + return (options.context && typeof options.context == 'string'); + } + + function needsPlural(options) { + return (options.count !== undefined && typeof options.count != 'string' && options.count !== 1); + } + + function translate(key, options){ + replacementCounter = 0; + return _translate(key, options); + } + + function _translate(key, options){ + options = options || {}; + + if (!resStore) { return notfound; } // no resStore to translate from + + var optionWithoutCount, translated + , notfound = options.defaultValue || key + , lngs = languages; + + if (options.lng) { + lngs = f.toLanguages(options.lng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.count; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(currentLng, options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + + translated = translate(pluralKey, optionWithoutCount); + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { count: options.count }); // apply replacement for count only + } // else continue translation with original/singular key + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (Object.prototype.toString.apply(value) === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned a object instead of string.'; + f.log(value); + } else { + var copy = {}; // apply child translation on a copy + for (var m in value) { + // apply translation on childs + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + } + value = copy; + } + } + found = value; + } + } + + if (found === undefined && o.fallbackToDefaultNS) { + found = _translate(key, options); + } + + if (found === undefined && o.sendMissing) { + if (options.lng) { + sync.postMissing(lngs[0], ns, key, notfound, lngs); + } else { + sync.postMissing(o.lng, ns, key, notfound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found !== undefined && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + if (found === undefined) { + notfound = applyReplacement(notfound, options); + notfound = applyReuse(notfound, options); + } + + return (found !== undefined) ? found : notfound; + } + + function detectLanguage() { + var detectedLng; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var parms = query.split('&'); + for (var i=0; i 0) { + var key = parms[i].substring(0,pos); + var val = parms[i].substring(pos+1); + qsParm[key] = val; + } + } + })(); + if (qsParm[o.detectLngQS]) { + detectedLng = qsParm[o.detectLngQS]; + } + } + + // get from cookie + if (!detectedLng && typeof document !== 'undefined' && o.useCookie ) { + var c = f.cookie.read(o.cookieName); + if (c) detectedLng = c; + } + + // get from navigator + if (!detectedLng && typeof navigator !== 'undefined') { + detectedLng = (navigator.language) ? navigator.language : navigator.userLanguage; + } + + return detectedLng; + } + var sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + window.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + cb(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + cb('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback') { + urls.push({lng: o.fallbackLng, url: applyReplacement(o.resPostPath, { lng: o.fallbackLng, ns: ns })}); + } else if (o.sendMissingTo === 'current') { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + } + }; + + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + var pluralExtensions = { + + rules: { + "ach": { + "name": "Acholi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "af": { + "name": "Afrikaans", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ak": { + "name": "Akan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "am": { + "name": "Amharic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "an": { + "name": "Aragonese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ar": { + "name": "Arabic", + "numbers": [ + 0, + 1, + 2, + 3, + 11, + 100 + ], + "plurals": function(n) { return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5); } + }, + "arn": { + "name": "Mapudungun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ast": { + "name": "Asturian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ay": { + "name": "Aymar\u00e1", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "az": { + "name": "Azerbaijani", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "be": { + "name": "Belarusian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "bg": { + "name": "Bulgarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bn": { + "name": "Bengali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bo": { + "name": "Tibetan", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "br": { + "name": "Breton", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "bs": { + "name": "Bosnian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ca": { + "name": "Catalan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "cgg": { + "name": "Chiga", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "cs": { + "name": "Czech", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "csb": { + "name": "Kashubian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "cy": { + "name": "Welsh", + "numbers": [ + 1, + 2, + 3, + 8 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3); } + }, + "da": { + "name": "Danish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "de": { + "name": "German", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "dz": { + "name": "Dzongkha", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "el": { + "name": "Greek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "en": { + "name": "English", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eo": { + "name": "Esperanto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es": { + "name": "Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es_ar": { + "name": "Argentinean Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "et": { + "name": "Estonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eu": { + "name": "Basque", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fa": { + "name": "Persian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "fi": { + "name": "Finnish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fil": { + "name": "Filipino", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fo": { + "name": "Faroese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fr": { + "name": "French", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fur": { + "name": "Friulian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fy": { + "name": "Frisian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ga": { + "name": "Irish", + "numbers": [ + 1, + 2, + 3, + 7, + 11 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;} + }, + "gd": { + "name": "Scottish Gaelic", + "numbers": [ + 1, + 2, + 3, + 20 + ], + "plurals": function(n) { return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3); } + }, + "gl": { + "name": "Galician", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gu": { + "name": "Gujarati", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gun": { + "name": "Gun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ha": { + "name": "Hausa", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "he": { + "name": "Hebrew", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hi": { + "name": "Hindi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hr": { + "name": "Croatian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "hu": { + "name": "Hungarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hy": { + "name": "Armenian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ia": { + "name": "Interlingua", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "id": { + "name": "Indonesian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "is": { + "name": "Icelandic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n%10!=1 || n%100==11); } + }, + "it": { + "name": "Italian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ja": { + "name": "Japanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jbo": { + "name": "Lojban", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jv": { + "name": "Javanese", + "numbers": [ + 0, + 1 + ], + "plurals": function(n) { return Number(n !== 0); } + }, + "ka": { + "name": "Georgian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kk": { + "name": "Kazakh", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "km": { + "name": "Khmer", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kn": { + "name": "Kannada", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ko": { + "name": "Korean", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ku": { + "name": "Kurdish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "kw": { + "name": "Cornish", + "numbers": [ + 1, + 2, + 3, + 4 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3); } + }, + "ky": { + "name": "Kyrgyz", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lb": { + "name": "Letzeburgesch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ln": { + "name": "Lingala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "lo": { + "name": "Lao", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lt": { + "name": "Lithuanian", + "numbers": [ + 1, + 2, + 10 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "lv": { + "name": "Latvian", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2); } + }, + "mai": { + "name": "Maithili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mfe": { + "name": "Mauritian Creole", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mg": { + "name": "Malagasy", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mi": { + "name": "Maori", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mk": { + "name": "Macedonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 || n%10==1 ? 0 : 1); } + }, + "ml": { + "name": "Malayalam", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mn": { + "name": "Mongolian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mnk": { + "name": "Mandinka", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(0 ? 0 : n==1 ? 1 : 2); } + }, + "mr": { + "name": "Marathi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ms": { + "name": "Malay", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "mt": { + "name": "Maltese", + "numbers": [ + 1, + 2, + 11, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3); } + }, + "nah": { + "name": "Nahuatl", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nap": { + "name": "Neapolitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nb": { + "name": "Norwegian Bokmal", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ne": { + "name": "Nepali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nl": { + "name": "Dutch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nn": { + "name": "Norwegian Nynorsk", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "no": { + "name": "Norwegian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nso": { + "name": "Northern Sotho", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "oc": { + "name": "Occitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "or": { + "name": "Oriya", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pa": { + "name": "Punjabi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pap": { + "name": "Papiamento", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pl": { + "name": "Polish", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "pms": { + "name": "Piemontese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ps": { + "name": "Pashto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt": { + "name": "Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt_br": { + "name": "Brazilian Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "rm": { + "name": "Romansh", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ro": { + "name": "Romanian", + "numbers": [ + 1, + 2, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2); } + }, + "ru": { + "name": "Russian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "sah": { + "name": "Yakut", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sco": { + "name": "Scots", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "se": { + "name": "Northern Sami", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "si": { + "name": "Sinhala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sk": { + "name": "Slovak", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "sl": { + "name": "Slovenian", + "numbers": [ + 5, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }, + "so": { + "name": "Somali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "son": { + "name": "Songhay", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sq": { + "name": "Albanian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sr": { + "name": "Serbian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "su": { + "name": "Sundanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sv": { + "name": "Swedish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sw": { + "name": "Swahili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ta": { + "name": "Tamil", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "te": { + "name": "Telugu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tg": { + "name": "Tajik", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "th": { + "name": "Thai", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ti": { + "name": "Tigrinya", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tk": { + "name": "Turkmen", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tr": { + "name": "Turkish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tt": { + "name": "Tatar", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ug": { + "name": "Uyghur", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "uk": { + "name": "Ukrainian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ur": { + "name": "Urdu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "uz": { + "name": "Uzbek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "vi": { + "name": "Vietnamese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "wa": { + "name": "Walloon", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "wo": { + "name": "Wolof", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "yo": { + "name": "Yoruba", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "zh": { + "name": "Chinese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + } + }, + + // for demonstration only sl and ar is added but you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i = ext.plurals(c); + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[0], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + + $.i18n = i18n; + $.t = i18n.t; + + return i18n; + +})); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd.withJQuery-1.6.1.js b/libs/i18next/release/i18next.amd.withJQuery-1.6.1.js new file mode 100644 index 00000000..79343a15 --- /dev/null +++ b/libs/i18next/release/i18next.amd.withJQuery-1.6.1.js @@ -0,0 +1,2595 @@ +// i18next, v1.6.1 +// Copyright (c)2013 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function (root, factory) { + if (typeof exports === 'object') { + + var jquery = require('jquery'); + + module.exports = factory(jquery); + + } else if (typeof define === 'function' && define.amd) { + + define(['jquery'], factory); + + } +}(this, function ($) { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + var i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = []; + + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: 'dev', + fallbackNS: [], + detectLngQS: 'setLng', + ns: 'translation', + fallbackOnNull: true, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + + postProcess: undefined + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + return JSON.parse(data); + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + if (status === 200) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + document.cookie = name+"="+value+expires+"; path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : _ajax, + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + toLanguages: function(lng) { + var languages = []; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + + if (o.load !== 'unspecific') languages.push(lng); + if (o.load !== 'current') languages.push(parts[0]); + } else { + languages.push(lng); + } + + if (languages.indexOf(o.fallbackLng) === -1 && o.fallbackLng) languages.push(o.fallbackLng); + + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + if (o.lng) { + // set cookie with lng set (as detectLanguage will set cookie on need) + if (o.useCookie) f.cookie.create(o.cookieName, o.lng, o.cookieExpirationTime); + } else { + o.lng = o.fallbackLng; + if (o.useCookie) f.cookie.remove(o.cookieName); + } + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + if (cb) cb(translate); + if (deferred) deferred.resolve(); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + + if (cb) cb(translate); + if (deferred) deferred.resolve(); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + f.extend(resStore[lng][ns], resources); + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, cb) { + return init({lng: lng}, cb); + } + + function lng() { + return currentLng; + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } + else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + f.each(replacementHash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), value); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.escape(value)); + }else{ + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), value); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, translated_token); + } + return translated; + } + + function hasContext(options) { + return (options.context && typeof options.context == 'string'); + } + + function needsPlural(options) { + return (options.count !== undefined && typeof options.count != 'string' && options.count !== 1); + } + + function exists(key, options) { + options = options || {}; + + var notFound = options.defaultValue || key + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(key, options) { + + if (typeof options == 'string') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else { + options = options || {}; + } + + var notFound = options.defaultValue || key + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng) : languages + , ns = options.ns || o.ns.defaultNs; + + if (found === undefined && o.sendMissing) { + if (options.lng) { + sync.postMissing(lngs[0], ns, key, notfound, lngs); + } else { + sync.postMissing(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found !== undefined && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessor && postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options){ + options = options || {}; + + if (!resStore) { return notfound; } // no resStore to translate from + + var optionWithoutCount, translated + , notFound = options.defaultValue || key + , lngs = languages; + + if (options.lng) { + lngs = f.toLanguages(options.lng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.count; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(currentLng, options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + + translated = translate(pluralKey, optionWithoutCount); + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } // else continue translation with original/singular key + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (Object.prototype.toString.apply(value) === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned a object instead of string.'; + f.log(value); + } else { + var copy = {}; // apply child translation on a copy + for (var m in value) { + // apply translation on childs + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + } + value = copy; + } + } + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _translate(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _translate(key, options); // fallback to default NS + } + } + + return found; + } + function detectLanguage() { + var detectedLng; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var parms = query.split('&'); + for (var i=0; i 0) { + var key = parms[i].substring(0,pos); + var val = parms[i].substring(pos+1); + qsParm[key] = val; + } + } + })(); + if (qsParm[o.detectLngQS]) { + detectedLng = qsParm[o.detectLngQS]; + } + } + + // get from cookie + if (!detectedLng && typeof document !== 'undefined' && o.useCookie ) { + var c = f.cookie.read(o.cookieName); + if (c) detectedLng = c; + } + + // get from navigator + if (!detectedLng && typeof navigator !== 'undefined') { + detectedLng = (navigator.language) ? navigator.language : navigator.userLanguage; + } + + return detectedLng; + } + var sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + window.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback') { + urls.push({lng: o.fallbackLng, url: applyReplacement(o.resPostPath, { lng: o.fallbackLng, ns: ns })}); + } else if (o.sendMissingTo === 'current') { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + } + }; + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + var pluralExtensions = { + + rules: { + "ach": { + "name": "Acholi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "af": { + "name": "Afrikaans", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ak": { + "name": "Akan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "am": { + "name": "Amharic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "an": { + "name": "Aragonese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ar": { + "name": "Arabic", + "numbers": [ + 0, + 1, + 2, + 3, + 11, + 100 + ], + "plurals": function(n) { return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5); } + }, + "arn": { + "name": "Mapudungun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ast": { + "name": "Asturian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ay": { + "name": "Aymar\u00e1", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "az": { + "name": "Azerbaijani", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "be": { + "name": "Belarusian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "bg": { + "name": "Bulgarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bn": { + "name": "Bengali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bo": { + "name": "Tibetan", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "br": { + "name": "Breton", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "bs": { + "name": "Bosnian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ca": { + "name": "Catalan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "cgg": { + "name": "Chiga", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "cs": { + "name": "Czech", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "csb": { + "name": "Kashubian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "cy": { + "name": "Welsh", + "numbers": [ + 1, + 2, + 3, + 8 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3); } + }, + "da": { + "name": "Danish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "de": { + "name": "German", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "dz": { + "name": "Dzongkha", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "el": { + "name": "Greek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "en": { + "name": "English", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eo": { + "name": "Esperanto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es": { + "name": "Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es_ar": { + "name": "Argentinean Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "et": { + "name": "Estonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eu": { + "name": "Basque", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fa": { + "name": "Persian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "fi": { + "name": "Finnish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fil": { + "name": "Filipino", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fo": { + "name": "Faroese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fr": { + "name": "French", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fur": { + "name": "Friulian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fy": { + "name": "Frisian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ga": { + "name": "Irish", + "numbers": [ + 1, + 2, + 3, + 7, + 11 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;} + }, + "gd": { + "name": "Scottish Gaelic", + "numbers": [ + 1, + 2, + 3, + 20 + ], + "plurals": function(n) { return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3); } + }, + "gl": { + "name": "Galician", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gu": { + "name": "Gujarati", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gun": { + "name": "Gun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ha": { + "name": "Hausa", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "he": { + "name": "Hebrew", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hi": { + "name": "Hindi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hr": { + "name": "Croatian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "hu": { + "name": "Hungarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hy": { + "name": "Armenian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ia": { + "name": "Interlingua", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "id": { + "name": "Indonesian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "is": { + "name": "Icelandic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n%10!=1 || n%100==11); } + }, + "it": { + "name": "Italian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ja": { + "name": "Japanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jbo": { + "name": "Lojban", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jv": { + "name": "Javanese", + "numbers": [ + 0, + 1 + ], + "plurals": function(n) { return Number(n !== 0); } + }, + "ka": { + "name": "Georgian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kk": { + "name": "Kazakh", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "km": { + "name": "Khmer", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kn": { + "name": "Kannada", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ko": { + "name": "Korean", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ku": { + "name": "Kurdish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "kw": { + "name": "Cornish", + "numbers": [ + 1, + 2, + 3, + 4 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3); } + }, + "ky": { + "name": "Kyrgyz", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lb": { + "name": "Letzeburgesch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ln": { + "name": "Lingala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "lo": { + "name": "Lao", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lt": { + "name": "Lithuanian", + "numbers": [ + 1, + 2, + 10 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "lv": { + "name": "Latvian", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2); } + }, + "mai": { + "name": "Maithili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mfe": { + "name": "Mauritian Creole", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mg": { + "name": "Malagasy", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mi": { + "name": "Maori", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mk": { + "name": "Macedonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 || n%10==1 ? 0 : 1); } + }, + "ml": { + "name": "Malayalam", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mn": { + "name": "Mongolian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mnk": { + "name": "Mandinka", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(0 ? 0 : n==1 ? 1 : 2); } + }, + "mr": { + "name": "Marathi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ms": { + "name": "Malay", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "mt": { + "name": "Maltese", + "numbers": [ + 1, + 2, + 11, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3); } + }, + "nah": { + "name": "Nahuatl", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nap": { + "name": "Neapolitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nb": { + "name": "Norwegian Bokmal", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ne": { + "name": "Nepali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nl": { + "name": "Dutch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nn": { + "name": "Norwegian Nynorsk", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "no": { + "name": "Norwegian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nso": { + "name": "Northern Sotho", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "oc": { + "name": "Occitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "or": { + "name": "Oriya", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pa": { + "name": "Punjabi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pap": { + "name": "Papiamento", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pl": { + "name": "Polish", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "pms": { + "name": "Piemontese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ps": { + "name": "Pashto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt": { + "name": "Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt_br": { + "name": "Brazilian Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "rm": { + "name": "Romansh", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ro": { + "name": "Romanian", + "numbers": [ + 1, + 2, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2); } + }, + "ru": { + "name": "Russian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "sah": { + "name": "Yakut", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sco": { + "name": "Scots", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "se": { + "name": "Northern Sami", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "si": { + "name": "Sinhala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sk": { + "name": "Slovak", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "sl": { + "name": "Slovenian", + "numbers": [ + 5, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }, + "so": { + "name": "Somali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "son": { + "name": "Songhay", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sq": { + "name": "Albanian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sr": { + "name": "Serbian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "su": { + "name": "Sundanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sv": { + "name": "Swedish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sw": { + "name": "Swahili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ta": { + "name": "Tamil", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "te": { + "name": "Telugu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tg": { + "name": "Tajik", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "th": { + "name": "Thai", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ti": { + "name": "Tigrinya", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tk": { + "name": "Turkmen", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tr": { + "name": "Turkish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tt": { + "name": "Tatar", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ug": { + "name": "Uyghur", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "uk": { + "name": "Ukrainian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ur": { + "name": "Urdu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "uz": { + "name": "Uzbek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "vi": { + "name": "Vietnamese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "wa": { + "name": "Walloon", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "wo": { + "name": "Wolof", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "yo": { + "name": "Yoruba", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "zh": { + "name": "Chinese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + } + }, + + // for demonstration only sl and ar is added but you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i = ext.plurals(c); + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[0], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + + $.i18n = i18n; + $.t = i18n.t; + + return i18n; + +})); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd.withJQuery-1.6.1.min.js b/libs/i18next/release/i18next.amd.withJQuery-1.6.1.min.js new file mode 100644 index 00000000..2b52b085 --- /dev/null +++ b/libs/i18next/release/i18next.amd.withJQuery-1.6.1.min.js @@ -0,0 +1,5 @@ +// i18next, v1.6.1 +// Copyright (c)2013 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function(n,e){if("object"==typeof exports){var r=require("jquery");module.exports=e(r)}else"function"==typeof define&&define.amd&&define(["jquery"],e)})(this,function(n){function e(n,e){if(!e||"function"==typeof e)return n;for(var r in e)n[r]=e[r];return n}function r(n,e,r){var t,u=0,a=n.length,o=void 0===a||"function"==typeof n;if(r)if(o){for(t in n)if(e.apply(n[t],r)===!1)break}else for(;a>u&&e.apply(n[u++],r)!==!1;);else if(o){for(t in n)if(e.call(n[t],t,n[t])===!1)break}else for(;a>u&&e.call(n[u],u,n[u++])!==!1;);return n}function t(n){return"string"==typeof n?n.replace(/[&<>"'\/]/g,function(n){return A[n]}):n}function u(n){var e=function(n){if(window.XMLHttpRequest)return n(null,new XMLHttpRequest);if(window.ActiveXObject)try{return n(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(e){return n(null,new ActiveXObject("Microsoft.XMLHTTP"))}return n(Error())},r=function(n){if("string"==typeof n)return n;var e=[];for(var r in n)n.hasOwnProperty(r)&&e.push(encodeURIComponent(r)+"="+encodeURIComponent(n[r]));return e.join("&")},t=function(n){n=n.replace(/\r\n/g,"\n");for(var e="",r=0;n.length>r;r++){var t=n.charCodeAt(r);128>t?e+=String.fromCharCode(t):t>127&&2048>t?(e+=String.fromCharCode(192|t>>6),e+=String.fromCharCode(128|63&t)):(e+=String.fromCharCode(224|t>>12),e+=String.fromCharCode(128|63&t>>6),e+=String.fromCharCode(128|63&t))}return e},u=function(n){var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";n=t(n);var r,u,a,o,s,i,l,c="",f=0;do r=n.charCodeAt(f++),u=n.charCodeAt(f++),a=n.charCodeAt(f++),o=r>>2,s=(3&r)<<4|u>>4,i=(15&u)<<2|a>>6,l=63&a,isNaN(u)?i=l=64:isNaN(a)&&(l=64),c+=e.charAt(o)+e.charAt(s)+e.charAt(i)+e.charAt(l),r=u=a="",o=s=i=l="";while(n.length>f);return c},a=function(){for(var n=arguments[0],e=1;arguments.length>e;e++){var r=arguments[e];for(var t in r)r.hasOwnProperty(t)&&(n[t]=r[t])}return n},o=function(n,t,u,s){"function"==typeof u&&(s=u,u={}),u.cache=u.cache||!1,u.data=u.data||{},u.headers=u.headers||{},u.jsonp=u.jsonp||!1,u.async=void 0===u.async?!0:u.async;var i,l=a({accept:"*/*","content-type":"application/x-www-form-urlencoded;charset=UTF-8"},o.headers,u.headers);if(i="application/json"===l["content-type"]?JSON.stringify(u.data):r(u.data),"GET"===n){var c=[];if(i&&(c.push(i),i=null),u.cache||c.push("_="+(new Date).getTime()),u.jsonp&&(c.push("callback="+u.jsonp),c.push("jsonp="+u.jsonp)),c=c.join("&"),c.length>1&&(t+=t.indexOf("?")>-1?"&"+c:"?"+c),u.jsonp){var f=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=t,f.appendChild(m),void 0}}e(function(e,r){if(e)return s(e);r.open(n,t,u.async);for(var a in l)l.hasOwnProperty(a)&&r.setRequestHeader(a,l[a]);r.onreadystatechange=function(){if(4===r.readyState){var n=r.responseText||"";if(!s)return;s(r.status,{text:function(){return n},json:function(){return JSON.parse(n)}})}},r.send(i)})},s={authBasic:function(n,e){o.headers.Authorization="Basic "+u(n+":"+e)},connect:function(n,e,r){return o("CONNECT",n,e,r)},del:function(n,e,r){return o("DELETE",n,e,r)},get:function(n,e,r){return o("GET",n,e,r)},head:function(n,e,r){return o("HEAD",n,e,r)},headers:function(n){o.headers=n||{}},isAllowed:function(n,e,r){this.options(n,function(n,t){r(-1!==t.text().indexOf(e))})},options:function(n,e,r){return o("OPTIONS",n,e,r)},patch:function(n,e,r){return o("PATCH",n,e,r)},post:function(n,e,r){return o("POST",n,e,r)},put:function(n,e,r){return o("PUT",n,e,r)},trace:function(n,e,r){return o("TRACE",n,e,r)}},i=n.type?n.type.toLowerCase():"get";s[i](n.url,n,function(e,r){200===e?n.success(r.json(),e,null):n.error(r.text(),e,null)})}function a(e,r){"function"==typeof e&&(r=e,e={}),e=e||{},M.extend(P,e),"string"==typeof P.ns&&(P.ns={namespaces:[P.ns],defaultNs:P.ns}),"string"==typeof P.fallbackNS&&(P.fallbackNS=[P.fallbackNS]),P.interpolationPrefixEscaped=M.regexEscape(P.interpolationPrefix),P.interpolationSuffixEscaped=M.regexEscape(P.interpolationSuffix),P.lng||(P.lng=M.detectLanguage()),P.lng?P.useCookie&&M.cookie.create(P.cookieName,P.lng,P.cookieExpirationTime):(P.lng=P.fallbackLng,P.useCookie&&M.cookie.remove(P.cookieName)),T=M.toLanguages(P.lng),O=T[0],M.log("currentLng set to: "+O),F.setCurrentLng(O),n&&P.setJqueryExt&&p();var t;if(n&&n.Deferred&&(t=n.Deferred()),!P.resStore){var u=M.toLanguages(P.lng);"string"==typeof P.preload&&(P.preload=[P.preload]);for(var a=0,o=P.preload.length;o>a;a++)for(var s=M.toLanguages(P.preload[a]),i=0,l=s.length;l>i;i++)0>u.indexOf(s[i])&&u.push(s[i]);return L.sync.load(u,P,function(n,e){w=e,r&&r(v),t&&t.resolve()}),t?t.promise():void 0}return w=P.resStore,r&&r(v),t&&t.resolve(),t?t.promise():void 0}function o(n,e){"string"==typeof n&&(n=[n]);for(var r=0,t=n.length;t>r;r++)0>P.preload.indexOf(n[r])&&P.preload.push(n[r]);return a(e)}function s(n,e,r){"string"!=typeof e?(r=e,e=P.ns.defaultNs):0>P.ns.namespaces.indexOf(e)&&P.ns.namespaces.push(e),w[n]=w[n]||{},w[n][e]=w[n][e]||{},M.extend(w[n][e],r)}function i(n){P.ns.defaultNs=n}function l(n,e){c([n],e)}function c(n,e){var r={dynamicLoad:P.dynamicLoad,resGetPath:P.resGetPath,getAsync:P.getAsync,customLoad:P.customLoad,ns:{namespaces:n,defaultNs:""}},t=M.toLanguages(P.lng);"string"==typeof P.preload&&(P.preload=[P.preload]);for(var u=0,a=P.preload.length;a>u;u++)for(var o=M.toLanguages(P.preload[u]),s=0,i=o.length;i>s;s++)0>t.indexOf(o[s])&&t.push(o[s]);for(var l=[],c=0,f=t.length;f>c;c++){var m=!1,p=w[t[c]];if(p)for(var b=0,g=n.length;g>b;b++)p[n[b]]||(m=!0);else m=!0;m&&l.push(t[c])}l.length?L.sync._fetch(l,r,function(r,t){var u=n.length*l.length;M.each(n,function(n,r){0>P.ns.namespaces.indexOf(r)&&P.ns.namespaces.push(r),M.each(l,function(n,a){w[a]=w[a]||{},w[a][r]=t[a][r],u--,0===u&&e&&(P.useLocalStorage&&L.sync._storeLocal(w),e())})})}):e&&e()}function f(n,e){return a({lng:n},e)}function m(){return O}function p(){function e(e,r,t){if(0!==r.length){var u="text";if(0===r.indexOf("[")){var a=r.split("]");r=a[1],u=a[0].substr(1,a[0].length-1)}r.indexOf(";")===r.length-1&&(r=r.substr(0,r.length-2));var o;"html"===u?(o=P.defaultValueFromContent?n.extend({defaultValue:e.html()},t):t,e.html(n.t(r,o))):"text"===u?(o=P.defaultValueFromContent?n.extend({defaultValue:e.text()},t):t,e.text(n.t(r,o))):(o=P.defaultValueFromContent?n.extend({defaultValue:e.attr(u)},t):t,e.attr(u,n.t(r,o)))}}function r(r,t){var u=r.attr(P.selectorAttr);if(u){var a=r,o=r.data("i18n-target");if(o&&(a=r.find(o)||r),t||P.useDataAttrOptions!==!0||(t=r.data("i18n-options")),t=t||{},u.indexOf(";")>=0){var s=u.split(";");n.each(s,function(n,r){""!==r&&e(a,r,t)})}else e(a,u,t);P.useDataAttrOptions===!0&&r.data("i18n-options",t)}}n.t=n.t||v,n.fn.i18n=function(e){return this.each(function(){r(n(this),e);var t=n(this).find("["+P.selectorAttr+"]");t.each(function(){r(n(this),e)})})}}function b(n,e,r,t){if(!n)return n;if(t=t||e,0>n.indexOf(t.interpolationPrefix||P.interpolationPrefix))return n;var u=t.interpolationPrefix?M.regexEscape(t.interpolationPrefix):P.interpolationPrefixEscaped,a=t.interpolationSuffix?M.regexEscape(t.interpolationSuffix):P.interpolationSuffixEscaped,o="HTML"+a;return M.each(e,function(e,s){var i=r?r+P.keyseparator+e:e;"object"==typeof s&&null!==s?n=b(n,s,i,t):t.escapeInterpolation||P.escapeInterpolation?(n=n.replace(RegExp([u,i,o].join(""),"g"),s),n=n.replace(RegExp([u,i,a].join(""),"g"),M.escape(s))):n=n.replace(RegExp([u,i,a].join(""),"g"),s)}),n}function g(n,e){var r=",",t="{",u="}",a=M.extend({},e);for(delete a.postProcess;-1!=n.indexOf(P.reusePrefix)&&(j++,!(j>P.maxRecursion));){var o=n.lastIndexOf(P.reusePrefix),s=n.indexOf(P.reuseSuffix,o)+P.reuseSuffix.length,i=n.substring(o,s),l=i.replace(P.reusePrefix,"").replace(P.reuseSuffix,"");if(-1!=l.indexOf(r)){var c=l.indexOf(r);if(-1!=l.indexOf(t,c)&&-1!=l.indexOf(u,c)){var f=l.indexOf(t,c),m=l.indexOf(u,f)+u.length;try{a=M.extend(a,JSON.parse(l.substring(f,m))),l=l.substring(0,c)}catch(p){}}}var b=y(l,a);n=n.replace(i,b)}return n}function d(n){return n.context&&"string"==typeof n.context}function h(n){return void 0!==n.count&&"string"!=typeof n.count&&1!==n.count}function N(n,e){e=e||{};var r=e.defaultValue||n,t=k(n,e);return void 0!==t||t===r}function v(){return j=0,y.apply(null,arguments)}function x(){for(var n=[],e=1;arguments.length>e;e++)n.push(arguments[e]);return{postProcess:"sprintf",sprintf:n}}function y(n,e){e="string"==typeof e?x.apply(null,arguments):e||{};var r=e.defaultValue||n,t=k(n,e),u=e.lng?M.toLanguages(e.lng):T,a=e.ns||P.ns.defaultNs;void 0===t&&P.sendMissing&&(e.lng?E.postMissing(u[0],a,n,notfound,u):E.postMissing(P.lng,a,n,r,u));var o=e.postProcess||P.postProcess;return void 0!==t&&o&&R[o]&&(t=R[o](t,n,e)),void 0===t&&(r=b(r,e),r=g(r,e),o&&R[o]&&(t=R[o](t,n,e))),void 0!==t?t:r}function k(n,e){if(e=e||{},!w)return notfound;var r,t,u=e.defaultValue||n,a=T;if(e.lng&&(a=M.toLanguages(e.lng),!w[a[0]])){var o=P.getAsync;P.getAsync=!1,L.sync.load(a,P,function(n,e){M.extend(w,e),P.getAsync=o})}var s=e.ns||P.ns.defaultNs;if(n.indexOf(P.nsseparator)>-1){var i=n.split(P.nsseparator);s=i[0],n=i[1]}if(d(e)){r=M.extend({},e),delete r.context,r.defaultValue=P.contextNotFound;var l=s+P.nsseparator+n+"_"+e.context;if(t=v(l,r),t!=P.contextNotFound)return b(t,{context:e.context})}if(h(e)){r=M.extend({},e),delete r.count,r.defaultValue=P.pluralNotFound;var c=s+P.nsseparator+n+P.pluralSuffix,f=F.get(O,e.count);if(f>=0?c=c+"_"+f:1===f&&(c=s+P.nsseparator+n),t=v(c,r),t!=P.pluralNotFound)return b(t,{count:e.count,interpolationPrefix:e.interpolationPrefix,interpolationSuffix:e.interpolationSuffix})}for(var m,p=n.split(P.keyseparator),N=0,x=a.length;x>N&&void 0===m;N++){for(var k=a[N],S=0,j=w[k]&&w[k][s];p[S];)j=j&&j[p[S]],S++;if(void 0!==j){if("string"==typeof j)j=b(j,e),j=g(j,e);else if("[object Array]"!==Object.prototype.toString.apply(j)||P.returnObjectTrees||e.returnObjectTrees){if(null===j&&P.fallbackOnNull===!0)j=void 0;else if(null!==j)if(P.returnObjectTrees||e.returnObjectTrees){var A={};for(var C in j)A[C]=y(s+P.nsseparator+n+P.keyseparator+C,e);j=A}else j="key '"+s+":"+n+" ("+k+")' "+"returned a object instead of string.",M.log(j)}else j=j.join("\n"),j=b(j,e),j=g(j,e);m=j}}if(void 0===m&&!e.isFallbackLookup&&(P.fallbackToDefaultNS===!0||P.fallbackNS&&P.fallbackNS.length))if(e.isFallbackLookup=!0,P.fallbackNS.length){for(var _=0,E=P.fallbackNS.length;E>_;_++)if(m=y(P.fallbackNS[_]+P.nsseparator+n,e)){var R=m.indexOf(P.nsseparator)>-1?m.split(P.nsseparator)[1]:m,z=u.indexOf(P.nsseparator)>-1?u.split(P.nsseparator)[1]:u;if(R!==z)break}}else m=y(n,e);return m}function S(){var n,e=[];if("undefined"!=typeof window&&(function(){for(var n=window.location.search.substring(1),r=n.split("&"),t=0;r.length>t;t++){var u=r[t].indexOf("=");if(u>0){var a=r[t].substring(0,u),o=r[t].substring(u+1);e[a]=o}}}(),e[P.detectLngQS]&&(n=e[P.detectLngQS])),!n&&"undefined"!=typeof document&&P.useCookie){var r=M.cookie.read(P.cookieName);r&&(n=r)}return n||"undefined"==typeof navigator||(n=navigator.language?navigator.language:navigator.userLanguage),n}Array.prototype.indexOf||(Array.prototype.indexOf=function(n){"use strict";if(null==this)throw new TypeError;var e=Object(this),r=e.length>>>0;if(0===r)return-1;var t=0;if(arguments.length>0&&(t=Number(arguments[1]),t!=t?t=0:0!=t&&1/0!=t&&t!=-1/0&&(t=(t>0||-1)*Math.floor(Math.abs(t)))),t>=r)return-1;for(var u=t>=0?t:Math.max(r-Math.abs(t),0);r>u;u++)if(u in e&&e[u]===n)return u;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(n){"use strict";if(null==this)throw new TypeError;var e=Object(this),r=e.length>>>0;if(0===r)return-1;var t=r;arguments.length>1&&(t=Number(arguments[1]),t!=t?t=0:0!=t&&t!=1/0&&t!=-(1/0)&&(t=(t>0||-1)*Math.floor(Math.abs(t))));for(var u=t>=0?Math.min(t,r-1):r-Math.abs(t);u>=0;u--)if(u in e&&e[u]===n)return u;return-1});var O,L={},w={},j=0,T=[],P={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:"dev",fallbackNS:[],detectLngQS:"setLng",ns:"translation",fallbackOnNull:!0,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",postProcess:void 0},A={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},C={create:function(n,e,r){var t;if(r){var u=new Date;u.setTime(u.getTime()+1e3*60*r),t="; expires="+u.toGMTString()}else t="";document.cookie=n+"="+e+t+"; path=/"},read:function(n){for(var e=n+"=",r=document.cookie.split(";"),t=0;r.length>t;t++){for(var u=r[t];" "==u.charAt(0);)u=u.substring(1,u.length);if(0===u.indexOf(e))return u.substring(e.length,u.length)}return null},remove:function(n){this.create(n,"",-1)}},_={create:function(){},read:function(){return null},remove:function(){}},M={extend:n?n.extend:e,each:n?n.each:r,ajax:n?n.ajax:u,cookie:"undefined"!=typeof document?C:_,detectLanguage:S,escape:t,log:function(n){P.debug&&"undefined"!=typeof console&&console.log(n)},toLanguages:function(n){var e=[];if("string"==typeof n&&n.indexOf("-")>-1){var r=n.split("-");n=P.lowerCaseLng?r[0].toLowerCase()+"-"+r[1].toLowerCase():r[0].toLowerCase()+"-"+r[1].toUpperCase(),"unspecific"!==P.load&&e.push(n),"current"!==P.load&&e.push(r[0])}else e.push(n);return-1===e.indexOf(P.fallbackLng)&&P.fallbackLng&&e.push(P.fallbackLng),e},regexEscape:function(n){return n.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}};M.applyReplacement=b;var E={load:function(n,e,r){e.useLocalStorage?E._loadLocal(n,e,function(t,u){for(var a=[],o=0,s=n.length;s>o;o++)u[n[o]]||a.push(n[o]);a.length>0?E._fetch(a,e,function(n,e){M.extend(u,e),E._storeLocal(e),r(null,u)}):r(null,u)}):E._fetch(n,e,function(n,e){r(null,e)})},_loadLocal:function(n,e,r){var t={},u=(new Date).getTime();if(window.localStorage){var a=n.length;M.each(n,function(n,o){var s=window.localStorage.getItem("res_"+o);s&&(s=JSON.parse(s),s.i18nStamp&&s.i18nStamp+e.localStorageExpirationTime>u&&(t[o]=s)),a--,0===a&&r(null,t)})}},_storeLocal:function(n){if(window.localStorage)for(var e in n)n[e].i18nStamp=(new Date).getTime(),window.localStorage.setItem("res_"+e,JSON.stringify(n[e]))},_fetch:function(n,e,r){var t=e.ns,u={};if(e.dynamicLoad){var a=function(n,e){r(null,e)};if("function"==typeof e.customLoad)e.customLoad(n,t.namespaces,e,a);else{var o=b(e.resGetPath,{lng:n.join("+"),ns:t.namespaces.join("+")});M.ajax({url:o,success:function(n){M.log("loaded: "+o),a(null,n)},error:function(n,e,r){M.log("failed loading: "+o),a("failed loading resource.json error: "+r)},dataType:"json",async:e.getAsync})}}else{var s,i=t.namespaces.length*n.length;M.each(t.namespaces,function(t,a){M.each(n,function(n,t){var o=function(n,e){n&&(s=s||[],s.push(n)),u[t]=u[t]||{},u[t][a]=e,i--,0===i&&r(s,u)};"function"==typeof e.customLoad?e.customLoad(t,a,e,o):E._fetchOne(t,a,e,o)})})}},_fetchOne:function(n,e,r,t){var u=b(r.resGetPath,{lng:n,ns:e});M.ajax({url:u,success:function(n){M.log("loaded: "+u),t(null,n)},error:function(n,e,r){M.log("failed loading: "+u),t(r,{})},dataType:"json",async:r.getAsync})},postMissing:function(n,e,r,t,u){var a={};a[r]=t;var o=[];if("fallback"===P.sendMissingTo)o.push({lng:P.fallbackLng,url:b(P.resPostPath,{lng:P.fallbackLng,ns:e})});else if("current"===P.sendMissingTo)o.push({lng:n,url:b(P.resPostPath,{lng:n,ns:e})});else if("all"===P.sendMissingTo)for(var s=0,i=u.length;i>s;s++)o.push({lng:u[s],url:b(P.resPostPath,{lng:u[s],ns:e})});for(var l=0,c=o.length;c>l;l++){var f=o[l];M.ajax({url:f.url,type:P.sendType,data:a,success:function(){M.log("posted missing key '"+r+"' to: "+f.url);for(var n=r.split("."),u=0,a=w[f.lng][e];n[u];)a=a[n[u]]=u===n.length-1?t:a[n[u]]||{},u++},error:function(){M.log("failed posting missing key '"+r+"' to: "+f.url)},dataType:"json",async:P.postAsync})}}},F={rules:{ach:{name:"Acholi",numbers:[1,2],plurals:function(n){return Number(n>1)}},af:{name:"Afrikaans",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ak:{name:"Akan",numbers:[1,2],plurals:function(n){return Number(n>1)}},am:{name:"Amharic",numbers:[1,2],plurals:function(n){return Number(n>1)}},an:{name:"Aragonese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ar:{name:"Arabic",numbers:[0,1,2,3,11,100],plurals:function(n){return Number(0===n?0:1==n?1:2==n?2:n%100>=3&&10>=n%100?3:n%100>=11?4:5)}},arn:{name:"Mapudungun",numbers:[1,2],plurals:function(n){return Number(n>1)}},ast:{name:"Asturian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ay:{name:"Aymará",numbers:[1],plurals:function(){return 0}},az:{name:"Azerbaijani",numbers:[1,2],plurals:function(n){return Number(1!=n)}},be:{name:"Belarusian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},bg:{name:"Bulgarian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},bn:{name:"Bengali",numbers:[1,2],plurals:function(n){return Number(1!=n)}},bo:{name:"Tibetan",numbers:[1],plurals:function(){return 0}},br:{name:"Breton",numbers:[1,2],plurals:function(n){return Number(n>1)}},bs:{name:"Bosnian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},ca:{name:"Catalan",numbers:[1,2],plurals:function(n){return Number(1!=n)}},cgg:{name:"Chiga",numbers:[1],plurals:function(){return 0}},cs:{name:"Czech",numbers:[1,2,5],plurals:function(n){return Number(1==n?0:n>=2&&4>=n?1:2)}},csb:{name:"Kashubian",numbers:[1,2,5],plurals:function(n){return Number(1==n?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},cy:{name:"Welsh",numbers:[1,2,3,8],plurals:function(n){return Number(1==n?0:2==n?1:8!=n&&11!=n?2:3)}},da:{name:"Danish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},de:{name:"German",numbers:[1,2],plurals:function(n){return Number(1!=n)}},dz:{name:"Dzongkha",numbers:[1],plurals:function(){return 0}},el:{name:"Greek",numbers:[1,2],plurals:function(n){return Number(1!=n)}},en:{name:"English",numbers:[1,2],plurals:function(n){return Number(1!=n)}},eo:{name:"Esperanto",numbers:[1,2],plurals:function(n){return Number(1!=n)}},es:{name:"Spanish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},es_ar:{name:"Argentinean Spanish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},et:{name:"Estonian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},eu:{name:"Basque",numbers:[1,2],plurals:function(n){return Number(1!=n)}},fa:{name:"Persian",numbers:[1],plurals:function(){return 0}},fi:{name:"Finnish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},fil:{name:"Filipino",numbers:[1,2],plurals:function(n){return Number(n>1)}},fo:{name:"Faroese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},fr:{name:"French",numbers:[1,2],plurals:function(n){return Number(n>1)}},fur:{name:"Friulian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},fy:{name:"Frisian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ga:{name:"Irish",numbers:[1,2,3,7,11],plurals:function(n){return Number(1==n?0:2==n?1:7>n?2:11>n?3:4)}},gd:{name:"Scottish Gaelic",numbers:[1,2,3,20],plurals:function(n){return Number(1==n||11==n?0:2==n||12==n?1:n>2&&20>n?2:3)}},gl:{name:"Galician",numbers:[1,2],plurals:function(n){return Number(1!=n)}},gu:{name:"Gujarati",numbers:[1,2],plurals:function(n){return Number(1!=n)}},gun:{name:"Gun",numbers:[1,2],plurals:function(n){return Number(n>1)}},ha:{name:"Hausa",numbers:[1,2],plurals:function(n){return Number(1!=n)}},he:{name:"Hebrew",numbers:[1,2],plurals:function(n){return Number(1!=n)}},hi:{name:"Hindi",numbers:[1,2],plurals:function(n){return Number(1!=n)}},hr:{name:"Croatian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},hu:{name:"Hungarian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},hy:{name:"Armenian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ia:{name:"Interlingua",numbers:[1,2],plurals:function(n){return Number(1!=n)}},id:{name:"Indonesian",numbers:[1],plurals:function(){return 0}},is:{name:"Icelandic",numbers:[1,2],plurals:function(n){return Number(1!=n%10||11==n%100)}},it:{name:"Italian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ja:{name:"Japanese",numbers:[1],plurals:function(){return 0}},jbo:{name:"Lojban",numbers:[1],plurals:function(){return 0}},jv:{name:"Javanese",numbers:[0,1],plurals:function(n){return Number(0!==n)}},ka:{name:"Georgian",numbers:[1],plurals:function(){return 0}},kk:{name:"Kazakh",numbers:[1],plurals:function(){return 0}},km:{name:"Khmer",numbers:[1],plurals:function(){return 0}},kn:{name:"Kannada",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ko:{name:"Korean",numbers:[1],plurals:function(){return 0}},ku:{name:"Kurdish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},kw:{name:"Cornish",numbers:[1,2,3,4],plurals:function(n){return Number(1==n?0:2==n?1:3==n?2:3)}},ky:{name:"Kyrgyz",numbers:[1],plurals:function(){return 0}},lb:{name:"Letzeburgesch",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ln:{name:"Lingala",numbers:[1,2],plurals:function(n){return Number(n>1)}},lo:{name:"Lao",numbers:[1],plurals:function(){return 0}},lt:{name:"Lithuanian",numbers:[1,2,10],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&(10>n%100||n%100>=20)?1:2)}},lv:{name:"Latvian",numbers:[0,1,2],plurals:function(n){return Number(1==n%10&&11!=n%100?0:0!==n?1:2)}},mai:{name:"Maithili",numbers:[1,2],plurals:function(n){return Number(1!=n)}},mfe:{name:"Mauritian Creole",numbers:[1,2],plurals:function(n){return Number(n>1)}},mg:{name:"Malagasy",numbers:[1,2],plurals:function(n){return Number(n>1)}},mi:{name:"Maori",numbers:[1,2],plurals:function(n){return Number(n>1)}},mk:{name:"Macedonian",numbers:[1,2],plurals:function(n){return Number(1==n||1==n%10?0:1)}},ml:{name:"Malayalam",numbers:[1,2],plurals:function(n){return Number(1!=n)}},mn:{name:"Mongolian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},mnk:{name:"Mandinka",numbers:[0,1,2],plurals:function(n){return Number(1==n?1:2)}},mr:{name:"Marathi",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ms:{name:"Malay",numbers:[1],plurals:function(){return 0}},mt:{name:"Maltese",numbers:[1,2,11,20],plurals:function(n){return Number(1==n?0:0===n||n%100>1&&11>n%100?1:n%100>10&&20>n%100?2:3)}},nah:{name:"Nahuatl",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nap:{name:"Neapolitan",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nb:{name:"Norwegian Bokmal",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ne:{name:"Nepali",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nl:{name:"Dutch",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nn:{name:"Norwegian Nynorsk",numbers:[1,2],plurals:function(n){return Number(1!=n)}},no:{name:"Norwegian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nso:{name:"Northern Sotho",numbers:[1,2],plurals:function(n){return Number(1!=n)}},oc:{name:"Occitan",numbers:[1,2],plurals:function(n){return Number(n>1)}},or:{name:"Oriya",numbers:[2,1],plurals:function(n){return Number(1!=n)}},pa:{name:"Punjabi",numbers:[1,2],plurals:function(n){return Number(1!=n)}},pap:{name:"Papiamento",numbers:[1,2],plurals:function(n){return Number(1!=n)}},pl:{name:"Polish",numbers:[1,2,5],plurals:function(n){return Number(1==n?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},pms:{name:"Piemontese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ps:{name:"Pashto",numbers:[1,2],plurals:function(n){return Number(1!=n)}},pt:{name:"Portuguese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},pt_br:{name:"Brazilian Portuguese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},rm:{name:"Romansh",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ro:{name:"Romanian",numbers:[1,2,20],plurals:function(n){return Number(1==n?0:0===n||n%100>0&&20>n%100?1:2)}},ru:{name:"Russian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},sah:{name:"Yakut",numbers:[1],plurals:function(){return 0}},sco:{name:"Scots",numbers:[1,2],plurals:function(n){return Number(1!=n)}},se:{name:"Northern Sami",numbers:[1,2],plurals:function(n){return Number(1!=n)}},si:{name:"Sinhala",numbers:[1,2],plurals:function(n){return Number(1!=n)}},sk:{name:"Slovak",numbers:[1,2,5],plurals:function(n){return Number(1==n?0:n>=2&&4>=n?1:2)}},sl:{name:"Slovenian",numbers:[5,1,2,3],plurals:function(n){return Number(1==n%100?1:2==n%100?2:3==n%100||4==n%100?3:0)}},so:{name:"Somali",numbers:[1,2],plurals:function(n){return Number(1!=n)}},son:{name:"Songhay",numbers:[1,2],plurals:function(n){return Number(1!=n)}},sq:{name:"Albanian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},sr:{name:"Serbian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},su:{name:"Sundanese",numbers:[1],plurals:function(){return 0}},sv:{name:"Swedish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},sw:{name:"Swahili",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ta:{name:"Tamil",numbers:[1,2],plurals:function(n){return Number(1!=n)}},te:{name:"Telugu",numbers:[1,2],plurals:function(n){return Number(1!=n)}},tg:{name:"Tajik",numbers:[1,2],plurals:function(n){return Number(n>1)}},th:{name:"Thai",numbers:[1],plurals:function(){return 0}},ti:{name:"Tigrinya",numbers:[1,2],plurals:function(n){return Number(n>1)}},tk:{name:"Turkmen",numbers:[1,2],plurals:function(n){return Number(1!=n)}},tr:{name:"Turkish",numbers:[1,2],plurals:function(n){return Number(n>1)}},tt:{name:"Tatar",numbers:[1],plurals:function(){return 0}},ug:{name:"Uyghur",numbers:[1],plurals:function(){return 0}},uk:{name:"Ukrainian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},ur:{name:"Urdu",numbers:[1,2],plurals:function(n){return Number(1!=n)}},uz:{name:"Uzbek",numbers:[1,2],plurals:function(n){return Number(n>1)}},vi:{name:"Vietnamese",numbers:[1],plurals:function(){return 0}},wa:{name:"Walloon",numbers:[1,2],plurals:function(n){return Number(n>1)}},wo:{name:"Wolof",numbers:[1],plurals:function(){return 0}},yo:{name:"Yoruba",numbers:[1,2],plurals:function(n){return Number(1!=n)}},zh:{name:"Chinese",numbers:[1],plurals:function(){return 0}}},addRule:function(n,e){F.rules[n]=e},setCurrentLng:function(n){if(!F.currentRule||F.currentRule.lng!==n){var e=n.split("-");F.currentRule={lng:n,rule:F.rules[e[0]]}}},get:function(n,e){function r(e,r){var t;if(t=F.currentRule&&F.currentRule.lng===n?F.currentRule.rule:F.rules[e]){var u=t.plurals(r),a=t.numbers[u];return 2===t.numbers.length&&1===t.numbers[0]&&(2===a?a=-1:1===a&&(a=1)),a}return 1===r?"1":"-1"}var t=n.split("-");return r(t[0],e)}},R={},z=function(n,e){R[n]=e},D=function(){function n(n){return Object.prototype.toString.call(n).slice(8,-1).toLowerCase()}function e(n,e){for(var r=[];e>0;r[--e]=n);return r.join("")}var r=function(){return r.cache.hasOwnProperty(arguments[0])||(r.cache[arguments[0]]=r.parse(arguments[0])),r.format.call(null,r.cache[arguments[0]],arguments)};return r.format=function(r,t){var u,a,o,s,i,l,c,f=1,m=r.length,p="",b=[];for(a=0;m>a;a++)if(p=n(r[a]),"string"===p)b.push(r[a]);else if("array"===p){if(s=r[a],s[2])for(u=t[f],o=0;s[2].length>o;o++){if(!u.hasOwnProperty(s[2][o]))throw D('[sprintf] property "%s" does not exist',s[2][o]);u=u[s[2][o]]}else u=s[1]?t[s[1]]:t[f++];if(/[^s]/.test(s[8])&&"number"!=n(u))throw D("[sprintf] expecting number but found %s",n(u));switch(s[8]){case"b":u=u.toString(2);break;case"c":u=String.fromCharCode(u);break;case"d":u=parseInt(u,10);break;case"e":u=s[7]?u.toExponential(s[7]):u.toExponential();break;case"f":u=s[7]?parseFloat(u).toFixed(s[7]):parseFloat(u);break;case"o":u=u.toString(8);break;case"s":u=(u+="")&&s[7]?u.substring(0,s[7]):u;break;case"u":u=Math.abs(u);break;case"x":u=u.toString(16);break;case"X":u=u.toString(16).toUpperCase()}u=/[def]/.test(s[8])&&s[3]&&u>=0?"+"+u:u,l=s[4]?"0"==s[4]?"0":s[4].charAt(1):" ",c=s[6]-(u+"").length,i=s[6]?e(l,c):"",b.push(s[5]?u+i:i+u)}return b.join("")},r.cache={},r.parse=function(n){for(var e=n,r=[],t=[],u=0;e;){if(null!==(r=/^[^\x25]+/.exec(e)))t.push(r[0]);else if(null!==(r=/^\x25{2}/.exec(e)))t.push("%");else{if(null===(r=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(e)))throw"[sprintf] huh?";if(r[2]){u|=1;var a=[],o=r[2],s=[];if(null===(s=/^([a-z_][a-z_\d]*)/i.exec(o)))throw"[sprintf] huh?";for(a.push(s[1]);""!==(o=o.substring(s[0].length));)if(null!==(s=/^\.([a-z_][a-z_\d]*)/i.exec(o)))a.push(s[1]);else{if(null===(s=/^\[(\d+)\]/.exec(o)))throw"[sprintf] huh?";a.push(s[1])}r[2]=a}else u|=2;if(3===u)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";t.push(r)}e=e.substring(r[0].length)}return t},r}(),I=function(n,e){return e.unshift(n),D.apply(null,e)};return z("sprintf",function(n,e,r){return r.sprintf?"[object Array]"===Object.prototype.toString.apply(r.sprintf)?I(n,r.sprintf):"object"==typeof r.sprintf?D(n,r.sprintf):n:n}),L.init=a,L.setLng=f,L.preload=o,L.addResourceBundle=s,L.loadNamespace=l,L.loadNamespaces=c,L.setDefaultNamespace=i,L.t=v,L.translate=v,L.exists=N,L.detectLanguage=M.detectLanguage,L.pluralExtensions=F,L.sync=E,L.functions=M,L.lng=m,L.addPostProcessor=z,L.options=P,n.i18n=L,n.t=L.t,L}); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd.withJQuery-1.6.2.js b/libs/i18next/release/i18next.amd.withJQuery-1.6.2.js new file mode 100644 index 00000000..06988086 --- /dev/null +++ b/libs/i18next/release/i18next.amd.withJQuery-1.6.2.js @@ -0,0 +1,2602 @@ +// i18next, v1.6.2 +// Copyright (c)2013 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function (root, factory) { + if (typeof exports === 'object') { + + var jquery = require('jquery'); + + module.exports = factory(jquery); + + } else if (typeof define === 'function' && define.amd) { + + define(['jquery'], factory); + + } +}(this, function ($) { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + var i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = []; + + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: 'dev', + fallbackNS: [], + detectLngQS: 'setLng', + ns: 'translation', + fallbackOnNull: true, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + + postProcess: undefined + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + return JSON.parse(data); + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + if (status === 200) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + document.cookie = name+"="+value+expires+"; path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : _ajax, + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + toLanguages: function(lng) { + var languages = []; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + + if (o.load !== 'unspecific') languages.push(lng); + if (o.load !== 'current') languages.push(parts[0]); + } else { + languages.push(lng); + } + + if (languages.indexOf(o.fallbackLng) === -1 && o.fallbackLng) languages.push(o.fallbackLng); + + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + if (o.lng) { + // set cookie with lng set (as detectLanguage will set cookie on need) + if (o.useCookie) f.cookie.create(o.cookieName, o.lng, o.cookieExpirationTime); + } else { + o.lng = o.fallbackLng; + if (o.useCookie) f.cookie.remove(o.cookieName); + } + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + if (cb) cb(translate); + if (deferred) deferred.resolve(); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + + if (cb) cb(translate); + if (deferred) deferred.resolve(); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + f.extend(resStore[lng][ns], resources); + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, cb) { + return init({lng: lng}, cb); + } + + function lng() { + return currentLng; + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } + else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + f.each(replacementHash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), value); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.escape(value)); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), value); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, translated_token); + } + return translated; + } + + function hasContext(options) { + return (options.context && typeof options.context == 'string'); + } + + function needsPlural(options) { + return (options.count !== undefined && typeof options.count != 'string' && options.count !== 1); + } + + function exists(key, options) { + options = options || {}; + + var notFound = options.defaultValue || key + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(key, options) { + + if (typeof options == 'string') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else { + options = options || {}; + } + + var notFound = options.defaultValue || key + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng) : languages + , ns = options.ns || o.ns.defaultNs; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing) { + if (options.lng) { + sync.postMissing(lngs[0], ns, key, notFound, lngs); + } else { + sync.postMissing(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found !== undefined && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessor && postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options){ + options = options || {}; + + var optionWithoutCount, translated + , notFound = options.defaultValue || key + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + if (options.lng) { + lngs = f.toLanguages(options.lng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.count; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(currentLng, options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + + translated = translate(pluralKey, optionWithoutCount); + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } // else continue translation with original/singular key + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (Object.prototype.toString.apply(value) === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned a object instead of string.'; + f.log(value); + } else { + var copy = {}; // apply child translation on a copy + for (var m in value) { + // apply translation on childs + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + } + value = copy; + } + } + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + } + + return found; + } + function detectLanguage() { + var detectedLng; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var parms = query.split('&'); + for (var i=0; i 0) { + var key = parms[i].substring(0,pos); + var val = parms[i].substring(pos+1); + qsParm[key] = val; + } + } + })(); + if (qsParm[o.detectLngQS]) { + detectedLng = qsParm[o.detectLngQS]; + } + } + + // get from cookie + if (!detectedLng && typeof document !== 'undefined' && o.useCookie ) { + var c = f.cookie.read(o.cookieName); + if (c) detectedLng = c; + } + + // get from navigator + if (!detectedLng && typeof navigator !== 'undefined') { + detectedLng = (navigator.language) ? navigator.language : navigator.userLanguage; + } + + return detectedLng; + } + var sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + window.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback') { + urls.push({lng: o.fallbackLng, url: applyReplacement(o.resPostPath, { lng: o.fallbackLng, ns: ns })}); + } else if (o.sendMissingTo === 'current') { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + } + }; + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + var pluralExtensions = { + + rules: { + "ach": { + "name": "Acholi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "af": { + "name": "Afrikaans", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ak": { + "name": "Akan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "am": { + "name": "Amharic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "an": { + "name": "Aragonese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ar": { + "name": "Arabic", + "numbers": [ + 0, + 1, + 2, + 3, + 11, + 100 + ], + "plurals": function(n) { return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5); } + }, + "arn": { + "name": "Mapudungun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ast": { + "name": "Asturian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ay": { + "name": "Aymar\u00e1", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "az": { + "name": "Azerbaijani", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "be": { + "name": "Belarusian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "bg": { + "name": "Bulgarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bn": { + "name": "Bengali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bo": { + "name": "Tibetan", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "br": { + "name": "Breton", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "bs": { + "name": "Bosnian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ca": { + "name": "Catalan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "cgg": { + "name": "Chiga", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "cs": { + "name": "Czech", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "csb": { + "name": "Kashubian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "cy": { + "name": "Welsh", + "numbers": [ + 1, + 2, + 3, + 8 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3); } + }, + "da": { + "name": "Danish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "de": { + "name": "German", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "dz": { + "name": "Dzongkha", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "el": { + "name": "Greek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "en": { + "name": "English", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eo": { + "name": "Esperanto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es": { + "name": "Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es_ar": { + "name": "Argentinean Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "et": { + "name": "Estonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eu": { + "name": "Basque", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fa": { + "name": "Persian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "fi": { + "name": "Finnish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fil": { + "name": "Filipino", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fo": { + "name": "Faroese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fr": { + "name": "French", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fur": { + "name": "Friulian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fy": { + "name": "Frisian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ga": { + "name": "Irish", + "numbers": [ + 1, + 2, + 3, + 7, + 11 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;} + }, + "gd": { + "name": "Scottish Gaelic", + "numbers": [ + 1, + 2, + 3, + 20 + ], + "plurals": function(n) { return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3); } + }, + "gl": { + "name": "Galician", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gu": { + "name": "Gujarati", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gun": { + "name": "Gun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ha": { + "name": "Hausa", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "he": { + "name": "Hebrew", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hi": { + "name": "Hindi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hr": { + "name": "Croatian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "hu": { + "name": "Hungarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hy": { + "name": "Armenian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ia": { + "name": "Interlingua", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "id": { + "name": "Indonesian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "is": { + "name": "Icelandic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n%10!=1 || n%100==11); } + }, + "it": { + "name": "Italian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ja": { + "name": "Japanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jbo": { + "name": "Lojban", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jv": { + "name": "Javanese", + "numbers": [ + 0, + 1 + ], + "plurals": function(n) { return Number(n !== 0); } + }, + "ka": { + "name": "Georgian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kk": { + "name": "Kazakh", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "km": { + "name": "Khmer", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kn": { + "name": "Kannada", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ko": { + "name": "Korean", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ku": { + "name": "Kurdish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "kw": { + "name": "Cornish", + "numbers": [ + 1, + 2, + 3, + 4 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3); } + }, + "ky": { + "name": "Kyrgyz", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lb": { + "name": "Letzeburgesch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ln": { + "name": "Lingala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "lo": { + "name": "Lao", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lt": { + "name": "Lithuanian", + "numbers": [ + 1, + 2, + 10 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "lv": { + "name": "Latvian", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2); } + }, + "mai": { + "name": "Maithili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mfe": { + "name": "Mauritian Creole", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mg": { + "name": "Malagasy", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mi": { + "name": "Maori", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mk": { + "name": "Macedonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 || n%10==1 ? 0 : 1); } + }, + "ml": { + "name": "Malayalam", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mn": { + "name": "Mongolian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mnk": { + "name": "Mandinka", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(0 ? 0 : n==1 ? 1 : 2); } + }, + "mr": { + "name": "Marathi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ms": { + "name": "Malay", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "mt": { + "name": "Maltese", + "numbers": [ + 1, + 2, + 11, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3); } + }, + "nah": { + "name": "Nahuatl", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nap": { + "name": "Neapolitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nb": { + "name": "Norwegian Bokmal", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ne": { + "name": "Nepali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nl": { + "name": "Dutch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nn": { + "name": "Norwegian Nynorsk", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "no": { + "name": "Norwegian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nso": { + "name": "Northern Sotho", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "oc": { + "name": "Occitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "or": { + "name": "Oriya", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pa": { + "name": "Punjabi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pap": { + "name": "Papiamento", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pl": { + "name": "Polish", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "pms": { + "name": "Piemontese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ps": { + "name": "Pashto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt": { + "name": "Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt_br": { + "name": "Brazilian Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "rm": { + "name": "Romansh", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ro": { + "name": "Romanian", + "numbers": [ + 1, + 2, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2); } + }, + "ru": { + "name": "Russian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "sah": { + "name": "Yakut", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sco": { + "name": "Scots", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "se": { + "name": "Northern Sami", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "si": { + "name": "Sinhala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sk": { + "name": "Slovak", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "sl": { + "name": "Slovenian", + "numbers": [ + 5, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }, + "so": { + "name": "Somali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "son": { + "name": "Songhay", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sq": { + "name": "Albanian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sr": { + "name": "Serbian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "su": { + "name": "Sundanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sv": { + "name": "Swedish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sw": { + "name": "Swahili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ta": { + "name": "Tamil", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "te": { + "name": "Telugu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tg": { + "name": "Tajik", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "th": { + "name": "Thai", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ti": { + "name": "Tigrinya", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tk": { + "name": "Turkmen", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tr": { + "name": "Turkish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tt": { + "name": "Tatar", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ug": { + "name": "Uyghur", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "uk": { + "name": "Ukrainian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ur": { + "name": "Urdu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "uz": { + "name": "Uzbek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "vi": { + "name": "Vietnamese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "wa": { + "name": "Walloon", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "wo": { + "name": "Wolof", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "yo": { + "name": "Yoruba", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "zh": { + "name": "Chinese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + } + }, + + // for demonstration only sl and ar is added but you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i = ext.plurals(c); + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[0], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + + $.i18n = i18n; + $.t = i18n.t; + + return i18n; + +})); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd.withJQuery-1.6.2.min.js b/libs/i18next/release/i18next.amd.withJQuery-1.6.2.min.js new file mode 100644 index 00000000..772ad9b2 --- /dev/null +++ b/libs/i18next/release/i18next.amd.withJQuery-1.6.2.min.js @@ -0,0 +1,5 @@ +// i18next, v1.6.2 +// Copyright (c)2013 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function(n,e){if("object"==typeof exports){var r=require("jquery");module.exports=e(r)}else"function"==typeof define&&define.amd&&define(["jquery"],e)})(this,function(n){function e(n,e){if(!e||"function"==typeof e)return n;for(var r in e)n[r]=e[r];return n}function r(n,e,r){var t,u=0,a=n.length,s=void 0===a||"function"==typeof n;if(r)if(s){for(t in n)if(e.apply(n[t],r)===!1)break}else for(;a>u&&e.apply(n[u++],r)!==!1;);else if(s){for(t in n)if(e.call(n[t],t,n[t])===!1)break}else for(;a>u&&e.call(n[u],u,n[u++])!==!1;);return n}function t(n){return"string"==typeof n?n.replace(/[&<>"'\/]/g,function(n){return A[n]}):n}function u(n){var e=function(n){if(window.XMLHttpRequest)return n(null,new XMLHttpRequest);if(window.ActiveXObject)try{return n(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(e){return n(null,new ActiveXObject("Microsoft.XMLHTTP"))}return n(Error())},r=function(n){if("string"==typeof n)return n;var e=[];for(var r in n)n.hasOwnProperty(r)&&e.push(encodeURIComponent(r)+"="+encodeURIComponent(n[r]));return e.join("&")},t=function(n){n=n.replace(/\r\n/g,"\n");for(var e="",r=0;n.length>r;r++){var t=n.charCodeAt(r);128>t?e+=String.fromCharCode(t):t>127&&2048>t?(e+=String.fromCharCode(192|t>>6),e+=String.fromCharCode(128|63&t)):(e+=String.fromCharCode(224|t>>12),e+=String.fromCharCode(128|63&t>>6),e+=String.fromCharCode(128|63&t))}return e},u=function(n){var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";n=t(n);var r,u,a,s,o,i,l,c="",f=0;do r=n.charCodeAt(f++),u=n.charCodeAt(f++),a=n.charCodeAt(f++),s=r>>2,o=(3&r)<<4|u>>4,i=(15&u)<<2|a>>6,l=63&a,isNaN(u)?i=l=64:isNaN(a)&&(l=64),c+=e.charAt(s)+e.charAt(o)+e.charAt(i)+e.charAt(l),r=u=a="",s=o=i=l="";while(n.length>f);return c},a=function(){for(var n=arguments[0],e=1;arguments.length>e;e++){var r=arguments[e];for(var t in r)r.hasOwnProperty(t)&&(n[t]=r[t])}return n},s=function(n,t,u,o){"function"==typeof u&&(o=u,u={}),u.cache=u.cache||!1,u.data=u.data||{},u.headers=u.headers||{},u.jsonp=u.jsonp||!1,u.async=void 0===u.async?!0:u.async;var i,l=a({accept:"*/*","content-type":"application/x-www-form-urlencoded;charset=UTF-8"},s.headers,u.headers);if(i="application/json"===l["content-type"]?JSON.stringify(u.data):r(u.data),"GET"===n){var c=[];if(i&&(c.push(i),i=null),u.cache||c.push("_="+(new Date).getTime()),u.jsonp&&(c.push("callback="+u.jsonp),c.push("jsonp="+u.jsonp)),c=c.join("&"),c.length>1&&(t+=t.indexOf("?")>-1?"&"+c:"?"+c),u.jsonp){var f=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=t,f.appendChild(m),void 0}}e(function(e,r){if(e)return o(e);r.open(n,t,u.async);for(var a in l)l.hasOwnProperty(a)&&r.setRequestHeader(a,l[a]);r.onreadystatechange=function(){if(4===r.readyState){var n=r.responseText||"";if(!o)return;o(r.status,{text:function(){return n},json:function(){return JSON.parse(n)}})}},r.send(i)})},o={authBasic:function(n,e){s.headers.Authorization="Basic "+u(n+":"+e)},connect:function(n,e,r){return s("CONNECT",n,e,r)},del:function(n,e,r){return s("DELETE",n,e,r)},get:function(n,e,r){return s("GET",n,e,r)},head:function(n,e,r){return s("HEAD",n,e,r)},headers:function(n){s.headers=n||{}},isAllowed:function(n,e,r){this.options(n,function(n,t){r(-1!==t.text().indexOf(e))})},options:function(n,e,r){return s("OPTIONS",n,e,r)},patch:function(n,e,r){return s("PATCH",n,e,r)},post:function(n,e,r){return s("POST",n,e,r)},put:function(n,e,r){return s("PUT",n,e,r)},trace:function(n,e,r){return s("TRACE",n,e,r)}},i=n.type?n.type.toLowerCase():"get";o[i](n.url,n,function(e,r){200===e?n.success(r.json(),e,null):n.error(r.text(),e,null)})}function a(e,r){"function"==typeof e&&(r=e,e={}),e=e||{},M.extend(P,e),"string"==typeof P.ns&&(P.ns={namespaces:[P.ns],defaultNs:P.ns}),"string"==typeof P.fallbackNS&&(P.fallbackNS=[P.fallbackNS]),P.interpolationPrefixEscaped=M.regexEscape(P.interpolationPrefix),P.interpolationSuffixEscaped=M.regexEscape(P.interpolationSuffix),P.lng||(P.lng=M.detectLanguage()),P.lng?P.useCookie&&M.cookie.create(P.cookieName,P.lng,P.cookieExpirationTime):(P.lng=P.fallbackLng,P.useCookie&&M.cookie.remove(P.cookieName)),T=M.toLanguages(P.lng),O=T[0],M.log("currentLng set to: "+O),F.setCurrentLng(O),n&&P.setJqueryExt&&p();var t;if(n&&n.Deferred&&(t=n.Deferred()),!P.resStore){var u=M.toLanguages(P.lng);"string"==typeof P.preload&&(P.preload=[P.preload]);for(var a=0,s=P.preload.length;s>a;a++)for(var o=M.toLanguages(P.preload[a]),i=0,l=o.length;l>i;i++)0>u.indexOf(o[i])&&u.push(o[i]);return L.sync.load(u,P,function(n,e){w=e,r&&r(v),t&&t.resolve()}),t?t.promise():void 0}return w=P.resStore,r&&r(v),t&&t.resolve(),t?t.promise():void 0}function s(n,e){"string"==typeof n&&(n=[n]);for(var r=0,t=n.length;t>r;r++)0>P.preload.indexOf(n[r])&&P.preload.push(n[r]);return a(e)}function o(n,e,r){"string"!=typeof e?(r=e,e=P.ns.defaultNs):0>P.ns.namespaces.indexOf(e)&&P.ns.namespaces.push(e),w[n]=w[n]||{},w[n][e]=w[n][e]||{},M.extend(w[n][e],r)}function i(n){P.ns.defaultNs=n}function l(n,e){c([n],e)}function c(n,e){var r={dynamicLoad:P.dynamicLoad,resGetPath:P.resGetPath,getAsync:P.getAsync,customLoad:P.customLoad,ns:{namespaces:n,defaultNs:""}},t=M.toLanguages(P.lng);"string"==typeof P.preload&&(P.preload=[P.preload]);for(var u=0,a=P.preload.length;a>u;u++)for(var s=M.toLanguages(P.preload[u]),o=0,i=s.length;i>o;o++)0>t.indexOf(s[o])&&t.push(s[o]);for(var l=[],c=0,f=t.length;f>c;c++){var m=!1,p=w[t[c]];if(p)for(var b=0,g=n.length;g>b;b++)p[n[b]]||(m=!0);else m=!0;m&&l.push(t[c])}l.length?L.sync._fetch(l,r,function(r,t){var u=n.length*l.length;M.each(n,function(n,r){0>P.ns.namespaces.indexOf(r)&&P.ns.namespaces.push(r),M.each(l,function(n,a){w[a]=w[a]||{},w[a][r]=t[a][r],u--,0===u&&e&&(P.useLocalStorage&&L.sync._storeLocal(w),e())})})}):e&&e()}function f(n,e){return a({lng:n},e)}function m(){return O}function p(){function e(e,r,t){if(0!==r.length){var u="text";if(0===r.indexOf("[")){var a=r.split("]");r=a[1],u=a[0].substr(1,a[0].length-1)}r.indexOf(";")===r.length-1&&(r=r.substr(0,r.length-2));var s;"html"===u?(s=P.defaultValueFromContent?n.extend({defaultValue:e.html()},t):t,e.html(n.t(r,s))):"text"===u?(s=P.defaultValueFromContent?n.extend({defaultValue:e.text()},t):t,e.text(n.t(r,s))):(s=P.defaultValueFromContent?n.extend({defaultValue:e.attr(u)},t):t,e.attr(u,n.t(r,s)))}}function r(r,t){var u=r.attr(P.selectorAttr);if(u){var a=r,s=r.data("i18n-target");if(s&&(a=r.find(s)||r),t||P.useDataAttrOptions!==!0||(t=r.data("i18n-options")),t=t||{},u.indexOf(";")>=0){var o=u.split(";");n.each(o,function(n,r){""!==r&&e(a,r,t)})}else e(a,u,t);P.useDataAttrOptions===!0&&r.data("i18n-options",t)}}n.t=n.t||v,n.fn.i18n=function(e){return this.each(function(){r(n(this),e);var t=n(this).find("["+P.selectorAttr+"]");t.each(function(){r(n(this),e)})})}}function b(n,e,r,t){if(!n)return n;if(t=t||e,0>n.indexOf(t.interpolationPrefix||P.interpolationPrefix))return n;var u=t.interpolationPrefix?M.regexEscape(t.interpolationPrefix):P.interpolationPrefixEscaped,a=t.interpolationSuffix?M.regexEscape(t.interpolationSuffix):P.interpolationSuffixEscaped,s="HTML"+a;return M.each(e,function(e,o){var i=r?r+P.keyseparator+e:e;"object"==typeof o&&null!==o?n=b(n,o,i,t):t.escapeInterpolation||P.escapeInterpolation?(n=n.replace(RegExp([u,i,s].join(""),"g"),o),n=n.replace(RegExp([u,i,a].join(""),"g"),M.escape(o))):n=n.replace(RegExp([u,i,a].join(""),"g"),o)}),n}function g(n,e){var r=",",t="{",u="}",a=M.extend({},e);for(delete a.postProcess;-1!=n.indexOf(P.reusePrefix)&&(j++,!(j>P.maxRecursion));){var s=n.lastIndexOf(P.reusePrefix),o=n.indexOf(P.reuseSuffix,s)+P.reuseSuffix.length,i=n.substring(s,o),l=i.replace(P.reusePrefix,"").replace(P.reuseSuffix,"");if(-1!=l.indexOf(r)){var c=l.indexOf(r);if(-1!=l.indexOf(t,c)&&-1!=l.indexOf(u,c)){var f=l.indexOf(t,c),m=l.indexOf(u,f)+u.length;try{a=M.extend(a,JSON.parse(l.substring(f,m))),l=l.substring(0,c)}catch(p){}}}var b=y(l,a);n=n.replace(i,b)}return n}function d(n){return n.context&&"string"==typeof n.context}function h(n){return void 0!==n.count&&"string"!=typeof n.count&&1!==n.count}function N(n,e){e=e||{};var r=e.defaultValue||n,t=k(n,e);return void 0!==t||t===r}function v(){return j=0,y.apply(null,arguments)}function x(){for(var n=[],e=1;arguments.length>e;e++)n.push(arguments[e]);return{postProcess:"sprintf",sprintf:n}}function y(n,e){e="string"==typeof e?x.apply(null,arguments):e||{};var r=e.defaultValue||n,t=k(n,e),u=e.lng?M.toLanguages(e.lng):T,a=e.ns||P.ns.defaultNs;if(n.indexOf(P.nsseparator)>-1){var s=n.split(P.nsseparator);a=s[0],n=s[1]}void 0===t&&P.sendMissing&&(e.lng?E.postMissing(u[0],a,n,r,u):E.postMissing(P.lng,a,n,r,u));var o=e.postProcess||P.postProcess;return void 0!==t&&o&&R[o]&&(t=R[o](t,n,e)),void 0===t&&(r=b(r,e),r=g(r,e),o&&R[o]&&(t=R[o](t,n,e))),void 0!==t?t:r}function k(n,e){e=e||{};var r,t,u=e.defaultValue||n,a=T;if(!w)return u;if(e.lng&&(a=M.toLanguages(e.lng),!w[a[0]])){var s=P.getAsync;P.getAsync=!1,L.sync.load(a,P,function(n,e){M.extend(w,e),P.getAsync=s})}var o=e.ns||P.ns.defaultNs;if(n.indexOf(P.nsseparator)>-1){var i=n.split(P.nsseparator);o=i[0],n=i[1]}if(d(e)){r=M.extend({},e),delete r.context,r.defaultValue=P.contextNotFound;var l=o+P.nsseparator+n+"_"+e.context;if(t=v(l,r),t!=P.contextNotFound)return b(t,{context:e.context})}if(h(e)){r=M.extend({},e),delete r.count,r.defaultValue=P.pluralNotFound;var c=o+P.nsseparator+n+P.pluralSuffix,f=F.get(O,e.count);if(f>=0?c=c+"_"+f:1===f&&(c=o+P.nsseparator+n),t=v(c,r),t!=P.pluralNotFound)return b(t,{count:e.count,interpolationPrefix:e.interpolationPrefix,interpolationSuffix:e.interpolationSuffix})}for(var m,p=n.split(P.keyseparator),N=0,x=a.length;x>N&&void 0===m;N++){for(var S=a[N],j=0,A=w[S]&&w[S][o];p[j];)A=A&&A[p[j]],j++;if(void 0!==A){if("string"==typeof A)A=b(A,e),A=g(A,e);else if("[object Array]"!==Object.prototype.toString.apply(A)||P.returnObjectTrees||e.returnObjectTrees){if(null===A&&P.fallbackOnNull===!0)A=void 0;else if(null!==A)if(P.returnObjectTrees||e.returnObjectTrees){var C={};for(var _ in A)C[_]=y(o+P.nsseparator+n+P.keyseparator+_,e);A=C}else A="key '"+o+":"+n+" ("+S+")' "+"returned a object instead of string.",M.log(A)}else A=A.join("\n"),A=b(A,e),A=g(A,e);m=A}}if(void 0===m&&!e.isFallbackLookup&&(P.fallbackToDefaultNS===!0||P.fallbackNS&&P.fallbackNS.length))if(e.isFallbackLookup=!0,P.fallbackNS.length){for(var E=0,R=P.fallbackNS.length;R>E;E++)if(m=k(P.fallbackNS[E]+P.nsseparator+n,e)){var z=m.indexOf(P.nsseparator)>-1?m.split(P.nsseparator)[1]:m,D=u.indexOf(P.nsseparator)>-1?u.split(P.nsseparator)[1]:u;if(z!==D)break}}else m=k(n,e);return m}function S(){var n,e=[];if("undefined"!=typeof window&&(function(){for(var n=window.location.search.substring(1),r=n.split("&"),t=0;r.length>t;t++){var u=r[t].indexOf("=");if(u>0){var a=r[t].substring(0,u),s=r[t].substring(u+1);e[a]=s}}}(),e[P.detectLngQS]&&(n=e[P.detectLngQS])),!n&&"undefined"!=typeof document&&P.useCookie){var r=M.cookie.read(P.cookieName);r&&(n=r)}return n||"undefined"==typeof navigator||(n=navigator.language?navigator.language:navigator.userLanguage),n}Array.prototype.indexOf||(Array.prototype.indexOf=function(n){"use strict";if(null==this)throw new TypeError;var e=Object(this),r=e.length>>>0;if(0===r)return-1;var t=0;if(arguments.length>0&&(t=Number(arguments[1]),t!=t?t=0:0!=t&&1/0!=t&&t!=-1/0&&(t=(t>0||-1)*Math.floor(Math.abs(t)))),t>=r)return-1;for(var u=t>=0?t:Math.max(r-Math.abs(t),0);r>u;u++)if(u in e&&e[u]===n)return u;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(n){"use strict";if(null==this)throw new TypeError;var e=Object(this),r=e.length>>>0;if(0===r)return-1;var t=r;arguments.length>1&&(t=Number(arguments[1]),t!=t?t=0:0!=t&&t!=1/0&&t!=-(1/0)&&(t=(t>0||-1)*Math.floor(Math.abs(t))));for(var u=t>=0?Math.min(t,r-1):r-Math.abs(t);u>=0;u--)if(u in e&&e[u]===n)return u;return-1});var O,L={},w={},j=0,T=[],P={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:"dev",fallbackNS:[],detectLngQS:"setLng",ns:"translation",fallbackOnNull:!0,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",postProcess:void 0},A={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},C={create:function(n,e,r){var t;if(r){var u=new Date;u.setTime(u.getTime()+1e3*60*r),t="; expires="+u.toGMTString()}else t="";document.cookie=n+"="+e+t+"; path=/"},read:function(n){for(var e=n+"=",r=document.cookie.split(";"),t=0;r.length>t;t++){for(var u=r[t];" "==u.charAt(0);)u=u.substring(1,u.length);if(0===u.indexOf(e))return u.substring(e.length,u.length)}return null},remove:function(n){this.create(n,"",-1)}},_={create:function(){},read:function(){return null},remove:function(){}},M={extend:n?n.extend:e,each:n?n.each:r,ajax:n?n.ajax:u,cookie:"undefined"!=typeof document?C:_,detectLanguage:S,escape:t,log:function(n){P.debug&&"undefined"!=typeof console&&console.log(n)},toLanguages:function(n){var e=[];if("string"==typeof n&&n.indexOf("-")>-1){var r=n.split("-");n=P.lowerCaseLng?r[0].toLowerCase()+"-"+r[1].toLowerCase():r[0].toLowerCase()+"-"+r[1].toUpperCase(),"unspecific"!==P.load&&e.push(n),"current"!==P.load&&e.push(r[0])}else e.push(n);return-1===e.indexOf(P.fallbackLng)&&P.fallbackLng&&e.push(P.fallbackLng),e},regexEscape:function(n){return n.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}};M.applyReplacement=b;var E={load:function(n,e,r){e.useLocalStorage?E._loadLocal(n,e,function(t,u){for(var a=[],s=0,o=n.length;o>s;s++)u[n[s]]||a.push(n[s]);a.length>0?E._fetch(a,e,function(n,e){M.extend(u,e),E._storeLocal(e),r(null,u)}):r(null,u)}):E._fetch(n,e,function(n,e){r(null,e)})},_loadLocal:function(n,e,r){var t={},u=(new Date).getTime();if(window.localStorage){var a=n.length;M.each(n,function(n,s){var o=window.localStorage.getItem("res_"+s);o&&(o=JSON.parse(o),o.i18nStamp&&o.i18nStamp+e.localStorageExpirationTime>u&&(t[s]=o)),a--,0===a&&r(null,t)})}},_storeLocal:function(n){if(window.localStorage)for(var e in n)n[e].i18nStamp=(new Date).getTime(),window.localStorage.setItem("res_"+e,JSON.stringify(n[e]))},_fetch:function(n,e,r){var t=e.ns,u={};if(e.dynamicLoad){var a=function(n,e){r(null,e)};if("function"==typeof e.customLoad)e.customLoad(n,t.namespaces,e,a);else{var s=b(e.resGetPath,{lng:n.join("+"),ns:t.namespaces.join("+")});M.ajax({url:s,success:function(n){M.log("loaded: "+s),a(null,n)},error:function(n,e,r){M.log("failed loading: "+s),a("failed loading resource.json error: "+r)},dataType:"json",async:e.getAsync})}}else{var o,i=t.namespaces.length*n.length;M.each(t.namespaces,function(t,a){M.each(n,function(n,t){var s=function(n,e){n&&(o=o||[],o.push(n)),u[t]=u[t]||{},u[t][a]=e,i--,0===i&&r(o,u)};"function"==typeof e.customLoad?e.customLoad(t,a,e,s):E._fetchOne(t,a,e,s)})})}},_fetchOne:function(n,e,r,t){var u=b(r.resGetPath,{lng:n,ns:e});M.ajax({url:u,success:function(n){M.log("loaded: "+u),t(null,n)},error:function(n,e,r){M.log("failed loading: "+u),t(r,{})},dataType:"json",async:r.getAsync})},postMissing:function(n,e,r,t,u){var a={};a[r]=t;var s=[];if("fallback"===P.sendMissingTo)s.push({lng:P.fallbackLng,url:b(P.resPostPath,{lng:P.fallbackLng,ns:e})});else if("current"===P.sendMissingTo)s.push({lng:n,url:b(P.resPostPath,{lng:n,ns:e})});else if("all"===P.sendMissingTo)for(var o=0,i=u.length;i>o;o++)s.push({lng:u[o],url:b(P.resPostPath,{lng:u[o],ns:e})});for(var l=0,c=s.length;c>l;l++){var f=s[l];M.ajax({url:f.url,type:P.sendType,data:a,success:function(){M.log("posted missing key '"+r+"' to: "+f.url);for(var n=r.split("."),u=0,a=w[f.lng][e];n[u];)a=a[n[u]]=u===n.length-1?t:a[n[u]]||{},u++},error:function(){M.log("failed posting missing key '"+r+"' to: "+f.url)},dataType:"json",async:P.postAsync})}}},F={rules:{ach:{name:"Acholi",numbers:[1,2],plurals:function(n){return Number(n>1)}},af:{name:"Afrikaans",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ak:{name:"Akan",numbers:[1,2],plurals:function(n){return Number(n>1)}},am:{name:"Amharic",numbers:[1,2],plurals:function(n){return Number(n>1)}},an:{name:"Aragonese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ar:{name:"Arabic",numbers:[0,1,2,3,11,100],plurals:function(n){return Number(0===n?0:1==n?1:2==n?2:n%100>=3&&10>=n%100?3:n%100>=11?4:5)}},arn:{name:"Mapudungun",numbers:[1,2],plurals:function(n){return Number(n>1)}},ast:{name:"Asturian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ay:{name:"Aymará",numbers:[1],plurals:function(){return 0}},az:{name:"Azerbaijani",numbers:[1,2],plurals:function(n){return Number(1!=n)}},be:{name:"Belarusian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},bg:{name:"Bulgarian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},bn:{name:"Bengali",numbers:[1,2],plurals:function(n){return Number(1!=n)}},bo:{name:"Tibetan",numbers:[1],plurals:function(){return 0}},br:{name:"Breton",numbers:[1,2],plurals:function(n){return Number(n>1)}},bs:{name:"Bosnian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},ca:{name:"Catalan",numbers:[1,2],plurals:function(n){return Number(1!=n)}},cgg:{name:"Chiga",numbers:[1],plurals:function(){return 0}},cs:{name:"Czech",numbers:[1,2,5],plurals:function(n){return Number(1==n?0:n>=2&&4>=n?1:2)}},csb:{name:"Kashubian",numbers:[1,2,5],plurals:function(n){return Number(1==n?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},cy:{name:"Welsh",numbers:[1,2,3,8],plurals:function(n){return Number(1==n?0:2==n?1:8!=n&&11!=n?2:3)}},da:{name:"Danish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},de:{name:"German",numbers:[1,2],plurals:function(n){return Number(1!=n)}},dz:{name:"Dzongkha",numbers:[1],plurals:function(){return 0}},el:{name:"Greek",numbers:[1,2],plurals:function(n){return Number(1!=n)}},en:{name:"English",numbers:[1,2],plurals:function(n){return Number(1!=n)}},eo:{name:"Esperanto",numbers:[1,2],plurals:function(n){return Number(1!=n)}},es:{name:"Spanish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},es_ar:{name:"Argentinean Spanish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},et:{name:"Estonian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},eu:{name:"Basque",numbers:[1,2],plurals:function(n){return Number(1!=n)}},fa:{name:"Persian",numbers:[1],plurals:function(){return 0}},fi:{name:"Finnish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},fil:{name:"Filipino",numbers:[1,2],plurals:function(n){return Number(n>1)}},fo:{name:"Faroese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},fr:{name:"French",numbers:[1,2],plurals:function(n){return Number(n>1)}},fur:{name:"Friulian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},fy:{name:"Frisian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ga:{name:"Irish",numbers:[1,2,3,7,11],plurals:function(n){return Number(1==n?0:2==n?1:7>n?2:11>n?3:4)}},gd:{name:"Scottish Gaelic",numbers:[1,2,3,20],plurals:function(n){return Number(1==n||11==n?0:2==n||12==n?1:n>2&&20>n?2:3)}},gl:{name:"Galician",numbers:[1,2],plurals:function(n){return Number(1!=n)}},gu:{name:"Gujarati",numbers:[1,2],plurals:function(n){return Number(1!=n)}},gun:{name:"Gun",numbers:[1,2],plurals:function(n){return Number(n>1)}},ha:{name:"Hausa",numbers:[1,2],plurals:function(n){return Number(1!=n)}},he:{name:"Hebrew",numbers:[1,2],plurals:function(n){return Number(1!=n)}},hi:{name:"Hindi",numbers:[1,2],plurals:function(n){return Number(1!=n)}},hr:{name:"Croatian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},hu:{name:"Hungarian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},hy:{name:"Armenian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ia:{name:"Interlingua",numbers:[1,2],plurals:function(n){return Number(1!=n)}},id:{name:"Indonesian",numbers:[1],plurals:function(){return 0}},is:{name:"Icelandic",numbers:[1,2],plurals:function(n){return Number(1!=n%10||11==n%100)}},it:{name:"Italian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ja:{name:"Japanese",numbers:[1],plurals:function(){return 0}},jbo:{name:"Lojban",numbers:[1],plurals:function(){return 0}},jv:{name:"Javanese",numbers:[0,1],plurals:function(n){return Number(0!==n)}},ka:{name:"Georgian",numbers:[1],plurals:function(){return 0}},kk:{name:"Kazakh",numbers:[1],plurals:function(){return 0}},km:{name:"Khmer",numbers:[1],plurals:function(){return 0}},kn:{name:"Kannada",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ko:{name:"Korean",numbers:[1],plurals:function(){return 0}},ku:{name:"Kurdish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},kw:{name:"Cornish",numbers:[1,2,3,4],plurals:function(n){return Number(1==n?0:2==n?1:3==n?2:3)}},ky:{name:"Kyrgyz",numbers:[1],plurals:function(){return 0}},lb:{name:"Letzeburgesch",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ln:{name:"Lingala",numbers:[1,2],plurals:function(n){return Number(n>1)}},lo:{name:"Lao",numbers:[1],plurals:function(){return 0}},lt:{name:"Lithuanian",numbers:[1,2,10],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&(10>n%100||n%100>=20)?1:2)}},lv:{name:"Latvian",numbers:[0,1,2],plurals:function(n){return Number(1==n%10&&11!=n%100?0:0!==n?1:2)}},mai:{name:"Maithili",numbers:[1,2],plurals:function(n){return Number(1!=n)}},mfe:{name:"Mauritian Creole",numbers:[1,2],plurals:function(n){return Number(n>1)}},mg:{name:"Malagasy",numbers:[1,2],plurals:function(n){return Number(n>1)}},mi:{name:"Maori",numbers:[1,2],plurals:function(n){return Number(n>1)}},mk:{name:"Macedonian",numbers:[1,2],plurals:function(n){return Number(1==n||1==n%10?0:1)}},ml:{name:"Malayalam",numbers:[1,2],plurals:function(n){return Number(1!=n)}},mn:{name:"Mongolian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},mnk:{name:"Mandinka",numbers:[0,1,2],plurals:function(n){return Number(1==n?1:2)}},mr:{name:"Marathi",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ms:{name:"Malay",numbers:[1],plurals:function(){return 0}},mt:{name:"Maltese",numbers:[1,2,11,20],plurals:function(n){return Number(1==n?0:0===n||n%100>1&&11>n%100?1:n%100>10&&20>n%100?2:3)}},nah:{name:"Nahuatl",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nap:{name:"Neapolitan",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nb:{name:"Norwegian Bokmal",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ne:{name:"Nepali",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nl:{name:"Dutch",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nn:{name:"Norwegian Nynorsk",numbers:[1,2],plurals:function(n){return Number(1!=n)}},no:{name:"Norwegian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nso:{name:"Northern Sotho",numbers:[1,2],plurals:function(n){return Number(1!=n)}},oc:{name:"Occitan",numbers:[1,2],plurals:function(n){return Number(n>1)}},or:{name:"Oriya",numbers:[2,1],plurals:function(n){return Number(1!=n)}},pa:{name:"Punjabi",numbers:[1,2],plurals:function(n){return Number(1!=n)}},pap:{name:"Papiamento",numbers:[1,2],plurals:function(n){return Number(1!=n)}},pl:{name:"Polish",numbers:[1,2,5],plurals:function(n){return Number(1==n?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},pms:{name:"Piemontese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ps:{name:"Pashto",numbers:[1,2],plurals:function(n){return Number(1!=n)}},pt:{name:"Portuguese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},pt_br:{name:"Brazilian Portuguese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},rm:{name:"Romansh",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ro:{name:"Romanian",numbers:[1,2,20],plurals:function(n){return Number(1==n?0:0===n||n%100>0&&20>n%100?1:2)}},ru:{name:"Russian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},sah:{name:"Yakut",numbers:[1],plurals:function(){return 0}},sco:{name:"Scots",numbers:[1,2],plurals:function(n){return Number(1!=n)}},se:{name:"Northern Sami",numbers:[1,2],plurals:function(n){return Number(1!=n)}},si:{name:"Sinhala",numbers:[1,2],plurals:function(n){return Number(1!=n)}},sk:{name:"Slovak",numbers:[1,2,5],plurals:function(n){return Number(1==n?0:n>=2&&4>=n?1:2)}},sl:{name:"Slovenian",numbers:[5,1,2,3],plurals:function(n){return Number(1==n%100?1:2==n%100?2:3==n%100||4==n%100?3:0)}},so:{name:"Somali",numbers:[1,2],plurals:function(n){return Number(1!=n)}},son:{name:"Songhay",numbers:[1,2],plurals:function(n){return Number(1!=n)}},sq:{name:"Albanian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},sr:{name:"Serbian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},su:{name:"Sundanese",numbers:[1],plurals:function(){return 0}},sv:{name:"Swedish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},sw:{name:"Swahili",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ta:{name:"Tamil",numbers:[1,2],plurals:function(n){return Number(1!=n)}},te:{name:"Telugu",numbers:[1,2],plurals:function(n){return Number(1!=n)}},tg:{name:"Tajik",numbers:[1,2],plurals:function(n){return Number(n>1)}},th:{name:"Thai",numbers:[1],plurals:function(){return 0}},ti:{name:"Tigrinya",numbers:[1,2],plurals:function(n){return Number(n>1)}},tk:{name:"Turkmen",numbers:[1,2],plurals:function(n){return Number(1!=n)}},tr:{name:"Turkish",numbers:[1,2],plurals:function(n){return Number(n>1)}},tt:{name:"Tatar",numbers:[1],plurals:function(){return 0}},ug:{name:"Uyghur",numbers:[1],plurals:function(){return 0}},uk:{name:"Ukrainian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},ur:{name:"Urdu",numbers:[1,2],plurals:function(n){return Number(1!=n)}},uz:{name:"Uzbek",numbers:[1,2],plurals:function(n){return Number(n>1)}},vi:{name:"Vietnamese",numbers:[1],plurals:function(){return 0}},wa:{name:"Walloon",numbers:[1,2],plurals:function(n){return Number(n>1)}},wo:{name:"Wolof",numbers:[1],plurals:function(){return 0}},yo:{name:"Yoruba",numbers:[1,2],plurals:function(n){return Number(1!=n)}},zh:{name:"Chinese",numbers:[1],plurals:function(){return 0}}},addRule:function(n,e){F.rules[n]=e},setCurrentLng:function(n){if(!F.currentRule||F.currentRule.lng!==n){var e=n.split("-");F.currentRule={lng:n,rule:F.rules[e[0]]}}},get:function(n,e){function r(e,r){var t;if(t=F.currentRule&&F.currentRule.lng===n?F.currentRule.rule:F.rules[e]){var u=t.plurals(r),a=t.numbers[u];return 2===t.numbers.length&&1===t.numbers[0]&&(2===a?a=-1:1===a&&(a=1)),a}return 1===r?"1":"-1"}var t=n.split("-");return r(t[0],e)}},R={},z=function(n,e){R[n]=e},D=function(){function n(n){return Object.prototype.toString.call(n).slice(8,-1).toLowerCase()}function e(n,e){for(var r=[];e>0;r[--e]=n);return r.join("")}var r=function(){return r.cache.hasOwnProperty(arguments[0])||(r.cache[arguments[0]]=r.parse(arguments[0])),r.format.call(null,r.cache[arguments[0]],arguments)};return r.format=function(r,t){var u,a,s,o,i,l,c,f=1,m=r.length,p="",b=[];for(a=0;m>a;a++)if(p=n(r[a]),"string"===p)b.push(r[a]);else if("array"===p){if(o=r[a],o[2])for(u=t[f],s=0;o[2].length>s;s++){if(!u.hasOwnProperty(o[2][s]))throw D('[sprintf] property "%s" does not exist',o[2][s]);u=u[o[2][s]]}else u=o[1]?t[o[1]]:t[f++];if(/[^s]/.test(o[8])&&"number"!=n(u))throw D("[sprintf] expecting number but found %s",n(u));switch(o[8]){case"b":u=u.toString(2);break;case"c":u=String.fromCharCode(u);break;case"d":u=parseInt(u,10);break;case"e":u=o[7]?u.toExponential(o[7]):u.toExponential();break;case"f":u=o[7]?parseFloat(u).toFixed(o[7]):parseFloat(u);break;case"o":u=u.toString(8);break;case"s":u=(u+="")&&o[7]?u.substring(0,o[7]):u;break;case"u":u=Math.abs(u);break;case"x":u=u.toString(16);break;case"X":u=u.toString(16).toUpperCase()}u=/[def]/.test(o[8])&&o[3]&&u>=0?"+"+u:u,l=o[4]?"0"==o[4]?"0":o[4].charAt(1):" ",c=o[6]-(u+"").length,i=o[6]?e(l,c):"",b.push(o[5]?u+i:i+u)}return b.join("")},r.cache={},r.parse=function(n){for(var e=n,r=[],t=[],u=0;e;){if(null!==(r=/^[^\x25]+/.exec(e)))t.push(r[0]);else if(null!==(r=/^\x25{2}/.exec(e)))t.push("%");else{if(null===(r=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(e)))throw"[sprintf] huh?";if(r[2]){u|=1;var a=[],s=r[2],o=[];if(null===(o=/^([a-z_][a-z_\d]*)/i.exec(s)))throw"[sprintf] huh?";for(a.push(o[1]);""!==(s=s.substring(o[0].length));)if(null!==(o=/^\.([a-z_][a-z_\d]*)/i.exec(s)))a.push(o[1]);else{if(null===(o=/^\[(\d+)\]/.exec(s)))throw"[sprintf] huh?";a.push(o[1])}r[2]=a}else u|=2;if(3===u)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";t.push(r)}e=e.substring(r[0].length)}return t},r}(),I=function(n,e){return e.unshift(n),D.apply(null,e)};return z("sprintf",function(n,e,r){return r.sprintf?"[object Array]"===Object.prototype.toString.apply(r.sprintf)?I(n,r.sprintf):"object"==typeof r.sprintf?D(n,r.sprintf):n:n}),L.init=a,L.setLng=f,L.preload=s,L.addResourceBundle=o,L.loadNamespace=l,L.loadNamespaces=c,L.setDefaultNamespace=i,L.t=v,L.translate=v,L.exists=N,L.detectLanguage=M.detectLanguage,L.pluralExtensions=F,L.sync=E,L.functions=M,L.lng=m,L.addPostProcessor=z,L.options=P,n.i18n=L,n.t=L.t,L}); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd.withJQuery-1.6.3.js b/libs/i18next/release/i18next.amd.withJQuery-1.6.3.js new file mode 100644 index 00000000..96e9a220 --- /dev/null +++ b/libs/i18next/release/i18next.amd.withJQuery-1.6.3.js @@ -0,0 +1,2615 @@ +// i18next, v1.6.3 +// Copyright (c)2013 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function (root, factory) { + if (typeof exports === 'object') { + + var jquery = require('jquery'); + + module.exports = factory(jquery); + + } else if (typeof define === 'function' && define.amd) { + + define(['jquery'], factory); + + } +}(this, function ($) { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + var i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = []; + + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: 'dev', + fallbackNS: [], + detectLngQS: 'setLng', + ns: 'translation', + fallbackOnNull: true, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + + postProcess: undefined, + parseMissingKey: undefined + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + return JSON.parse(data); + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + if (status === 200) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + document.cookie = name+"="+value+expires+"; path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : _ajax, + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + toLanguages: function(lng) { + var languages = []; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + + if (o.load !== 'unspecific') languages.push(lng); + if (o.load !== 'current') languages.push(parts[0]); + } else { + languages.push(lng); + } + + if (languages.indexOf(o.fallbackLng) === -1 && o.fallbackLng) languages.push(o.fallbackLng); + + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + if (o.lng) { + // set cookie with lng set (as detectLanguage will set cookie on need) + if (o.useCookie) f.cookie.create(o.cookieName, o.lng, o.cookieExpirationTime); + } else { + o.lng = o.fallbackLng; + if (o.useCookie) f.cookie.remove(o.cookieName); + } + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + if (cb) cb(translate); + if (deferred) deferred.resolve(); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + + if (cb) cb(translate); + if (deferred) deferred.resolve(); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + f.extend(resStore[lng][ns], resources); + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, cb) { + return init({lng: lng}, cb); + } + + function lng() { + return currentLng; + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } + else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + f.each(replacementHash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), value); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.escape(value)); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), value); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, translated_token); + } + return translated; + } + + function hasContext(options) { + return (options.context && typeof options.context == 'string'); + } + + function needsPlural(options) { + return (options.count !== undefined && typeof options.count != 'string' && options.count !== 1); + } + + function exists(key, options) { + options = options || {}; + + var notFound = options.defaultValue || key + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(key, options) { + + if (typeof options == 'string') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else { + options = options || {}; + } + + var notFound = options.defaultValue || key + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng) : languages + , ns = options.ns || o.ns.defaultNs + , parts; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing) { + if (options.lng) { + sync.postMissing(lngs[0], ns, key, notFound, lngs); + } else { + sync.postMissing(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found !== undefined && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + // process notFound if function exists + var splitNotFound = notFound; + if (notFound.indexOf(o.nsseparator) > -1) { + parts = notFound.split(o.nsseparator); + splitNotFound = parts[1]; + } + if (splitNotFound === key && o.parseMissingKey) { + notFound = o.parseMissingKey(notFound); + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessor && postProcessors[postProcessor]) { + var val = options.defaultValue || key; + found = postProcessors[postProcessor](val, key, options); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options){ + options = options || {}; + + var optionWithoutCount, translated + , notFound = options.defaultValue || key + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + if (options.lng) { + lngs = f.toLanguages(options.lng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.count; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(lngs[0], options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + + translated = translate(pluralKey, optionWithoutCount); + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } // else continue translation with original/singular key + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (Object.prototype.toString.apply(value) === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned a object instead of string.'; + f.log(value); + } else { + var copy = {}; // apply child translation on a copy + for (var m in value) { + // apply translation on childs + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + } + value = copy; + } + } + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length > 0))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + } + + return found; + } + function detectLanguage() { + var detectedLng; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var parms = query.split('&'); + for (var i=0; i 0) { + var key = parms[i].substring(0,pos); + var val = parms[i].substring(pos+1); + qsParm[key] = val; + } + } + })(); + if (qsParm[o.detectLngQS]) { + detectedLng = qsParm[o.detectLngQS]; + } + } + + // get from cookie + if (!detectedLng && typeof document !== 'undefined' && o.useCookie ) { + var c = f.cookie.read(o.cookieName); + if (c) detectedLng = c; + } + + // get from navigator + if (!detectedLng && typeof navigator !== 'undefined') { + detectedLng = (navigator.language) ? navigator.language : navigator.userLanguage; + } + + return detectedLng; + } + var sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + window.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback' && o.fallbackLng !== false) { + urls.push({lng: o.fallbackLng, url: applyReplacement(o.resPostPath, { lng: o.fallbackLng, ns: ns })}); + } else if (o.sendMissingTo === 'current' || (o.sendMissingTo === 'fallback' && o.fallbackLng === false) ) { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + } + }; + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + var pluralExtensions = { + + rules: { + "ach": { + "name": "Acholi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "af": { + "name": "Afrikaans", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ak": { + "name": "Akan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "am": { + "name": "Amharic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "an": { + "name": "Aragonese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ar": { + "name": "Arabic", + "numbers": [ + 0, + 1, + 2, + 3, + 11, + 100 + ], + "plurals": function(n) { return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5); } + }, + "arn": { + "name": "Mapudungun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ast": { + "name": "Asturian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ay": { + "name": "Aymar\u00e1", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "az": { + "name": "Azerbaijani", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "be": { + "name": "Belarusian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "bg": { + "name": "Bulgarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bn": { + "name": "Bengali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bo": { + "name": "Tibetan", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "br": { + "name": "Breton", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "bs": { + "name": "Bosnian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ca": { + "name": "Catalan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "cgg": { + "name": "Chiga", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "cs": { + "name": "Czech", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "csb": { + "name": "Kashubian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "cy": { + "name": "Welsh", + "numbers": [ + 1, + 2, + 3, + 8 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3); } + }, + "da": { + "name": "Danish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "de": { + "name": "German", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "dz": { + "name": "Dzongkha", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "el": { + "name": "Greek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "en": { + "name": "English", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eo": { + "name": "Esperanto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es": { + "name": "Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es_ar": { + "name": "Argentinean Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "et": { + "name": "Estonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eu": { + "name": "Basque", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fa": { + "name": "Persian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "fi": { + "name": "Finnish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fil": { + "name": "Filipino", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fo": { + "name": "Faroese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fr": { + "name": "French", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fur": { + "name": "Friulian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fy": { + "name": "Frisian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ga": { + "name": "Irish", + "numbers": [ + 1, + 2, + 3, + 7, + 11 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;} + }, + "gd": { + "name": "Scottish Gaelic", + "numbers": [ + 1, + 2, + 3, + 20 + ], + "plurals": function(n) { return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3); } + }, + "gl": { + "name": "Galician", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gu": { + "name": "Gujarati", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gun": { + "name": "Gun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ha": { + "name": "Hausa", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "he": { + "name": "Hebrew", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hi": { + "name": "Hindi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hr": { + "name": "Croatian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "hu": { + "name": "Hungarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hy": { + "name": "Armenian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ia": { + "name": "Interlingua", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "id": { + "name": "Indonesian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "is": { + "name": "Icelandic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n%10!=1 || n%100==11); } + }, + "it": { + "name": "Italian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ja": { + "name": "Japanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jbo": { + "name": "Lojban", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jv": { + "name": "Javanese", + "numbers": [ + 0, + 1 + ], + "plurals": function(n) { return Number(n !== 0); } + }, + "ka": { + "name": "Georgian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kk": { + "name": "Kazakh", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "km": { + "name": "Khmer", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kn": { + "name": "Kannada", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ko": { + "name": "Korean", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ku": { + "name": "Kurdish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "kw": { + "name": "Cornish", + "numbers": [ + 1, + 2, + 3, + 4 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3); } + }, + "ky": { + "name": "Kyrgyz", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lb": { + "name": "Letzeburgesch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ln": { + "name": "Lingala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "lo": { + "name": "Lao", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lt": { + "name": "Lithuanian", + "numbers": [ + 1, + 2, + 10 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "lv": { + "name": "Latvian", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2); } + }, + "mai": { + "name": "Maithili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mfe": { + "name": "Mauritian Creole", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mg": { + "name": "Malagasy", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mi": { + "name": "Maori", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mk": { + "name": "Macedonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 || n%10==1 ? 0 : 1); } + }, + "ml": { + "name": "Malayalam", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mn": { + "name": "Mongolian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mnk": { + "name": "Mandinka", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(0 ? 0 : n==1 ? 1 : 2); } + }, + "mr": { + "name": "Marathi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ms": { + "name": "Malay", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "mt": { + "name": "Maltese", + "numbers": [ + 1, + 2, + 11, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3); } + }, + "nah": { + "name": "Nahuatl", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nap": { + "name": "Neapolitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nb": { + "name": "Norwegian Bokmal", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ne": { + "name": "Nepali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nl": { + "name": "Dutch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nn": { + "name": "Norwegian Nynorsk", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "no": { + "name": "Norwegian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nso": { + "name": "Northern Sotho", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "oc": { + "name": "Occitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "or": { + "name": "Oriya", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pa": { + "name": "Punjabi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pap": { + "name": "Papiamento", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pl": { + "name": "Polish", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "pms": { + "name": "Piemontese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ps": { + "name": "Pashto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt": { + "name": "Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt_br": { + "name": "Brazilian Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "rm": { + "name": "Romansh", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ro": { + "name": "Romanian", + "numbers": [ + 1, + 2, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2); } + }, + "ru": { + "name": "Russian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "sah": { + "name": "Yakut", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sco": { + "name": "Scots", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "se": { + "name": "Northern Sami", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "si": { + "name": "Sinhala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sk": { + "name": "Slovak", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "sl": { + "name": "Slovenian", + "numbers": [ + 5, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }, + "so": { + "name": "Somali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "son": { + "name": "Songhay", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sq": { + "name": "Albanian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sr": { + "name": "Serbian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "su": { + "name": "Sundanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sv": { + "name": "Swedish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sw": { + "name": "Swahili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ta": { + "name": "Tamil", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "te": { + "name": "Telugu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tg": { + "name": "Tajik", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "th": { + "name": "Thai", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ti": { + "name": "Tigrinya", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tk": { + "name": "Turkmen", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tr": { + "name": "Turkish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tt": { + "name": "Tatar", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ug": { + "name": "Uyghur", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "uk": { + "name": "Ukrainian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ur": { + "name": "Urdu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "uz": { + "name": "Uzbek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "vi": { + "name": "Vietnamese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "wa": { + "name": "Walloon", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "wo": { + "name": "Wolof", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "yo": { + "name": "Yoruba", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "zh": { + "name": "Chinese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + } + }, + + // for demonstration only sl and ar is added but you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i = ext.plurals(c); + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[0], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + + $.i18n = i18n; + $.t = i18n.t; + + return i18n; + +})); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd.withJQuery-1.6.3.min.js b/libs/i18next/release/i18next.amd.withJQuery-1.6.3.min.js new file mode 100644 index 00000000..fa06abf5 --- /dev/null +++ b/libs/i18next/release/i18next.amd.withJQuery-1.6.3.min.js @@ -0,0 +1,5 @@ +// i18next, v1.6.3 +// Copyright (c)2013 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function(n,e){if("object"==typeof exports){var r=require("jquery");module.exports=e(r)}else"function"==typeof define&&define.amd&&define(["jquery"],e)})(this,function(n){function e(n,e){if(!e||"function"==typeof e)return n;for(var r in e)n[r]=e[r];return n}function r(n,e,r){var t,u=0,a=n.length,s=void 0===a||"function"==typeof n;if(r)if(s){for(t in n)if(e.apply(n[t],r)===!1)break}else for(;a>u&&e.apply(n[u++],r)!==!1;);else if(s){for(t in n)if(e.call(n[t],t,n[t])===!1)break}else for(;a>u&&e.call(n[u],u,n[u++])!==!1;);return n}function t(n){return"string"==typeof n?n.replace(/[&<>"'\/]/g,function(n){return A[n]}):n}function u(n){var e=function(n){if(window.XMLHttpRequest)return n(null,new XMLHttpRequest);if(window.ActiveXObject)try{return n(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(e){return n(null,new ActiveXObject("Microsoft.XMLHTTP"))}return n(Error())},r=function(n){if("string"==typeof n)return n;var e=[];for(var r in n)n.hasOwnProperty(r)&&e.push(encodeURIComponent(r)+"="+encodeURIComponent(n[r]));return e.join("&")},t=function(n){n=n.replace(/\r\n/g,"\n");for(var e="",r=0;n.length>r;r++){var t=n.charCodeAt(r);128>t?e+=String.fromCharCode(t):t>127&&2048>t?(e+=String.fromCharCode(192|t>>6),e+=String.fromCharCode(128|63&t)):(e+=String.fromCharCode(224|t>>12),e+=String.fromCharCode(128|63&t>>6),e+=String.fromCharCode(128|63&t))}return e},u=function(n){var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";n=t(n);var r,u,a,s,o,i,l,f="",c=0;do r=n.charCodeAt(c++),u=n.charCodeAt(c++),a=n.charCodeAt(c++),s=r>>2,o=(3&r)<<4|u>>4,i=(15&u)<<2|a>>6,l=63&a,isNaN(u)?i=l=64:isNaN(a)&&(l=64),f+=e.charAt(s)+e.charAt(o)+e.charAt(i)+e.charAt(l),r=u=a="",s=o=i=l="";while(n.length>c);return f},a=function(){for(var n=arguments[0],e=1;arguments.length>e;e++){var r=arguments[e];for(var t in r)r.hasOwnProperty(t)&&(n[t]=r[t])}return n},s=function(n,t,u,o){"function"==typeof u&&(o=u,u={}),u.cache=u.cache||!1,u.data=u.data||{},u.headers=u.headers||{},u.jsonp=u.jsonp||!1,u.async=void 0===u.async?!0:u.async;var i,l=a({accept:"*/*","content-type":"application/x-www-form-urlencoded;charset=UTF-8"},s.headers,u.headers);if(i="application/json"===l["content-type"]?JSON.stringify(u.data):r(u.data),"GET"===n){var f=[];if(i&&(f.push(i),i=null),u.cache||f.push("_="+(new Date).getTime()),u.jsonp&&(f.push("callback="+u.jsonp),f.push("jsonp="+u.jsonp)),f=f.join("&"),f.length>1&&(t+=t.indexOf("?")>-1?"&"+f:"?"+f),u.jsonp){var c=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=t,c.appendChild(m),void 0}}e(function(e,r){if(e)return o(e);r.open(n,t,u.async);for(var a in l)l.hasOwnProperty(a)&&r.setRequestHeader(a,l[a]);r.onreadystatechange=function(){if(4===r.readyState){var n=r.responseText||"";if(!o)return;o(r.status,{text:function(){return n},json:function(){return JSON.parse(n)}})}},r.send(i)})},o={authBasic:function(n,e){s.headers.Authorization="Basic "+u(n+":"+e)},connect:function(n,e,r){return s("CONNECT",n,e,r)},del:function(n,e,r){return s("DELETE",n,e,r)},get:function(n,e,r){return s("GET",n,e,r)},head:function(n,e,r){return s("HEAD",n,e,r)},headers:function(n){s.headers=n||{}},isAllowed:function(n,e,r){this.options(n,function(n,t){r(-1!==t.text().indexOf(e))})},options:function(n,e,r){return s("OPTIONS",n,e,r)},patch:function(n,e,r){return s("PATCH",n,e,r)},post:function(n,e,r){return s("POST",n,e,r)},put:function(n,e,r){return s("PUT",n,e,r)},trace:function(n,e,r){return s("TRACE",n,e,r)}},i=n.type?n.type.toLowerCase():"get";o[i](n.url,n,function(e,r){200===e?n.success(r.json(),e,null):n.error(r.text(),e,null)})}function a(e,r){"function"==typeof e&&(r=e,e={}),e=e||{},M.extend(P,e),"string"==typeof P.ns&&(P.ns={namespaces:[P.ns],defaultNs:P.ns}),"string"==typeof P.fallbackNS&&(P.fallbackNS=[P.fallbackNS]),P.interpolationPrefixEscaped=M.regexEscape(P.interpolationPrefix),P.interpolationSuffixEscaped=M.regexEscape(P.interpolationSuffix),P.lng||(P.lng=M.detectLanguage()),P.lng?P.useCookie&&M.cookie.create(P.cookieName,P.lng,P.cookieExpirationTime):(P.lng=P.fallbackLng,P.useCookie&&M.cookie.remove(P.cookieName)),T=M.toLanguages(P.lng),O=T[0],M.log("currentLng set to: "+O),F.setCurrentLng(O),n&&P.setJqueryExt&&p();var t;if(n&&n.Deferred&&(t=n.Deferred()),!P.resStore){var u=M.toLanguages(P.lng);"string"==typeof P.preload&&(P.preload=[P.preload]);for(var a=0,s=P.preload.length;s>a;a++)for(var o=M.toLanguages(P.preload[a]),i=0,l=o.length;l>i;i++)0>u.indexOf(o[i])&&u.push(o[i]);return L.sync.load(u,P,function(n,e){w=e,r&&r(v),t&&t.resolve()}),t?t.promise():void 0}return w=P.resStore,r&&r(v),t&&t.resolve(),t?t.promise():void 0}function s(n,e){"string"==typeof n&&(n=[n]);for(var r=0,t=n.length;t>r;r++)0>P.preload.indexOf(n[r])&&P.preload.push(n[r]);return a(e)}function o(n,e,r){"string"!=typeof e?(r=e,e=P.ns.defaultNs):0>P.ns.namespaces.indexOf(e)&&P.ns.namespaces.push(e),w[n]=w[n]||{},w[n][e]=w[n][e]||{},M.extend(w[n][e],r)}function i(n){P.ns.defaultNs=n}function l(n,e){f([n],e)}function f(n,e){var r={dynamicLoad:P.dynamicLoad,resGetPath:P.resGetPath,getAsync:P.getAsync,customLoad:P.customLoad,ns:{namespaces:n,defaultNs:""}},t=M.toLanguages(P.lng);"string"==typeof P.preload&&(P.preload=[P.preload]);for(var u=0,a=P.preload.length;a>u;u++)for(var s=M.toLanguages(P.preload[u]),o=0,i=s.length;i>o;o++)0>t.indexOf(s[o])&&t.push(s[o]);for(var l=[],f=0,c=t.length;c>f;f++){var m=!1,p=w[t[f]];if(p)for(var b=0,g=n.length;g>b;b++)p[n[b]]||(m=!0);else m=!0;m&&l.push(t[f])}l.length?L.sync._fetch(l,r,function(r,t){var u=n.length*l.length;M.each(n,function(n,r){0>P.ns.namespaces.indexOf(r)&&P.ns.namespaces.push(r),M.each(l,function(n,a){w[a]=w[a]||{},w[a][r]=t[a][r],u--,0===u&&e&&(P.useLocalStorage&&L.sync._storeLocal(w),e())})})}):e&&e()}function c(n,e){return a({lng:n},e)}function m(){return O}function p(){function e(e,r,t){if(0!==r.length){var u="text";if(0===r.indexOf("[")){var a=r.split("]");r=a[1],u=a[0].substr(1,a[0].length-1)}r.indexOf(";")===r.length-1&&(r=r.substr(0,r.length-2));var s;"html"===u?(s=P.defaultValueFromContent?n.extend({defaultValue:e.html()},t):t,e.html(n.t(r,s))):"text"===u?(s=P.defaultValueFromContent?n.extend({defaultValue:e.text()},t):t,e.text(n.t(r,s))):(s=P.defaultValueFromContent?n.extend({defaultValue:e.attr(u)},t):t,e.attr(u,n.t(r,s)))}}function r(r,t){var u=r.attr(P.selectorAttr);if(u){var a=r,s=r.data("i18n-target");if(s&&(a=r.find(s)||r),t||P.useDataAttrOptions!==!0||(t=r.data("i18n-options")),t=t||{},u.indexOf(";")>=0){var o=u.split(";");n.each(o,function(n,r){""!==r&&e(a,r,t)})}else e(a,u,t);P.useDataAttrOptions===!0&&r.data("i18n-options",t)}}n.t=n.t||v,n.fn.i18n=function(e){return this.each(function(){r(n(this),e);var t=n(this).find("["+P.selectorAttr+"]");t.each(function(){r(n(this),e)})})}}function b(n,e,r,t){if(!n)return n;if(t=t||e,0>n.indexOf(t.interpolationPrefix||P.interpolationPrefix))return n;var u=t.interpolationPrefix?M.regexEscape(t.interpolationPrefix):P.interpolationPrefixEscaped,a=t.interpolationSuffix?M.regexEscape(t.interpolationSuffix):P.interpolationSuffixEscaped,s="HTML"+a;return M.each(e,function(e,o){var i=r?r+P.keyseparator+e:e;"object"==typeof o&&null!==o?n=b(n,o,i,t):t.escapeInterpolation||P.escapeInterpolation?(n=n.replace(RegExp([u,i,s].join(""),"g"),o),n=n.replace(RegExp([u,i,a].join(""),"g"),M.escape(o))):n=n.replace(RegExp([u,i,a].join(""),"g"),o)}),n}function g(n,e){var r=",",t="{",u="}",a=M.extend({},e);for(delete a.postProcess;-1!=n.indexOf(P.reusePrefix)&&(j++,!(j>P.maxRecursion));){var s=n.lastIndexOf(P.reusePrefix),o=n.indexOf(P.reuseSuffix,s)+P.reuseSuffix.length,i=n.substring(s,o),l=i.replace(P.reusePrefix,"").replace(P.reuseSuffix,"");if(-1!=l.indexOf(r)){var f=l.indexOf(r);if(-1!=l.indexOf(t,f)&&-1!=l.indexOf(u,f)){var c=l.indexOf(t,f),m=l.indexOf(u,c)+u.length;try{a=M.extend(a,JSON.parse(l.substring(c,m))),l=l.substring(0,f)}catch(p){}}}var b=y(l,a);n=n.replace(i,b)}return n}function d(n){return n.context&&"string"==typeof n.context}function h(n){return void 0!==n.count&&"string"!=typeof n.count&&1!==n.count}function N(n,e){e=e||{};var r=e.defaultValue||n,t=k(n,e);return void 0!==t||t===r}function v(){return j=0,y.apply(null,arguments)}function x(){for(var n=[],e=1;arguments.length>e;e++)n.push(arguments[e]);return{postProcess:"sprintf",sprintf:n}}function y(n,e){e="string"==typeof e?x.apply(null,arguments):e||{};var r,t=e.defaultValue||n,u=k(n,e),a=e.lng?M.toLanguages(e.lng):T,s=e.ns||P.ns.defaultNs;n.indexOf(P.nsseparator)>-1&&(r=n.split(P.nsseparator),s=r[0],n=r[1]),void 0===u&&P.sendMissing&&(e.lng?E.postMissing(a[0],s,n,t,a):E.postMissing(P.lng,s,n,t,a));var o=e.postProcess||P.postProcess;void 0!==u&&o&&R[o]&&(u=R[o](u,n,e));var i=t;if(t.indexOf(P.nsseparator)>-1&&(r=t.split(P.nsseparator),i=r[1]),i===n&&P.parseMissingKey&&(t=P.parseMissingKey(t)),void 0===u&&(t=b(t,e),t=g(t,e),o&&R[o])){var l=e.defaultValue||n;u=R[o](l,n,e)}return void 0!==u?u:t}function k(n,e){e=e||{};var r,t,u=e.defaultValue||n,a=T;if(!w)return u;if(e.lng&&(a=M.toLanguages(e.lng),!w[a[0]])){var s=P.getAsync;P.getAsync=!1,L.sync.load(a,P,function(n,e){M.extend(w,e),P.getAsync=s})}var o=e.ns||P.ns.defaultNs;if(n.indexOf(P.nsseparator)>-1){var i=n.split(P.nsseparator);o=i[0],n=i[1]}if(d(e)){r=M.extend({},e),delete r.context,r.defaultValue=P.contextNotFound;var l=o+P.nsseparator+n+"_"+e.context;if(t=v(l,r),t!=P.contextNotFound)return b(t,{context:e.context})}if(h(e)){r=M.extend({},e),delete r.count,r.defaultValue=P.pluralNotFound;var f=o+P.nsseparator+n+P.pluralSuffix,c=F.get(a[0],e.count);if(c>=0?f=f+"_"+c:1===c&&(f=o+P.nsseparator+n),t=v(f,r),t!=P.pluralNotFound)return b(t,{count:e.count,interpolationPrefix:e.interpolationPrefix,interpolationSuffix:e.interpolationSuffix})}for(var m,p=n.split(P.keyseparator),N=0,x=a.length;x>N&&void 0===m;N++){for(var S=a[N],O=0,j=w[S]&&w[S][o];p[O];)j=j&&j[p[O]],O++;if(void 0!==j){if("string"==typeof j)j=b(j,e),j=g(j,e);else if("[object Array]"!==Object.prototype.toString.apply(j)||P.returnObjectTrees||e.returnObjectTrees){if(null===j&&P.fallbackOnNull===!0)j=void 0;else if(null!==j)if(P.returnObjectTrees||e.returnObjectTrees){var A={};for(var C in j)A[C]=y(o+P.nsseparator+n+P.keyseparator+C,e);j=A}else j="key '"+o+":"+n+" ("+S+")' "+"returned a object instead of string.",M.log(j)}else j=j.join("\n"),j=b(j,e),j=g(j,e);m=j}}if(void 0===m&&!e.isFallbackLookup&&(P.fallbackToDefaultNS===!0||P.fallbackNS&&P.fallbackNS.length>0))if(e.isFallbackLookup=!0,P.fallbackNS.length){for(var _=0,E=P.fallbackNS.length;E>_;_++)if(m=k(P.fallbackNS[_]+P.nsseparator+n,e)){var R=m.indexOf(P.nsseparator)>-1?m.split(P.nsseparator)[1]:m,z=u.indexOf(P.nsseparator)>-1?u.split(P.nsseparator)[1]:u;if(R!==z)break}}else m=k(n,e);return m}function S(){var n,e=[];if("undefined"!=typeof window&&(function(){for(var n=window.location.search.substring(1),r=n.split("&"),t=0;r.length>t;t++){var u=r[t].indexOf("=");if(u>0){var a=r[t].substring(0,u),s=r[t].substring(u+1);e[a]=s}}}(),e[P.detectLngQS]&&(n=e[P.detectLngQS])),!n&&"undefined"!=typeof document&&P.useCookie){var r=M.cookie.read(P.cookieName);r&&(n=r)}return n||"undefined"==typeof navigator||(n=navigator.language?navigator.language:navigator.userLanguage),n}Array.prototype.indexOf||(Array.prototype.indexOf=function(n){"use strict";if(null==this)throw new TypeError;var e=Object(this),r=e.length>>>0;if(0===r)return-1;var t=0;if(arguments.length>0&&(t=Number(arguments[1]),t!=t?t=0:0!=t&&1/0!=t&&t!=-1/0&&(t=(t>0||-1)*Math.floor(Math.abs(t)))),t>=r)return-1;for(var u=t>=0?t:Math.max(r-Math.abs(t),0);r>u;u++)if(u in e&&e[u]===n)return u;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(n){"use strict";if(null==this)throw new TypeError;var e=Object(this),r=e.length>>>0;if(0===r)return-1;var t=r;arguments.length>1&&(t=Number(arguments[1]),t!=t?t=0:0!=t&&t!=1/0&&t!=-(1/0)&&(t=(t>0||-1)*Math.floor(Math.abs(t))));for(var u=t>=0?Math.min(t,r-1):r-Math.abs(t);u>=0;u--)if(u in e&&e[u]===n)return u;return-1});var O,L={},w={},j=0,T=[],P={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:"dev",fallbackNS:[],detectLngQS:"setLng",ns:"translation",fallbackOnNull:!0,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",postProcess:void 0,parseMissingKey:void 0},A={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},C={create:function(n,e,r){var t;if(r){var u=new Date;u.setTime(u.getTime()+1e3*60*r),t="; expires="+u.toGMTString()}else t="";document.cookie=n+"="+e+t+"; path=/"},read:function(n){for(var e=n+"=",r=document.cookie.split(";"),t=0;r.length>t;t++){for(var u=r[t];" "==u.charAt(0);)u=u.substring(1,u.length);if(0===u.indexOf(e))return u.substring(e.length,u.length)}return null},remove:function(n){this.create(n,"",-1)}},_={create:function(){},read:function(){return null},remove:function(){}},M={extend:n?n.extend:e,each:n?n.each:r,ajax:n?n.ajax:u,cookie:"undefined"!=typeof document?C:_,detectLanguage:S,escape:t,log:function(n){P.debug&&"undefined"!=typeof console&&console.log(n)},toLanguages:function(n){var e=[];if("string"==typeof n&&n.indexOf("-")>-1){var r=n.split("-");n=P.lowerCaseLng?r[0].toLowerCase()+"-"+r[1].toLowerCase():r[0].toLowerCase()+"-"+r[1].toUpperCase(),"unspecific"!==P.load&&e.push(n),"current"!==P.load&&e.push(r[0])}else e.push(n);return-1===e.indexOf(P.fallbackLng)&&P.fallbackLng&&e.push(P.fallbackLng),e},regexEscape:function(n){return n.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}};M.applyReplacement=b;var E={load:function(n,e,r){e.useLocalStorage?E._loadLocal(n,e,function(t,u){for(var a=[],s=0,o=n.length;o>s;s++)u[n[s]]||a.push(n[s]);a.length>0?E._fetch(a,e,function(n,e){M.extend(u,e),E._storeLocal(e),r(null,u)}):r(null,u)}):E._fetch(n,e,function(n,e){r(null,e)})},_loadLocal:function(n,e,r){var t={},u=(new Date).getTime();if(window.localStorage){var a=n.length;M.each(n,function(n,s){var o=window.localStorage.getItem("res_"+s);o&&(o=JSON.parse(o),o.i18nStamp&&o.i18nStamp+e.localStorageExpirationTime>u&&(t[s]=o)),a--,0===a&&r(null,t)})}},_storeLocal:function(n){if(window.localStorage)for(var e in n)n[e].i18nStamp=(new Date).getTime(),window.localStorage.setItem("res_"+e,JSON.stringify(n[e]))},_fetch:function(n,e,r){var t=e.ns,u={};if(e.dynamicLoad){var a=function(n,e){r(null,e)};if("function"==typeof e.customLoad)e.customLoad(n,t.namespaces,e,a);else{var s=b(e.resGetPath,{lng:n.join("+"),ns:t.namespaces.join("+")});M.ajax({url:s,success:function(n){M.log("loaded: "+s),a(null,n)},error:function(n,e,r){M.log("failed loading: "+s),a("failed loading resource.json error: "+r)},dataType:"json",async:e.getAsync})}}else{var o,i=t.namespaces.length*n.length;M.each(t.namespaces,function(t,a){M.each(n,function(n,t){var s=function(n,e){n&&(o=o||[],o.push(n)),u[t]=u[t]||{},u[t][a]=e,i--,0===i&&r(o,u)};"function"==typeof e.customLoad?e.customLoad(t,a,e,s):E._fetchOne(t,a,e,s)})})}},_fetchOne:function(n,e,r,t){var u=b(r.resGetPath,{lng:n,ns:e});M.ajax({url:u,success:function(n){M.log("loaded: "+u),t(null,n)},error:function(n,e,r){M.log("failed loading: "+u),t(r,{})},dataType:"json",async:r.getAsync})},postMissing:function(n,e,r,t,u){var a={};a[r]=t;var s=[];if("fallback"===P.sendMissingTo&&P.fallbackLng!==!1)s.push({lng:P.fallbackLng,url:b(P.resPostPath,{lng:P.fallbackLng,ns:e})});else if("current"===P.sendMissingTo||"fallback"===P.sendMissingTo&&P.fallbackLng===!1)s.push({lng:n,url:b(P.resPostPath,{lng:n,ns:e})});else if("all"===P.sendMissingTo)for(var o=0,i=u.length;i>o;o++)s.push({lng:u[o],url:b(P.resPostPath,{lng:u[o],ns:e})});for(var l=0,f=s.length;f>l;l++){var c=s[l];M.ajax({url:c.url,type:P.sendType,data:a,success:function(){M.log("posted missing key '"+r+"' to: "+c.url);for(var n=r.split("."),u=0,a=w[c.lng][e];n[u];)a=a[n[u]]=u===n.length-1?t:a[n[u]]||{},u++},error:function(){M.log("failed posting missing key '"+r+"' to: "+c.url)},dataType:"json",async:P.postAsync})}}},F={rules:{ach:{name:"Acholi",numbers:[1,2],plurals:function(n){return Number(n>1)}},af:{name:"Afrikaans",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ak:{name:"Akan",numbers:[1,2],plurals:function(n){return Number(n>1)}},am:{name:"Amharic",numbers:[1,2],plurals:function(n){return Number(n>1)}},an:{name:"Aragonese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ar:{name:"Arabic",numbers:[0,1,2,3,11,100],plurals:function(n){return Number(0===n?0:1==n?1:2==n?2:n%100>=3&&10>=n%100?3:n%100>=11?4:5)}},arn:{name:"Mapudungun",numbers:[1,2],plurals:function(n){return Number(n>1)}},ast:{name:"Asturian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ay:{name:"Aymará",numbers:[1],plurals:function(){return 0}},az:{name:"Azerbaijani",numbers:[1,2],plurals:function(n){return Number(1!=n)}},be:{name:"Belarusian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},bg:{name:"Bulgarian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},bn:{name:"Bengali",numbers:[1,2],plurals:function(n){return Number(1!=n)}},bo:{name:"Tibetan",numbers:[1],plurals:function(){return 0}},br:{name:"Breton",numbers:[1,2],plurals:function(n){return Number(n>1)}},bs:{name:"Bosnian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},ca:{name:"Catalan",numbers:[1,2],plurals:function(n){return Number(1!=n)}},cgg:{name:"Chiga",numbers:[1],plurals:function(){return 0}},cs:{name:"Czech",numbers:[1,2,5],plurals:function(n){return Number(1==n?0:n>=2&&4>=n?1:2)}},csb:{name:"Kashubian",numbers:[1,2,5],plurals:function(n){return Number(1==n?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},cy:{name:"Welsh",numbers:[1,2,3,8],plurals:function(n){return Number(1==n?0:2==n?1:8!=n&&11!=n?2:3)}},da:{name:"Danish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},de:{name:"German",numbers:[1,2],plurals:function(n){return Number(1!=n)}},dz:{name:"Dzongkha",numbers:[1],plurals:function(){return 0}},el:{name:"Greek",numbers:[1,2],plurals:function(n){return Number(1!=n)}},en:{name:"English",numbers:[1,2],plurals:function(n){return Number(1!=n)}},eo:{name:"Esperanto",numbers:[1,2],plurals:function(n){return Number(1!=n)}},es:{name:"Spanish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},es_ar:{name:"Argentinean Spanish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},et:{name:"Estonian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},eu:{name:"Basque",numbers:[1,2],plurals:function(n){return Number(1!=n)}},fa:{name:"Persian",numbers:[1],plurals:function(){return 0}},fi:{name:"Finnish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},fil:{name:"Filipino",numbers:[1,2],plurals:function(n){return Number(n>1)}},fo:{name:"Faroese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},fr:{name:"French",numbers:[1,2],plurals:function(n){return Number(n>1)}},fur:{name:"Friulian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},fy:{name:"Frisian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ga:{name:"Irish",numbers:[1,2,3,7,11],plurals:function(n){return Number(1==n?0:2==n?1:7>n?2:11>n?3:4)}},gd:{name:"Scottish Gaelic",numbers:[1,2,3,20],plurals:function(n){return Number(1==n||11==n?0:2==n||12==n?1:n>2&&20>n?2:3)}},gl:{name:"Galician",numbers:[1,2],plurals:function(n){return Number(1!=n)}},gu:{name:"Gujarati",numbers:[1,2],plurals:function(n){return Number(1!=n)}},gun:{name:"Gun",numbers:[1,2],plurals:function(n){return Number(n>1)}},ha:{name:"Hausa",numbers:[1,2],plurals:function(n){return Number(1!=n)}},he:{name:"Hebrew",numbers:[1,2],plurals:function(n){return Number(1!=n)}},hi:{name:"Hindi",numbers:[1,2],plurals:function(n){return Number(1!=n)}},hr:{name:"Croatian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},hu:{name:"Hungarian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},hy:{name:"Armenian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ia:{name:"Interlingua",numbers:[1,2],plurals:function(n){return Number(1!=n)}},id:{name:"Indonesian",numbers:[1],plurals:function(){return 0}},is:{name:"Icelandic",numbers:[1,2],plurals:function(n){return Number(1!=n%10||11==n%100)}},it:{name:"Italian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ja:{name:"Japanese",numbers:[1],plurals:function(){return 0}},jbo:{name:"Lojban",numbers:[1],plurals:function(){return 0}},jv:{name:"Javanese",numbers:[0,1],plurals:function(n){return Number(0!==n)}},ka:{name:"Georgian",numbers:[1],plurals:function(){return 0}},kk:{name:"Kazakh",numbers:[1],plurals:function(){return 0}},km:{name:"Khmer",numbers:[1],plurals:function(){return 0}},kn:{name:"Kannada",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ko:{name:"Korean",numbers:[1],plurals:function(){return 0}},ku:{name:"Kurdish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},kw:{name:"Cornish",numbers:[1,2,3,4],plurals:function(n){return Number(1==n?0:2==n?1:3==n?2:3)}},ky:{name:"Kyrgyz",numbers:[1],plurals:function(){return 0}},lb:{name:"Letzeburgesch",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ln:{name:"Lingala",numbers:[1,2],plurals:function(n){return Number(n>1)}},lo:{name:"Lao",numbers:[1],plurals:function(){return 0}},lt:{name:"Lithuanian",numbers:[1,2,10],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&(10>n%100||n%100>=20)?1:2)}},lv:{name:"Latvian",numbers:[0,1,2],plurals:function(n){return Number(1==n%10&&11!=n%100?0:0!==n?1:2)}},mai:{name:"Maithili",numbers:[1,2],plurals:function(n){return Number(1!=n)}},mfe:{name:"Mauritian Creole",numbers:[1,2],plurals:function(n){return Number(n>1)}},mg:{name:"Malagasy",numbers:[1,2],plurals:function(n){return Number(n>1)}},mi:{name:"Maori",numbers:[1,2],plurals:function(n){return Number(n>1)}},mk:{name:"Macedonian",numbers:[1,2],plurals:function(n){return Number(1==n||1==n%10?0:1)}},ml:{name:"Malayalam",numbers:[1,2],plurals:function(n){return Number(1!=n)}},mn:{name:"Mongolian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},mnk:{name:"Mandinka",numbers:[0,1,2],plurals:function(n){return Number(1==n?1:2)}},mr:{name:"Marathi",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ms:{name:"Malay",numbers:[1],plurals:function(){return 0}},mt:{name:"Maltese",numbers:[1,2,11,20],plurals:function(n){return Number(1==n?0:0===n||n%100>1&&11>n%100?1:n%100>10&&20>n%100?2:3)}},nah:{name:"Nahuatl",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nap:{name:"Neapolitan",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nb:{name:"Norwegian Bokmal",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ne:{name:"Nepali",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nl:{name:"Dutch",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nn:{name:"Norwegian Nynorsk",numbers:[1,2],plurals:function(n){return Number(1!=n)}},no:{name:"Norwegian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},nso:{name:"Northern Sotho",numbers:[1,2],plurals:function(n){return Number(1!=n)}},oc:{name:"Occitan",numbers:[1,2],plurals:function(n){return Number(n>1)}},or:{name:"Oriya",numbers:[2,1],plurals:function(n){return Number(1!=n)}},pa:{name:"Punjabi",numbers:[1,2],plurals:function(n){return Number(1!=n)}},pap:{name:"Papiamento",numbers:[1,2],plurals:function(n){return Number(1!=n)}},pl:{name:"Polish",numbers:[1,2,5],plurals:function(n){return Number(1==n?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},pms:{name:"Piemontese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ps:{name:"Pashto",numbers:[1,2],plurals:function(n){return Number(1!=n)}},pt:{name:"Portuguese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},pt_br:{name:"Brazilian Portuguese",numbers:[1,2],plurals:function(n){return Number(1!=n)}},rm:{name:"Romansh",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ro:{name:"Romanian",numbers:[1,2,20],plurals:function(n){return Number(1==n?0:0===n||n%100>0&&20>n%100?1:2)}},ru:{name:"Russian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},sah:{name:"Yakut",numbers:[1],plurals:function(){return 0}},sco:{name:"Scots",numbers:[1,2],plurals:function(n){return Number(1!=n)}},se:{name:"Northern Sami",numbers:[1,2],plurals:function(n){return Number(1!=n)}},si:{name:"Sinhala",numbers:[1,2],plurals:function(n){return Number(1!=n)}},sk:{name:"Slovak",numbers:[1,2,5],plurals:function(n){return Number(1==n?0:n>=2&&4>=n?1:2)}},sl:{name:"Slovenian",numbers:[5,1,2,3],plurals:function(n){return Number(1==n%100?1:2==n%100?2:3==n%100||4==n%100?3:0)}},so:{name:"Somali",numbers:[1,2],plurals:function(n){return Number(1!=n)}},son:{name:"Songhay",numbers:[1,2],plurals:function(n){return Number(1!=n)}},sq:{name:"Albanian",numbers:[1,2],plurals:function(n){return Number(1!=n)}},sr:{name:"Serbian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},su:{name:"Sundanese",numbers:[1],plurals:function(){return 0}},sv:{name:"Swedish",numbers:[1,2],plurals:function(n){return Number(1!=n)}},sw:{name:"Swahili",numbers:[1,2],plurals:function(n){return Number(1!=n)}},ta:{name:"Tamil",numbers:[1,2],plurals:function(n){return Number(1!=n)}},te:{name:"Telugu",numbers:[1,2],plurals:function(n){return Number(1!=n)}},tg:{name:"Tajik",numbers:[1,2],plurals:function(n){return Number(n>1)}},th:{name:"Thai",numbers:[1],plurals:function(){return 0}},ti:{name:"Tigrinya",numbers:[1,2],plurals:function(n){return Number(n>1)}},tk:{name:"Turkmen",numbers:[1,2],plurals:function(n){return Number(1!=n)}},tr:{name:"Turkish",numbers:[1,2],plurals:function(n){return Number(n>1)}},tt:{name:"Tatar",numbers:[1],plurals:function(){return 0}},ug:{name:"Uyghur",numbers:[1],plurals:function(){return 0}},uk:{name:"Ukrainian",numbers:[1,2,5],plurals:function(n){return Number(1==n%10&&11!=n%100?0:n%10>=2&&4>=n%10&&(10>n%100||n%100>=20)?1:2)}},ur:{name:"Urdu",numbers:[1,2],plurals:function(n){return Number(1!=n)}},uz:{name:"Uzbek",numbers:[1,2],plurals:function(n){return Number(n>1)}},vi:{name:"Vietnamese",numbers:[1],plurals:function(){return 0}},wa:{name:"Walloon",numbers:[1,2],plurals:function(n){return Number(n>1)}},wo:{name:"Wolof",numbers:[1],plurals:function(){return 0}},yo:{name:"Yoruba",numbers:[1,2],plurals:function(n){return Number(1!=n)}},zh:{name:"Chinese",numbers:[1],plurals:function(){return 0}}},addRule:function(n,e){F.rules[n]=e},setCurrentLng:function(n){if(!F.currentRule||F.currentRule.lng!==n){var e=n.split("-");F.currentRule={lng:n,rule:F.rules[e[0]]}}},get:function(n,e){function r(e,r){var t;if(t=F.currentRule&&F.currentRule.lng===n?F.currentRule.rule:F.rules[e]){var u=t.plurals(r),a=t.numbers[u];return 2===t.numbers.length&&1===t.numbers[0]&&(2===a?a=-1:1===a&&(a=1)),a}return 1===r?"1":"-1"}var t=n.split("-");return r(t[0],e)}},R={},z=function(n,e){R[n]=e},D=function(){function n(n){return Object.prototype.toString.call(n).slice(8,-1).toLowerCase()}function e(n,e){for(var r=[];e>0;r[--e]=n);return r.join("")}var r=function(){return r.cache.hasOwnProperty(arguments[0])||(r.cache[arguments[0]]=r.parse(arguments[0])),r.format.call(null,r.cache[arguments[0]],arguments)};return r.format=function(r,t){var u,a,s,o,i,l,f,c=1,m=r.length,p="",b=[];for(a=0;m>a;a++)if(p=n(r[a]),"string"===p)b.push(r[a]);else if("array"===p){if(o=r[a],o[2])for(u=t[c],s=0;o[2].length>s;s++){if(!u.hasOwnProperty(o[2][s]))throw D('[sprintf] property "%s" does not exist',o[2][s]);u=u[o[2][s]]}else u=o[1]?t[o[1]]:t[c++];if(/[^s]/.test(o[8])&&"number"!=n(u))throw D("[sprintf] expecting number but found %s",n(u));switch(o[8]){case"b":u=u.toString(2);break;case"c":u=String.fromCharCode(u);break;case"d":u=parseInt(u,10);break;case"e":u=o[7]?u.toExponential(o[7]):u.toExponential();break;case"f":u=o[7]?parseFloat(u).toFixed(o[7]):parseFloat(u);break;case"o":u=u.toString(8);break;case"s":u=(u+="")&&o[7]?u.substring(0,o[7]):u;break;case"u":u=Math.abs(u);break;case"x":u=u.toString(16);break;case"X":u=u.toString(16).toUpperCase()}u=/[def]/.test(o[8])&&o[3]&&u>=0?"+"+u:u,l=o[4]?"0"==o[4]?"0":o[4].charAt(1):" ",f=o[6]-(u+"").length,i=o[6]?e(l,f):"",b.push(o[5]?u+i:i+u)}return b.join("")},r.cache={},r.parse=function(n){for(var e=n,r=[],t=[],u=0;e;){if(null!==(r=/^[^\x25]+/.exec(e)))t.push(r[0]);else if(null!==(r=/^\x25{2}/.exec(e)))t.push("%");else{if(null===(r=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(e)))throw"[sprintf] huh?";if(r[2]){u|=1;var a=[],s=r[2],o=[];if(null===(o=/^([a-z_][a-z_\d]*)/i.exec(s)))throw"[sprintf] huh?";for(a.push(o[1]);""!==(s=s.substring(o[0].length));)if(null!==(o=/^\.([a-z_][a-z_\d]*)/i.exec(s)))a.push(o[1]);else{if(null===(o=/^\[(\d+)\]/.exec(s)))throw"[sprintf] huh?";a.push(o[1])}r[2]=a}else u|=2;if(3===u)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";t.push(r)}e=e.substring(r[0].length)}return t},r}(),I=function(n,e){return e.unshift(n),D.apply(null,e)};return z("sprintf",function(n,e,r){return r.sprintf?"[object Array]"===Object.prototype.toString.apply(r.sprintf)?I(n,r.sprintf):"object"==typeof r.sprintf?D(n,r.sprintf):n:n}),L.init=a,L.setLng=c,L.preload=s,L.addResourceBundle=o,L.loadNamespace=l,L.loadNamespaces=f,L.setDefaultNamespace=i,L.t=v,L.translate=v,L.exists=N,L.detectLanguage=M.detectLanguage,L.pluralExtensions=F,L.sync=E,L.functions=M,L.lng=m,L.addPostProcessor=z,L.options=P,n.i18n=L,n.t=L.t,L}); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd.withJQuery-1.7.0.js b/libs/i18next/release/i18next.amd.withJQuery-1.7.0.js new file mode 100644 index 00000000..19a5d651 --- /dev/null +++ b/libs/i18next/release/i18next.amd.withJQuery-1.7.0.js @@ -0,0 +1,2663 @@ +// i18next, v1.7.0 +// Copyright (c)2013 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function (root, factory) { + if (typeof exports === 'object') { + + var jquery = require('jquery'); + + module.exports = factory(jquery); + + } else if (typeof define === 'function' && define.amd) { + + define(['jquery'], factory); + + } +}(this, function ($) { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + var i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = []; + + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: 'dev', + fallbackNS: [], + detectLngQS: 'setLng', + ns: 'translation', + fallbackOnNull: true, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + cookieDomain: undefined, + + postProcess: undefined, + parseMissingKey: undefined, + + shortcutFunction: 'sprintf' // or: defaultValue + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + return JSON.parse(data); + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + if (status === 200) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes,domain) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + domain = (domain)? "domain="+domain+";" : ""; + document.cookie = name+"="+value+expires+";"+domain+"path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes,domain) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : _ajax, + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + toLanguages: function(lng) { + var languages = []; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + + if (o.load !== 'unspecific') languages.push(lng); + if (o.load !== 'current') languages.push(parts[0]); + } else { + languages.push(lng); + } + + if (languages.indexOf(o.fallbackLng) === -1 && o.fallbackLng) languages.push(o.fallbackLng); + + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + delete o.fixLng; /* passed in each time */ + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + if (o.lng) { + // set cookie with lng set (as detectLanguage will set cookie on need) + if (o.useCookie) f.cookie.create(o.cookieName, o.lng, o.cookieExpirationTime, o.cookieDomain); + } else { + o.lng = o.fallbackLng; + if (o.useCookie) f.cookie.remove(o.cookieName); + } + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + var lngTranslate = translate; + if (options.fixLng) { + lngTranslate = function(key, options) { + options = options || {}; + options.lng = options.lng || lngTranslate.lng; + return translate(key, options); + }; + lngTranslate.lng = currentLng; + } + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + initialized = true; + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + initialized = true; + + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + f.extend(resStore[lng][ns], resources); + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, options, cb) { + if (typeof options === 'function') { + cb = options; + options = {}; + } + options.lng = lng; + return init(options, cb); + } + + function lng() { + return currentLng; + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } + else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key && typeof key !== 'undefined' && key !== false) key = ele.text() || ele.val(); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + f.each(replacementHash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), value); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.escape(value)); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), value); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, translated_token); + } + return translated; + } + + function hasContext(options) { + return (options.context && typeof options.context == 'string'); + } + + function needsPlural(options) { + return (options.count !== undefined && typeof options.count != 'string' && options.count !== 1); + } + + function exists(key, options) { + options = options || {}; + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + if (!initialized) { + f.log('i18next not finished initialization. you might have called t function before loading resources finished.') + return options.defaultValue || ''; + }; + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _getDefaultValue(key, options) { + return (options.defaultValue !== undefined) ? options.defaultValue : key; + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(potentialKeys, options) { + if (typeof options == 'string') { + if (o.shortcutFunction === 'sprintf') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else if (o.shortcutFunction === 'defaultValue') { + options = { + defaultValue: options + } + } + } else { + options = options || {}; + } + + if (typeof potentialKeys == 'string') { + potentialKeys = [potentialKeys]; + } + + var key = null; + + for (var i = 0; i < potentialKeys.length; i++) { + key = potentialKeys[i]; + if (exists(key)) { + break; + } + } + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng) : languages + , ns = options.ns || o.ns.defaultNs + , parts; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing) { + if (options.lng) { + sync.postMissing(lngs[0], ns, key, notFound, lngs); + } else { + sync.postMissing(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found !== undefined && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + // process notFound if function exists + var splitNotFound = notFound; + if (notFound.indexOf(o.nsseparator) > -1) { + parts = notFound.split(o.nsseparator); + splitNotFound = parts[1]; + } + if (splitNotFound === key && o.parseMissingKey) { + notFound = o.parseMissingKey(notFound); + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessor && postProcessors[postProcessor]) { + var val = _getDefaultValue(key, options); + found = postProcessors[postProcessor](val, key, options); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options){ + options = options || {}; + + var optionWithoutCount, translated + , notFound = _getDefaultValue(key, options) + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + if (options.lng) { + lngs = f.toLanguages(options.lng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.count; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(lngs[0], options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + + translated = translate(pluralKey, optionWithoutCount); + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } // else continue translation with original/singular key + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (Object.prototype.toString.apply(value) === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned a object instead of string.'; + f.log(value); + } else if (typeof value !== 'number') { + var copy = {}; // apply child translation on a copy + f.each(value, function(m) { + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + }); + value = copy; + } + } + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length > 0))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + } + + return found; + } + function detectLanguage() { + var detectedLng; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var parms = query.split('&'); + for (var i=0; i 0) { + var key = parms[i].substring(0,pos); + var val = parms[i].substring(pos+1); + qsParm[key] = val; + } + } + })(); + if (qsParm[o.detectLngQS]) { + detectedLng = qsParm[o.detectLngQS]; + } + } + + // get from cookie + if (!detectedLng && typeof document !== 'undefined' && o.useCookie ) { + var c = f.cookie.read(o.cookieName); + if (c) detectedLng = c; + } + + // get from navigator + if (!detectedLng && typeof navigator !== 'undefined') { + detectedLng = (navigator.language) ? navigator.language : navigator.userLanguage; + } + + return detectedLng; + } + var sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + window.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback' && o.fallbackLng !== false) { + urls.push({lng: o.fallbackLng, url: applyReplacement(o.resPostPath, { lng: o.fallbackLng, ns: ns })}); + } else if (o.sendMissingTo === 'current' || (o.sendMissingTo === 'fallback' && o.fallbackLng === false) ) { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + } + }; + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + var pluralExtensions = { + + rules: { + "ach": { + "name": "Acholi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "af": { + "name": "Afrikaans", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ak": { + "name": "Akan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "am": { + "name": "Amharic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "an": { + "name": "Aragonese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ar": { + "name": "Arabic", + "numbers": [ + 0, + 1, + 2, + 3, + 11, + 100 + ], + "plurals": function(n) { return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5); } + }, + "arn": { + "name": "Mapudungun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ast": { + "name": "Asturian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ay": { + "name": "Aymar\u00e1", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "az": { + "name": "Azerbaijani", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "be": { + "name": "Belarusian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "bg": { + "name": "Bulgarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bn": { + "name": "Bengali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bo": { + "name": "Tibetan", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "br": { + "name": "Breton", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "bs": { + "name": "Bosnian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ca": { + "name": "Catalan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "cgg": { + "name": "Chiga", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "cs": { + "name": "Czech", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "csb": { + "name": "Kashubian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "cy": { + "name": "Welsh", + "numbers": [ + 1, + 2, + 3, + 8 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3); } + }, + "da": { + "name": "Danish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "de": { + "name": "German", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "dz": { + "name": "Dzongkha", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "el": { + "name": "Greek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "en": { + "name": "English", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eo": { + "name": "Esperanto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es": { + "name": "Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es_ar": { + "name": "Argentinean Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "et": { + "name": "Estonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eu": { + "name": "Basque", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fa": { + "name": "Persian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "fi": { + "name": "Finnish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fil": { + "name": "Filipino", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fo": { + "name": "Faroese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fr": { + "name": "French", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fur": { + "name": "Friulian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fy": { + "name": "Frisian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ga": { + "name": "Irish", + "numbers": [ + 1, + 2, + 3, + 7, + 11 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;} + }, + "gd": { + "name": "Scottish Gaelic", + "numbers": [ + 1, + 2, + 3, + 20 + ], + "plurals": function(n) { return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3); } + }, + "gl": { + "name": "Galician", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gu": { + "name": "Gujarati", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gun": { + "name": "Gun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ha": { + "name": "Hausa", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "he": { + "name": "Hebrew", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hi": { + "name": "Hindi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hr": { + "name": "Croatian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "hu": { + "name": "Hungarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hy": { + "name": "Armenian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ia": { + "name": "Interlingua", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "id": { + "name": "Indonesian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "is": { + "name": "Icelandic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n%10!=1 || n%100==11); } + }, + "it": { + "name": "Italian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ja": { + "name": "Japanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jbo": { + "name": "Lojban", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jv": { + "name": "Javanese", + "numbers": [ + 0, + 1 + ], + "plurals": function(n) { return Number(n !== 0); } + }, + "ka": { + "name": "Georgian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kk": { + "name": "Kazakh", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "km": { + "name": "Khmer", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kn": { + "name": "Kannada", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ko": { + "name": "Korean", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ku": { + "name": "Kurdish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "kw": { + "name": "Cornish", + "numbers": [ + 1, + 2, + 3, + 4 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3); } + }, + "ky": { + "name": "Kyrgyz", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lb": { + "name": "Letzeburgesch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ln": { + "name": "Lingala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "lo": { + "name": "Lao", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lt": { + "name": "Lithuanian", + "numbers": [ + 1, + 2, + 10 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "lv": { + "name": "Latvian", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2); } + }, + "mai": { + "name": "Maithili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mfe": { + "name": "Mauritian Creole", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mg": { + "name": "Malagasy", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mi": { + "name": "Maori", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mk": { + "name": "Macedonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 || n%10==1 ? 0 : 1); } + }, + "ml": { + "name": "Malayalam", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mn": { + "name": "Mongolian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mnk": { + "name": "Mandinka", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(0 ? 0 : n==1 ? 1 : 2); } + }, + "mr": { + "name": "Marathi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ms": { + "name": "Malay", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "mt": { + "name": "Maltese", + "numbers": [ + 1, + 2, + 11, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3); } + }, + "nah": { + "name": "Nahuatl", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nap": { + "name": "Neapolitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nb": { + "name": "Norwegian Bokmal", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ne": { + "name": "Nepali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nl": { + "name": "Dutch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nn": { + "name": "Norwegian Nynorsk", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "no": { + "name": "Norwegian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nso": { + "name": "Northern Sotho", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "oc": { + "name": "Occitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "or": { + "name": "Oriya", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pa": { + "name": "Punjabi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pap": { + "name": "Papiamento", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pl": { + "name": "Polish", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "pms": { + "name": "Piemontese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ps": { + "name": "Pashto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt": { + "name": "Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt_br": { + "name": "Brazilian Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "rm": { + "name": "Romansh", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ro": { + "name": "Romanian", + "numbers": [ + 1, + 2, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2); } + }, + "ru": { + "name": "Russian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "sah": { + "name": "Yakut", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sco": { + "name": "Scots", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "se": { + "name": "Northern Sami", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "si": { + "name": "Sinhala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sk": { + "name": "Slovak", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "sl": { + "name": "Slovenian", + "numbers": [ + 5, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }, + "so": { + "name": "Somali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "son": { + "name": "Songhay", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sq": { + "name": "Albanian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sr": { + "name": "Serbian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "su": { + "name": "Sundanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sv": { + "name": "Swedish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sw": { + "name": "Swahili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ta": { + "name": "Tamil", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "te": { + "name": "Telugu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tg": { + "name": "Tajik", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "th": { + "name": "Thai", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ti": { + "name": "Tigrinya", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tk": { + "name": "Turkmen", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tr": { + "name": "Turkish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tt": { + "name": "Tatar", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ug": { + "name": "Uyghur", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "uk": { + "name": "Ukrainian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ur": { + "name": "Urdu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "uz": { + "name": "Uzbek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "vi": { + "name": "Vietnamese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "wa": { + "name": "Walloon", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "wo": { + "name": "Wolof", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "yo": { + "name": "Yoruba", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "zh": { + "name": "Chinese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + } + }, + + // for demonstration only sl and ar is added but you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i = ext.plurals(c); + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[0], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + + $.i18n = i18n; + $.t = i18n.t; + + return i18n; + +})); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd.withJQuery-1.7.0.min.js b/libs/i18next/release/i18next.amd.withJQuery-1.7.0.min.js new file mode 100644 index 00000000..05013dd7 --- /dev/null +++ b/libs/i18next/release/i18next.amd.withJQuery-1.7.0.min.js @@ -0,0 +1,5 @@ +// i18next, v1.7.0 +// Copyright (c)2013 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +!function(a,b){if("object"==typeof exports){var c=require("jquery");module.exports=b(c)}else"function"==typeof define&&define.amd&&define(["jquery"],b)}(this,function(a){function b(a,b){if(!b||"function"==typeof b)return a;for(var c in b)a[c]=b[c];return a}function c(a,b,c){var d,e=0,f=a.length,g=void 0===f||"function"==typeof a;if(c)if(g){for(d in a)if(b.apply(a[d],c)===!1)break}else for(;f>e&&b.apply(a[e++],c)!==!1;);else if(g){for(d in a)if(b.call(a[d],d,a[d])===!1)break}else for(;f>e&&b.call(a[e],e,a[e++])!==!1;);return a}function d(a){return"string"==typeof a?a.replace(/[&<>"'\/]/g,function(a){return F[a]}):a}function e(a){var b=function(a){if(window.XMLHttpRequest)return a(null,new XMLHttpRequest);if(window.ActiveXObject)try{return a(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(b){return a(null,new ActiveXObject("Microsoft.XMLHTTP"))}return a(new Error)},c=function(a){if("string"==typeof a)return a;var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")},d=function(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;cd?b+=String.fromCharCode(d):d>127&&2048>d?(b+=String.fromCharCode(192|d>>6),b+=String.fromCharCode(128|63&d)):(b+=String.fromCharCode(224|d>>12),b+=String.fromCharCode(128|63&d>>6),b+=String.fromCharCode(128|63&d))}return b},e=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";a=d(a);var c,e,f,g,h,i,j,k="",l=0;do c=a.charCodeAt(l++),e=a.charCodeAt(l++),f=a.charCodeAt(l++),g=c>>2,h=(3&c)<<4|e>>4,i=(15&e)<<2|f>>6,j=63&f,isNaN(e)?i=j=64:isNaN(f)&&(j=64),k+=b.charAt(g)+b.charAt(h)+b.charAt(i)+b.charAt(j),c=e=f="",g=h=i=j="";while(l1&&(d+=d.indexOf("?")>-1?"&"+k:"?"+k),e.jsonp){var l=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=d,l.appendChild(m),void 0}}b(function(b,c){if(b)return h(b);c.open(a,d,e.async);for(var f in j)j.hasOwnProperty(f)&&c.setRequestHeader(f,j[f]);c.onreadystatechange=function(){if(4===c.readyState){var a=c.responseText||"";if(!h)return;h(c.status,{text:function(){return a},json:function(){return JSON.parse(a)}})}},c.send(i)})},h={authBasic:function(a,b){g.headers.Authorization="Basic "+e(a+":"+b)},connect:function(a,b,c){return g("CONNECT",a,b,c)},del:function(a,b,c){return g("DELETE",a,b,c)},get:function(a,b,c){return g("GET",a,b,c)},head:function(a,b,c){return g("HEAD",a,b,c)},headers:function(a){g.headers=a||{}},isAllowed:function(a,b,c){this.options(a,function(a,d){c(-1!==d.text().indexOf(b))})},options:function(a,b,c){return g("OPTIONS",a,b,c)},patch:function(a,b,c){return g("PATCH",a,b,c)},post:function(a,b,c){return g("POST",a,b,c)},put:function(a,b,c){return g("PUT",a,b,c)},trace:function(a,b,c){return g("TRACE",a,b,c)}},i=a.type?a.type.toLowerCase():"get";h[i](a.url,a,function(b,c){200===b?a.success(c.json(),b,null):a.error(c.text(),b,null)})}function f(b,c){"function"==typeof b&&(c=b,b={}),b=b||{},I.extend(E,b),delete E.fixLng,"string"==typeof E.ns&&(E.ns={namespaces:[E.ns],defaultNs:E.ns}),"string"==typeof E.fallbackNS&&(E.fallbackNS=[E.fallbackNS]),E.interpolationPrefixEscaped=I.regexEscape(E.interpolationPrefix),E.interpolationSuffixEscaped=I.regexEscape(E.interpolationSuffix),E.lng||(E.lng=I.detectLanguage()),E.lng?E.useCookie&&I.cookie.create(E.cookieName,E.lng,E.cookieExpirationTime,E.cookieDomain):(E.lng=E.fallbackLng,E.useCookie&&I.cookie.remove(E.cookieName)),D=I.toLanguages(E.lng),z=D[0],I.log("currentLng set to: "+z);var d=t;b.fixLng&&(d=function(a,b){return b=b||{},b.lng=b.lng||d.lng,t(a,b)},d.lng=z),K.setCurrentLng(z),a&&E.setJqueryExt&&n();var e;if(a&&a.Deferred&&(e=a.Deferred()),!E.resStore){var f=I.toLanguages(E.lng);"string"==typeof E.preload&&(E.preload=[E.preload]);for(var g=0,h=E.preload.length;h>g;g++)for(var i=I.toLanguages(E.preload[g]),j=0,k=i.length;k>j;j++)f.indexOf(i[j])<0&&f.push(i[j]);return A.sync.load(f,E,function(a,b){B=b,initialized=!0,c&&c(d),e&&e.resolve(d)}),e?e.promise():void 0}return B=E.resStore,initialized=!0,c&&c(d),e&&e.resolve(d),e?e.promise():void 0}function g(a,b){"string"==typeof a&&(a=[a]);for(var c=0,d=a.length;d>c;c++)E.preload.indexOf(a[c])<0&&E.preload.push(a[c]);return f(b)}function h(a,b,c){"string"!=typeof b?(c=b,b=E.ns.defaultNs):E.ns.namespaces.indexOf(b)<0&&E.ns.namespaces.push(b),B[a]=B[a]||{},B[a][b]=B[a][b]||{},I.extend(B[a][b],c)}function i(a){E.ns.defaultNs=a}function j(a,b){k([a],b)}function k(a,b){var c={dynamicLoad:E.dynamicLoad,resGetPath:E.resGetPath,getAsync:E.getAsync,customLoad:E.customLoad,ns:{namespaces:a,defaultNs:""}},d=I.toLanguages(E.lng);"string"==typeof E.preload&&(E.preload=[E.preload]);for(var e=0,f=E.preload.length;f>e;e++)for(var g=I.toLanguages(E.preload[e]),h=0,i=g.length;i>h;h++)d.indexOf(g[h])<0&&d.push(g[h]);for(var j=[],k=0,l=d.length;l>k;k++){var m=!1,n=B[d[k]];if(n)for(var o=0,p=a.length;p>o;o++)n[a[o]]||(m=!0);else m=!0;m&&j.push(d[k])}j.length?A.sync._fetch(j,c,function(c,d){var e=a.length*j.length;I.each(a,function(a,c){E.ns.namespaces.indexOf(c)<0&&E.ns.namespaces.push(c),I.each(j,function(a,f){B[f]=B[f]||{},B[f][c]=d[f][c],e--,0===e&&b&&(E.useLocalStorage&&A.sync._storeLocal(B),b())})})}):b&&b()}function l(a,b,c){return"function"==typeof b&&(c=b,b={}),b.lng=a,f(b,c)}function m(){return z}function n(){function b(b,c,d){if(0!==c.length){var e="text";if(0===c.indexOf("[")){var f=c.split("]");c=f[1],e=f[0].substr(1,f[0].length-1)}c.indexOf(";")===c.length-1&&(c=c.substr(0,c.length-2));var g;"html"===e?(g=E.defaultValueFromContent?a.extend({defaultValue:b.html()},d):d,b.html(a.t(c,g))):"text"===e?(g=E.defaultValueFromContent?a.extend({defaultValue:b.text()},d):d,b.text(a.t(c,g))):(g=E.defaultValueFromContent?a.extend({defaultValue:b.attr(e)},d):d,b.attr(e,a.t(c,g)))}}function c(c,d){var e=c.attr(E.selectorAttr);if(e||"undefined"==typeof e||e===!1||(e=c.text()||c.val()),e){var f=c,g=c.data("i18n-target");if(g&&(f=c.find(g)||c),d||E.useDataAttrOptions!==!0||(d=c.data("i18n-options")),d=d||{},e.indexOf(";")>=0){var h=e.split(";");a.each(h,function(a,c){""!==c&&b(f,c,d)})}else b(f,e,d);E.useDataAttrOptions===!0&&c.data("i18n-options",d)}}a.t=a.t||t,a.fn.i18n=function(b){return this.each(function(){c(a(this),b);var d=a(this).find("["+E.selectorAttr+"]");d.each(function(){c(a(this),b)})})}}function o(a,b,c,d){if(!a)return a;if(d=d||b,a.indexOf(d.interpolationPrefix||E.interpolationPrefix)<0)return a;var e=d.interpolationPrefix?I.regexEscape(d.interpolationPrefix):E.interpolationPrefixEscaped,f=d.interpolationSuffix?I.regexEscape(d.interpolationSuffix):E.interpolationSuffixEscaped,g="HTML"+f;return I.each(b,function(b,h){var i=c?c+E.keyseparator+b:b;"object"==typeof h&&null!==h?a=o(a,h,i,d):d.escapeInterpolation||E.escapeInterpolation?(a=a.replace(new RegExp([e,i,g].join(""),"g"),h),a=a.replace(new RegExp([e,i,f].join(""),"g"),I.escape(h))):a=a.replace(new RegExp([e,i,f].join(""),"g"),h)}),a}function p(a,b){var c=",",d="{",e="}",f=I.extend({},b);for(delete f.postProcess;-1!=a.indexOf(E.reusePrefix)&&(C++,!(C>E.maxRecursion));){var g=a.lastIndexOf(E.reusePrefix),h=a.indexOf(E.reuseSuffix,g)+E.reuseSuffix.length,i=a.substring(g,h),j=i.replace(E.reusePrefix,"").replace(E.reuseSuffix,"");if(-1!=j.indexOf(c)){var k=j.indexOf(c);if(-1!=j.indexOf(d,k)&&-1!=j.indexOf(e,k)){var l=j.indexOf(d,k),m=j.indexOf(e,l)+e.length;try{f=I.extend(f,JSON.parse(j.substring(l,m))),j=j.substring(0,k)}catch(n){}}}var o=w(j,f);a=a.replace(i,o)}return a}function q(a){return a.context&&"string"==typeof a.context}function r(a){return void 0!==a.count&&"string"!=typeof a.count&&1!==a.count}function s(a,b){b=b||{};var c=u(a,b),d=x(a,b);return void 0!==d||d===c}function t(a,b){return initialized?(C=0,w.apply(null,arguments)):(I.log("i18next not finished initialization. you might have called t function before loading resources finished."),b.defaultValue||"")}function u(a,b){return void 0!==b.defaultValue?b.defaultValue:a}function v(){for(var a=[],b=1;b-1&&(e=c.split(E.nsseparator),i=e[0],c=e[1]),void 0===g&&E.sendMissing&&(b.lng?J.postMissing(h[0],i,c,f,h):J.postMissing(E.lng,i,c,f,h));var j=b.postProcess||E.postProcess;void 0!==g&&j&&L[j]&&(g=L[j](g,c,b));var k=f;if(f.indexOf(E.nsseparator)>-1&&(e=f.split(E.nsseparator),k=e[1]),k===c&&E.parseMissingKey&&(f=E.parseMissingKey(f)),void 0===g&&(f=o(f,b),f=p(f,b),j&&L[j])){var l=u(c,b);g=L[j](l,c,b)}return void 0!==g?g:f}function x(a,b){b=b||{};var c,d,e=u(a,b),f=D;if(!B)return e;if(b.lng&&(f=I.toLanguages(b.lng),!B[f[0]])){var g=E.getAsync;E.getAsync=!1,A.sync.load(f,E,function(a,b){I.extend(B,b),E.getAsync=g})}var h=b.ns||E.ns.defaultNs;if(a.indexOf(E.nsseparator)>-1){var i=a.split(E.nsseparator);h=i[0],a=i[1]}if(q(b)){c=I.extend({},b),delete c.context,c.defaultValue=E.contextNotFound;var j=h+E.nsseparator+a+"_"+b.context;if(d=t(j,c),d!=E.contextNotFound)return o(d,{context:b.context})}if(r(b)){c=I.extend({},b),delete c.count,c.defaultValue=E.pluralNotFound;var k=h+E.nsseparator+a+E.pluralSuffix,l=K.get(f[0],b.count);if(l>=0?k=k+"_"+l:1===l&&(k=h+E.nsseparator+a),d=t(k,c),d!=E.pluralNotFound)return o(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix})}for(var m,n=a.split(E.keyseparator),s=0,v=f.length;v>s&&void 0===m;s++){for(var y=f[s],z=0,C=B[y]&&B[y][h];n[z];)C=C&&C[n[z]],z++;if(void 0!==C){if("string"==typeof C)C=o(C,b),C=p(C,b);else if("[object Array]"!==Object.prototype.toString.apply(C)||E.returnObjectTrees||b.returnObjectTrees){if(null===C&&E.fallbackOnNull===!0)C=void 0;else if(null!==C)if(E.returnObjectTrees||b.returnObjectTrees){if("number"!=typeof C){var F={};I.each(C,function(c){F[c]=w(h+E.nsseparator+a+E.keyseparator+c,b)}),C=F}}else C="key '"+h+":"+a+" ("+y+")' "+"returned a object instead of string.",I.log(C)}else C=C.join("\n"),C=o(C,b),C=p(C,b);m=C}}if(void 0===m&&!b.isFallbackLookup&&(E.fallbackToDefaultNS===!0||E.fallbackNS&&E.fallbackNS.length>0))if(b.isFallbackLookup=!0,E.fallbackNS.length){for(var G=0,H=E.fallbackNS.length;H>G;G++)if(m=x(E.fallbackNS[G]+E.nsseparator+a,b)){var J=m.indexOf(E.nsseparator)>-1?m.split(E.nsseparator)[1]:m,L=e.indexOf(E.nsseparator)>-1?e.split(E.nsseparator)[1]:e;if(J!==L)break}}else m=x(a,b);return m}function y(){var a,b=[];if("undefined"!=typeof window&&(!function(){for(var a=window.location.search.substring(1),c=a.split("&"),d=0;d0){var f=c[d].substring(0,e),g=c[d].substring(e+1);b[f]=g}}}(),b[E.detectLngQS]&&(a=b[E.detectLngQS])),!a&&"undefined"!=typeof document&&E.useCookie){var c=I.cookie.read(E.cookieName);c&&(a=c)}return a||"undefined"==typeof navigator||(a=navigator.language?navigator.language:navigator.userLanguage),a}Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>0&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&1/0!=d&&d!=-1/0&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=c;arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d))));for(var e=d>=0?Math.min(d,c-1):c-Math.abs(d);e>=0;e--)if(e in b&&b[e]===a)return e;return-1});var z,A={},B={},C=0,D=[],E={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:"dev",fallbackNS:[],detectLngQS:"setLng",ns:"translation",fallbackOnNull:!0,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",cookieDomain:void 0,postProcess:void 0,parseMissingKey:void 0,shortcutFunction:"sprintf"},F={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},G={create:function(a,b,c,d){var e;if(c){var f=new Date;f.setTime(f.getTime()+1e3*60*c),e="; expires="+f.toGMTString()}else e="";d=d?"domain="+d+";":"",document.cookie=a+"="+b+e+";"+d+"path=/"},read:function(a){for(var b=a+"=",c=document.cookie.split(";"),d=0;d-1){var c=a.split("-");a=E.lowerCaseLng?c[0].toLowerCase()+"-"+c[1].toLowerCase():c[0].toLowerCase()+"-"+c[1].toUpperCase(),"unspecific"!==E.load&&b.push(a),"current"!==E.load&&b.push(c[0])}else b.push(a);return-1===b.indexOf(E.fallbackLng)&&E.fallbackLng&&b.push(E.fallbackLng),b},regexEscape:function(a){return a.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}};I.applyReplacement=o;var J={load:function(a,b,c){b.useLocalStorage?J._loadLocal(a,b,function(d,e){for(var f=[],g=0,h=a.length;h>g;g++)e[a[g]]||f.push(a[g]);f.length>0?J._fetch(f,b,function(a,b){I.extend(e,b),J._storeLocal(b),c(null,e)}):c(null,e)}):J._fetch(a,b,function(a,b){c(null,b)})},_loadLocal:function(a,b,c){var d={},e=(new Date).getTime();if(window.localStorage){var f=a.length;I.each(a,function(a,g){var h=window.localStorage.getItem("res_"+g);h&&(h=JSON.parse(h),h.i18nStamp&&h.i18nStamp+b.localStorageExpirationTime>e&&(d[g]=h)),f--,0===f&&c(null,d)})}},_storeLocal:function(a){if(window.localStorage)for(var b in a)a[b].i18nStamp=(new Date).getTime(),window.localStorage.setItem("res_"+b,JSON.stringify(a[b]))},_fetch:function(a,b,c){var d=b.ns,e={};if(b.dynamicLoad){var f=function(a,b){c(null,b)};if("function"==typeof b.customLoad)b.customLoad(a,d.namespaces,b,f);else{var g=o(b.resGetPath,{lng:a.join("+"),ns:d.namespaces.join("+")});I.ajax({url:g,success:function(a){I.log("loaded: "+g),f(null,a)},error:function(a,b,c){I.log("failed loading: "+g),f("failed loading resource.json error: "+c)},dataType:"json",async:b.getAsync})}}else{var h,i=d.namespaces.length*a.length;I.each(d.namespaces,function(d,f){I.each(a,function(a,d){var g=function(a,b){a&&(h=h||[],h.push(a)),e[d]=e[d]||{},e[d][f]=b,i--,0===i&&c(h,e)};"function"==typeof b.customLoad?b.customLoad(d,f,b,g):J._fetchOne(d,f,b,g)})})}},_fetchOne:function(a,b,c,d){var e=o(c.resGetPath,{lng:a,ns:b});I.ajax({url:e,success:function(a){I.log("loaded: "+e),d(null,a)},error:function(a,b,c){I.log("failed loading: "+e),d(c,{})},dataType:"json",async:c.getAsync})},postMissing:function(a,b,c,d,e){var f={};f[c]=d;var g=[];if("fallback"===E.sendMissingTo&&E.fallbackLng!==!1)g.push({lng:E.fallbackLng,url:o(E.resPostPath,{lng:E.fallbackLng,ns:b})});else if("current"===E.sendMissingTo||"fallback"===E.sendMissingTo&&E.fallbackLng===!1)g.push({lng:a,url:o(E.resPostPath,{lng:a,ns:b})});else if("all"===E.sendMissingTo)for(var h=0,i=e.length;i>h;h++)g.push({lng:e[h],url:o(E.resPostPath,{lng:e[h],ns:b})});for(var j=0,k=g.length;k>j;j++){var l=g[j];I.ajax({url:l.url,type:E.sendType,data:f,success:function(){I.log("posted missing key '"+c+"' to: "+l.url);for(var a=c.split("."),e=0,f=B[l.lng][b];a[e];)f=f[a[e]]=e===a.length-1?d:f[a[e]]||{},e++},error:function(){I.log("failed posting missing key '"+c+"' to: "+l.url)},dataType:"json",async:E.postAsync})}}},K={rules:{ach:{name:"Acholi",numbers:[1,2],plurals:function(a){return Number(a>1)}},af:{name:"Afrikaans",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ak:{name:"Akan",numbers:[1,2],plurals:function(a){return Number(a>1)}},am:{name:"Amharic",numbers:[1,2],plurals:function(a){return Number(a>1)}},an:{name:"Aragonese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ar:{name:"Arabic",numbers:[0,1,2,3,11,100],plurals:function(a){return Number(0===a?0:1==a?1:2==a?2:a%100>=3&&10>=a%100?3:a%100>=11?4:5)}},arn:{name:"Mapudungun",numbers:[1,2],plurals:function(a){return Number(a>1)}},ast:{name:"Asturian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ay:{name:"Aymará",numbers:[1],plurals:function(){return 0}},az:{name:"Azerbaijani",numbers:[1,2],plurals:function(a){return Number(1!=a)}},be:{name:"Belarusian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},bg:{name:"Bulgarian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},bn:{name:"Bengali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},bo:{name:"Tibetan",numbers:[1],plurals:function(){return 0}},br:{name:"Breton",numbers:[1,2],plurals:function(a){return Number(a>1)}},bs:{name:"Bosnian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},ca:{name:"Catalan",numbers:[1,2],plurals:function(a){return Number(1!=a)}},cgg:{name:"Chiga",numbers:[1],plurals:function(){return 0}},cs:{name:"Czech",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)}},csb:{name:"Kashubian",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},cy:{name:"Welsh",numbers:[1,2,3,8],plurals:function(a){return Number(1==a?0:2==a?1:8!=a&&11!=a?2:3)}},da:{name:"Danish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},de:{name:"German",numbers:[1,2],plurals:function(a){return Number(1!=a)}},dz:{name:"Dzongkha",numbers:[1],plurals:function(){return 0}},el:{name:"Greek",numbers:[1,2],plurals:function(a){return Number(1!=a)}},en:{name:"English",numbers:[1,2],plurals:function(a){return Number(1!=a)}},eo:{name:"Esperanto",numbers:[1,2],plurals:function(a){return Number(1!=a)}},es:{name:"Spanish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},es_ar:{name:"Argentinean Spanish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},et:{name:"Estonian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},eu:{name:"Basque",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fa:{name:"Persian",numbers:[1],plurals:function(){return 0}},fi:{name:"Finnish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fil:{name:"Filipino",numbers:[1,2],plurals:function(a){return Number(a>1)}},fo:{name:"Faroese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fr:{name:"French",numbers:[1,2],plurals:function(a){return Number(a>1)}},fur:{name:"Friulian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fy:{name:"Frisian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ga:{name:"Irish",numbers:[1,2,3,7,11],plurals:function(a){return Number(1==a?0:2==a?1:7>a?2:11>a?3:4)}},gd:{name:"Scottish Gaelic",numbers:[1,2,3,20],plurals:function(a){return Number(1==a||11==a?0:2==a||12==a?1:a>2&&20>a?2:3)}},gl:{name:"Galician",numbers:[1,2],plurals:function(a){return Number(1!=a)}},gu:{name:"Gujarati",numbers:[1,2],plurals:function(a){return Number(1!=a)}},gun:{name:"Gun",numbers:[1,2],plurals:function(a){return Number(a>1)}},ha:{name:"Hausa",numbers:[1,2],plurals:function(a){return Number(1!=a)}},he:{name:"Hebrew",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hi:{name:"Hindi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hr:{name:"Croatian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},hu:{name:"Hungarian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hy:{name:"Armenian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ia:{name:"Interlingua",numbers:[1,2],plurals:function(a){return Number(1!=a)}},id:{name:"Indonesian",numbers:[1],plurals:function(){return 0}},is:{name:"Icelandic",numbers:[1,2],plurals:function(a){return Number(1!=a%10||11==a%100)}},it:{name:"Italian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ja:{name:"Japanese",numbers:[1],plurals:function(){return 0}},jbo:{name:"Lojban",numbers:[1],plurals:function(){return 0}},jv:{name:"Javanese",numbers:[0,1],plurals:function(a){return Number(0!==a)}},ka:{name:"Georgian",numbers:[1],plurals:function(){return 0}},kk:{name:"Kazakh",numbers:[1],plurals:function(){return 0}},km:{name:"Khmer",numbers:[1],plurals:function(){return 0}},kn:{name:"Kannada",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ko:{name:"Korean",numbers:[1],plurals:function(){return 0}},ku:{name:"Kurdish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},kw:{name:"Cornish",numbers:[1,2,3,4],plurals:function(a){return Number(1==a?0:2==a?1:3==a?2:3)}},ky:{name:"Kyrgyz",numbers:[1],plurals:function(){return 0}},lb:{name:"Letzeburgesch",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ln:{name:"Lingala",numbers:[1,2],plurals:function(a){return Number(a>1)}},lo:{name:"Lao",numbers:[1],plurals:function(){return 0}},lt:{name:"Lithuanian",numbers:[1,2,10],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&(10>a%100||a%100>=20)?1:2)}},lv:{name:"Latvian",numbers:[0,1,2],plurals:function(a){return Number(1==a%10&&11!=a%100?0:0!==a?1:2)}},mai:{name:"Maithili",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mfe:{name:"Mauritian Creole",numbers:[1,2],plurals:function(a){return Number(a>1)}},mg:{name:"Malagasy",numbers:[1,2],plurals:function(a){return Number(a>1)}},mi:{name:"Maori",numbers:[1,2],plurals:function(a){return Number(a>1)}},mk:{name:"Macedonian",numbers:[1,2],plurals:function(a){return Number(1==a||1==a%10?0:1)}},ml:{name:"Malayalam",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mn:{name:"Mongolian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mnk:{name:"Mandinka",numbers:[0,1,2],plurals:function(a){return Number(1==a?1:2)}},mr:{name:"Marathi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ms:{name:"Malay",numbers:[1],plurals:function(){return 0}},mt:{name:"Maltese",numbers:[1,2,11,20],plurals:function(a){return Number(1==a?0:0===a||a%100>1&&11>a%100?1:a%100>10&&20>a%100?2:3)}},nah:{name:"Nahuatl",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nap:{name:"Neapolitan",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nb:{name:"Norwegian Bokmal",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ne:{name:"Nepali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nl:{name:"Dutch",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nn:{name:"Norwegian Nynorsk",numbers:[1,2],plurals:function(a){return Number(1!=a)}},no:{name:"Norwegian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nso:{name:"Northern Sotho",numbers:[1,2],plurals:function(a){return Number(1!=a)}},oc:{name:"Occitan",numbers:[1,2],plurals:function(a){return Number(a>1)}},or:{name:"Oriya",numbers:[2,1],plurals:function(a){return Number(1!=a)}},pa:{name:"Punjabi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pap:{name:"Papiamento",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pl:{name:"Polish",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},pms:{name:"Piemontese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ps:{name:"Pashto",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pt:{name:"Portuguese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pt_br:{name:"Brazilian Portuguese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},rm:{name:"Romansh",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ro:{name:"Romanian",numbers:[1,2,20],plurals:function(a){return Number(1==a?0:0===a||a%100>0&&20>a%100?1:2)}},ru:{name:"Russian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},sah:{name:"Yakut",numbers:[1],plurals:function(){return 0}},sco:{name:"Scots",numbers:[1,2],plurals:function(a){return Number(1!=a)}},se:{name:"Northern Sami",numbers:[1,2],plurals:function(a){return Number(1!=a)}},si:{name:"Sinhala",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sk:{name:"Slovak",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)}},sl:{name:"Slovenian",numbers:[5,1,2,3],plurals:function(a){return Number(1==a%100?1:2==a%100?2:3==a%100||4==a%100?3:0)}},so:{name:"Somali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},son:{name:"Songhay",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sq:{name:"Albanian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sr:{name:"Serbian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},su:{name:"Sundanese",numbers:[1],plurals:function(){return 0}},sv:{name:"Swedish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sw:{name:"Swahili",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ta:{name:"Tamil",numbers:[1,2],plurals:function(a){return Number(1!=a)}},te:{name:"Telugu",numbers:[1,2],plurals:function(a){return Number(1!=a)}},tg:{name:"Tajik",numbers:[1,2],plurals:function(a){return Number(a>1)}},th:{name:"Thai",numbers:[1],plurals:function(){return 0}},ti:{name:"Tigrinya",numbers:[1,2],plurals:function(a){return Number(a>1)}},tk:{name:"Turkmen",numbers:[1,2],plurals:function(a){return Number(1!=a)}},tr:{name:"Turkish",numbers:[1,2],plurals:function(a){return Number(a>1)}},tt:{name:"Tatar",numbers:[1],plurals:function(){return 0}},ug:{name:"Uyghur",numbers:[1],plurals:function(){return 0}},uk:{name:"Ukrainian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},ur:{name:"Urdu",numbers:[1,2],plurals:function(a){return Number(1!=a)}},uz:{name:"Uzbek",numbers:[1,2],plurals:function(a){return Number(a>1)}},vi:{name:"Vietnamese",numbers:[1],plurals:function(){return 0}},wa:{name:"Walloon",numbers:[1,2],plurals:function(a){return Number(a>1)}},wo:{name:"Wolof",numbers:[1],plurals:function(){return 0}},yo:{name:"Yoruba",numbers:[1,2],plurals:function(a){return Number(1!=a)}},zh:{name:"Chinese",numbers:[1],plurals:function(){return 0}}},addRule:function(a,b){K.rules[a]=b},setCurrentLng:function(a){if(!K.currentRule||K.currentRule.lng!==a){var b=a.split("-");K.currentRule={lng:a,rule:K.rules[b[0]]}}},get:function(a,b){function c(b,c){var d;if(d=K.currentRule&&K.currentRule.lng===a?K.currentRule.rule:K.rules[b]){var e=d.plurals(c),f=d.numbers[e];return 2===d.numbers.length&&1===d.numbers[0]&&(2===f?f=-1:1===f&&(f=1)),f}return 1===c?"1":"-1"}var d=a.split("-");return c(d[0],b)}},L={},M=function(a,b){L[a]=b},N=function(){function a(a){return Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}function b(a,b){for(var c=[];b>0;c[--b]=a);return c.join("")}var c=function(){return c.cache.hasOwnProperty(arguments[0])||(c.cache[arguments[0]]=c.parse(arguments[0])),c.format.call(null,c.cache[arguments[0]],arguments)};return c.format=function(c,d){var e,f,g,h,i,j,k,l=1,m=c.length,n="",o=[];for(f=0;m>f;f++)if(n=a(c[f]),"string"===n)o.push(c[f]);else if("array"===n){if(h=c[f],h[2])for(e=d[l],g=0;g=0?"+"+e:e,j=h[4]?"0"==h[4]?"0":h[4].charAt(1):" ",k=h[6]-String(e).length,i=h[6]?b(j,k):"",o.push(h[5]?e+i:i+e)}return o.join("")},c.cache={},c.parse=function(a){for(var b=a,c=[],d=[],e=0;b;){if(null!==(c=/^[^\x25]+/.exec(b)))d.push(c[0]);else if(null!==(c=/^\x25{2}/.exec(b)))d.push("%");else{if(null===(c=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(b)))throw"[sprintf] huh?";if(c[2]){e|=1;var f=[],g=c[2],h=[];if(null===(h=/^([a-z_][a-z_\d]*)/i.exec(g)))throw"[sprintf] huh?";for(f.push(h[1]);""!==(g=g.substring(h[0].length));)if(null!==(h=/^\.([a-z_][a-z_\d]*)/i.exec(g)))f.push(h[1]);else{if(null===(h=/^\[(\d+)\]/.exec(g)))throw"[sprintf] huh?";f.push(h[1])}c[2]=f}else e|=2;if(3===e)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";d.push(c)}b=b.substring(c[0].length)}return d},c}(),O=function(a,b){return b.unshift(a),N.apply(null,b)};return M("sprintf",function(a,b,c){return c.sprintf?"[object Array]"===Object.prototype.toString.apply(c.sprintf)?O(a,c.sprintf):"object"==typeof c.sprintf?N(a,c.sprintf):a:a}),A.init=f,A.setLng=l,A.preload=g,A.addResourceBundle=h,A.loadNamespace=j,A.loadNamespaces=k,A.setDefaultNamespace=i,A.t=t,A.translate=t,A.exists=s,A.detectLanguage=I.detectLanguage,A.pluralExtensions=K,A.sync=J,A.functions=I,A.lng=m,A.addPostProcessor=M,A.options=E,a.i18n=A,a.t=A.t,A}); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd.withJQuery-1.7.1.js b/libs/i18next/release/i18next.amd.withJQuery-1.7.1.js new file mode 100644 index 00000000..11c56273 --- /dev/null +++ b/libs/i18next/release/i18next.amd.withJQuery-1.7.1.js @@ -0,0 +1,2670 @@ +// i18next, v1.7.1 +// Copyright (c)2014 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function (root, factory) { + if (typeof exports === 'object') { + + var jquery = require('jquery'); + + module.exports = factory(jquery); + + } else if (typeof define === 'function' && define.amd) { + + define(['jquery'], factory); + + } +}(this, function ($) { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + var i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = [] + , initialized = false; + + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: 'dev', + fallbackNS: [], + detectLngQS: 'setLng', + ns: 'translation', + fallbackOnNull: true, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + cookieDomain: undefined, + + postProcess: undefined, + parseMissingKey: undefined, + + shortcutFunction: 'sprintf' // or: defaultValue + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + return JSON.parse(data); + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + if (status === 200) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes,domain) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + domain = (domain)? "domain="+domain+";" : ""; + document.cookie = name+"="+value+expires+";"+domain+"path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes,domain) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : _ajax, + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + toLanguages: function(lng) { + var languages = []; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + + if (o.load !== 'unspecific') languages.push(lng); + if (o.load !== 'current') languages.push(parts[0]); + } else { + languages.push(lng); + } + + if (languages.indexOf(o.fallbackLng) === -1 && o.fallbackLng) languages.push(o.fallbackLng); + + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + delete o.fixLng; /* passed in each time */ + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + if (o.lng) { + // set cookie with lng set (as detectLanguage will set cookie on need) + if (o.useCookie) f.cookie.create(o.cookieName, o.lng, o.cookieExpirationTime, o.cookieDomain); + } else { + o.lng = o.fallbackLng; + if (o.useCookie) f.cookie.remove(o.cookieName); + } + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + var lngTranslate = translate; + if (options.fixLng) { + lngTranslate = function(key, options) { + options = options || {}; + options.lng = options.lng || lngTranslate.lng; + return translate(key, options); + }; + lngTranslate.lng = currentLng; + } + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + initialized = true; + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + initialized = true; + + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + f.extend(resStore[lng][ns], resources); + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, options, cb) { + if (typeof options === 'function') { + cb = options; + options = {}; + } + options.lng = lng; + return init(options, cb); + } + + function lng() { + return currentLng; + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } + else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key && typeof key !== 'undefined' && key !== false) key = ele.text() || ele.val(); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + f.each(replacementHash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), value); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.escape(value)); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), value); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, translated_token); + } + return translated; + } + + function hasContext(options) { + return (options.context && typeof options.context == 'string'); + } + + function needsPlural(options) { + return (options.count !== undefined && typeof options.count != 'string' && options.count !== 1); + } + + function exists(key, options) { + options = options || {}; + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + options = options || {}; + + if (!initialized) { + f.log('i18next not finished initialization. you might have called t function before loading resources finished.') + return options.defaultValue || ''; + }; + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _getDefaultValue(key, options) { + return (options.defaultValue !== undefined) ? options.defaultValue : key; + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(potentialKeys, options) { + if (typeof options == 'string') { + if (o.shortcutFunction === 'sprintf') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else if (o.shortcutFunction === 'defaultValue') { + options = { + defaultValue: options + } + } + } else { + options = options || {}; + } + + if (typeof potentialKeys == 'string') { + potentialKeys = [potentialKeys]; + } + + var key = null; + + for (var i = 0; i < potentialKeys.length; i++) { + key = potentialKeys[i]; + if (exists(key)) { + break; + } + } + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng) : languages + , ns = options.ns || o.ns.defaultNs + , parts; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing) { + if (options.lng) { + sync.postMissing(lngs[0], ns, key, notFound, lngs); + } else { + sync.postMissing(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found !== undefined && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + // process notFound if function exists + var splitNotFound = notFound; + if (notFound.indexOf(o.nsseparator) > -1) { + parts = notFound.split(o.nsseparator); + splitNotFound = parts[1]; + } + if (splitNotFound === key && o.parseMissingKey) { + notFound = o.parseMissingKey(notFound); + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessor && postProcessors[postProcessor]) { + var val = _getDefaultValue(key, options); + found = postProcessors[postProcessor](val, key, options); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options){ + options = options || {}; + + var optionWithoutCount, translated + , notFound = _getDefaultValue(key, options) + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + if (options.lng) { + lngs = f.toLanguages(options.lng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.count; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(lngs[0], options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + + translated = translate(pluralKey, optionWithoutCount); + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } // else continue translation with original/singular key + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (Object.prototype.toString.apply(value) === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned an object instead of string.'; + f.log(value); + } else if (typeof value !== 'number') { + var copy = {}; // apply child translation on a copy + f.each(value, function(m) { + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + }); + value = copy; + } + } + + if (typeof value === 'string' && value.trim() === '' && o.fallbackOnEmpty === true) + value = undefined; + + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length > 0))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + } + + return found; + } + function detectLanguage() { + var detectedLng; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var parms = query.split('&'); + for (var i=0; i 0) { + var key = parms[i].substring(0,pos); + var val = parms[i].substring(pos+1); + qsParm[key] = val; + } + } + })(); + if (qsParm[o.detectLngQS]) { + detectedLng = qsParm[o.detectLngQS]; + } + } + + // get from cookie + if (!detectedLng && typeof document !== 'undefined' && o.useCookie ) { + var c = f.cookie.read(o.cookieName); + if (c) detectedLng = c; + } + + // get from navigator + if (!detectedLng && typeof navigator !== 'undefined') { + detectedLng = (navigator.language) ? navigator.language : navigator.userLanguage; + } + + return detectedLng; + } + var sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + window.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback' && o.fallbackLng !== false) { + urls.push({lng: o.fallbackLng, url: applyReplacement(o.resPostPath, { lng: o.fallbackLng, ns: ns })}); + } else if (o.sendMissingTo === 'current' || (o.sendMissingTo === 'fallback' && o.fallbackLng === false) ) { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + } + }; + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + var pluralExtensions = { + + rules: { + "ach": { + "name": "Acholi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "af": { + "name": "Afrikaans", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ak": { + "name": "Akan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "am": { + "name": "Amharic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "an": { + "name": "Aragonese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ar": { + "name": "Arabic", + "numbers": [ + 0, + 1, + 2, + 3, + 11, + 100 + ], + "plurals": function(n) { return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5); } + }, + "arn": { + "name": "Mapudungun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ast": { + "name": "Asturian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ay": { + "name": "Aymar\u00e1", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "az": { + "name": "Azerbaijani", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "be": { + "name": "Belarusian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "bg": { + "name": "Bulgarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bn": { + "name": "Bengali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bo": { + "name": "Tibetan", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "br": { + "name": "Breton", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "bs": { + "name": "Bosnian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ca": { + "name": "Catalan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "cgg": { + "name": "Chiga", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "cs": { + "name": "Czech", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "csb": { + "name": "Kashubian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "cy": { + "name": "Welsh", + "numbers": [ + 1, + 2, + 3, + 8 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3); } + }, + "da": { + "name": "Danish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "de": { + "name": "German", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "dz": { + "name": "Dzongkha", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "el": { + "name": "Greek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "en": { + "name": "English", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eo": { + "name": "Esperanto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es": { + "name": "Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es_ar": { + "name": "Argentinean Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "et": { + "name": "Estonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eu": { + "name": "Basque", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fa": { + "name": "Persian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "fi": { + "name": "Finnish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fil": { + "name": "Filipino", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fo": { + "name": "Faroese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fr": { + "name": "French", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fur": { + "name": "Friulian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fy": { + "name": "Frisian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ga": { + "name": "Irish", + "numbers": [ + 1, + 2, + 3, + 7, + 11 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;} + }, + "gd": { + "name": "Scottish Gaelic", + "numbers": [ + 1, + 2, + 3, + 20 + ], + "plurals": function(n) { return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3); } + }, + "gl": { + "name": "Galician", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gu": { + "name": "Gujarati", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gun": { + "name": "Gun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ha": { + "name": "Hausa", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "he": { + "name": "Hebrew", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hi": { + "name": "Hindi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hr": { + "name": "Croatian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "hu": { + "name": "Hungarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hy": { + "name": "Armenian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ia": { + "name": "Interlingua", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "id": { + "name": "Indonesian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "is": { + "name": "Icelandic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n%10!=1 || n%100==11); } + }, + "it": { + "name": "Italian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ja": { + "name": "Japanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jbo": { + "name": "Lojban", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jv": { + "name": "Javanese", + "numbers": [ + 0, + 1 + ], + "plurals": function(n) { return Number(n !== 0); } + }, + "ka": { + "name": "Georgian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kk": { + "name": "Kazakh", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "km": { + "name": "Khmer", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kn": { + "name": "Kannada", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ko": { + "name": "Korean", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ku": { + "name": "Kurdish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "kw": { + "name": "Cornish", + "numbers": [ + 1, + 2, + 3, + 4 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3); } + }, + "ky": { + "name": "Kyrgyz", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lb": { + "name": "Letzeburgesch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ln": { + "name": "Lingala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "lo": { + "name": "Lao", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lt": { + "name": "Lithuanian", + "numbers": [ + 1, + 2, + 10 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "lv": { + "name": "Latvian", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2); } + }, + "mai": { + "name": "Maithili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mfe": { + "name": "Mauritian Creole", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mg": { + "name": "Malagasy", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mi": { + "name": "Maori", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mk": { + "name": "Macedonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 || n%10==1 ? 0 : 1); } + }, + "ml": { + "name": "Malayalam", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mn": { + "name": "Mongolian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mnk": { + "name": "Mandinka", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(0 ? 0 : n==1 ? 1 : 2); } + }, + "mr": { + "name": "Marathi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ms": { + "name": "Malay", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "mt": { + "name": "Maltese", + "numbers": [ + 1, + 2, + 11, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3); } + }, + "nah": { + "name": "Nahuatl", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nap": { + "name": "Neapolitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nb": { + "name": "Norwegian Bokmal", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ne": { + "name": "Nepali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nl": { + "name": "Dutch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nn": { + "name": "Norwegian Nynorsk", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "no": { + "name": "Norwegian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nso": { + "name": "Northern Sotho", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "oc": { + "name": "Occitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "or": { + "name": "Oriya", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pa": { + "name": "Punjabi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pap": { + "name": "Papiamento", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pl": { + "name": "Polish", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "pms": { + "name": "Piemontese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ps": { + "name": "Pashto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt": { + "name": "Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt_br": { + "name": "Brazilian Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "rm": { + "name": "Romansh", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ro": { + "name": "Romanian", + "numbers": [ + 1, + 2, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2); } + }, + "ru": { + "name": "Russian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "sah": { + "name": "Yakut", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sco": { + "name": "Scots", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "se": { + "name": "Northern Sami", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "si": { + "name": "Sinhala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sk": { + "name": "Slovak", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "sl": { + "name": "Slovenian", + "numbers": [ + 5, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }, + "so": { + "name": "Somali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "son": { + "name": "Songhay", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sq": { + "name": "Albanian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sr": { + "name": "Serbian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "su": { + "name": "Sundanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sv": { + "name": "Swedish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sw": { + "name": "Swahili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ta": { + "name": "Tamil", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "te": { + "name": "Telugu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tg": { + "name": "Tajik", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "th": { + "name": "Thai", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ti": { + "name": "Tigrinya", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tk": { + "name": "Turkmen", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tr": { + "name": "Turkish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tt": { + "name": "Tatar", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ug": { + "name": "Uyghur", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "uk": { + "name": "Ukrainian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ur": { + "name": "Urdu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "uz": { + "name": "Uzbek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "vi": { + "name": "Vietnamese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "wa": { + "name": "Walloon", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "wo": { + "name": "Wolof", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "yo": { + "name": "Yoruba", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "zh": { + "name": "Chinese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + } + }, + + // for demonstration only sl and ar is added but you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i = ext.plurals(c); + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[0], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + + $.i18n = i18n; + $.t = i18n.t; + + return i18n; + +})); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd.withJQuery-1.7.1.min.js b/libs/i18next/release/i18next.amd.withJQuery-1.7.1.min.js new file mode 100644 index 00000000..9839c0c9 --- /dev/null +++ b/libs/i18next/release/i18next.amd.withJQuery-1.7.1.min.js @@ -0,0 +1,5 @@ +// i18next, v1.7.1 +// Copyright (c)2014 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +!function(a,b){if("object"==typeof exports){var c=require("jquery");module.exports=b(c)}else"function"==typeof define&&define.amd&&define(["jquery"],b)}(this,function(a){function b(a,b){if(!b||"function"==typeof b)return a;for(var c in b)a[c]=b[c];return a}function c(a,b,c){var d,e=0,f=a.length,g=void 0===f||"function"==typeof a;if(c)if(g){for(d in a)if(b.apply(a[d],c)===!1)break}else for(;f>e&&b.apply(a[e++],c)!==!1;);else if(g){for(d in a)if(b.call(a[d],d,a[d])===!1)break}else for(;f>e&&b.call(a[e],e,a[e++])!==!1;);return a}function d(a){return"string"==typeof a?a.replace(/[&<>"'\/]/g,function(a){return G[a]}):a}function e(a){var b=function(a){if(window.XMLHttpRequest)return a(null,new XMLHttpRequest);if(window.ActiveXObject)try{return a(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(b){return a(null,new ActiveXObject("Microsoft.XMLHTTP"))}return a(new Error)},c=function(a){if("string"==typeof a)return a;var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")},d=function(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;cd?b+=String.fromCharCode(d):d>127&&2048>d?(b+=String.fromCharCode(d>>6|192),b+=String.fromCharCode(63&d|128)):(b+=String.fromCharCode(d>>12|224),b+=String.fromCharCode(d>>6&63|128),b+=String.fromCharCode(63&d|128))}return b},e=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";a=d(a);var c,e,f,g,h,i,j,k="",l=0;do c=a.charCodeAt(l++),e=a.charCodeAt(l++),f=a.charCodeAt(l++),g=c>>2,h=(3&c)<<4|e>>4,i=(15&e)<<2|f>>6,j=63&f,isNaN(e)?i=j=64:isNaN(f)&&(j=64),k+=b.charAt(g)+b.charAt(h)+b.charAt(i)+b.charAt(j),c=e=f="",g=h=i=j="";while(l1&&(d+=d.indexOf("?")>-1?"&"+k:"?"+k),e.jsonp){var l=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=d,void l.appendChild(m)}}b(function(b,c){if(b)return h(b);c.open(a,d,e.async);for(var f in j)j.hasOwnProperty(f)&&c.setRequestHeader(f,j[f]);c.onreadystatechange=function(){if(4===c.readyState){var a=c.responseText||"";if(!h)return;h(c.status,{text:function(){return a},json:function(){return JSON.parse(a)}})}},c.send(i)})},h={authBasic:function(a,b){g.headers.Authorization="Basic "+e(a+":"+b)},connect:function(a,b,c){return g("CONNECT",a,b,c)},del:function(a,b,c){return g("DELETE",a,b,c)},get:function(a,b,c){return g("GET",a,b,c)},head:function(a,b,c){return g("HEAD",a,b,c)},headers:function(a){g.headers=a||{}},isAllowed:function(a,b,c){this.options(a,function(a,d){c(-1!==d.text().indexOf(b))})},options:function(a,b,c){return g("OPTIONS",a,b,c)},patch:function(a,b,c){return g("PATCH",a,b,c)},post:function(a,b,c){return g("POST",a,b,c)},put:function(a,b,c){return g("PUT",a,b,c)},trace:function(a,b,c){return g("TRACE",a,b,c)}},i=a.type?a.type.toLowerCase():"get";h[i](a.url,a,function(b,c){200===b?a.success(c.json(),b,null):a.error(c.text(),b,null)})}function f(b,c){"function"==typeof b&&(c=b,b={}),b=b||{},J.extend(F,b),delete F.fixLng,"string"==typeof F.ns&&(F.ns={namespaces:[F.ns],defaultNs:F.ns}),"string"==typeof F.fallbackNS&&(F.fallbackNS=[F.fallbackNS]),F.interpolationPrefixEscaped=J.regexEscape(F.interpolationPrefix),F.interpolationSuffixEscaped=J.regexEscape(F.interpolationSuffix),F.lng||(F.lng=J.detectLanguage()),F.lng?F.useCookie&&J.cookie.create(F.cookieName,F.lng,F.cookieExpirationTime,F.cookieDomain):(F.lng=F.fallbackLng,F.useCookie&&J.cookie.remove(F.cookieName)),D=J.toLanguages(F.lng),z=D[0],J.log("currentLng set to: "+z);var d=t;b.fixLng&&(d=function(a,b){return b=b||{},b.lng=b.lng||d.lng,t(a,b)},d.lng=z),L.setCurrentLng(z),a&&F.setJqueryExt&&n();var e;if(a&&a.Deferred&&(e=a.Deferred()),!F.resStore){var f=J.toLanguages(F.lng);"string"==typeof F.preload&&(F.preload=[F.preload]);for(var g=0,h=F.preload.length;h>g;g++)for(var i=J.toLanguages(F.preload[g]),j=0,k=i.length;k>j;j++)f.indexOf(i[j])<0&&f.push(i[j]);return A.sync.load(f,F,function(a,b){B=b,E=!0,c&&c(d),e&&e.resolve(d)}),e?e.promise():void 0}return B=F.resStore,E=!0,c&&c(d),e&&e.resolve(d),e?e.promise():void 0}function g(a,b){"string"==typeof a&&(a=[a]);for(var c=0,d=a.length;d>c;c++)F.preload.indexOf(a[c])<0&&F.preload.push(a[c]);return f(b)}function h(a,b,c){"string"!=typeof b?(c=b,b=F.ns.defaultNs):F.ns.namespaces.indexOf(b)<0&&F.ns.namespaces.push(b),B[a]=B[a]||{},B[a][b]=B[a][b]||{},J.extend(B[a][b],c)}function i(a){F.ns.defaultNs=a}function j(a,b){k([a],b)}function k(a,b){var c={dynamicLoad:F.dynamicLoad,resGetPath:F.resGetPath,getAsync:F.getAsync,customLoad:F.customLoad,ns:{namespaces:a,defaultNs:""}},d=J.toLanguages(F.lng);"string"==typeof F.preload&&(F.preload=[F.preload]);for(var e=0,f=F.preload.length;f>e;e++)for(var g=J.toLanguages(F.preload[e]),h=0,i=g.length;i>h;h++)d.indexOf(g[h])<0&&d.push(g[h]);for(var j=[],k=0,l=d.length;l>k;k++){var m=!1,n=B[d[k]];if(n)for(var o=0,p=a.length;p>o;o++)n[a[o]]||(m=!0);else m=!0;m&&j.push(d[k])}j.length?A.sync._fetch(j,c,function(c,d){var e=a.length*j.length;J.each(a,function(a,c){F.ns.namespaces.indexOf(c)<0&&F.ns.namespaces.push(c),J.each(j,function(a,f){B[f]=B[f]||{},B[f][c]=d[f][c],e--,0===e&&b&&(F.useLocalStorage&&A.sync._storeLocal(B),b())})})}):b&&b()}function l(a,b,c){return"function"==typeof b&&(c=b,b={}),b.lng=a,f(b,c)}function m(){return z}function n(){function b(b,c,d){if(0!==c.length){var e="text";if(0===c.indexOf("[")){var f=c.split("]");c=f[1],e=f[0].substr(1,f[0].length-1)}c.indexOf(";")===c.length-1&&(c=c.substr(0,c.length-2));var g;"html"===e?(g=F.defaultValueFromContent?a.extend({defaultValue:b.html()},d):d,b.html(a.t(c,g))):"text"===e?(g=F.defaultValueFromContent?a.extend({defaultValue:b.text()},d):d,b.text(a.t(c,g))):(g=F.defaultValueFromContent?a.extend({defaultValue:b.attr(e)},d):d,b.attr(e,a.t(c,g)))}}function c(c,d){var e=c.attr(F.selectorAttr);if(e||"undefined"==typeof e||e===!1||(e=c.text()||c.val()),e){var f=c,g=c.data("i18n-target");if(g&&(f=c.find(g)||c),d||F.useDataAttrOptions!==!0||(d=c.data("i18n-options")),d=d||{},e.indexOf(";")>=0){var h=e.split(";");a.each(h,function(a,c){""!==c&&b(f,c,d)})}else b(f,e,d);F.useDataAttrOptions===!0&&c.data("i18n-options",d)}}a.t=a.t||t,a.fn.i18n=function(b){return this.each(function(){c(a(this),b);var d=a(this).find("["+F.selectorAttr+"]");d.each(function(){c(a(this),b)})})}}function o(a,b,c,d){if(!a)return a;if(d=d||b,a.indexOf(d.interpolationPrefix||F.interpolationPrefix)<0)return a;var e=d.interpolationPrefix?J.regexEscape(d.interpolationPrefix):F.interpolationPrefixEscaped,f=d.interpolationSuffix?J.regexEscape(d.interpolationSuffix):F.interpolationSuffixEscaped,g="HTML"+f;return J.each(b,function(b,h){var i=c?c+F.keyseparator+b:b;"object"==typeof h&&null!==h?a=o(a,h,i,d):d.escapeInterpolation||F.escapeInterpolation?(a=a.replace(new RegExp([e,i,g].join(""),"g"),h),a=a.replace(new RegExp([e,i,f].join(""),"g"),J.escape(h))):a=a.replace(new RegExp([e,i,f].join(""),"g"),h)}),a}function p(a,b){var c=",",d="{",e="}",f=J.extend({},b);for(delete f.postProcess;-1!=a.indexOf(F.reusePrefix)&&(C++,!(C>F.maxRecursion));){var g=a.lastIndexOf(F.reusePrefix),h=a.indexOf(F.reuseSuffix,g)+F.reuseSuffix.length,i=a.substring(g,h),j=i.replace(F.reusePrefix,"").replace(F.reuseSuffix,"");if(-1!=j.indexOf(c)){var k=j.indexOf(c);if(-1!=j.indexOf(d,k)&&-1!=j.indexOf(e,k)){var l=j.indexOf(d,k),m=j.indexOf(e,l)+e.length;try{f=J.extend(f,JSON.parse(j.substring(l,m))),j=j.substring(0,k)}catch(n){}}}var o=w(j,f);a=a.replace(i,o)}return a}function q(a){return a.context&&"string"==typeof a.context}function r(a){return void 0!==a.count&&"string"!=typeof a.count&&1!==a.count}function s(a,b){b=b||{};var c=u(a,b),d=x(a,b);return void 0!==d||d===c}function t(a,b){return b=b||{},E?(C=0,w.apply(null,arguments)):(J.log("i18next not finished initialization. you might have called t function before loading resources finished."),b.defaultValue||"")}function u(a,b){return void 0!==b.defaultValue?b.defaultValue:a}function v(){for(var a=[],b=1;b-1&&(e=c.split(F.nsseparator),i=e[0],c=e[1]),void 0===g&&F.sendMissing&&(b.lng?K.postMissing(h[0],i,c,f,h):K.postMissing(F.lng,i,c,f,h));var j=b.postProcess||F.postProcess;void 0!==g&&j&&M[j]&&(g=M[j](g,c,b));var k=f;if(f.indexOf(F.nsseparator)>-1&&(e=f.split(F.nsseparator),k=e[1]),k===c&&F.parseMissingKey&&(f=F.parseMissingKey(f)),void 0===g&&(f=o(f,b),f=p(f,b),j&&M[j])){var l=u(c,b);g=M[j](l,c,b)}return void 0!==g?g:f}function x(a,b){b=b||{};var c,d,e=u(a,b),f=D;if(!B)return e;if(b.lng&&(f=J.toLanguages(b.lng),!B[f[0]])){var g=F.getAsync;F.getAsync=!1,A.sync.load(f,F,function(a,b){J.extend(B,b),F.getAsync=g})}var h=b.ns||F.ns.defaultNs;if(a.indexOf(F.nsseparator)>-1){var i=a.split(F.nsseparator);h=i[0],a=i[1]}if(q(b)){c=J.extend({},b),delete c.context,c.defaultValue=F.contextNotFound;var j=h+F.nsseparator+a+"_"+b.context;if(d=t(j,c),d!=F.contextNotFound)return o(d,{context:b.context})}if(r(b)){c=J.extend({},b),delete c.count,c.defaultValue=F.pluralNotFound;var k=h+F.nsseparator+a+F.pluralSuffix,l=L.get(f[0],b.count);if(l>=0?k=k+"_"+l:1===l&&(k=h+F.nsseparator+a),d=t(k,c),d!=F.pluralNotFound)return o(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix})}for(var m,n=a.split(F.keyseparator),s=0,v=f.length;v>s&&void 0===m;s++){for(var y=f[s],z=0,C=B[y]&&B[y][h];n[z];)C=C&&C[n[z]],z++;if(void 0!==C){if("string"==typeof C)C=o(C,b),C=p(C,b);else if("[object Array]"!==Object.prototype.toString.apply(C)||F.returnObjectTrees||b.returnObjectTrees){if(null===C&&F.fallbackOnNull===!0)C=void 0;else if(null!==C)if(F.returnObjectTrees||b.returnObjectTrees){if("number"!=typeof C){var E={};J.each(C,function(c){E[c]=w(h+F.nsseparator+a+F.keyseparator+c,b)}),C=E}}else C="key '"+h+":"+a+" ("+y+")' returned an object instead of string.",J.log(C)}else C=C.join("\n"),C=o(C,b),C=p(C,b);"string"==typeof C&&""===C.trim()&&F.fallbackOnEmpty===!0&&(C=void 0),m=C}}if(void 0===m&&!b.isFallbackLookup&&(F.fallbackToDefaultNS===!0||F.fallbackNS&&F.fallbackNS.length>0))if(b.isFallbackLookup=!0,F.fallbackNS.length){for(var G=0,H=F.fallbackNS.length;H>G;G++)if(m=x(F.fallbackNS[G]+F.nsseparator+a,b)){var I=m.indexOf(F.nsseparator)>-1?m.split(F.nsseparator)[1]:m,K=e.indexOf(F.nsseparator)>-1?e.split(F.nsseparator)[1]:e;if(I!==K)break}}else m=x(a,b);return m}function y(){var a,b=[];if("undefined"!=typeof window&&(!function(){for(var a=window.location.search.substring(1),c=a.split("&"),d=0;d0){var f=c[d].substring(0,e),g=c[d].substring(e+1);b[f]=g}}}(),b[F.detectLngQS]&&(a=b[F.detectLngQS])),!a&&"undefined"!=typeof document&&F.useCookie){var c=J.cookie.read(F.cookieName);c&&(a=c)}return a||"undefined"==typeof navigator||(a=navigator.language?navigator.language:navigator.userLanguage),a}Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>0&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&1/0!=d&&d!=-1/0&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=c;arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d))));for(var e=d>=0?Math.min(d,c-1):c-Math.abs(d);e>=0;e--)if(e in b&&b[e]===a)return e;return-1});var z,A={},B={},C=0,D=[],E=!1,F={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:"dev",fallbackNS:[],detectLngQS:"setLng",ns:"translation",fallbackOnNull:!0,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",cookieDomain:void 0,postProcess:void 0,parseMissingKey:void 0,shortcutFunction:"sprintf"},G={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},H={create:function(a,b,c,d){var e;if(c){var f=new Date;f.setTime(f.getTime()+60*c*1e3),e="; expires="+f.toGMTString()}else e="";d=d?"domain="+d+";":"",document.cookie=a+"="+b+e+";"+d+"path=/"},read:function(a){for(var b=a+"=",c=document.cookie.split(";"),d=0;d-1){var c=a.split("-");a=F.lowerCaseLng?c[0].toLowerCase()+"-"+c[1].toLowerCase():c[0].toLowerCase()+"-"+c[1].toUpperCase(),"unspecific"!==F.load&&b.push(a),"current"!==F.load&&b.push(c[0])}else b.push(a);return-1===b.indexOf(F.fallbackLng)&&F.fallbackLng&&b.push(F.fallbackLng),b},regexEscape:function(a){return a.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}};J.applyReplacement=o;var K={load:function(a,b,c){b.useLocalStorage?K._loadLocal(a,b,function(d,e){for(var f=[],g=0,h=a.length;h>g;g++)e[a[g]]||f.push(a[g]);f.length>0?K._fetch(f,b,function(a,b){J.extend(e,b),K._storeLocal(b),c(null,e)}):c(null,e)}):K._fetch(a,b,function(a,b){c(null,b)})},_loadLocal:function(a,b,c){var d={},e=(new Date).getTime();if(window.localStorage){var f=a.length;J.each(a,function(a,g){var h=window.localStorage.getItem("res_"+g);h&&(h=JSON.parse(h),h.i18nStamp&&h.i18nStamp+b.localStorageExpirationTime>e&&(d[g]=h)),f--,0===f&&c(null,d)})}},_storeLocal:function(a){if(window.localStorage)for(var b in a)a[b].i18nStamp=(new Date).getTime(),window.localStorage.setItem("res_"+b,JSON.stringify(a[b]))},_fetch:function(a,b,c){var d=b.ns,e={};if(b.dynamicLoad){var f=function(a,b){c(null,b)};if("function"==typeof b.customLoad)b.customLoad(a,d.namespaces,b,f);else{var g=o(b.resGetPath,{lng:a.join("+"),ns:d.namespaces.join("+")});J.ajax({url:g,success:function(a){J.log("loaded: "+g),f(null,a)},error:function(a,b,c){J.log("failed loading: "+g),f("failed loading resource.json error: "+c)},dataType:"json",async:b.getAsync})}}else{var h,i=d.namespaces.length*a.length;J.each(d.namespaces,function(d,f){J.each(a,function(a,d){var g=function(a,b){a&&(h=h||[],h.push(a)),e[d]=e[d]||{},e[d][f]=b,i--,0===i&&c(h,e)};"function"==typeof b.customLoad?b.customLoad(d,f,b,g):K._fetchOne(d,f,b,g)})})}},_fetchOne:function(a,b,c,d){var e=o(c.resGetPath,{lng:a,ns:b});J.ajax({url:e,success:function(a){J.log("loaded: "+e),d(null,a)},error:function(a,b,c){J.log("failed loading: "+e),d(c,{})},dataType:"json",async:c.getAsync})},postMissing:function(a,b,c,d,e){var f={};f[c]=d;var g=[];if("fallback"===F.sendMissingTo&&F.fallbackLng!==!1)g.push({lng:F.fallbackLng,url:o(F.resPostPath,{lng:F.fallbackLng,ns:b})});else if("current"===F.sendMissingTo||"fallback"===F.sendMissingTo&&F.fallbackLng===!1)g.push({lng:a,url:o(F.resPostPath,{lng:a,ns:b})});else if("all"===F.sendMissingTo)for(var h=0,i=e.length;i>h;h++)g.push({lng:e[h],url:o(F.resPostPath,{lng:e[h],ns:b})});for(var j=0,k=g.length;k>j;j++){var l=g[j];J.ajax({url:l.url,type:F.sendType,data:f,success:function(){J.log("posted missing key '"+c+"' to: "+l.url);for(var a=c.split("."),e=0,f=B[l.lng][b];a[e];)f=f[a[e]]=e===a.length-1?d:f[a[e]]||{},e++},error:function(){J.log("failed posting missing key '"+c+"' to: "+l.url)},dataType:"json",async:F.postAsync})}}},L={rules:{ach:{name:"Acholi",numbers:[1,2],plurals:function(a){return Number(a>1)}},af:{name:"Afrikaans",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ak:{name:"Akan",numbers:[1,2],plurals:function(a){return Number(a>1)}},am:{name:"Amharic",numbers:[1,2],plurals:function(a){return Number(a>1)}},an:{name:"Aragonese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ar:{name:"Arabic",numbers:[0,1,2,3,11,100],plurals:function(a){return Number(0===a?0:1==a?1:2==a?2:a%100>=3&&10>=a%100?3:a%100>=11?4:5)}},arn:{name:"Mapudungun",numbers:[1,2],plurals:function(a){return Number(a>1)}},ast:{name:"Asturian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ay:{name:"Aymará",numbers:[1],plurals:function(){return 0}},az:{name:"Azerbaijani",numbers:[1,2],plurals:function(a){return Number(1!=a)}},be:{name:"Belarusian",numbers:[1,2,5],plurals:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},bg:{name:"Bulgarian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},bn:{name:"Bengali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},bo:{name:"Tibetan",numbers:[1],plurals:function(){return 0}},br:{name:"Breton",numbers:[1,2],plurals:function(a){return Number(a>1)}},bs:{name:"Bosnian",numbers:[1,2,5],plurals:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},ca:{name:"Catalan",numbers:[1,2],plurals:function(a){return Number(1!=a)}},cgg:{name:"Chiga",numbers:[1],plurals:function(){return 0}},cs:{name:"Czech",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)}},csb:{name:"Kashubian",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},cy:{name:"Welsh",numbers:[1,2,3,8],plurals:function(a){return Number(1==a?0:2==a?1:8!=a&&11!=a?2:3)}},da:{name:"Danish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},de:{name:"German",numbers:[1,2],plurals:function(a){return Number(1!=a)}},dz:{name:"Dzongkha",numbers:[1],plurals:function(){return 0}},el:{name:"Greek",numbers:[1,2],plurals:function(a){return Number(1!=a)}},en:{name:"English",numbers:[1,2],plurals:function(a){return Number(1!=a)}},eo:{name:"Esperanto",numbers:[1,2],plurals:function(a){return Number(1!=a)}},es:{name:"Spanish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},es_ar:{name:"Argentinean Spanish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},et:{name:"Estonian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},eu:{name:"Basque",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fa:{name:"Persian",numbers:[1],plurals:function(){return 0}},fi:{name:"Finnish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fil:{name:"Filipino",numbers:[1,2],plurals:function(a){return Number(a>1)}},fo:{name:"Faroese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fr:{name:"French",numbers:[1,2],plurals:function(a){return Number(a>1)}},fur:{name:"Friulian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fy:{name:"Frisian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ga:{name:"Irish",numbers:[1,2,3,7,11],plurals:function(a){return Number(1==a?0:2==a?1:7>a?2:11>a?3:4)}},gd:{name:"Scottish Gaelic",numbers:[1,2,3,20],plurals:function(a){return Number(1==a||11==a?0:2==a||12==a?1:a>2&&20>a?2:3)}},gl:{name:"Galician",numbers:[1,2],plurals:function(a){return Number(1!=a)}},gu:{name:"Gujarati",numbers:[1,2],plurals:function(a){return Number(1!=a)}},gun:{name:"Gun",numbers:[1,2],plurals:function(a){return Number(a>1)}},ha:{name:"Hausa",numbers:[1,2],plurals:function(a){return Number(1!=a)}},he:{name:"Hebrew",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hi:{name:"Hindi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hr:{name:"Croatian",numbers:[1,2,5],plurals:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},hu:{name:"Hungarian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hy:{name:"Armenian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ia:{name:"Interlingua",numbers:[1,2],plurals:function(a){return Number(1!=a)}},id:{name:"Indonesian",numbers:[1],plurals:function(){return 0}},is:{name:"Icelandic",numbers:[1,2],plurals:function(a){return Number(a%10!=1||a%100==11)}},it:{name:"Italian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ja:{name:"Japanese",numbers:[1],plurals:function(){return 0}},jbo:{name:"Lojban",numbers:[1],plurals:function(){return 0}},jv:{name:"Javanese",numbers:[0,1],plurals:function(a){return Number(0!==a)}},ka:{name:"Georgian",numbers:[1],plurals:function(){return 0}},kk:{name:"Kazakh",numbers:[1],plurals:function(){return 0}},km:{name:"Khmer",numbers:[1],plurals:function(){return 0}},kn:{name:"Kannada",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ko:{name:"Korean",numbers:[1],plurals:function(){return 0}},ku:{name:"Kurdish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},kw:{name:"Cornish",numbers:[1,2,3,4],plurals:function(a){return Number(1==a?0:2==a?1:3==a?2:3)}},ky:{name:"Kyrgyz",numbers:[1],plurals:function(){return 0}},lb:{name:"Letzeburgesch",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ln:{name:"Lingala",numbers:[1,2],plurals:function(a){return Number(a>1)}},lo:{name:"Lao",numbers:[1],plurals:function(){return 0}},lt:{name:"Lithuanian",numbers:[1,2,10],plurals:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&(10>a%100||a%100>=20)?1:2)}},lv:{name:"Latvian",numbers:[0,1,2],plurals:function(a){return Number(a%10==1&&a%100!=11?0:0!==a?1:2)}},mai:{name:"Maithili",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mfe:{name:"Mauritian Creole",numbers:[1,2],plurals:function(a){return Number(a>1)}},mg:{name:"Malagasy",numbers:[1,2],plurals:function(a){return Number(a>1)}},mi:{name:"Maori",numbers:[1,2],plurals:function(a){return Number(a>1)}},mk:{name:"Macedonian",numbers:[1,2],plurals:function(a){return Number(1==a||a%10==1?0:1)}},ml:{name:"Malayalam",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mn:{name:"Mongolian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mnk:{name:"Mandinka",numbers:[0,1,2],plurals:function(a){return Number(1==a?1:2)}},mr:{name:"Marathi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ms:{name:"Malay",numbers:[1],plurals:function(){return 0}},mt:{name:"Maltese",numbers:[1,2,11,20],plurals:function(a){return Number(1==a?0:0===a||a%100>1&&11>a%100?1:a%100>10&&20>a%100?2:3)}},nah:{name:"Nahuatl",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nap:{name:"Neapolitan",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nb:{name:"Norwegian Bokmal",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ne:{name:"Nepali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nl:{name:"Dutch",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nn:{name:"Norwegian Nynorsk",numbers:[1,2],plurals:function(a){return Number(1!=a)}},no:{name:"Norwegian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nso:{name:"Northern Sotho",numbers:[1,2],plurals:function(a){return Number(1!=a)}},oc:{name:"Occitan",numbers:[1,2],plurals:function(a){return Number(a>1)}},or:{name:"Oriya",numbers:[2,1],plurals:function(a){return Number(1!=a)}},pa:{name:"Punjabi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pap:{name:"Papiamento",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pl:{name:"Polish",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},pms:{name:"Piemontese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ps:{name:"Pashto",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pt:{name:"Portuguese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pt_br:{name:"Brazilian Portuguese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},rm:{name:"Romansh",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ro:{name:"Romanian",numbers:[1,2,20],plurals:function(a){return Number(1==a?0:0===a||a%100>0&&20>a%100?1:2)}},ru:{name:"Russian",numbers:[1,2,5],plurals:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},sah:{name:"Yakut",numbers:[1],plurals:function(){return 0}},sco:{name:"Scots",numbers:[1,2],plurals:function(a){return Number(1!=a)}},se:{name:"Northern Sami",numbers:[1,2],plurals:function(a){return Number(1!=a)}},si:{name:"Sinhala",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sk:{name:"Slovak",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)}},sl:{name:"Slovenian",numbers:[5,1,2,3],plurals:function(a){return Number(a%100==1?1:a%100==2?2:a%100==3||a%100==4?3:0)}},so:{name:"Somali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},son:{name:"Songhay",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sq:{name:"Albanian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sr:{name:"Serbian",numbers:[1,2,5],plurals:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},su:{name:"Sundanese",numbers:[1],plurals:function(){return 0}},sv:{name:"Swedish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sw:{name:"Swahili",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ta:{name:"Tamil",numbers:[1,2],plurals:function(a){return Number(1!=a)}},te:{name:"Telugu",numbers:[1,2],plurals:function(a){return Number(1!=a)}},tg:{name:"Tajik",numbers:[1,2],plurals:function(a){return Number(a>1)}},th:{name:"Thai",numbers:[1],plurals:function(){return 0}},ti:{name:"Tigrinya",numbers:[1,2],plurals:function(a){return Number(a>1)}},tk:{name:"Turkmen",numbers:[1,2],plurals:function(a){return Number(1!=a)}},tr:{name:"Turkish",numbers:[1,2],plurals:function(a){return Number(a>1)}},tt:{name:"Tatar",numbers:[1],plurals:function(){return 0}},ug:{name:"Uyghur",numbers:[1],plurals:function(){return 0}},uk:{name:"Ukrainian",numbers:[1,2,5],plurals:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},ur:{name:"Urdu",numbers:[1,2],plurals:function(a){return Number(1!=a)}},uz:{name:"Uzbek",numbers:[1,2],plurals:function(a){return Number(a>1)}},vi:{name:"Vietnamese",numbers:[1],plurals:function(){return 0}},wa:{name:"Walloon",numbers:[1,2],plurals:function(a){return Number(a>1)}},wo:{name:"Wolof",numbers:[1],plurals:function(){return 0}},yo:{name:"Yoruba",numbers:[1,2],plurals:function(a){return Number(1!=a)}},zh:{name:"Chinese",numbers:[1],plurals:function(){return 0}}},addRule:function(a,b){L.rules[a]=b},setCurrentLng:function(a){if(!L.currentRule||L.currentRule.lng!==a){var b=a.split("-");L.currentRule={lng:a,rule:L.rules[b[0]]}}},get:function(a,b){function c(b,c){var d;if(d=L.currentRule&&L.currentRule.lng===a?L.currentRule.rule:L.rules[b]){var e=d.plurals(c),f=d.numbers[e];return 2===d.numbers.length&&1===d.numbers[0]&&(2===f?f=-1:1===f&&(f=1)),f}return 1===c?"1":"-1"}var d=a.split("-");return c(d[0],b)}},M={},N=function(a,b){M[a]=b},O=function(){function a(a){return Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}function b(a,b){for(var c=[];b>0;c[--b]=a);return c.join("")}var c=function(){return c.cache.hasOwnProperty(arguments[0])||(c.cache[arguments[0]]=c.parse(arguments[0])),c.format.call(null,c.cache[arguments[0]],arguments)};return c.format=function(c,d){var e,f,g,h,i,j,k,l=1,m=c.length,n="",o=[];for(f=0;m>f;f++)if(n=a(c[f]),"string"===n)o.push(c[f]);else if("array"===n){if(h=c[f],h[2])for(e=d[l],g=0;g=0?"+"+e:e,j=h[4]?"0"==h[4]?"0":h[4].charAt(1):" ",k=h[6]-String(e).length,i=h[6]?b(j,k):"",o.push(h[5]?e+i:i+e)}return o.join("")},c.cache={},c.parse=function(a){for(var b=a,c=[],d=[],e=0;b;){if(null!==(c=/^[^\x25]+/.exec(b)))d.push(c[0]);else if(null!==(c=/^\x25{2}/.exec(b)))d.push("%");else{if(null===(c=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(b)))throw"[sprintf] huh?";if(c[2]){e|=1;var f=[],g=c[2],h=[];if(null===(h=/^([a-z_][a-z_\d]*)/i.exec(g)))throw"[sprintf] huh?";for(f.push(h[1]);""!==(g=g.substring(h[0].length));)if(null!==(h=/^\.([a-z_][a-z_\d]*)/i.exec(g)))f.push(h[1]);else{if(null===(h=/^\[(\d+)\]/.exec(g)))throw"[sprintf] huh?";f.push(h[1])}c[2]=f}else e|=2;if(3===e)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";d.push(c)}b=b.substring(c[0].length)}return d},c}(),P=function(a,b){return b.unshift(a),O.apply(null,b)};return N("sprintf",function(a,b,c){return c.sprintf?"[object Array]"===Object.prototype.toString.apply(c.sprintf)?P(a,c.sprintf):"object"==typeof c.sprintf?O(a,c.sprintf):a:a}),A.init=f,A.setLng=l,A.preload=g,A.addResourceBundle=h,A.loadNamespace=j,A.loadNamespaces=k,A.setDefaultNamespace=i,A.t=t,A.translate=t,A.exists=s,A.detectLanguage=J.detectLanguage,A.pluralExtensions=L,A.sync=K,A.functions=J,A.lng=m,A.addPostProcessor=N,A.options=F,a.i18n=A,a.t=A.t,A}); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd.withJQuery-1.7.2.js b/libs/i18next/release/i18next.amd.withJQuery-1.7.2.js new file mode 100644 index 00000000..c6b9a272 --- /dev/null +++ b/libs/i18next/release/i18next.amd.withJQuery-1.7.2.js @@ -0,0 +1,2707 @@ +// i18next, v1.7.2 +// Copyright (c)2014 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function (root, factory) { + if (typeof exports === 'object') { + + var jquery = require('jquery'); + + module.exports = factory(jquery); + + } else if (typeof define === 'function' && define.amd) { + + define(['jquery'], factory); + + } +}(this, function ($) { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + var i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = [] + , initialized = false; + + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: 'dev', + fallbackNS: [], + detectLngQS: 'setLng', + ns: 'translation', + fallbackOnNull: true, + fallbackOnEmpty: false, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + cookieDomain: undefined, + + objectTreeKeyHandler: undefined, + postProcess: undefined, + parseMissingKey: undefined, + + shortcutFunction: 'sprintf' // or: defaultValue + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + return JSON.parse(data); + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + if (status === 200) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes,domain) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + domain = (domain)? "domain="+domain+";" : ""; + document.cookie = name+"="+value+expires+";"+domain+"path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes,domain) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : (typeof document !== 'undefined' ? _ajax : function() {}), + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + toLanguages: function(lng) { + var languages = []; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + + if (o.load !== 'unspecific') languages.push(lng); + if (o.load !== 'current') languages.push(parts[0]); + } else { + languages.push(lng); + } + + if (languages.indexOf(o.fallbackLng) === -1 && o.fallbackLng) languages.push(o.fallbackLng); + + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + delete o.fixLng; /* passed in each time */ + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + if (o.lng) { + // set cookie with lng set (as detectLanguage will set cookie on need) + if (o.useCookie) f.cookie.create(o.cookieName, o.lng, o.cookieExpirationTime, o.cookieDomain); + } else { + o.lng = o.fallbackLng; + if (o.useCookie) f.cookie.remove(o.cookieName); + } + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + var lngTranslate = translate; + if (options.fixLng) { + lngTranslate = function(key, options) { + options = options || {}; + options.lng = options.lng || lngTranslate.lng; + return translate(key, options); + }; + lngTranslate.lng = currentLng; + } + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + initialized = true; + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + initialized = true; + + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + f.extend(resStore[lng][ns], resources); + } + + function removeResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = {}; + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, options, cb) { + if (typeof options === 'function') { + cb = options; + options = {}; + } else if (!options) { + options = {}; + } + + options.lng = lng; + return init(options, cb); + } + + function lng() { + return currentLng; + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else if (attr === 'prepend') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.prepend($.t(key, optionsToUse)); + } else if (attr === 'append') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.append($.t(key, optionsToUse)); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key && typeof key !== 'undefined' && key !== false) key = ele.text() || ele.val(); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + f.each(replacementHash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), value); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.escape(value)); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), value); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, translated_token); + } + return translated; + } + + function hasContext(options) { + return (options.context && (typeof options.context == 'string' || typeof options.context == 'number')); + } + + function needsPlural(options) { + return (options.count !== undefined && typeof options.count != 'string' && options.count !== 1); + } + + function exists(key, options) { + options = options || {}; + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + options = options || {}; + + if (!initialized) { + f.log('i18next not finished initialization. you might have called t function before loading resources finished.') + return options.defaultValue || ''; + }; + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _getDefaultValue(key, options) { + return (options.defaultValue !== undefined) ? options.defaultValue : key; + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(potentialKeys, options) { + if (typeof options == 'string') { + if (o.shortcutFunction === 'sprintf') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else if (o.shortcutFunction === 'defaultValue') { + options = { + defaultValue: options + } + } + } else { + options = options || {}; + } + + if (potentialKeys === undefined || potentialKeys === null) return ''; + + if (typeof potentialKeys == 'string') { + potentialKeys = [potentialKeys]; + } + + var key = potentialKeys[0]; + + if (potentialKeys.length > 1) { + for (var i = 0; i < potentialKeys.length; i++) { + key = potentialKeys[i]; + if (exists(key)) { + break; + } + } + } + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng) : languages + , ns = options.ns || o.ns.defaultNs + , parts; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing) { + if (options.lng) { + sync.postMissing(lngs[0], ns, key, notFound, lngs); + } else { + sync.postMissing(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found !== undefined && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + // process notFound if function exists + var splitNotFound = notFound; + if (notFound.indexOf(o.nsseparator) > -1) { + parts = notFound.split(o.nsseparator); + splitNotFound = parts[1]; + } + if (splitNotFound === key && o.parseMissingKey) { + notFound = o.parseMissingKey(notFound); + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessor && postProcessors[postProcessor]) { + var val = _getDefaultValue(key, options); + found = postProcessors[postProcessor](val, key, options); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options) { + options = options || {}; + + var optionWithoutCount, translated + , notFound = _getDefaultValue(key, options) + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + if (options.lng) { + lngs = f.toLanguages(options.lng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.count; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(lngs[0], options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + + translated = translate(pluralKey, optionWithoutCount); + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } // else continue translation with original/singular key + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + var valueType = Object.prototype.toString.apply(value); + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (valueType === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + if (o.objectTreeKeyHandler && typeof o.objectTreeKeyHandler == 'function') { + value = o.objectTreeKeyHandler(key, value, l, ns, options); + } else { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned an object instead of string.'; + f.log(value); + } + } else if (valueType !== '[object Number]' && valueType !== '[object Function]' && valueType !== '[object RegExp]') { + var copy = (valueType === '[object Array]') ? [] : {}; // apply child translation on a copy + f.each(value, function(m) { + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + }); + value = copy; + } + } + + if (typeof value === 'string' && value.trim() === '' && o.fallbackOnEmpty === true) + value = undefined; + + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length > 0))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + } + + return found; + } + function detectLanguage() { + var detectedLng; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var parms = query.split('&'); + for (var i=0; i 0) { + var key = parms[i].substring(0,pos); + var val = parms[i].substring(pos+1); + qsParm[key] = val; + } + } + })(); + if (qsParm[o.detectLngQS]) { + detectedLng = qsParm[o.detectLngQS]; + } + } + + // get from cookie + if (!detectedLng && typeof document !== 'undefined' && o.useCookie ) { + var c = f.cookie.read(o.cookieName); + if (c) detectedLng = c; + } + + // get from navigator + if (!detectedLng && typeof navigator !== 'undefined') { + detectedLng = (navigator.language) ? navigator.language : navigator.userLanguage; + } + + return detectedLng; + } + var sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + window.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + if (error.status == 200) { + // file loaded but invalid json, stop waste time ! + f.log('There is a typo in: ' + url); + } else if (error.status == 404) { + f.log('Does not exist: ' + url); + } else { + f.log(error.status + ' when loading ' + url); + } + + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback' && o.fallbackLng !== false) { + urls.push({lng: o.fallbackLng, url: applyReplacement(o.resPostPath, { lng: o.fallbackLng, ns: ns })}); + } else if (o.sendMissingTo === 'current' || (o.sendMissingTo === 'fallback' && o.fallbackLng === false) ) { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + } + }; + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + var pluralExtensions = { + + rules: { + "ach": { + "name": "Acholi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "af": { + "name": "Afrikaans", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ak": { + "name": "Akan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "am": { + "name": "Amharic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "an": { + "name": "Aragonese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ar": { + "name": "Arabic", + "numbers": [ + 0, + 1, + 2, + 3, + 11, + 100 + ], + "plurals": function(n) { return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5); } + }, + "arn": { + "name": "Mapudungun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ast": { + "name": "Asturian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ay": { + "name": "Aymar\u00e1", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "az": { + "name": "Azerbaijani", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "be": { + "name": "Belarusian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "bg": { + "name": "Bulgarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bn": { + "name": "Bengali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bo": { + "name": "Tibetan", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "br": { + "name": "Breton", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "bs": { + "name": "Bosnian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ca": { + "name": "Catalan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "cgg": { + "name": "Chiga", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "cs": { + "name": "Czech", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "csb": { + "name": "Kashubian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "cy": { + "name": "Welsh", + "numbers": [ + 1, + 2, + 3, + 8 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3); } + }, + "da": { + "name": "Danish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "de": { + "name": "German", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "dz": { + "name": "Dzongkha", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "el": { + "name": "Greek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "en": { + "name": "English", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eo": { + "name": "Esperanto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es": { + "name": "Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es_ar": { + "name": "Argentinean Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "et": { + "name": "Estonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eu": { + "name": "Basque", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fa": { + "name": "Persian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "fi": { + "name": "Finnish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fil": { + "name": "Filipino", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fo": { + "name": "Faroese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fr": { + "name": "French", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fur": { + "name": "Friulian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fy": { + "name": "Frisian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ga": { + "name": "Irish", + "numbers": [ + 1, + 2, + 3, + 7, + 11 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;} + }, + "gd": { + "name": "Scottish Gaelic", + "numbers": [ + 1, + 2, + 3, + 20 + ], + "plurals": function(n) { return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3); } + }, + "gl": { + "name": "Galician", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gu": { + "name": "Gujarati", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gun": { + "name": "Gun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ha": { + "name": "Hausa", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "he": { + "name": "Hebrew", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hi": { + "name": "Hindi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hr": { + "name": "Croatian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "hu": { + "name": "Hungarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hy": { + "name": "Armenian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ia": { + "name": "Interlingua", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "id": { + "name": "Indonesian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "is": { + "name": "Icelandic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n%10!=1 || n%100==11); } + }, + "it": { + "name": "Italian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ja": { + "name": "Japanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jbo": { + "name": "Lojban", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jv": { + "name": "Javanese", + "numbers": [ + 0, + 1 + ], + "plurals": function(n) { return Number(n !== 0); } + }, + "ka": { + "name": "Georgian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kk": { + "name": "Kazakh", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "km": { + "name": "Khmer", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kn": { + "name": "Kannada", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ko": { + "name": "Korean", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ku": { + "name": "Kurdish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "kw": { + "name": "Cornish", + "numbers": [ + 1, + 2, + 3, + 4 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3); } + }, + "ky": { + "name": "Kyrgyz", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lb": { + "name": "Letzeburgesch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ln": { + "name": "Lingala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "lo": { + "name": "Lao", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lt": { + "name": "Lithuanian", + "numbers": [ + 1, + 2, + 10 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "lv": { + "name": "Latvian", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2); } + }, + "mai": { + "name": "Maithili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mfe": { + "name": "Mauritian Creole", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mg": { + "name": "Malagasy", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mi": { + "name": "Maori", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mk": { + "name": "Macedonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 || n%10==1 ? 0 : 1); } + }, + "ml": { + "name": "Malayalam", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mn": { + "name": "Mongolian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mnk": { + "name": "Mandinka", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(0 ? 0 : n==1 ? 1 : 2); } + }, + "mr": { + "name": "Marathi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ms": { + "name": "Malay", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "mt": { + "name": "Maltese", + "numbers": [ + 1, + 2, + 11, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3); } + }, + "nah": { + "name": "Nahuatl", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nap": { + "name": "Neapolitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nb": { + "name": "Norwegian Bokmal", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ne": { + "name": "Nepali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nl": { + "name": "Dutch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nn": { + "name": "Norwegian Nynorsk", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "no": { + "name": "Norwegian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nso": { + "name": "Northern Sotho", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "oc": { + "name": "Occitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "or": { + "name": "Oriya", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pa": { + "name": "Punjabi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pap": { + "name": "Papiamento", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pl": { + "name": "Polish", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "pms": { + "name": "Piemontese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ps": { + "name": "Pashto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt": { + "name": "Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt_br": { + "name": "Brazilian Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "rm": { + "name": "Romansh", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ro": { + "name": "Romanian", + "numbers": [ + 1, + 2, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2); } + }, + "ru": { + "name": "Russian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "sah": { + "name": "Yakut", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sco": { + "name": "Scots", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "se": { + "name": "Northern Sami", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "si": { + "name": "Sinhala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sk": { + "name": "Slovak", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "sl": { + "name": "Slovenian", + "numbers": [ + 5, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }, + "so": { + "name": "Somali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "son": { + "name": "Songhay", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sq": { + "name": "Albanian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sr": { + "name": "Serbian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "su": { + "name": "Sundanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sv": { + "name": "Swedish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sw": { + "name": "Swahili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ta": { + "name": "Tamil", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "te": { + "name": "Telugu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tg": { + "name": "Tajik", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "th": { + "name": "Thai", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ti": { + "name": "Tigrinya", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tk": { + "name": "Turkmen", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tr": { + "name": "Turkish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tt": { + "name": "Tatar", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ug": { + "name": "Uyghur", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "uk": { + "name": "Ukrainian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ur": { + "name": "Urdu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "uz": { + "name": "Uzbek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "vi": { + "name": "Vietnamese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "wa": { + "name": "Walloon", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "wo": { + "name": "Wolof", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "yo": { + "name": "Yoruba", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "zh": { + "name": "Chinese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + } + }, + + // for demonstration only sl and ar is added but you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i = ext.plurals(c); + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[0], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.removeResourceBundle = removeResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + + $.i18n = i18n; + $.t = i18n.t; + + return i18n; + +})); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd.withJQuery-1.7.2.min.js b/libs/i18next/release/i18next.amd.withJQuery-1.7.2.min.js new file mode 100644 index 00000000..597f7543 --- /dev/null +++ b/libs/i18next/release/i18next.amd.withJQuery-1.7.2.min.js @@ -0,0 +1,5 @@ +// i18next, v1.7.2 +// Copyright (c)2014 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +!function(a,b){if("object"==typeof exports){var c=require("jquery");module.exports=b(c)}else"function"==typeof define&&define.amd&&define(["jquery"],b)}(this,function(a){function b(a,b){if(!b||"function"==typeof b)return a;for(var c in b)a[c]=b[c];return a}function c(a,b,c){var d,e=0,f=a.length,g=void 0===f||"function"==typeof a;if(c)if(g){for(d in a)if(b.apply(a[d],c)===!1)break}else for(;f>e&&b.apply(a[e++],c)!==!1;);else if(g){for(d in a)if(b.call(a[d],d,a[d])===!1)break}else for(;f>e&&b.call(a[e],e,a[e++])!==!1;);return a}function d(a){return"string"==typeof a?a.replace(/[&<>"'\/]/g,function(a){return H[a]}):a}function e(a){var b=function(a){if(window.XMLHttpRequest)return a(null,new XMLHttpRequest);if(window.ActiveXObject)try{return a(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(b){return a(null,new ActiveXObject("Microsoft.XMLHTTP"))}return a(new Error)},c=function(a){if("string"==typeof a)return a;var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")},d=function(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;cd?b+=String.fromCharCode(d):d>127&&2048>d?(b+=String.fromCharCode(192|d>>6),b+=String.fromCharCode(128|63&d)):(b+=String.fromCharCode(224|d>>12),b+=String.fromCharCode(128|63&d>>6),b+=String.fromCharCode(128|63&d))}return b},e=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";a=d(a);var c,e,f,g,h,i,j,k="",l=0;do c=a.charCodeAt(l++),e=a.charCodeAt(l++),f=a.charCodeAt(l++),g=c>>2,h=(3&c)<<4|e>>4,i=(15&e)<<2|f>>6,j=63&f,isNaN(e)?i=j=64:isNaN(f)&&(j=64),k+=b.charAt(g)+b.charAt(h)+b.charAt(i)+b.charAt(j),c=e=f="",g=h=i=j="";while(l1&&(d+=d.indexOf("?")>-1?"&"+k:"?"+k),e.jsonp){var l=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=d,l.appendChild(m),void 0}}b(function(b,c){if(b)return h(b);c.open(a,d,e.async);for(var f in j)j.hasOwnProperty(f)&&c.setRequestHeader(f,j[f]);c.onreadystatechange=function(){if(4===c.readyState){var a=c.responseText||"";if(!h)return;h(c.status,{text:function(){return a},json:function(){return JSON.parse(a)}})}},c.send(i)})},h={authBasic:function(a,b){g.headers.Authorization="Basic "+e(a+":"+b)},connect:function(a,b,c){return g("CONNECT",a,b,c)},del:function(a,b,c){return g("DELETE",a,b,c)},get:function(a,b,c){return g("GET",a,b,c)},head:function(a,b,c){return g("HEAD",a,b,c)},headers:function(a){g.headers=a||{}},isAllowed:function(a,b,c){this.options(a,function(a,d){c(-1!==d.text().indexOf(b))})},options:function(a,b,c){return g("OPTIONS",a,b,c)},patch:function(a,b,c){return g("PATCH",a,b,c)},post:function(a,b,c){return g("POST",a,b,c)},put:function(a,b,c){return g("PUT",a,b,c)},trace:function(a,b,c){return g("TRACE",a,b,c)}},i=a.type?a.type.toLowerCase():"get";h[i](a.url,a,function(b,c){200===b?a.success(c.json(),b,null):a.error(c.text(),b,null)})}function f(b,c){"function"==typeof b&&(c=b,b={}),b=b||{},K.extend(G,b),delete G.fixLng,"string"==typeof G.ns&&(G.ns={namespaces:[G.ns],defaultNs:G.ns}),"string"==typeof G.fallbackNS&&(G.fallbackNS=[G.fallbackNS]),G.interpolationPrefixEscaped=K.regexEscape(G.interpolationPrefix),G.interpolationSuffixEscaped=K.regexEscape(G.interpolationSuffix),G.lng||(G.lng=K.detectLanguage()),G.lng?G.useCookie&&K.cookie.create(G.cookieName,G.lng,G.cookieExpirationTime,G.cookieDomain):(G.lng=G.fallbackLng,G.useCookie&&K.cookie.remove(G.cookieName)),E=K.toLanguages(G.lng),A=E[0],K.log("currentLng set to: "+A);var d=u;b.fixLng&&(d=function(a,b){return b=b||{},b.lng=b.lng||d.lng,u(a,b)},d.lng=A),M.setCurrentLng(A),a&&G.setJqueryExt&&o();var e;if(a&&a.Deferred&&(e=a.Deferred()),!G.resStore){var f=K.toLanguages(G.lng);"string"==typeof G.preload&&(G.preload=[G.preload]);for(var g=0,h=G.preload.length;h>g;g++)for(var i=K.toLanguages(G.preload[g]),j=0,k=i.length;k>j;j++)f.indexOf(i[j])<0&&f.push(i[j]);return B.sync.load(f,G,function(a,b){C=b,F=!0,c&&c(d),e&&e.resolve(d)}),e?e.promise():void 0}return C=G.resStore,F=!0,c&&c(d),e&&e.resolve(d),e?e.promise():void 0}function g(a,b){"string"==typeof a&&(a=[a]);for(var c=0,d=a.length;d>c;c++)G.preload.indexOf(a[c])<0&&G.preload.push(a[c]);return f(b)}function h(a,b,c){"string"!=typeof b?(c=b,b=G.ns.defaultNs):G.ns.namespaces.indexOf(b)<0&&G.ns.namespaces.push(b),C[a]=C[a]||{},C[a][b]=C[a][b]||{},K.extend(C[a][b],c)}function i(a,b){"string"!=typeof b&&(b=G.ns.defaultNs),C[a]=C[a]||{},C[a][b]={}}function j(a){G.ns.defaultNs=a}function k(a,b){l([a],b)}function l(a,b){var c={dynamicLoad:G.dynamicLoad,resGetPath:G.resGetPath,getAsync:G.getAsync,customLoad:G.customLoad,ns:{namespaces:a,defaultNs:""}},d=K.toLanguages(G.lng);"string"==typeof G.preload&&(G.preload=[G.preload]);for(var e=0,f=G.preload.length;f>e;e++)for(var g=K.toLanguages(G.preload[e]),h=0,i=g.length;i>h;h++)d.indexOf(g[h])<0&&d.push(g[h]);for(var j=[],k=0,l=d.length;l>k;k++){var m=!1,n=C[d[k]];if(n)for(var o=0,p=a.length;p>o;o++)n[a[o]]||(m=!0);else m=!0;m&&j.push(d[k])}j.length?B.sync._fetch(j,c,function(c,d){var e=a.length*j.length;K.each(a,function(a,c){G.ns.namespaces.indexOf(c)<0&&G.ns.namespaces.push(c),K.each(j,function(a,f){C[f]=C[f]||{},C[f][c]=d[f][c],e--,0===e&&b&&(G.useLocalStorage&&B.sync._storeLocal(C),b())})})}):b&&b()}function m(a,b,c){return"function"==typeof b?(c=b,b={}):b||(b={}),b.lng=a,f(b,c)}function n(){return A}function o(){function b(b,c,d){if(0!==c.length){var e="text";if(0===c.indexOf("[")){var f=c.split("]");c=f[1],e=f[0].substr(1,f[0].length-1)}c.indexOf(";")===c.length-1&&(c=c.substr(0,c.length-2));var g;"html"===e?(g=G.defaultValueFromContent?a.extend({defaultValue:b.html()},d):d,b.html(a.t(c,g))):"text"===e?(g=G.defaultValueFromContent?a.extend({defaultValue:b.text()},d):d,b.text(a.t(c,g))):"prepend"===e?(g=G.defaultValueFromContent?a.extend({defaultValue:b.html()},d):d,b.prepend(a.t(c,g))):"append"===e?(g=G.defaultValueFromContent?a.extend({defaultValue:b.html()},d):d,b.append(a.t(c,g))):(g=G.defaultValueFromContent?a.extend({defaultValue:b.attr(e)},d):d,b.attr(e,a.t(c,g)))}}function c(c,d){var e=c.attr(G.selectorAttr);if(e||"undefined"==typeof e||e===!1||(e=c.text()||c.val()),e){var f=c,g=c.data("i18n-target");if(g&&(f=c.find(g)||c),d||G.useDataAttrOptions!==!0||(d=c.data("i18n-options")),d=d||{},e.indexOf(";")>=0){var h=e.split(";");a.each(h,function(a,c){""!==c&&b(f,c,d)})}else b(f,e,d);G.useDataAttrOptions===!0&&c.data("i18n-options",d)}}a.t=a.t||u,a.fn.i18n=function(b){return this.each(function(){c(a(this),b);var d=a(this).find("["+G.selectorAttr+"]");d.each(function(){c(a(this),b)})})}}function p(a,b,c,d){if(!a)return a;if(d=d||b,a.indexOf(d.interpolationPrefix||G.interpolationPrefix)<0)return a;var e=d.interpolationPrefix?K.regexEscape(d.interpolationPrefix):G.interpolationPrefixEscaped,f=d.interpolationSuffix?K.regexEscape(d.interpolationSuffix):G.interpolationSuffixEscaped,g="HTML"+f;return K.each(b,function(b,h){var i=c?c+G.keyseparator+b:b;"object"==typeof h&&null!==h?a=p(a,h,i,d):d.escapeInterpolation||G.escapeInterpolation?(a=a.replace(new RegExp([e,i,g].join(""),"g"),h),a=a.replace(new RegExp([e,i,f].join(""),"g"),K.escape(h))):a=a.replace(new RegExp([e,i,f].join(""),"g"),h)}),a}function q(a,b){var c=",",d="{",e="}",f=K.extend({},b);for(delete f.postProcess;-1!=a.indexOf(G.reusePrefix)&&(D++,!(D>G.maxRecursion));){var g=a.lastIndexOf(G.reusePrefix),h=a.indexOf(G.reuseSuffix,g)+G.reuseSuffix.length,i=a.substring(g,h),j=i.replace(G.reusePrefix,"").replace(G.reuseSuffix,"");if(-1!=j.indexOf(c)){var k=j.indexOf(c);if(-1!=j.indexOf(d,k)&&-1!=j.indexOf(e,k)){var l=j.indexOf(d,k),m=j.indexOf(e,l)+e.length;try{f=K.extend(f,JSON.parse(j.substring(l,m))),j=j.substring(0,k)}catch(n){}}}var o=x(j,f);a=a.replace(i,o)}return a}function r(a){return a.context&&("string"==typeof a.context||"number"==typeof a.context)}function s(a){return void 0!==a.count&&"string"!=typeof a.count&&1!==a.count}function t(a,b){b=b||{};var c=v(a,b),d=y(a,b);return void 0!==d||d===c}function u(a,b){return b=b||{},F?(D=0,x.apply(null,arguments)):(K.log("i18next not finished initialization. you might have called t function before loading resources finished."),b.defaultValue||"")}function v(a,b){return void 0!==b.defaultValue?b.defaultValue:a}function w(){for(var a=[],b=1;b1)for(var d=0;d-1&&(e=c.split(G.nsseparator),i=e[0],c=e[1]),void 0===g&&G.sendMissing&&(b.lng?L.postMissing(h[0],i,c,f,h):L.postMissing(G.lng,i,c,f,h));var j=b.postProcess||G.postProcess;void 0!==g&&j&&N[j]&&(g=N[j](g,c,b));var k=f;if(f.indexOf(G.nsseparator)>-1&&(e=f.split(G.nsseparator),k=e[1]),k===c&&G.parseMissingKey&&(f=G.parseMissingKey(f)),void 0===g&&(f=p(f,b),f=q(f,b),j&&N[j])){var l=v(c,b);g=N[j](l,c,b)}return void 0!==g?g:f}function y(a,b){b=b||{};var c,d,e=v(a,b),f=E;if(!C)return e;if(b.lng&&(f=K.toLanguages(b.lng),!C[f[0]])){var g=G.getAsync;G.getAsync=!1,B.sync.load(f,G,function(a,b){K.extend(C,b),G.getAsync=g})}var h=b.ns||G.ns.defaultNs;if(a.indexOf(G.nsseparator)>-1){var i=a.split(G.nsseparator);h=i[0],a=i[1]}if(r(b)){c=K.extend({},b),delete c.context,c.defaultValue=G.contextNotFound;var j=h+G.nsseparator+a+"_"+b.context;if(d=u(j,c),d!=G.contextNotFound)return p(d,{context:b.context})}if(s(b)){c=K.extend({},b),delete c.count,c.defaultValue=G.pluralNotFound;var k=h+G.nsseparator+a+G.pluralSuffix,l=M.get(f[0],b.count);if(l>=0?k=k+"_"+l:1===l&&(k=h+G.nsseparator+a),d=u(k,c),d!=G.pluralNotFound)return p(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix})}for(var m,n=a.split(G.keyseparator),o=0,t=f.length;t>o&&void 0===m;o++){for(var w=f[o],z=0,A=C[w]&&C[w][h];n[z];)A=A&&A[n[z]],z++;if(void 0!==A){var D=Object.prototype.toString.apply(A);if("string"==typeof A)A=p(A,b),A=q(A,b);else if("[object Array]"!==D||G.returnObjectTrees||b.returnObjectTrees){if(null===A&&G.fallbackOnNull===!0)A=void 0;else if(null!==A)if(G.returnObjectTrees||b.returnObjectTrees){if("[object Number]"!==D&&"[object Function]"!==D&&"[object RegExp]"!==D){var F="[object Array]"===D?[]:{};K.each(A,function(c){F[c]=x(h+G.nsseparator+a+G.keyseparator+c,b)}),A=F}}else G.objectTreeKeyHandler&&"function"==typeof G.objectTreeKeyHandler?A=G.objectTreeKeyHandler(a,A,w,h,b):(A="key '"+h+":"+a+" ("+w+")' "+"returned an object instead of string.",K.log(A))}else A=A.join("\n"),A=p(A,b),A=q(A,b);"string"==typeof A&&""===A.trim()&&G.fallbackOnEmpty===!0&&(A=void 0),m=A}}if(void 0===m&&!b.isFallbackLookup&&(G.fallbackToDefaultNS===!0||G.fallbackNS&&G.fallbackNS.length>0))if(b.isFallbackLookup=!0,G.fallbackNS.length){for(var H=0,I=G.fallbackNS.length;I>H;H++)if(m=y(G.fallbackNS[H]+G.nsseparator+a,b)){var J=m.indexOf(G.nsseparator)>-1?m.split(G.nsseparator)[1]:m,L=e.indexOf(G.nsseparator)>-1?e.split(G.nsseparator)[1]:e;if(J!==L)break}}else m=y(a,b);return m}function z(){var a,b=[];if("undefined"!=typeof window&&(!function(){for(var a=window.location.search.substring(1),c=a.split("&"),d=0;d0){var f=c[d].substring(0,e),g=c[d].substring(e+1);b[f]=g}}}(),b[G.detectLngQS]&&(a=b[G.detectLngQS])),!a&&"undefined"!=typeof document&&G.useCookie){var c=K.cookie.read(G.cookieName);c&&(a=c)}return a||"undefined"==typeof navigator||(a=navigator.language?navigator.language:navigator.userLanguage),a}Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>0&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&1/0!=d&&d!=-1/0&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=c;arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d))));for(var e=d>=0?Math.min(d,c-1):c-Math.abs(d);e>=0;e--)if(e in b&&b[e]===a)return e;return-1});var A,B={},C={},D=0,E=[],F=!1,G={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:"dev",fallbackNS:[],detectLngQS:"setLng",ns:"translation",fallbackOnNull:!0,fallbackOnEmpty:!1,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",cookieDomain:void 0,objectTreeKeyHandler:void 0,postProcess:void 0,parseMissingKey:void 0,shortcutFunction:"sprintf"},H={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},I={create:function(a,b,c,d){var e;if(c){var f=new Date;f.setTime(f.getTime()+1e3*60*c),e="; expires="+f.toGMTString()}else e="";d=d?"domain="+d+";":"",document.cookie=a+"="+b+e+";"+d+"path=/"},read:function(a){for(var b=a+"=",c=document.cookie.split(";"),d=0;d-1){var c=a.split("-");a=G.lowerCaseLng?c[0].toLowerCase()+"-"+c[1].toLowerCase():c[0].toLowerCase()+"-"+c[1].toUpperCase(),"unspecific"!==G.load&&b.push(a),"current"!==G.load&&b.push(c[0])}else b.push(a);return-1===b.indexOf(G.fallbackLng)&&G.fallbackLng&&b.push(G.fallbackLng),b},regexEscape:function(a){return a.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}};K.applyReplacement=p;var L={load:function(a,b,c){b.useLocalStorage?L._loadLocal(a,b,function(d,e){for(var f=[],g=0,h=a.length;h>g;g++)e[a[g]]||f.push(a[g]);f.length>0?L._fetch(f,b,function(a,b){K.extend(e,b),L._storeLocal(b),c(null,e)}):c(null,e)}):L._fetch(a,b,function(a,b){c(null,b)})},_loadLocal:function(a,b,c){var d={},e=(new Date).getTime();if(window.localStorage){var f=a.length;K.each(a,function(a,g){var h=window.localStorage.getItem("res_"+g);h&&(h=JSON.parse(h),h.i18nStamp&&h.i18nStamp+b.localStorageExpirationTime>e&&(d[g]=h)),f--,0===f&&c(null,d)})}},_storeLocal:function(a){if(window.localStorage)for(var b in a)a[b].i18nStamp=(new Date).getTime(),window.localStorage.setItem("res_"+b,JSON.stringify(a[b]))},_fetch:function(a,b,c){var d=b.ns,e={};if(b.dynamicLoad){var f=function(a,b){c(null,b)};if("function"==typeof b.customLoad)b.customLoad(a,d.namespaces,b,f);else{var g=p(b.resGetPath,{lng:a.join("+"),ns:d.namespaces.join("+")});K.ajax({url:g,success:function(a){K.log("loaded: "+g),f(null,a)},error:function(a,b,c){K.log("failed loading: "+g),f("failed loading resource.json error: "+c)},dataType:"json",async:b.getAsync})}}else{var h,i=d.namespaces.length*a.length;K.each(d.namespaces,function(d,f){K.each(a,function(a,d){var g=function(a,b){a&&(h=h||[],h.push(a)),e[d]=e[d]||{},e[d][f]=b,i--,0===i&&c(h,e)};"function"==typeof b.customLoad?b.customLoad(d,f,b,g):L._fetchOne(d,f,b,g)})})}},_fetchOne:function(a,b,c,d){var e=p(c.resGetPath,{lng:a,ns:b});K.ajax({url:e,success:function(a){K.log("loaded: "+e),d(null,a)},error:function(a,b,c){200==c.status?K.log("There is a typo in: "+e):404==c.status?K.log("Does not exist: "+e):K.log(c.status+" when loading "+e),d(c,{})},dataType:"json",async:c.getAsync})},postMissing:function(a,b,c,d,e){var f={};f[c]=d;var g=[];if("fallback"===G.sendMissingTo&&G.fallbackLng!==!1)g.push({lng:G.fallbackLng,url:p(G.resPostPath,{lng:G.fallbackLng,ns:b})});else if("current"===G.sendMissingTo||"fallback"===G.sendMissingTo&&G.fallbackLng===!1)g.push({lng:a,url:p(G.resPostPath,{lng:a,ns:b})});else if("all"===G.sendMissingTo)for(var h=0,i=e.length;i>h;h++)g.push({lng:e[h],url:p(G.resPostPath,{lng:e[h],ns:b})});for(var j=0,k=g.length;k>j;j++){var l=g[j];K.ajax({url:l.url,type:G.sendType,data:f,success:function(){K.log("posted missing key '"+c+"' to: "+l.url);for(var a=c.split("."),e=0,f=C[l.lng][b];a[e];)f=f[a[e]]=e===a.length-1?d:f[a[e]]||{},e++},error:function(){K.log("failed posting missing key '"+c+"' to: "+l.url)},dataType:"json",async:G.postAsync})}}},M={rules:{ach:{name:"Acholi",numbers:[1,2],plurals:function(a){return Number(a>1)}},af:{name:"Afrikaans",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ak:{name:"Akan",numbers:[1,2],plurals:function(a){return Number(a>1)}},am:{name:"Amharic",numbers:[1,2],plurals:function(a){return Number(a>1)}},an:{name:"Aragonese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ar:{name:"Arabic",numbers:[0,1,2,3,11,100],plurals:function(a){return Number(0===a?0:1==a?1:2==a?2:a%100>=3&&10>=a%100?3:a%100>=11?4:5)}},arn:{name:"Mapudungun",numbers:[1,2],plurals:function(a){return Number(a>1)}},ast:{name:"Asturian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ay:{name:"Aymará",numbers:[1],plurals:function(){return 0}},az:{name:"Azerbaijani",numbers:[1,2],plurals:function(a){return Number(1!=a)}},be:{name:"Belarusian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},bg:{name:"Bulgarian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},bn:{name:"Bengali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},bo:{name:"Tibetan",numbers:[1],plurals:function(){return 0}},br:{name:"Breton",numbers:[1,2],plurals:function(a){return Number(a>1)}},bs:{name:"Bosnian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},ca:{name:"Catalan",numbers:[1,2],plurals:function(a){return Number(1!=a)}},cgg:{name:"Chiga",numbers:[1],plurals:function(){return 0}},cs:{name:"Czech",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)}},csb:{name:"Kashubian",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},cy:{name:"Welsh",numbers:[1,2,3,8],plurals:function(a){return Number(1==a?0:2==a?1:8!=a&&11!=a?2:3)}},da:{name:"Danish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},de:{name:"German",numbers:[1,2],plurals:function(a){return Number(1!=a)}},dz:{name:"Dzongkha",numbers:[1],plurals:function(){return 0}},el:{name:"Greek",numbers:[1,2],plurals:function(a){return Number(1!=a)}},en:{name:"English",numbers:[1,2],plurals:function(a){return Number(1!=a)}},eo:{name:"Esperanto",numbers:[1,2],plurals:function(a){return Number(1!=a)}},es:{name:"Spanish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},es_ar:{name:"Argentinean Spanish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},et:{name:"Estonian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},eu:{name:"Basque",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fa:{name:"Persian",numbers:[1],plurals:function(){return 0}},fi:{name:"Finnish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fil:{name:"Filipino",numbers:[1,2],plurals:function(a){return Number(a>1)}},fo:{name:"Faroese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fr:{name:"French",numbers:[1,2],plurals:function(a){return Number(a>1)}},fur:{name:"Friulian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fy:{name:"Frisian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ga:{name:"Irish",numbers:[1,2,3,7,11],plurals:function(a){return Number(1==a?0:2==a?1:7>a?2:11>a?3:4)}},gd:{name:"Scottish Gaelic",numbers:[1,2,3,20],plurals:function(a){return Number(1==a||11==a?0:2==a||12==a?1:a>2&&20>a?2:3)}},gl:{name:"Galician",numbers:[1,2],plurals:function(a){return Number(1!=a)}},gu:{name:"Gujarati",numbers:[1,2],plurals:function(a){return Number(1!=a)}},gun:{name:"Gun",numbers:[1,2],plurals:function(a){return Number(a>1)}},ha:{name:"Hausa",numbers:[1,2],plurals:function(a){return Number(1!=a)}},he:{name:"Hebrew",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hi:{name:"Hindi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hr:{name:"Croatian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},hu:{name:"Hungarian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hy:{name:"Armenian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ia:{name:"Interlingua",numbers:[1,2],plurals:function(a){return Number(1!=a)}},id:{name:"Indonesian",numbers:[1],plurals:function(){return 0}},is:{name:"Icelandic",numbers:[1,2],plurals:function(a){return Number(1!=a%10||11==a%100)}},it:{name:"Italian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ja:{name:"Japanese",numbers:[1],plurals:function(){return 0}},jbo:{name:"Lojban",numbers:[1],plurals:function(){return 0}},jv:{name:"Javanese",numbers:[0,1],plurals:function(a){return Number(0!==a)}},ka:{name:"Georgian",numbers:[1],plurals:function(){return 0}},kk:{name:"Kazakh",numbers:[1],plurals:function(){return 0}},km:{name:"Khmer",numbers:[1],plurals:function(){return 0}},kn:{name:"Kannada",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ko:{name:"Korean",numbers:[1],plurals:function(){return 0}},ku:{name:"Kurdish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},kw:{name:"Cornish",numbers:[1,2,3,4],plurals:function(a){return Number(1==a?0:2==a?1:3==a?2:3)}},ky:{name:"Kyrgyz",numbers:[1],plurals:function(){return 0}},lb:{name:"Letzeburgesch",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ln:{name:"Lingala",numbers:[1,2],plurals:function(a){return Number(a>1)}},lo:{name:"Lao",numbers:[1],plurals:function(){return 0}},lt:{name:"Lithuanian",numbers:[1,2,10],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&(10>a%100||a%100>=20)?1:2)}},lv:{name:"Latvian",numbers:[0,1,2],plurals:function(a){return Number(1==a%10&&11!=a%100?0:0!==a?1:2)}},mai:{name:"Maithili",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mfe:{name:"Mauritian Creole",numbers:[1,2],plurals:function(a){return Number(a>1)}},mg:{name:"Malagasy",numbers:[1,2],plurals:function(a){return Number(a>1)}},mi:{name:"Maori",numbers:[1,2],plurals:function(a){return Number(a>1)}},mk:{name:"Macedonian",numbers:[1,2],plurals:function(a){return Number(1==a||1==a%10?0:1)}},ml:{name:"Malayalam",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mn:{name:"Mongolian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mnk:{name:"Mandinka",numbers:[0,1,2],plurals:function(a){return Number(1==a?1:2)}},mr:{name:"Marathi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ms:{name:"Malay",numbers:[1],plurals:function(){return 0}},mt:{name:"Maltese",numbers:[1,2,11,20],plurals:function(a){return Number(1==a?0:0===a||a%100>1&&11>a%100?1:a%100>10&&20>a%100?2:3)}},nah:{name:"Nahuatl",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nap:{name:"Neapolitan",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nb:{name:"Norwegian Bokmal",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ne:{name:"Nepali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nl:{name:"Dutch",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nn:{name:"Norwegian Nynorsk",numbers:[1,2],plurals:function(a){return Number(1!=a)}},no:{name:"Norwegian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nso:{name:"Northern Sotho",numbers:[1,2],plurals:function(a){return Number(1!=a)}},oc:{name:"Occitan",numbers:[1,2],plurals:function(a){return Number(a>1)}},or:{name:"Oriya",numbers:[2,1],plurals:function(a){return Number(1!=a)}},pa:{name:"Punjabi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pap:{name:"Papiamento",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pl:{name:"Polish",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},pms:{name:"Piemontese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ps:{name:"Pashto",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pt:{name:"Portuguese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pt_br:{name:"Brazilian Portuguese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},rm:{name:"Romansh",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ro:{name:"Romanian",numbers:[1,2,20],plurals:function(a){return Number(1==a?0:0===a||a%100>0&&20>a%100?1:2)}},ru:{name:"Russian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},sah:{name:"Yakut",numbers:[1],plurals:function(){return 0}},sco:{name:"Scots",numbers:[1,2],plurals:function(a){return Number(1!=a)}},se:{name:"Northern Sami",numbers:[1,2],plurals:function(a){return Number(1!=a)}},si:{name:"Sinhala",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sk:{name:"Slovak",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)}},sl:{name:"Slovenian",numbers:[5,1,2,3],plurals:function(a){return Number(1==a%100?1:2==a%100?2:3==a%100||4==a%100?3:0)}},so:{name:"Somali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},son:{name:"Songhay",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sq:{name:"Albanian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sr:{name:"Serbian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},su:{name:"Sundanese",numbers:[1],plurals:function(){return 0}},sv:{name:"Swedish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sw:{name:"Swahili",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ta:{name:"Tamil",numbers:[1,2],plurals:function(a){return Number(1!=a)}},te:{name:"Telugu",numbers:[1,2],plurals:function(a){return Number(1!=a)}},tg:{name:"Tajik",numbers:[1,2],plurals:function(a){return Number(a>1)}},th:{name:"Thai",numbers:[1],plurals:function(){return 0}},ti:{name:"Tigrinya",numbers:[1,2],plurals:function(a){return Number(a>1)}},tk:{name:"Turkmen",numbers:[1,2],plurals:function(a){return Number(1!=a)}},tr:{name:"Turkish",numbers:[1,2],plurals:function(a){return Number(a>1)}},tt:{name:"Tatar",numbers:[1],plurals:function(){return 0}},ug:{name:"Uyghur",numbers:[1],plurals:function(){return 0}},uk:{name:"Ukrainian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},ur:{name:"Urdu",numbers:[1,2],plurals:function(a){return Number(1!=a)}},uz:{name:"Uzbek",numbers:[1,2],plurals:function(a){return Number(a>1)}},vi:{name:"Vietnamese",numbers:[1],plurals:function(){return 0}},wa:{name:"Walloon",numbers:[1,2],plurals:function(a){return Number(a>1)}},wo:{name:"Wolof",numbers:[1],plurals:function(){return 0}},yo:{name:"Yoruba",numbers:[1,2],plurals:function(a){return Number(1!=a)}},zh:{name:"Chinese",numbers:[1],plurals:function(){return 0}}},addRule:function(a,b){M.rules[a]=b},setCurrentLng:function(a){if(!M.currentRule||M.currentRule.lng!==a){var b=a.split("-");M.currentRule={lng:a,rule:M.rules[b[0]]}}},get:function(a,b){function c(b,c){var d;if(d=M.currentRule&&M.currentRule.lng===a?M.currentRule.rule:M.rules[b]){var e=d.plurals(c),f=d.numbers[e];return 2===d.numbers.length&&1===d.numbers[0]&&(2===f?f=-1:1===f&&(f=1)),f}return 1===c?"1":"-1"}var d=a.split("-");return c(d[0],b)}},N={},O=function(a,b){N[a]=b},P=function(){function a(a){return Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}function b(a,b){for(var c=[];b>0;c[--b]=a);return c.join("")}var c=function(){return c.cache.hasOwnProperty(arguments[0])||(c.cache[arguments[0]]=c.parse(arguments[0])),c.format.call(null,c.cache[arguments[0]],arguments)};return c.format=function(c,d){var e,f,g,h,i,j,k,l=1,m=c.length,n="",o=[];for(f=0;m>f;f++)if(n=a(c[f]),"string"===n)o.push(c[f]);else if("array"===n){if(h=c[f],h[2])for(e=d[l],g=0;g=0?"+"+e:e,j=h[4]?"0"==h[4]?"0":h[4].charAt(1):" ",k=h[6]-String(e).length,i=h[6]?b(j,k):"",o.push(h[5]?e+i:i+e)}return o.join("")},c.cache={},c.parse=function(a){for(var b=a,c=[],d=[],e=0;b;){if(null!==(c=/^[^\x25]+/.exec(b)))d.push(c[0]);else if(null!==(c=/^\x25{2}/.exec(b)))d.push("%");else{if(null===(c=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(b)))throw"[sprintf] huh?";if(c[2]){e|=1;var f=[],g=c[2],h=[];if(null===(h=/^([a-z_][a-z_\d]*)/i.exec(g)))throw"[sprintf] huh?";for(f.push(h[1]);""!==(g=g.substring(h[0].length));)if(null!==(h=/^\.([a-z_][a-z_\d]*)/i.exec(g)))f.push(h[1]);else{if(null===(h=/^\[(\d+)\]/.exec(g)))throw"[sprintf] huh?";f.push(h[1])}c[2]=f}else e|=2;if(3===e)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";d.push(c)}b=b.substring(c[0].length)}return d},c}(),Q=function(a,b){return b.unshift(a),P.apply(null,b)};return O("sprintf",function(a,b,c){return c.sprintf?"[object Array]"===Object.prototype.toString.apply(c.sprintf)?Q(a,c.sprintf):"object"==typeof c.sprintf?P(a,c.sprintf):a:a}),B.init=f,B.setLng=m,B.preload=g,B.addResourceBundle=h,B.removeResourceBundle=i,B.loadNamespace=k,B.loadNamespaces=l,B.setDefaultNamespace=j,B.t=u,B.translate=u,B.exists=t,B.detectLanguage=K.detectLanguage,B.pluralExtensions=M,B.sync=L,B.functions=K,B.lng=n,B.addPostProcessor=O,B.options=G,a.i18n=B,a.t=B.t,B}); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd.withJQuery-1.7.3.js b/libs/i18next/release/i18next.amd.withJQuery-1.7.3.js new file mode 100644 index 00000000..9b1be90c --- /dev/null +++ b/libs/i18next/release/i18next.amd.withJQuery-1.7.3.js @@ -0,0 +1,2748 @@ +// i18next, v1.7.3 +// Copyright (c)2014 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function (root, factory) { + if (typeof exports === 'object') { + + var jquery = require('jquery'); + + module.exports = factory(jquery); + + } else if (typeof define === 'function' && define.amd) { + + define(['jquery'], factory); + + } +}(this, function ($) { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + // Add string trim for IE8. + if (typeof String.prototype.trim !== 'function') { + String.prototype.trim = function() { + return this.replace(/^\s+|\s+$/g, ''); + } + } + + var i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = [] + , initialized = false; + + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: ['dev'], + fallbackNS: [], + detectLngQS: 'setLng', + ns: 'translation', + fallbackOnNull: true, + fallbackOnEmpty: false, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + cookieDomain: undefined, + + objectTreeKeyHandler: undefined, + postProcess: undefined, + parseMissingKey: undefined, + + shortcutFunction: 'sprintf' // or: defaultValue + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || Object.prototype.toString.apply(object) !== '[object Array]' || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + return JSON.parse(data); + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + if (status === 200) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes,domain) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + domain = (domain)? "domain="+domain+";" : ""; + document.cookie = name+"="+value+expires+";"+domain+"path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes,domain) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : (typeof document !== 'undefined' ? _ajax : function() {}), + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + toLanguages: function(lng) { + var log = this.log; + var languages = []; + var whitelist = o.langWhitelist || false; + var addLanguage = function(language){ + //reject langs not whitelisted + if(!whitelist || whitelist.indexOf(language) > -1){ + languages.push(language); + }else{ + log('rejecting non-whitelisted language: ' + language); + } + }; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + + if (o.load !== 'unspecific') addLanguage(lng); + if (o.load !== 'current') addLanguage(parts[0]); + } else { + addLanguage(lng); + } + + for (var i = 0; i < o.fallbackLng.length; i++) { + if (languages.indexOf(o.fallbackLng[i]) === -1 && o.fallbackLng[i]) languages.push(o.fallbackLng[i]); + } + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + delete o.fixLng; /* passed in each time */ + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // fallback languages + if (typeof o.fallbackLng == 'string' || typeof o.fallbackLng == 'boolean') { + o.fallbackLng = [o.fallbackLng]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + if (o.useCookie && f.cookie.read(o.cookieName) !== currentLng){ //cookie is unset or invalid + f.cookie.create(o.cookieName, currentLng, o.cookieExpirationTime, o.cookieDomain); + } + + + var lngTranslate = translate; + if (options.fixLng) { + lngTranslate = function(key, options) { + options = options || {}; + options.lng = options.lng || lngTranslate.lng; + return translate(key, options); + }; + lngTranslate.lng = currentLng; + } + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + initialized = true; + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + initialized = true; + + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + f.extend(resStore[lng][ns], resources); + } + + function removeResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = {}; + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, options, cb) { + if (typeof options === 'function') { + cb = options; + options = {}; + } else if (!options) { + options = {}; + } + + options.lng = lng; + return init(options, cb); + } + + function lng() { + return currentLng; + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else if (attr === 'prepend') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.prepend($.t(key, optionsToUse)); + } else if (attr === 'append') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.append($.t(key, optionsToUse)); + } else if (attr.indexOf("data-") === 0) { + var dataAttr = attr.substr(("data-").length); + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.data(dataAttr) }, options) : options; + var translated = $.t(key, optionsToUse); + //we change into the data cache + ele.data(dataAttr, translated); + //we change into the dom + ele.attr(attr, translated); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key && typeof key !== 'undefined' && key !== false) key = ele.text() || ele.val(); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + f.each(replacementHash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), value); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.escape(value)); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), value); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, translated_token); + } + return translated; + } + + function hasContext(options) { + return (options.context && (typeof options.context == 'string' || typeof options.context == 'number')); + } + + function needsPlural(options) { + return (options.count !== undefined && typeof options.count != 'string' && options.count !== 1); + } + + function exists(key, options) { + options = options || {}; + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + options = options || {}; + + if (!initialized) { + f.log('i18next not finished initialization. you might have called t function before loading resources finished.') + return options.defaultValue || ''; + }; + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _getDefaultValue(key, options) { + return (options.defaultValue !== undefined) ? options.defaultValue : key; + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(potentialKeys, options) { + if (options && typeof options !== 'object') { + if (o.shortcutFunction === 'sprintf') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else if (o.shortcutFunction === 'defaultValue') { + options = { + defaultValue: options + } + } + } else { + options = options || {}; + } + + if (potentialKeys === undefined || potentialKeys === null) return ''; + + if (typeof potentialKeys == 'string') { + potentialKeys = [potentialKeys]; + } + + var key = potentialKeys[0]; + + if (potentialKeys.length > 1) { + for (var i = 0; i < potentialKeys.length; i++) { + key = potentialKeys[i]; + if (exists(key, options)) { + break; + } + } + } + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng) : languages + , ns = options.ns || o.ns.defaultNs + , parts; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing) { + if (options.lng) { + sync.postMissing(lngs[0], ns, key, notFound, lngs); + } else { + sync.postMissing(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found !== undefined && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + // process notFound if function exists + var splitNotFound = notFound; + if (notFound.indexOf(o.nsseparator) > -1) { + parts = notFound.split(o.nsseparator); + splitNotFound = parts[1]; + } + if (splitNotFound === key && o.parseMissingKey) { + notFound = o.parseMissingKey(notFound); + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessor && postProcessors[postProcessor]) { + var val = _getDefaultValue(key, options); + found = postProcessors[postProcessor](val, key, options); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options) { + options = options || {}; + + var optionWithoutCount, translated + , notFound = _getDefaultValue(key, options) + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + // CI mode + if (lngs[0].toLowerCase() === 'cimode') return notFound; + + // passed in lng + if (options.lng) { + lngs = f.toLanguages(options.lng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.count; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(lngs[0], options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + + translated = translate(pluralKey, optionWithoutCount); + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } // else continue translation with original/singular key + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + var valueType = Object.prototype.toString.apply(value); + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (valueType === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + if (o.objectTreeKeyHandler && typeof o.objectTreeKeyHandler == 'function') { + value = o.objectTreeKeyHandler(key, value, l, ns, options); + } else { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned an object instead of string.'; + f.log(value); + } + } else if (valueType !== '[object Number]' && valueType !== '[object Function]' && valueType !== '[object RegExp]') { + var copy = (valueType === '[object Array]') ? [] : {}; // apply child translation on a copy + f.each(value, function(m) { + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + }); + value = copy; + } + } + + if (typeof value === 'string' && value.trim() === '' && o.fallbackOnEmpty === true) + value = undefined; + + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length > 0))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + } + + return found; + } + function detectLanguage() { + var detectedLng; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var parms = query.split('&'); + for (var i=0; i 0) { + var key = parms[i].substring(0,pos); + var val = parms[i].substring(pos+1); + qsParm[key] = val; + } + } + })(); + if (qsParm[o.detectLngQS]) { + detectedLng = qsParm[o.detectLngQS]; + } + } + + // get from cookie + if (!detectedLng && typeof document !== 'undefined' && o.useCookie ) { + var c = f.cookie.read(o.cookieName); + if (c) detectedLng = c; + } + + // get from navigator + if (!detectedLng && typeof navigator !== 'undefined') { + detectedLng = (navigator.language) ? navigator.language : navigator.userLanguage; + } + + //fallback + if(!detectedLng){ + detectedLng = o.fallbackLng[0]; + } + + return detectedLng; + } + var sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + window.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + if ((status && status == 200) || (xhr && xhr.status && xhr.status == 200)) { + // file loaded but invalid json, stop waste time ! + f.log('There is a typo in: ' + url); + } else if ((status && status == 404) || (xhr && xhr.status && xhr.status == 404)) { + f.log('Does not exist: ' + url); + } else { + var theStatus = status ? status : ((xhr && xhr.status) ? xhr.status : null); + f.log(theStatus + ' when loading ' + url); + } + + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback' && o.fallbackLng[0] !== false) { + for (var i = 0; i < o.fallbackLng.length; i++) { + urls.push({lng: o.fallbackLng[i], url: applyReplacement(o.resPostPath, { lng: o.fallbackLng[i], ns: ns })}); + } + } else if (o.sendMissingTo === 'current' || (o.sendMissingTo === 'fallback' && o.fallbackLng[0] === false) ) { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + } + }; + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + var pluralExtensions = { + + rules: { + "ach": { + "name": "Acholi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "af": { + "name": "Afrikaans", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ak": { + "name": "Akan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "am": { + "name": "Amharic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "an": { + "name": "Aragonese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ar": { + "name": "Arabic", + "numbers": [ + 0, + 1, + 2, + 3, + 11, + 100 + ], + "plurals": function(n) { return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5); } + }, + "arn": { + "name": "Mapudungun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ast": { + "name": "Asturian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ay": { + "name": "Aymar\u00e1", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "az": { + "name": "Azerbaijani", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "be": { + "name": "Belarusian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "bg": { + "name": "Bulgarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bn": { + "name": "Bengali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bo": { + "name": "Tibetan", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "br": { + "name": "Breton", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "bs": { + "name": "Bosnian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ca": { + "name": "Catalan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "cgg": { + "name": "Chiga", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "cs": { + "name": "Czech", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "csb": { + "name": "Kashubian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "cy": { + "name": "Welsh", + "numbers": [ + 1, + 2, + 3, + 8 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3); } + }, + "da": { + "name": "Danish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "de": { + "name": "German", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "dz": { + "name": "Dzongkha", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "el": { + "name": "Greek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "en": { + "name": "English", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eo": { + "name": "Esperanto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es": { + "name": "Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es_ar": { + "name": "Argentinean Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "et": { + "name": "Estonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eu": { + "name": "Basque", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fa": { + "name": "Persian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "fi": { + "name": "Finnish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fil": { + "name": "Filipino", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fo": { + "name": "Faroese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fr": { + "name": "French", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fur": { + "name": "Friulian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fy": { + "name": "Frisian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ga": { + "name": "Irish", + "numbers": [ + 1, + 2, + 3, + 7, + 11 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;} + }, + "gd": { + "name": "Scottish Gaelic", + "numbers": [ + 1, + 2, + 3, + 20 + ], + "plurals": function(n) { return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3); } + }, + "gl": { + "name": "Galician", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gu": { + "name": "Gujarati", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gun": { + "name": "Gun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ha": { + "name": "Hausa", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "he": { + "name": "Hebrew", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hi": { + "name": "Hindi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hr": { + "name": "Croatian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "hu": { + "name": "Hungarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hy": { + "name": "Armenian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ia": { + "name": "Interlingua", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "id": { + "name": "Indonesian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "is": { + "name": "Icelandic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n%10!=1 || n%100==11); } + }, + "it": { + "name": "Italian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ja": { + "name": "Japanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jbo": { + "name": "Lojban", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jv": { + "name": "Javanese", + "numbers": [ + 0, + 1 + ], + "plurals": function(n) { return Number(n !== 0); } + }, + "ka": { + "name": "Georgian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kk": { + "name": "Kazakh", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "km": { + "name": "Khmer", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kn": { + "name": "Kannada", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ko": { + "name": "Korean", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ku": { + "name": "Kurdish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "kw": { + "name": "Cornish", + "numbers": [ + 1, + 2, + 3, + 4 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3); } + }, + "ky": { + "name": "Kyrgyz", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lb": { + "name": "Letzeburgesch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ln": { + "name": "Lingala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "lo": { + "name": "Lao", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lt": { + "name": "Lithuanian", + "numbers": [ + 1, + 2, + 10 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "lv": { + "name": "Latvian", + "numbers": [ + 1, + 2, + 0 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2); } + }, + "mai": { + "name": "Maithili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mfe": { + "name": "Mauritian Creole", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mg": { + "name": "Malagasy", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mi": { + "name": "Maori", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mk": { + "name": "Macedonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 || n%10==1 ? 0 : 1); } + }, + "ml": { + "name": "Malayalam", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mn": { + "name": "Mongolian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mnk": { + "name": "Mandinka", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(0 ? 0 : n==1 ? 1 : 2); } + }, + "mr": { + "name": "Marathi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ms": { + "name": "Malay", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "mt": { + "name": "Maltese", + "numbers": [ + 1, + 2, + 11, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3); } + }, + "nah": { + "name": "Nahuatl", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nap": { + "name": "Neapolitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nb": { + "name": "Norwegian Bokmal", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ne": { + "name": "Nepali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nl": { + "name": "Dutch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nn": { + "name": "Norwegian Nynorsk", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "no": { + "name": "Norwegian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nso": { + "name": "Northern Sotho", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "oc": { + "name": "Occitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "or": { + "name": "Oriya", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pa": { + "name": "Punjabi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pap": { + "name": "Papiamento", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pl": { + "name": "Polish", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "pms": { + "name": "Piemontese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ps": { + "name": "Pashto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt": { + "name": "Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt_br": { + "name": "Brazilian Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "rm": { + "name": "Romansh", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ro": { + "name": "Romanian", + "numbers": [ + 1, + 2, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2); } + }, + "ru": { + "name": "Russian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "sah": { + "name": "Yakut", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sco": { + "name": "Scots", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "se": { + "name": "Northern Sami", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "si": { + "name": "Sinhala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sk": { + "name": "Slovak", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "sl": { + "name": "Slovenian", + "numbers": [ + 5, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }, + "so": { + "name": "Somali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "son": { + "name": "Songhay", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sq": { + "name": "Albanian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sr": { + "name": "Serbian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "su": { + "name": "Sundanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sv": { + "name": "Swedish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sw": { + "name": "Swahili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ta": { + "name": "Tamil", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "te": { + "name": "Telugu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tg": { + "name": "Tajik", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "th": { + "name": "Thai", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ti": { + "name": "Tigrinya", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tk": { + "name": "Turkmen", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tr": { + "name": "Turkish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tt": { + "name": "Tatar", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ug": { + "name": "Uyghur", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "uk": { + "name": "Ukrainian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ur": { + "name": "Urdu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "uz": { + "name": "Uzbek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "vi": { + "name": "Vietnamese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "wa": { + "name": "Walloon", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "wo": { + "name": "Wolof", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "yo": { + "name": "Yoruba", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "zh": { + "name": "Chinese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + } + }, + + // for demonstration only sl and ar is added but you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i = ext.plurals(c); + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[0], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.removeResourceBundle = removeResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + + $.i18n = i18n; + $.t = i18n.t; + + return i18n; + +})); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd.withJQuery-1.7.3.min.js b/libs/i18next/release/i18next.amd.withJQuery-1.7.3.min.js new file mode 100644 index 00000000..c64571ec --- /dev/null +++ b/libs/i18next/release/i18next.amd.withJQuery-1.7.3.min.js @@ -0,0 +1,6 @@ +// i18next, v1.7.3 +// Copyright (c)2014 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +!function(a,b){if("object"==typeof exports){var c=require("jquery");module.exports=b(c)}else"function"==typeof define&&define.amd&&define(["jquery"],b)}(this,function(a){function b(a,b){if(!b||"function"==typeof b)return a;for(var c in b)a[c]=b[c];return a}function c(a,b,c){var d,e=0,f=a.length,g=void 0===f||"[object Array]"!==Object.prototype.toString.apply(a)||"function"==typeof a;if(c)if(g){for(d in a)if(b.apply(a[d],c)===!1)break}else for(;f>e&&b.apply(a[e++],c)!==!1;);else if(g){for(d in a)if(b.call(a[d],d,a[d])===!1)break}else for(;f>e&&b.call(a[e],e,a[e++])!==!1;);return a}function d(a){return"string"==typeof a?a.replace(/[&<>"'\/]/g,function(a){return H[a]}):a}function e(a){var b=function(a){if(window.XMLHttpRequest)return a(null,new XMLHttpRequest);if(window.ActiveXObject)try{return a(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(b){return a(null,new ActiveXObject("Microsoft.XMLHTTP"))}return a(new Error)},c=function(a){if("string"==typeof a)return a;var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")},d=function(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;cd?b+=String.fromCharCode(d):d>127&&2048>d?(b+=String.fromCharCode(d>>6|192),b+=String.fromCharCode(63&d|128)):(b+=String.fromCharCode(d>>12|224),b+=String.fromCharCode(d>>6&63|128),b+=String.fromCharCode(63&d|128))}return b},e=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";a=d(a);var c,e,f,g,h,i,j,k="",l=0;do c=a.charCodeAt(l++),e=a.charCodeAt(l++),f=a.charCodeAt(l++),g=c>>2,h=(3&c)<<4|e>>4,i=(15&e)<<2|f>>6,j=63&f,isNaN(e)?i=j=64:isNaN(f)&&(j=64),k+=b.charAt(g)+b.charAt(h)+b.charAt(i)+b.charAt(j),c=e=f="",g=h=i=j="";while(l1&&(d+=d.indexOf("?")>-1?"&"+k:"?"+k),e.jsonp){var l=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=d,void l.appendChild(m)}}b(function(b,c){if(b)return h(b);c.open(a,d,e.async);for(var f in j)j.hasOwnProperty(f)&&c.setRequestHeader(f,j[f]);c.onreadystatechange=function(){if(4===c.readyState){var a=c.responseText||"";if(!h)return;h(c.status,{text:function(){return a},json:function(){return JSON.parse(a)}})}},c.send(i)})},h={authBasic:function(a,b){g.headers.Authorization="Basic "+e(a+":"+b)},connect:function(a,b,c){return g("CONNECT",a,b,c)},del:function(a,b,c){return g("DELETE",a,b,c)},get:function(a,b,c){return g("GET",a,b,c)},head:function(a,b,c){return g("HEAD",a,b,c)},headers:function(a){g.headers=a||{}},isAllowed:function(a,b,c){this.options(a,function(a,d){c(-1!==d.text().indexOf(b))})},options:function(a,b,c){return g("OPTIONS",a,b,c)},patch:function(a,b,c){return g("PATCH",a,b,c)},post:function(a,b,c){return g("POST",a,b,c)},put:function(a,b,c){return g("PUT",a,b,c)},trace:function(a,b,c){return g("TRACE",a,b,c)}},i=a.type?a.type.toLowerCase():"get";h[i](a.url,a,function(b,c){200===b?a.success(c.json(),b,null):a.error(c.text(),b,null)})}function f(b,c){"function"==typeof b&&(c=b,b={}),b=b||{},K.extend(G,b),delete G.fixLng,"string"==typeof G.ns&&(G.ns={namespaces:[G.ns],defaultNs:G.ns}),"string"==typeof G.fallbackNS&&(G.fallbackNS=[G.fallbackNS]),("string"==typeof G.fallbackLng||"boolean"==typeof G.fallbackLng)&&(G.fallbackLng=[G.fallbackLng]),G.interpolationPrefixEscaped=K.regexEscape(G.interpolationPrefix),G.interpolationSuffixEscaped=K.regexEscape(G.interpolationSuffix),G.lng||(G.lng=K.detectLanguage()),E=K.toLanguages(G.lng),A=E[0],K.log("currentLng set to: "+A),G.useCookie&&K.cookie.read(G.cookieName)!==A&&K.cookie.create(G.cookieName,A,G.cookieExpirationTime,G.cookieDomain);var d=u;b.fixLng&&(d=function(a,b){return b=b||{},b.lng=b.lng||d.lng,u(a,b)},d.lng=A),M.setCurrentLng(A),a&&G.setJqueryExt&&o();var e;if(a&&a.Deferred&&(e=a.Deferred()),!G.resStore){var f=K.toLanguages(G.lng);"string"==typeof G.preload&&(G.preload=[G.preload]);for(var g=0,h=G.preload.length;h>g;g++)for(var i=K.toLanguages(G.preload[g]),j=0,k=i.length;k>j;j++)f.indexOf(i[j])<0&&f.push(i[j]);return B.sync.load(f,G,function(a,b){C=b,F=!0,c&&c(d),e&&e.resolve(d)}),e?e.promise():void 0}return C=G.resStore,F=!0,c&&c(d),e&&e.resolve(d),e?e.promise():void 0}function g(a,b){"string"==typeof a&&(a=[a]);for(var c=0,d=a.length;d>c;c++)G.preload.indexOf(a[c])<0&&G.preload.push(a[c]);return f(b)}function h(a,b,c){"string"!=typeof b?(c=b,b=G.ns.defaultNs):G.ns.namespaces.indexOf(b)<0&&G.ns.namespaces.push(b),C[a]=C[a]||{},C[a][b]=C[a][b]||{},K.extend(C[a][b],c)}function i(a,b){"string"!=typeof b&&(b=G.ns.defaultNs),C[a]=C[a]||{},C[a][b]={}}function j(a){G.ns.defaultNs=a}function k(a,b){l([a],b)}function l(a,b){var c={dynamicLoad:G.dynamicLoad,resGetPath:G.resGetPath,getAsync:G.getAsync,customLoad:G.customLoad,ns:{namespaces:a,defaultNs:""}},d=K.toLanguages(G.lng);"string"==typeof G.preload&&(G.preload=[G.preload]);for(var e=0,f=G.preload.length;f>e;e++)for(var g=K.toLanguages(G.preload[e]),h=0,i=g.length;i>h;h++)d.indexOf(g[h])<0&&d.push(g[h]);for(var j=[],k=0,l=d.length;l>k;k++){var m=!1,n=C[d[k]];if(n)for(var o=0,p=a.length;p>o;o++)n[a[o]]||(m=!0);else m=!0;m&&j.push(d[k])}j.length?B.sync._fetch(j,c,function(c,d){var e=a.length*j.length;K.each(a,function(a,c){G.ns.namespaces.indexOf(c)<0&&G.ns.namespaces.push(c),K.each(j,function(a,f){C[f]=C[f]||{},C[f][c]=d[f][c],e--,0===e&&b&&(G.useLocalStorage&&B.sync._storeLocal(C),b())})})}):b&&b()}function m(a,b,c){return"function"==typeof b?(c=b,b={}):b||(b={}),b.lng=a,f(b,c)}function n(){return A}function o(){function b(b,c,d){if(0!==c.length){var e="text";if(0===c.indexOf("[")){var f=c.split("]");c=f[1],e=f[0].substr(1,f[0].length-1)}c.indexOf(";")===c.length-1&&(c=c.substr(0,c.length-2));var g;if("html"===e)g=G.defaultValueFromContent?a.extend({defaultValue:b.html()},d):d,b.html(a.t(c,g));else if("text"===e)g=G.defaultValueFromContent?a.extend({defaultValue:b.text()},d):d,b.text(a.t(c,g));else if("prepend"===e)g=G.defaultValueFromContent?a.extend({defaultValue:b.html()},d):d,b.prepend(a.t(c,g));else if("append"===e)g=G.defaultValueFromContent?a.extend({defaultValue:b.html()},d):d,b.append(a.t(c,g));else if(0===e.indexOf("data-")){var h=e.substr("data-".length);g=G.defaultValueFromContent?a.extend({defaultValue:b.data(h)},d):d;var i=a.t(c,g);b.data(h,i),b.attr(e,i)}else g=G.defaultValueFromContent?a.extend({defaultValue:b.attr(e)},d):d,b.attr(e,a.t(c,g))}}function c(c,d){var e=c.attr(G.selectorAttr);if(e||"undefined"==typeof e||e===!1||(e=c.text()||c.val()),e){var f=c,g=c.data("i18n-target");if(g&&(f=c.find(g)||c),d||G.useDataAttrOptions!==!0||(d=c.data("i18n-options")),d=d||{},e.indexOf(";")>=0){var h=e.split(";");a.each(h,function(a,c){""!==c&&b(f,c,d)})}else b(f,e,d);G.useDataAttrOptions===!0&&c.data("i18n-options",d)}}a.t=a.t||u,a.fn.i18n=function(b){return this.each(function(){c(a(this),b);var d=a(this).find("["+G.selectorAttr+"]");d.each(function(){c(a(this),b)})})}}function p(a,b,c,d){if(!a)return a;if(d=d||b,a.indexOf(d.interpolationPrefix||G.interpolationPrefix)<0)return a;var e=d.interpolationPrefix?K.regexEscape(d.interpolationPrefix):G.interpolationPrefixEscaped,f=d.interpolationSuffix?K.regexEscape(d.interpolationSuffix):G.interpolationSuffixEscaped,g="HTML"+f;return K.each(b,function(b,h){var i=c?c+G.keyseparator+b:b;"object"==typeof h&&null!==h?a=p(a,h,i,d):d.escapeInterpolation||G.escapeInterpolation?(a=a.replace(new RegExp([e,i,g].join(""),"g"),h),a=a.replace(new RegExp([e,i,f].join(""),"g"),K.escape(h))):a=a.replace(new RegExp([e,i,f].join(""),"g"),h)}),a}function q(a,b){var c=",",d="{",e="}",f=K.extend({},b);for(delete f.postProcess;-1!=a.indexOf(G.reusePrefix)&&(D++,!(D>G.maxRecursion));){var g=a.lastIndexOf(G.reusePrefix),h=a.indexOf(G.reuseSuffix,g)+G.reuseSuffix.length,i=a.substring(g,h),j=i.replace(G.reusePrefix,"").replace(G.reuseSuffix,"");if(-1!=j.indexOf(c)){var k=j.indexOf(c);if(-1!=j.indexOf(d,k)&&-1!=j.indexOf(e,k)){var l=j.indexOf(d,k),m=j.indexOf(e,l)+e.length;try{f=K.extend(f,JSON.parse(j.substring(l,m))),j=j.substring(0,k)}catch(n){}}}var o=x(j,f);a=a.replace(i,o)}return a}function r(a){return a.context&&("string"==typeof a.context||"number"==typeof a.context)}function s(a){return void 0!==a.count&&"string"!=typeof a.count&&1!==a.count}function t(a,b){b=b||{};var c=v(a,b),d=y(a,b);return void 0!==d||d===c}function u(a,b){return b=b||{},F?(D=0,x.apply(null,arguments)):(K.log("i18next not finished initialization. you might have called t function before loading resources finished."),b.defaultValue||"")}function v(a,b){return void 0!==b.defaultValue?b.defaultValue:a}function w(){for(var a=[],b=1;b1)for(var d=0;d-1&&(e=c.split(G.nsseparator),i=e[0],c=e[1]),void 0===g&&G.sendMissing&&(b.lng?L.postMissing(h[0],i,c,f,h):L.postMissing(G.lng,i,c,f,h));var j=b.postProcess||G.postProcess;void 0!==g&&j&&N[j]&&(g=N[j](g,c,b));var k=f;if(f.indexOf(G.nsseparator)>-1&&(e=f.split(G.nsseparator),k=e[1]),k===c&&G.parseMissingKey&&(f=G.parseMissingKey(f)),void 0===g&&(f=p(f,b),f=q(f,b),j&&N[j])){var l=v(c,b);g=N[j](l,c,b)}return void 0!==g?g:f}function y(a,b){b=b||{};var c,d,e=v(a,b),f=E;if(!C)return e;if("cimode"===f[0].toLowerCase())return e;if(b.lng&&(f=K.toLanguages(b.lng),!C[f[0]])){var g=G.getAsync;G.getAsync=!1,B.sync.load(f,G,function(a,b){K.extend(C,b),G.getAsync=g})}var h=b.ns||G.ns.defaultNs;if(a.indexOf(G.nsseparator)>-1){var i=a.split(G.nsseparator);h=i[0],a=i[1]}if(r(b)){c=K.extend({},b),delete c.context,c.defaultValue=G.contextNotFound;var j=h+G.nsseparator+a+"_"+b.context;if(d=u(j,c),d!=G.contextNotFound)return p(d,{context:b.context})}if(s(b)){c=K.extend({},b),delete c.count,c.defaultValue=G.pluralNotFound;var k=h+G.nsseparator+a+G.pluralSuffix,l=M.get(f[0],b.count);if(l>=0?k=k+"_"+l:1===l&&(k=h+G.nsseparator+a),d=u(k,c),d!=G.pluralNotFound)return p(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix})}for(var m,n=a.split(G.keyseparator),o=0,t=f.length;t>o&&void 0===m;o++){for(var w=f[o],z=0,A=C[w]&&C[w][h];n[z];)A=A&&A[n[z]],z++;if(void 0!==A){var D=Object.prototype.toString.apply(A);if("string"==typeof A)A=p(A,b),A=q(A,b);else if("[object Array]"!==D||G.returnObjectTrees||b.returnObjectTrees){if(null===A&&G.fallbackOnNull===!0)A=void 0;else if(null!==A)if(G.returnObjectTrees||b.returnObjectTrees){if("[object Number]"!==D&&"[object Function]"!==D&&"[object RegExp]"!==D){var F="[object Array]"===D?[]:{};K.each(A,function(c){F[c]=x(h+G.nsseparator+a+G.keyseparator+c,b)}),A=F}}else G.objectTreeKeyHandler&&"function"==typeof G.objectTreeKeyHandler?A=G.objectTreeKeyHandler(a,A,w,h,b):(A="key '"+h+":"+a+" ("+w+")' returned an object instead of string.",K.log(A))}else A=A.join("\n"),A=p(A,b),A=q(A,b);"string"==typeof A&&""===A.trim()&&G.fallbackOnEmpty===!0&&(A=void 0),m=A}}if(void 0===m&&!b.isFallbackLookup&&(G.fallbackToDefaultNS===!0||G.fallbackNS&&G.fallbackNS.length>0))if(b.isFallbackLookup=!0,G.fallbackNS.length){for(var H=0,I=G.fallbackNS.length;I>H;H++)if(m=y(G.fallbackNS[H]+G.nsseparator+a,b)){var J=m.indexOf(G.nsseparator)>-1?m.split(G.nsseparator)[1]:m,L=e.indexOf(G.nsseparator)>-1?e.split(G.nsseparator)[1]:e;if(J!==L)break}}else m=y(a,b);return m}function z(){var a,b=[];if("undefined"!=typeof window&&(!function(){for(var a=window.location.search.substring(1),c=a.split("&"),d=0;d0){var f=c[d].substring(0,e),g=c[d].substring(e+1);b[f]=g}}}(),b[G.detectLngQS]&&(a=b[G.detectLngQS])),!a&&"undefined"!=typeof document&&G.useCookie){var c=K.cookie.read(G.cookieName);c&&(a=c)}return a||"undefined"==typeof navigator||(a=navigator.language?navigator.language:navigator.userLanguage),a||(a=G.fallbackLng[0]),a}Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>0&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&1/0!=d&&d!=-1/0&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=c;arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d))));for(var e=d>=0?Math.min(d,c-1):c-Math.abs(d);e>=0;e--)if(e in b&&b[e]===a)return e;return-1}),"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")});var A,B={},C={},D=0,E=[],F=!1,G={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:["dev"],fallbackNS:[],detectLngQS:"setLng",ns:"translation",fallbackOnNull:!0,fallbackOnEmpty:!1,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",cookieDomain:void 0,objectTreeKeyHandler:void 0,postProcess:void 0,parseMissingKey:void 0,shortcutFunction:"sprintf"},H={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},I={create:function(a,b,c,d){var e;if(c){var f=new Date;f.setTime(f.getTime()+60*c*1e3),e="; expires="+f.toGMTString()}else e="";d=d?"domain="+d+";":"",document.cookie=a+"="+b+e+";"+d+"path=/"},read:function(a){for(var b=a+"=",c=document.cookie.split(";"),d=0;d-1?c.push(a):b("rejecting non-whitelisted language: "+a)};if("string"==typeof a&&a.indexOf("-")>-1){var f=a.split("-");a=G.lowerCaseLng?f[0].toLowerCase()+"-"+f[1].toLowerCase():f[0].toLowerCase()+"-"+f[1].toUpperCase(),"unspecific"!==G.load&&e(a),"current"!==G.load&&e(f[0])}else e(a);for(var g=0;gg;g++)e[a[g]]||f.push(a[g]);f.length>0?L._fetch(f,b,function(a,b){K.extend(e,b),L._storeLocal(b),c(null,e)}):c(null,e)}):L._fetch(a,b,function(a,b){c(null,b)})},_loadLocal:function(a,b,c){var d={},e=(new Date).getTime();if(window.localStorage){var f=a.length;K.each(a,function(a,g){var h=window.localStorage.getItem("res_"+g);h&&(h=JSON.parse(h),h.i18nStamp&&h.i18nStamp+b.localStorageExpirationTime>e&&(d[g]=h)),f--,0===f&&c(null,d)})}},_storeLocal:function(a){if(window.localStorage)for(var b in a)a[b].i18nStamp=(new Date).getTime(),window.localStorage.setItem("res_"+b,JSON.stringify(a[b]))},_fetch:function(a,b,c){var d=b.ns,e={};if(b.dynamicLoad){var f=function(a,b){c(null,b)};if("function"==typeof b.customLoad)b.customLoad(a,d.namespaces,b,f);else{var g=p(b.resGetPath,{lng:a.join("+"),ns:d.namespaces.join("+")});K.ajax({url:g,success:function(a){K.log("loaded: "+g),f(null,a)},error:function(a,b,c){K.log("failed loading: "+g),f("failed loading resource.json error: "+c)},dataType:"json",async:b.getAsync})}}else{var h,i=d.namespaces.length*a.length;K.each(d.namespaces,function(d,f){K.each(a,function(a,d){var g=function(a,b){a&&(h=h||[],h.push(a)),e[d]=e[d]||{},e[d][f]=b,i--,0===i&&c(h,e)};"function"==typeof b.customLoad?b.customLoad(d,f,b,g):L._fetchOne(d,f,b,g)})})}},_fetchOne:function(a,b,c,d){var e=p(c.resGetPath,{lng:a,ns:b});K.ajax({url:e,success:function(a){K.log("loaded: "+e),d(null,a)},error:function(a,b,c){if(b&&200==b||a&&a.status&&200==a.status)K.log("There is a typo in: "+e);else if(b&&404==b||a&&a.status&&404==a.status)K.log("Does not exist: "+e);else{var f=b?b:a&&a.status?a.status:null;K.log(f+" when loading "+e)}d(c,{})},dataType:"json",async:c.getAsync})},postMissing:function(a,b,c,d,e){var f={};f[c]=d;var g=[];if("fallback"===G.sendMissingTo&&G.fallbackLng[0]!==!1)for(var h=0;hh;h++)g.push({lng:e[h],url:p(G.resPostPath,{lng:e[h],ns:b})});for(var j=0,k=g.length;k>j;j++){var l=g[j];K.ajax({url:l.url,type:G.sendType,data:f,success:function(){K.log("posted missing key '"+c+"' to: "+l.url);for(var a=c.split("."),e=0,f=C[l.lng][b];a[e];)f=f[a[e]]=e===a.length-1?d:f[a[e]]||{},e++},error:function(){K.log("failed posting missing key '"+c+"' to: "+l.url)},dataType:"json",async:G.postAsync})}}},M={rules:{ach:{name:"Acholi",numbers:[1,2],plurals:function(a){return Number(a>1)}},af:{name:"Afrikaans",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ak:{name:"Akan",numbers:[1,2],plurals:function(a){return Number(a>1)}},am:{name:"Amharic",numbers:[1,2],plurals:function(a){return Number(a>1)}},an:{name:"Aragonese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ar:{name:"Arabic",numbers:[0,1,2,3,11,100],plurals:function(a){return Number(0===a?0:1==a?1:2==a?2:a%100>=3&&10>=a%100?3:a%100>=11?4:5)}},arn:{name:"Mapudungun",numbers:[1,2],plurals:function(a){return Number(a>1)}},ast:{name:"Asturian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ay:{name:"Aymará",numbers:[1],plurals:function(){return 0}},az:{name:"Azerbaijani",numbers:[1,2],plurals:function(a){return Number(1!=a)}},be:{name:"Belarusian",numbers:[1,2,5],plurals:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},bg:{name:"Bulgarian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},bn:{name:"Bengali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},bo:{name:"Tibetan",numbers:[1],plurals:function(){return 0}},br:{name:"Breton",numbers:[1,2],plurals:function(a){return Number(a>1)}},bs:{name:"Bosnian",numbers:[1,2,5],plurals:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},ca:{name:"Catalan",numbers:[1,2],plurals:function(a){return Number(1!=a)}},cgg:{name:"Chiga",numbers:[1],plurals:function(){return 0}},cs:{name:"Czech",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)}},csb:{name:"Kashubian",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},cy:{name:"Welsh",numbers:[1,2,3,8],plurals:function(a){return Number(1==a?0:2==a?1:8!=a&&11!=a?2:3)}},da:{name:"Danish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},de:{name:"German",numbers:[1,2],plurals:function(a){return Number(1!=a)}},dz:{name:"Dzongkha",numbers:[1],plurals:function(){return 0}},el:{name:"Greek",numbers:[1,2],plurals:function(a){return Number(1!=a)}},en:{name:"English",numbers:[1,2],plurals:function(a){return Number(1!=a)}},eo:{name:"Esperanto",numbers:[1,2],plurals:function(a){return Number(1!=a)}},es:{name:"Spanish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},es_ar:{name:"Argentinean Spanish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},et:{name:"Estonian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},eu:{name:"Basque",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fa:{name:"Persian",numbers:[1],plurals:function(){return 0}},fi:{name:"Finnish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fil:{name:"Filipino",numbers:[1,2],plurals:function(a){return Number(a>1)}},fo:{name:"Faroese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fr:{name:"French",numbers:[1,2],plurals:function(a){return Number(a>1)}},fur:{name:"Friulian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fy:{name:"Frisian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ga:{name:"Irish",numbers:[1,2,3,7,11],plurals:function(a){return Number(1==a?0:2==a?1:7>a?2:11>a?3:4)}},gd:{name:"Scottish Gaelic",numbers:[1,2,3,20],plurals:function(a){return Number(1==a||11==a?0:2==a||12==a?1:a>2&&20>a?2:3)}},gl:{name:"Galician",numbers:[1,2],plurals:function(a){return Number(1!=a)}},gu:{name:"Gujarati",numbers:[1,2],plurals:function(a){return Number(1!=a)}},gun:{name:"Gun",numbers:[1,2],plurals:function(a){return Number(a>1)}},ha:{name:"Hausa",numbers:[1,2],plurals:function(a){return Number(1!=a)}},he:{name:"Hebrew",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hi:{name:"Hindi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hr:{name:"Croatian",numbers:[1,2,5],plurals:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},hu:{name:"Hungarian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hy:{name:"Armenian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ia:{name:"Interlingua",numbers:[1,2],plurals:function(a){return Number(1!=a)}},id:{name:"Indonesian",numbers:[1],plurals:function(){return 0}},is:{name:"Icelandic",numbers:[1,2],plurals:function(a){return Number(a%10!=1||a%100==11)}},it:{name:"Italian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ja:{name:"Japanese",numbers:[1],plurals:function(){return 0}},jbo:{name:"Lojban",numbers:[1],plurals:function(){return 0}},jv:{name:"Javanese",numbers:[0,1],plurals:function(a){return Number(0!==a)}},ka:{name:"Georgian",numbers:[1],plurals:function(){return 0}},kk:{name:"Kazakh",numbers:[1],plurals:function(){return 0}},km:{name:"Khmer",numbers:[1],plurals:function(){return 0}},kn:{name:"Kannada",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ko:{name:"Korean",numbers:[1],plurals:function(){return 0}},ku:{name:"Kurdish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},kw:{name:"Cornish",numbers:[1,2,3,4],plurals:function(a){return Number(1==a?0:2==a?1:3==a?2:3)}},ky:{name:"Kyrgyz",numbers:[1],plurals:function(){return 0}},lb:{name:"Letzeburgesch",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ln:{name:"Lingala",numbers:[1,2],plurals:function(a){return Number(a>1)}},lo:{name:"Lao",numbers:[1],plurals:function(){return 0}},lt:{name:"Lithuanian",numbers:[1,2,10],plurals:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&(10>a%100||a%100>=20)?1:2)}},lv:{name:"Latvian",numbers:[1,2,0],plurals:function(a){return Number(a%10==1&&a%100!=11?0:0!==a?1:2)}},mai:{name:"Maithili",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mfe:{name:"Mauritian Creole",numbers:[1,2],plurals:function(a){return Number(a>1)}},mg:{name:"Malagasy",numbers:[1,2],plurals:function(a){return Number(a>1)}},mi:{name:"Maori",numbers:[1,2],plurals:function(a){return Number(a>1)}},mk:{name:"Macedonian",numbers:[1,2],plurals:function(a){return Number(1==a||a%10==1?0:1)}},ml:{name:"Malayalam",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mn:{name:"Mongolian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mnk:{name:"Mandinka",numbers:[0,1,2],plurals:function(a){return Number(1==a?1:2)}},mr:{name:"Marathi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ms:{name:"Malay",numbers:[1],plurals:function(){return 0}},mt:{name:"Maltese",numbers:[1,2,11,20],plurals:function(a){return Number(1==a?0:0===a||a%100>1&&11>a%100?1:a%100>10&&20>a%100?2:3)}},nah:{name:"Nahuatl",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nap:{name:"Neapolitan",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nb:{name:"Norwegian Bokmal",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ne:{name:"Nepali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nl:{name:"Dutch",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nn:{name:"Norwegian Nynorsk",numbers:[1,2],plurals:function(a){return Number(1!=a)}},no:{name:"Norwegian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nso:{name:"Northern Sotho",numbers:[1,2],plurals:function(a){return Number(1!=a)}},oc:{name:"Occitan",numbers:[1,2],plurals:function(a){return Number(a>1)}},or:{name:"Oriya",numbers:[2,1],plurals:function(a){return Number(1!=a)}},pa:{name:"Punjabi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pap:{name:"Papiamento",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pl:{name:"Polish",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},pms:{name:"Piemontese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ps:{name:"Pashto",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pt:{name:"Portuguese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pt_br:{name:"Brazilian Portuguese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},rm:{name:"Romansh",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ro:{name:"Romanian",numbers:[1,2,20],plurals:function(a){return Number(1==a?0:0===a||a%100>0&&20>a%100?1:2)}},ru:{name:"Russian",numbers:[1,2,5],plurals:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},sah:{name:"Yakut",numbers:[1],plurals:function(){return 0}},sco:{name:"Scots",numbers:[1,2],plurals:function(a){return Number(1!=a)}},se:{name:"Northern Sami",numbers:[1,2],plurals:function(a){return Number(1!=a)}},si:{name:"Sinhala",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sk:{name:"Slovak",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)}},sl:{name:"Slovenian",numbers:[5,1,2,3],plurals:function(a){return Number(a%100==1?1:a%100==2?2:a%100==3||a%100==4?3:0)}},so:{name:"Somali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},son:{name:"Songhay",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sq:{name:"Albanian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sr:{name:"Serbian",numbers:[1,2,5],plurals:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},su:{name:"Sundanese",numbers:[1],plurals:function(){return 0}},sv:{name:"Swedish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sw:{name:"Swahili",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ta:{name:"Tamil",numbers:[1,2],plurals:function(a){return Number(1!=a)}},te:{name:"Telugu",numbers:[1,2],plurals:function(a){return Number(1!=a)}},tg:{name:"Tajik",numbers:[1,2],plurals:function(a){return Number(a>1)}},th:{name:"Thai",numbers:[1],plurals:function(){return 0}},ti:{name:"Tigrinya",numbers:[1,2],plurals:function(a){return Number(a>1)}},tk:{name:"Turkmen",numbers:[1,2],plurals:function(a){return Number(1!=a)}},tr:{name:"Turkish",numbers:[1,2],plurals:function(a){return Number(a>1)}},tt:{name:"Tatar",numbers:[1],plurals:function(){return 0}},ug:{name:"Uyghur",numbers:[1],plurals:function(){return 0}},uk:{name:"Ukrainian",numbers:[1,2,5],plurals:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},ur:{name:"Urdu",numbers:[1,2],plurals:function(a){return Number(1!=a)}},uz:{name:"Uzbek",numbers:[1,2],plurals:function(a){return Number(a>1)}},vi:{name:"Vietnamese",numbers:[1],plurals:function(){return 0}},wa:{name:"Walloon",numbers:[1,2],plurals:function(a){return Number(a>1)}},wo:{name:"Wolof",numbers:[1],plurals:function(){return 0}},yo:{name:"Yoruba",numbers:[1,2],plurals:function(a){return Number(1!=a)}},zh:{name:"Chinese",numbers:[1],plurals:function(){return 0}}},addRule:function(a,b){M.rules[a]=b},setCurrentLng:function(a){if(!M.currentRule||M.currentRule.lng!==a){var b=a.split("-");M.currentRule={lng:a,rule:M.rules[b[0]]}}},get:function(a,b){function c(b,c){var d;if(d=M.currentRule&&M.currentRule.lng===a?M.currentRule.rule:M.rules[b]){var e=d.plurals(c),f=d.numbers[e];return 2===d.numbers.length&&1===d.numbers[0]&&(2===f?f=-1:1===f&&(f=1)),f}return 1===c?"1":"-1"}var d=a.split("-");return c(d[0],b)}},N={},O=function(a,b){N[a]=b},P=function(){function a(a){return Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}function b(a,b){for(var c=[];b>0;c[--b]=a);return c.join("")}var c=function(){return c.cache.hasOwnProperty(arguments[0])||(c.cache[arguments[0]]=c.parse(arguments[0])),c.format.call(null,c.cache[arguments[0]],arguments)};return c.format=function(c,d){var e,f,g,h,i,j,k,l=1,m=c.length,n="",o=[];for(f=0;m>f;f++)if(n=a(c[f]),"string"===n)o.push(c[f]);else if("array"===n){if(h=c[f],h[2])for(e=d[l],g=0;g=0?"+"+e:e,j=h[4]?"0"==h[4]?"0":h[4].charAt(1):" ",k=h[6]-String(e).length,i=h[6]?b(j,k):"",o.push(h[5]?e+i:i+e)}return o.join("")},c.cache={},c.parse=function(a){for(var b=a,c=[],d=[],e=0;b;){if(null!==(c=/^[^\x25]+/.exec(b)))d.push(c[0]);else if(null!==(c=/^\x25{2}/.exec(b)))d.push("%");else{if(null===(c=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(b)))throw"[sprintf] huh?";if(c[2]){e|=1;var f=[],g=c[2],h=[];if(null===(h=/^([a-z_][a-z_\d]*)/i.exec(g)))throw"[sprintf] huh?";for(f.push(h[1]);""!==(g=g.substring(h[0].length));)if(null!==(h=/^\.([a-z_][a-z_\d]*)/i.exec(g)))f.push(h[1]);else{if(null===(h=/^\[(\d+)\]/.exec(g)))throw"[sprintf] huh?";f.push(h[1])}c[2]=f}else e|=2;if(3===e)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";d.push(c)}b=b.substring(c[0].length)}return d},c}(),Q=function(a,b){return b.unshift(a),P.apply(null,b)};return O("sprintf",function(a,b,c){return c.sprintf?"[object Array]"===Object.prototype.toString.apply(c.sprintf)?Q(a,c.sprintf):"object"==typeof c.sprintf?P(a,c.sprintf):a:a +}),B.init=f,B.setLng=m,B.preload=g,B.addResourceBundle=h,B.removeResourceBundle=i,B.loadNamespace=k,B.loadNamespaces=l,B.setDefaultNamespace=j,B.t=u,B.translate=u,B.exists=t,B.detectLanguage=K.detectLanguage,B.pluralExtensions=M,B.sync=L,B.functions=K,B.lng=n,B.addPostProcessor=O,B.options=G,a.i18n=B,a.t=B.t,B}); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd.withJQuery-1.7.4.js b/libs/i18next/release/i18next.amd.withJQuery-1.7.4.js new file mode 100644 index 00000000..2cb880ff --- /dev/null +++ b/libs/i18next/release/i18next.amd.withJQuery-1.7.4.js @@ -0,0 +1,2879 @@ +// i18next, v1.7.4 +// Copyright (c)2014 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function (root, factory) { + if (typeof exports === 'object') { + + var jquery = require('jquery'); + + module.exports = factory(jquery); + + } else if (typeof define === 'function' && define.amd) { + + define(['jquery'], factory); + + } +}(this, function ($) { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + // Add string trim for IE8. + if (typeof String.prototype.trim !== 'function') { + String.prototype.trim = function() { + return this.replace(/^\s+|\s+$/g, ''); + } + } + + var i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = [] + , initialized = false; + + sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + window.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + if ((status && status == 200) || (xhr && xhr.status && xhr.status == 200)) { + // file loaded but invalid json, stop waste time ! + f.error('There is a typo in: ' + url); + } else if ((status && status == 404) || (xhr && xhr.status && xhr.status == 404)) { + f.log('Does not exist: ' + url); + } else { + var theStatus = status ? status : ((xhr && xhr.status) ? xhr.status : null); + f.log(theStatus + ' when loading ' + url); + } + + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback' && o.fallbackLng[0] !== false) { + for (var i = 0; i < o.fallbackLng.length; i++) { + urls.push({lng: o.fallbackLng[i], url: applyReplacement(o.resPostPath, { lng: o.fallbackLng[i], ns: ns })}); + } + } else if (o.sendMissingTo === 'current' || (o.sendMissingTo === 'fallback' && o.fallbackLng[0] === false) ) { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + } + }; + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: ['dev'], + fallbackNS: [], + detectLngQS: 'setLng', + detectLngFromLocalStorage: false, + ns: 'translation', + fallbackOnNull: true, + fallbackOnEmpty: false, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + indefiniteSuffix: '_indefinite', + indefiniteNotFound: ['indefinite_not_found', Math.random()].join(''), + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + cookieDomain: undefined, + + objectTreeKeyHandler: undefined, + postProcess: undefined, + parseMissingKey: undefined, + missingKeyHandler: sync.postMissing, + + shortcutFunction: 'sprintf' // or: defaultValue + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _deepExtend(target, source) { + for (var prop in source) + if (prop in target) + _deepExtend(target[prop], source[prop]); + else + target[prop] = source[prop]; + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || Object.prototype.toString.apply(object) !== '[object Array]' || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + return JSON.parse(data); + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + // file: protocol always gives status code 0, so check for data + if (status === 200 || (status === 0 && data.text())) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes,domain) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + domain = (domain)? "domain="+domain+";" : ""; + document.cookie = name+"="+value+expires+";"+domain+"path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes,domain) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + deepExtend: _deepExtend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : (typeof document !== 'undefined' ? _ajax : function() {}), + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + error: function(str) { + if (typeof console !== "undefined") console.error(str); + }, + getCountyIndexOfLng: function(lng) { + var lng_index = 0; + if (lng === 'nb-NO' || lng === 'nn-NO') lng_index = 1; + return lng_index; + }, + toLanguages: function(lng) { + var log = this.log; + + var languages = []; + var whitelist = o.lngWhitelist || false; + var addLanguage = function(language){ + //reject langs not whitelisted + if(!whitelist || whitelist.indexOf(language) > -1){ + languages.push(language); + }else{ + log('rejecting non-whitelisted language: ' + language); + } + }; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + + if (o.load !== 'unspecific') addLanguage(lng); + if (o.load !== 'current') addLanguage(parts[this.getCountyIndexOfLng(lng)]); + } else { + addLanguage(lng); + } + + for (var i = 0; i < o.fallbackLng.length; i++) { + if (languages.indexOf(o.fallbackLng[i]) === -1 && o.fallbackLng[i]) languages.push(o.fallbackLng[i]); + } + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + }, + regexReplacementEscape: function(strOrFn) { + if (typeof strOrFn === 'string') { + return strOrFn.replace(/\$/g, "$$$$"); + } else { + return strOrFn; + } + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + delete o.fixLng; /* passed in each time */ + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // fallback languages + if (typeof o.fallbackLng == 'string' || typeof o.fallbackLng == 'boolean') { + o.fallbackLng = [o.fallbackLng]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + if (o.useCookie && f.cookie.read(o.cookieName) !== currentLng){ //cookie is unset or invalid + f.cookie.create(o.cookieName, currentLng, o.cookieExpirationTime, o.cookieDomain); + } + if (o.detectLngFromLocalStorage && typeof document !== 'undefined' && window.localstorage) { + window.localStorage.setItem('i18next_lng', currentLng); + } + + var lngTranslate = translate; + if (options.fixLng) { + lngTranslate = function(key, options) { + options = options || {}; + options.lng = options.lng || lngTranslate.lng; + return translate(key, options); + }; + lngTranslate.lng = currentLng; + } + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + initialized = true; + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + initialized = true; + + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources, deep) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + if (deep) { + f.deepExtend(resStore[lng][ns], resources); + } else { + f.extend(resStore[lng][ns], resources); + } + } + + function removeResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = {}; + } + + function addResource(lng, ns, key, value) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + var keys = key.split(o.keyseparator); + var x = 0; + var node = resStore[o.lng][ns]; + var origRef = node; + + while (keys[x]) { + if (x == keys.length - 1) + node[keys[x]] = value; + else { + if (node[keys[x]] == null) + node[keys[x]] = {}; + + node = node[keys[x]]; + } + x++; + } + } + + function addResources(lng, ns, resources) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + for (var m in resources) { + if (typeof resources[m] === 'string') addResource(lng, ns, m, resources[m]); + } + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, options, cb) { + if (typeof options === 'function') { + cb = options; + options = {}; + } else if (!options) { + options = {}; + } + + options.lng = lng; + return init(options, cb); + } + + function lng() { + return currentLng; + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else if (attr === 'prepend') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.prepend($.t(key, optionsToUse)); + } else if (attr === 'append') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.append($.t(key, optionsToUse)); + } else if (attr.indexOf("data-") === 0) { + var dataAttr = attr.substr(("data-").length); + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.data(dataAttr) }, options) : options; + var translated = $.t(key, optionsToUse); + //we change into the data cache + ele.data(dataAttr, translated); + //we change into the dom + ele.attr(attr, translated); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key && typeof key !== 'undefined' && key !== false) key = ele.text() || ele.val(); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + var hash = replacementHash.replace && typeof replacementHash.replace === 'object' ? replacementHash.replace : replacementHash; + f.each(hash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), f.regexReplacementEscape(value)); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(f.escape(value))); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(value)); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + if (index_of_end_of_closing <= index_of_opening) { + f.error('there is an missing closing in following translation value', translated); + return ''; + } + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, f.regexReplacementEscape(translated_token)); + } + return translated; + } + + function hasContext(options) { + return (options.context && (typeof options.context == 'string' || typeof options.context == 'number')); + } + + function needsPlural(options, lng) { + return (options.count !== undefined && typeof options.count != 'string' && pluralExtensions.needsPlural(lng, options.count)); + } + + function needsIndefiniteArticle(options) { + return (options.indefinite_article !== undefined && typeof options.indefinite_article != 'string' && options.indefinite_article); + } + + function exists(key, options) { + options = options || {}; + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + options = options || {}; + + if (!initialized) { + f.log('i18next not finished initialization. you might have called t function before loading resources finished.') + return options.defaultValue || ''; + }; + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _getDefaultValue(key, options) { + return (options.defaultValue !== undefined) ? options.defaultValue : key; + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(potentialKeys, options) { + if (options && typeof options !== 'object') { + if (o.shortcutFunction === 'sprintf') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else if (o.shortcutFunction === 'defaultValue') { + options = { + defaultValue: options + } + } + } else { + options = options || {}; + } + + if (potentialKeys === undefined || potentialKeys === null || potentialKeys === '') return ''; + + if (typeof potentialKeys == 'string') { + potentialKeys = [potentialKeys]; + } + + var key = potentialKeys[0]; + + if (potentialKeys.length > 1) { + for (var i = 0; i < potentialKeys.length; i++) { + key = potentialKeys[i]; + if (exists(key, options)) { + break; + } + } + } + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng, options.fallbackLng) : languages + , ns = options.ns || o.ns.defaultNs + , parts; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing && typeof o.missingKeyHandler === 'function') { + if (options.lng) { + o.missingKeyHandler(lngs[0], ns, key, notFound, lngs); + } else { + o.missingKeyHandler(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found !== undefined && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + // process notFound if function exists + var splitNotFound = notFound; + if (notFound.indexOf(o.nsseparator) > -1) { + parts = notFound.split(o.nsseparator); + splitNotFound = parts[1]; + } + if (splitNotFound === key && o.parseMissingKey) { + notFound = o.parseMissingKey(notFound); + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessor && postProcessors[postProcessor]) { + var val = _getDefaultValue(key, options); + found = postProcessors[postProcessor](val, key, options); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options) { + options = options || {}; + + var optionWithoutCount, translated + , notFound = _getDefaultValue(key, options) + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + // CI mode + if (lngs[0].toLowerCase() === 'cimode') return notFound; + + // passed in lng + if (options.lng) { + lngs = f.toLanguages(options.lng, options.fallbackLng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options, lngs[0])) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.count; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(lngs[0], options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + + translated = translate(pluralKey, optionWithoutCount); + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } // else continue translation with original/singular key + } + + if (needsIndefiniteArticle(options)) { + var optionsWithoutIndef = f.extend({}, options); + delete optionsWithoutIndef.indefinite_article; + optionsWithoutIndef.defaultValue = o.indefiniteNotFound; + // If we don't have a count, we want the indefinite, if we do have a count, and needsPlural is false + var indefiniteKey = ns + o.nsseparator + key + (((options.count && !needsPlural(options, lngs[0])) || !options.count) ? o.indefiniteSuffix : ""); + translated = translate(indefiniteKey, optionsWithoutIndef); + if (translated != o.indefiniteNotFound) { + return translated; + } + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + var valueType = Object.prototype.toString.apply(value); + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (valueType === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + if (o.objectTreeKeyHandler && typeof o.objectTreeKeyHandler == 'function') { + value = o.objectTreeKeyHandler(key, value, l, ns, options); + } else { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned an object instead of string.'; + f.log(value); + } + } else if (valueType !== '[object Number]' && valueType !== '[object Function]' && valueType !== '[object RegExp]') { + var copy = (valueType === '[object Array]') ? [] : {}; // apply child translation on a copy + f.each(value, function(m) { + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + }); + value = copy; + } + } + + if (typeof value === 'string' && value.trim() === '' && o.fallbackOnEmpty === true) + value = undefined; + + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length > 0))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + options.isFallbackLookup = false; + } + + return found; + } + function detectLanguage() { + var detectedLng; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var parms = query.split('&'); + for (var i=0; i 0) { + var key = parms[i].substring(0,pos); + var val = parms[i].substring(pos+1); + qsParm[key] = val; + } + } + })(); + if (qsParm[o.detectLngQS]) { + detectedLng = qsParm[o.detectLngQS]; + } + } + + // get from cookie + if (!detectedLng && typeof document !== 'undefined' && o.useCookie ) { + var c = f.cookie.read(o.cookieName); + if (c) detectedLng = c; + } + + // get from localstorage + if (!detectedLng && typeof document !== 'undefined' && window.localstorage && o.detectLngFromLocalStorage) { + detectedLng = window.localStorage.getItem('i18next_lng'); + } + + // get from navigator + if (!detectedLng && typeof navigator !== 'undefined') { + detectedLng = (navigator.language) ? navigator.language : navigator.userLanguage; + } + + //fallback + if(!detectedLng){ + detectedLng = o.fallbackLng[0]; + } + + return detectedLng; + } + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + var pluralExtensions = { + + rules: { + "ach": { + "name": "Acholi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "af": { + "name": "Afrikaans", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ak": { + "name": "Akan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "am": { + "name": "Amharic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "an": { + "name": "Aragonese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ar": { + "name": "Arabic", + "numbers": [ + 0, + 1, + 2, + 3, + 11, + 100 + ], + "plurals": function(n) { return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5); } + }, + "arn": { + "name": "Mapudungun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ast": { + "name": "Asturian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ay": { + "name": "Aymar\u00e1", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "az": { + "name": "Azerbaijani", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "be": { + "name": "Belarusian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "bg": { + "name": "Bulgarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bn": { + "name": "Bengali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "bo": { + "name": "Tibetan", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "br": { + "name": "Breton", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "bs": { + "name": "Bosnian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ca": { + "name": "Catalan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "cgg": { + "name": "Chiga", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "cs": { + "name": "Czech", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "csb": { + "name": "Kashubian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "cy": { + "name": "Welsh", + "numbers": [ + 1, + 2, + 3, + 8 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3); } + }, + "da": { + "name": "Danish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "de": { + "name": "German", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "dz": { + "name": "Dzongkha", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "el": { + "name": "Greek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "en": { + "name": "English", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eo": { + "name": "Esperanto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es": { + "name": "Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "es_ar": { + "name": "Argentinean Spanish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "et": { + "name": "Estonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "eu": { + "name": "Basque", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fa": { + "name": "Persian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "fi": { + "name": "Finnish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fil": { + "name": "Filipino", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "fo": { + "name": "Faroese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fr": { + "name": "French", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n >= 2); } + }, + "fur": { + "name": "Friulian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "fy": { + "name": "Frisian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ga": { + "name": "Irish", + "numbers": [ + 1, + 2, + 3, + 7, + 11 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;} + }, + "gd": { + "name": "Scottish Gaelic", + "numbers": [ + 1, + 2, + 3, + 20 + ], + "plurals": function(n) { return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3); } + }, + "gl": { + "name": "Galician", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gu": { + "name": "Gujarati", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "gun": { + "name": "Gun", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "ha": { + "name": "Hausa", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "he": { + "name": "Hebrew", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hi": { + "name": "Hindi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hr": { + "name": "Croatian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "hu": { + "name": "Hungarian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "hy": { + "name": "Armenian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ia": { + "name": "Interlingua", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "id": { + "name": "Indonesian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "is": { + "name": "Icelandic", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n%10!=1 || n%100==11); } + }, + "it": { + "name": "Italian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ja": { + "name": "Japanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jbo": { + "name": "Lojban", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "jv": { + "name": "Javanese", + "numbers": [ + 0, + 1 + ], + "plurals": function(n) { return Number(n !== 0); } + }, + "ka": { + "name": "Georgian", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kk": { + "name": "Kazakh", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "km": { + "name": "Khmer", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "kn": { + "name": "Kannada", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ko": { + "name": "Korean", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ku": { + "name": "Kurdish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "kw": { + "name": "Cornish", + "numbers": [ + 1, + 2, + 3, + 4 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3); } + }, + "ky": { + "name": "Kyrgyz", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lb": { + "name": "Letzeburgesch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ln": { + "name": "Lingala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "lo": { + "name": "Lao", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "lt": { + "name": "Lithuanian", + "numbers": [ + 1, + 2, + 10 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "lv": { + "name": "Latvian", + "numbers": [ + 1, + 2, + 0 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2); } + }, + "mai": { + "name": "Maithili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mfe": { + "name": "Mauritian Creole", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mg": { + "name": "Malagasy", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mi": { + "name": "Maori", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "mk": { + "name": "Macedonian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n==1 || n%10==1 ? 0 : 1); } + }, + "ml": { + "name": "Malayalam", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mn": { + "name": "Mongolian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "mnk": { + "name": "Mandinka", + "numbers": [ + 0, + 1, + 2 + ], + "plurals": function(n) { return Number(0 ? 0 : n==1 ? 1 : 2); } + }, + "mr": { + "name": "Marathi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ms": { + "name": "Malay", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "mt": { + "name": "Maltese", + "numbers": [ + 1, + 2, + 11, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3); } + }, + "nah": { + "name": "Nahuatl", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nap": { + "name": "Neapolitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nb": { + "name": "Norwegian Bokmal", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ne": { + "name": "Nepali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nl": { + "name": "Dutch", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nn": { + "name": "Norwegian Nynorsk", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "no": { + "name": "Norwegian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "nso": { + "name": "Northern Sotho", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "oc": { + "name": "Occitan", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "or": { + "name": "Oriya", + "numbers": [ + 2, + 1 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pa": { + "name": "Punjabi", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pap": { + "name": "Papiamento", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pl": { + "name": "Polish", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "pms": { + "name": "Piemontese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ps": { + "name": "Pashto", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt": { + "name": "Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "pt_br": { + "name": "Brazilian Portuguese", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "rm": { + "name": "Romansh", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ro": { + "name": "Romanian", + "numbers": [ + 1, + 2, + 20 + ], + "plurals": function(n) { return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2); } + }, + "ru": { + "name": "Russian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "sah": { + "name": "Yakut", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sco": { + "name": "Scots", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "se": { + "name": "Northern Sami", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "si": { + "name": "Sinhala", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sk": { + "name": "Slovak", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2); } + }, + "sl": { + "name": "Slovenian", + "numbers": [ + 5, + 1, + 2, + 3 + ], + "plurals": function(n) { return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }, + "so": { + "name": "Somali", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "son": { + "name": "Songhay", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sq": { + "name": "Albanian", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sr": { + "name": "Serbian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "su": { + "name": "Sundanese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "sv": { + "name": "Swedish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "sw": { + "name": "Swahili", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "ta": { + "name": "Tamil", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "te": { + "name": "Telugu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tg": { + "name": "Tajik", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "th": { + "name": "Thai", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ti": { + "name": "Tigrinya", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tk": { + "name": "Turkmen", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "tr": { + "name": "Turkish", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "tt": { + "name": "Tatar", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "ug": { + "name": "Uyghur", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "uk": { + "name": "Ukrainian", + "numbers": [ + 1, + 2, + 5 + ], + "plurals": function(n) { return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); } + }, + "ur": { + "name": "Urdu", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "uz": { + "name": "Uzbek", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "vi": { + "name": "Vietnamese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "wa": { + "name": "Walloon", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n > 1); } + }, + "wo": { + "name": "Wolof", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + }, + "yo": { + "name": "Yoruba", + "numbers": [ + 1, + 2 + ], + "plurals": function(n) { return Number(n != 1); } + }, + "zh": { + "name": "Chinese", + "numbers": [ + 1 + ], + "plurals": function(n) { return 0; } + } + }, + + // for demonstration only sl and ar is added but you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + needsPlural: function(lng, count) { + var parts = lng.split('-'); + + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[parts[f.getCountyIndexOfLng(lng)]]; + } + + if (ext && ext.numbers.length <= 1) { + return false; + } else { + return this.get(lng, count) !== 1; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i; + if (ext.noAbs) { + i = ext.plurals(c); + } else { + i = ext.plurals(Math.abs(c)); + } + + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[f.getCountyIndexOfLng(lng)], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.addResource = addResource; + i18n.addResources = addResources; + i18n.removeResourceBundle = removeResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + + $.i18n = i18n; + $.t = i18n.t; + + return i18n; + +})); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd.withJQuery-1.7.4.min.js b/libs/i18next/release/i18next.amd.withJQuery-1.7.4.min.js new file mode 100644 index 00000000..36a97bb6 --- /dev/null +++ b/libs/i18next/release/i18next.amd.withJQuery-1.7.4.min.js @@ -0,0 +1,6 @@ +// i18next, v1.7.4 +// Copyright (c)2014 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +!function(a,b){if("object"==typeof exports){var c=require("jquery");module.exports=b(c)}else"function"==typeof define&&define.amd&&define(["jquery"],b)}(this,function(a){function b(a,b){if(!b||"function"==typeof b)return a;for(var c in b)a[c]=b[c];return a}function c(a,b){for(var d in b)d in a?c(a[d],b[d]):a[d]=b[d];return a}function d(a,b,c){var d,e=0,f=a.length,g=void 0===f||"[object Array]"!==Object.prototype.toString.apply(a)||"function"==typeof a;if(c)if(g){for(d in a)if(b.apply(a[d],c)===!1)break}else for(;f>e&&b.apply(a[e++],c)!==!1;);else if(g){for(d in a)if(b.call(a[d],d,a[d])===!1)break}else for(;f>e&&b.call(a[e],e,a[e++])!==!1;);return a}function e(a){return"string"==typeof a?a.replace(/[&<>"'\/]/g,function(a){return L[a]}):a}function f(a){var b=function(a){if(window.XMLHttpRequest)return a(null,new XMLHttpRequest);if(window.ActiveXObject)try{return a(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(b){return a(null,new ActiveXObject("Microsoft.XMLHTTP"))}return a(new Error)},c=function(a){if("string"==typeof a)return a;var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")},d=function(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;cd?b+=String.fromCharCode(d):d>127&&2048>d?(b+=String.fromCharCode(192|d>>6),b+=String.fromCharCode(128|63&d)):(b+=String.fromCharCode(224|d>>12),b+=String.fromCharCode(128|63&d>>6),b+=String.fromCharCode(128|63&d))}return b},e=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";a=d(a);var c,e,f,g,h,i,j,k="",l=0;do c=a.charCodeAt(l++),e=a.charCodeAt(l++),f=a.charCodeAt(l++),g=c>>2,h=(3&c)<<4|e>>4,i=(15&e)<<2|f>>6,j=63&f,isNaN(e)?i=j=64:isNaN(f)&&(j=64),k+=b.charAt(g)+b.charAt(h)+b.charAt(i)+b.charAt(j),c=e=f="",g=h=i=j="";while(l1&&(d+=d.indexOf("?")>-1?"&"+k:"?"+k),e.jsonp){var l=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=d,l.appendChild(m),void 0}}b(function(b,c){if(b)return h(b);c.open(a,d,e.async);for(var f in j)j.hasOwnProperty(f)&&c.setRequestHeader(f,j[f]);c.onreadystatechange=function(){if(4===c.readyState){var a=c.responseText||"";if(!h)return;h(c.status,{text:function(){return a},json:function(){return JSON.parse(a)}})}},c.send(i)})},h={authBasic:function(a,b){g.headers.Authorization="Basic "+e(a+":"+b)},connect:function(a,b,c){return g("CONNECT",a,b,c)},del:function(a,b,c){return g("DELETE",a,b,c)},get:function(a,b,c){return g("GET",a,b,c)},head:function(a,b,c){return g("HEAD",a,b,c)},headers:function(a){g.headers=a||{}},isAllowed:function(a,b,c){this.options(a,function(a,d){c(-1!==d.text().indexOf(b))})},options:function(a,b,c){return g("OPTIONS",a,b,c)},patch:function(a,b,c){return g("PATCH",a,b,c)},post:function(a,b,c){return g("POST",a,b,c)},put:function(a,b,c){return g("PUT",a,b,c)},trace:function(a,b,c){return g("TRACE",a,b,c)}},i=a.type?a.type.toLowerCase():"get";h[i](a.url,a,function(b,c){200===b||0===b&&c.text()?a.success(c.json(),b,null):a.error(c.text(),b,null)})}function g(b,c){"function"==typeof b&&(c=b,b={}),b=b||{},O.extend(K,b),delete K.fixLng,"string"==typeof K.ns&&(K.ns={namespaces:[K.ns],defaultNs:K.ns}),"string"==typeof K.fallbackNS&&(K.fallbackNS=[K.fallbackNS]),("string"==typeof K.fallbackLng||"boolean"==typeof K.fallbackLng)&&(K.fallbackLng=[K.fallbackLng]),K.interpolationPrefixEscaped=O.regexEscape(K.interpolationPrefix),K.interpolationSuffixEscaped=O.regexEscape(K.interpolationSuffix),K.lng||(K.lng=O.detectLanguage()),I=O.toLanguages(K.lng),E=I[0],O.log("currentLng set to: "+E),K.useCookie&&O.cookie.read(K.cookieName)!==E&&O.cookie.create(K.cookieName,E,K.cookieExpirationTime,K.cookieDomain),K.detectLngFromLocalStorage&&"undefined"!=typeof document&&window.localstorage&&window.localStorage.setItem("i18next_lng",E);var d=y;b.fixLng&&(d=function(a,b){return b=b||{},b.lng=b.lng||d.lng,y(a,b)},d.lng=E),P.setCurrentLng(E),a&&K.setJqueryExt&&r();var e;if(a&&a.Deferred&&(e=a.Deferred()),!K.resStore){var f=O.toLanguages(K.lng);"string"==typeof K.preload&&(K.preload=[K.preload]);for(var g=0,h=K.preload.length;h>g;g++)for(var i=O.toLanguages(K.preload[g]),j=0,k=i.length;k>j;j++)f.indexOf(i[j])<0&&f.push(i[j]);return F.sync.load(f,K,function(a,b){G=b,J=!0,c&&c(d),e&&e.resolve(d)}),e?e.promise():void 0}return G=K.resStore,J=!0,c&&c(d),e&&e.resolve(d),e?e.promise():void 0}function h(a,b){"string"==typeof a&&(a=[a]);for(var c=0,d=a.length;d>c;c++)K.preload.indexOf(a[c])<0&&K.preload.push(a[c]);return g(b)}function i(a,b,c,d){"string"!=typeof b?(c=b,b=K.ns.defaultNs):K.ns.namespaces.indexOf(b)<0&&K.ns.namespaces.push(b),G[a]=G[a]||{},G[a][b]=G[a][b]||{},d?O.deepExtend(G[a][b],c):O.extend(G[a][b],c)}function j(a,b){"string"!=typeof b&&(b=K.ns.defaultNs),G[a]=G[a]||{},G[a][b]={}}function k(a,b,c,d){"string"!=typeof b?(resource=b,b=K.ns.defaultNs):K.ns.namespaces.indexOf(b)<0&&K.ns.namespaces.push(b),G[a]=G[a]||{},G[a][b]=G[a][b]||{};for(var e=c.split(K.keyseparator),f=0,g=G[K.lng][b];e[f];)f==e.length-1?g[e[f]]=d:(null==g[e[f]]&&(g[e[f]]={}),g=g[e[f]]),f++}function l(a,b,c){"string"!=typeof b?(resource=b,b=K.ns.defaultNs):K.ns.namespaces.indexOf(b)<0&&K.ns.namespaces.push(b);for(var d in c)"string"==typeof c[d]&&k(a,b,d,c[d])}function m(a){K.ns.defaultNs=a}function n(a,b){o([a],b)}function o(a,b){var c={dynamicLoad:K.dynamicLoad,resGetPath:K.resGetPath,getAsync:K.getAsync,customLoad:K.customLoad,ns:{namespaces:a,defaultNs:""}},d=O.toLanguages(K.lng);"string"==typeof K.preload&&(K.preload=[K.preload]);for(var e=0,f=K.preload.length;f>e;e++)for(var g=O.toLanguages(K.preload[e]),h=0,i=g.length;i>h;h++)d.indexOf(g[h])<0&&d.push(g[h]);for(var j=[],k=0,l=d.length;l>k;k++){var m=!1,n=G[d[k]];if(n)for(var o=0,p=a.length;p>o;o++)n[a[o]]||(m=!0);else m=!0;m&&j.push(d[k])}j.length?F.sync._fetch(j,c,function(c,d){var e=a.length*j.length;O.each(a,function(a,c){K.ns.namespaces.indexOf(c)<0&&K.ns.namespaces.push(c),O.each(j,function(a,f){G[f]=G[f]||{},G[f][c]=d[f][c],e--,0===e&&b&&(K.useLocalStorage&&F.sync._storeLocal(G),b())})})}):b&&b()}function p(a,b,c){return"function"==typeof b?(c=b,b={}):b||(b={}),b.lng=a,g(b,c)}function q(){return E}function r(){function b(b,c,d){if(0!==c.length){var e="text";if(0===c.indexOf("[")){var f=c.split("]");c=f[1],e=f[0].substr(1,f[0].length-1)}c.indexOf(";")===c.length-1&&(c=c.substr(0,c.length-2));var g;if("html"===e)g=K.defaultValueFromContent?a.extend({defaultValue:b.html()},d):d,b.html(a.t(c,g));else if("text"===e)g=K.defaultValueFromContent?a.extend({defaultValue:b.text()},d):d,b.text(a.t(c,g));else if("prepend"===e)g=K.defaultValueFromContent?a.extend({defaultValue:b.html()},d):d,b.prepend(a.t(c,g));else if("append"===e)g=K.defaultValueFromContent?a.extend({defaultValue:b.html()},d):d,b.append(a.t(c,g));else if(0===e.indexOf("data-")){var h=e.substr("data-".length);g=K.defaultValueFromContent?a.extend({defaultValue:b.data(h)},d):d;var i=a.t(c,g);b.data(h,i),b.attr(e,i)}else g=K.defaultValueFromContent?a.extend({defaultValue:b.attr(e)},d):d,b.attr(e,a.t(c,g))}}function c(c,d){var e=c.attr(K.selectorAttr);if(e||"undefined"==typeof e||e===!1||(e=c.text()||c.val()),e){var f=c,g=c.data("i18n-target");if(g&&(f=c.find(g)||c),d||K.useDataAttrOptions!==!0||(d=c.data("i18n-options")),d=d||{},e.indexOf(";")>=0){var h=e.split(";");a.each(h,function(a,c){""!==c&&b(f,c,d)})}else b(f,e,d);K.useDataAttrOptions===!0&&c.data("i18n-options",d)}}a.t=a.t||y,a.fn.i18n=function(b){return this.each(function(){c(a(this),b);var d=a(this).find("["+K.selectorAttr+"]");d.each(function(){c(a(this),b)})})}}function s(a,b,c,d){if(!a)return a;if(d=d||b,a.indexOf(d.interpolationPrefix||K.interpolationPrefix)<0)return a;var e=d.interpolationPrefix?O.regexEscape(d.interpolationPrefix):K.interpolationPrefixEscaped,f=d.interpolationSuffix?O.regexEscape(d.interpolationSuffix):K.interpolationSuffixEscaped,g="HTML"+f,h=b.replace&&"object"==typeof b.replace?b.replace:b;return O.each(h,function(b,h){var i=c?c+K.keyseparator+b:b;"object"==typeof h&&null!==h?a=s(a,h,i,d):d.escapeInterpolation||K.escapeInterpolation?(a=a.replace(new RegExp([e,i,g].join(""),"g"),O.regexReplacementEscape(h)),a=a.replace(new RegExp([e,i,f].join(""),"g"),O.regexReplacementEscape(O.escape(h)))):a=a.replace(new RegExp([e,i,f].join(""),"g"),O.regexReplacementEscape(h))}),a}function t(a,b){var c=",",d="{",e="}",f=O.extend({},b);for(delete f.postProcess;-1!=a.indexOf(K.reusePrefix)&&(H++,!(H>K.maxRecursion));){var g=a.lastIndexOf(K.reusePrefix),h=a.indexOf(K.reuseSuffix,g)+K.reuseSuffix.length,i=a.substring(g,h),j=i.replace(K.reusePrefix,"").replace(K.reuseSuffix,"");if(g>=h)return O.error("there is an missing closing in following translation value",a),"";if(-1!=j.indexOf(c)){var k=j.indexOf(c);if(-1!=j.indexOf(d,k)&&-1!=j.indexOf(e,k)){var l=j.indexOf(d,k),m=j.indexOf(e,l)+e.length;try{f=O.extend(f,JSON.parse(j.substring(l,m))),j=j.substring(0,k)}catch(n){}}}var o=B(j,f);a=a.replace(i,O.regexReplacementEscape(o))}return a}function u(a){return a.context&&("string"==typeof a.context||"number"==typeof a.context)}function v(a,b){return void 0!==a.count&&"string"!=typeof a.count&&P.needsPlural(b,a.count)}function w(a){return void 0!==a.indefinite_article&&"string"!=typeof a.indefinite_article&&a.indefinite_article}function x(a,b){b=b||{};var c=z(a,b),d=C(a,b);return void 0!==d||d===c}function y(a,b){return b=b||{},J?(H=0,B.apply(null,arguments)):(O.log("i18next not finished initialization. you might have called t function before loading resources finished."),b.defaultValue||"")}function z(a,b){return void 0!==b.defaultValue?b.defaultValue:a}function A(){for(var a=[],b=1;b1)for(var d=0;d-1&&(e=c.split(K.nsseparator),i=e[0],c=e[1]),void 0===g&&K.sendMissing&&"function"==typeof K.missingKeyHandler&&(b.lng?K.missingKeyHandler(h[0],i,c,f,h):K.missingKeyHandler(K.lng,i,c,f,h));var j=b.postProcess||K.postProcess;void 0!==g&&j&&Q[j]&&(g=Q[j](g,c,b));var k=f;if(f.indexOf(K.nsseparator)>-1&&(e=f.split(K.nsseparator),k=e[1]),k===c&&K.parseMissingKey&&(f=K.parseMissingKey(f)),void 0===g&&(f=s(f,b),f=t(f,b),j&&Q[j])){var l=z(c,b);g=Q[j](l,c,b)}return void 0!==g?g:f}function C(a,b){b=b||{};var c,d,e=z(a,b),f=I;if(!G)return e;if("cimode"===f[0].toLowerCase())return e;if(b.lng&&(f=O.toLanguages(b.lng,b.fallbackLng),!G[f[0]])){var g=K.getAsync;K.getAsync=!1,F.sync.load(f,K,function(a,b){O.extend(G,b),K.getAsync=g})}var h=b.ns||K.ns.defaultNs;if(a.indexOf(K.nsseparator)>-1){var i=a.split(K.nsseparator);h=i[0],a=i[1]}if(u(b)){c=O.extend({},b),delete c.context,c.defaultValue=K.contextNotFound;var j=h+K.nsseparator+a+"_"+b.context;if(d=y(j,c),d!=K.contextNotFound)return s(d,{context:b.context})}if(v(b,f[0])){c=O.extend({},b),delete c.count,c.defaultValue=K.pluralNotFound;var k=h+K.nsseparator+a+K.pluralSuffix,l=P.get(f[0],b.count);if(l>=0?k=k+"_"+l:1===l&&(k=h+K.nsseparator+a),d=y(k,c),d!=K.pluralNotFound)return s(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix})}if(w(b)){var m=O.extend({},b);delete m.indefinite_article,m.defaultValue=K.indefiniteNotFound;var n=h+K.nsseparator+a+(b.count&&!v(b,f[0])||!b.count?K.indefiniteSuffix:"");if(d=y(n,m),d!=K.indefiniteNotFound)return d}for(var o,p=a.split(K.keyseparator),q=0,r=f.length;r>q&&void 0===o;q++){for(var x=f[q],A=0,D=G[x]&&G[x][h];p[A];)D=D&&D[p[A]],A++;if(void 0!==D){var E=Object.prototype.toString.apply(D);if("string"==typeof D)D=s(D,b),D=t(D,b);else if("[object Array]"!==E||K.returnObjectTrees||b.returnObjectTrees){if(null===D&&K.fallbackOnNull===!0)D=void 0;else if(null!==D)if(K.returnObjectTrees||b.returnObjectTrees){if("[object Number]"!==E&&"[object Function]"!==E&&"[object RegExp]"!==E){var H="[object Array]"===E?[]:{};O.each(D,function(c){H[c]=B(h+K.nsseparator+a+K.keyseparator+c,b)}),D=H}}else K.objectTreeKeyHandler&&"function"==typeof K.objectTreeKeyHandler?D=K.objectTreeKeyHandler(a,D,x,h,b):(D="key '"+h+":"+a+" ("+x+")' "+"returned an object instead of string.",O.log(D))}else D=D.join("\n"),D=s(D,b),D=t(D,b);"string"==typeof D&&""===D.trim()&&K.fallbackOnEmpty===!0&&(D=void 0),o=D}}if(void 0===o&&!b.isFallbackLookup&&(K.fallbackToDefaultNS===!0||K.fallbackNS&&K.fallbackNS.length>0)){if(b.isFallbackLookup=!0,K.fallbackNS.length){for(var J=0,L=K.fallbackNS.length;L>J;J++)if(o=C(K.fallbackNS[J]+K.nsseparator+a,b)){var M=o.indexOf(K.nsseparator)>-1?o.split(K.nsseparator)[1]:o,N=e.indexOf(K.nsseparator)>-1?e.split(K.nsseparator)[1]:e;if(M!==N)break}}else o=C(a,b);b.isFallbackLookup=!1}return o}function D(){var a,b=[];if("undefined"!=typeof window&&(!function(){for(var a=window.location.search.substring(1),c=a.split("&"),d=0;d0){var f=c[d].substring(0,e),g=c[d].substring(e+1);b[f]=g}}}(),b[K.detectLngQS]&&(a=b[K.detectLngQS])),!a&&"undefined"!=typeof document&&K.useCookie){var c=O.cookie.read(K.cookieName);c&&(a=c)}return!a&&"undefined"!=typeof document&&window.localstorage&&K.detectLngFromLocalStorage&&(a=window.localStorage.getItem("i18next_lng")),a||"undefined"==typeof navigator||(a=navigator.language?navigator.language:navigator.userLanguage),a||(a=K.fallbackLng[0]),a}Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>0&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&1/0!=d&&d!=-1/0&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=c;arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d))));for(var e=d>=0?Math.min(d,c-1):c-Math.abs(d);e>=0;e--)if(e in b&&b[e]===a)return e;return-1}),"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")});var E,F={},G={},H=0,I=[],J=!1;sync={load:function(a,b,c){b.useLocalStorage?sync._loadLocal(a,b,function(d,e){for(var f=[],g=0,h=a.length;h>g;g++)e[a[g]]||f.push(a[g]);f.length>0?sync._fetch(f,b,function(a,b){O.extend(e,b),sync._storeLocal(b),c(null,e)}):c(null,e)}):sync._fetch(a,b,function(a,b){c(null,b)})},_loadLocal:function(a,b,c){var d={},e=(new Date).getTime();if(window.localStorage){var f=a.length;O.each(a,function(a,g){var h=window.localStorage.getItem("res_"+g);h&&(h=JSON.parse(h),h.i18nStamp&&h.i18nStamp+b.localStorageExpirationTime>e&&(d[g]=h)),f--,0===f&&c(null,d)})}},_storeLocal:function(a){if(window.localStorage)for(var b in a)a[b].i18nStamp=(new Date).getTime(),window.localStorage.setItem("res_"+b,JSON.stringify(a[b]))},_fetch:function(a,b,c){var d=b.ns,e={};if(b.dynamicLoad){var f=function(a,b){c(null,b)};if("function"==typeof b.customLoad)b.customLoad(a,d.namespaces,b,f);else{var g=s(b.resGetPath,{lng:a.join("+"),ns:d.namespaces.join("+")});O.ajax({url:g,success:function(a){O.log("loaded: "+g),f(null,a)},error:function(a,b,c){O.log("failed loading: "+g),f("failed loading resource.json error: "+c)},dataType:"json",async:b.getAsync})}}else{var h,i=d.namespaces.length*a.length;O.each(d.namespaces,function(d,f){O.each(a,function(a,d){var g=function(a,b){a&&(h=h||[],h.push(a)),e[d]=e[d]||{},e[d][f]=b,i--,0===i&&c(h,e)};"function"==typeof b.customLoad?b.customLoad(d,f,b,g):sync._fetchOne(d,f,b,g)})})}},_fetchOne:function(a,b,c,d){var e=s(c.resGetPath,{lng:a,ns:b});O.ajax({url:e,success:function(a){O.log("loaded: "+e),d(null,a)},error:function(a,b,c){if(b&&200==b||a&&a.status&&200==a.status)O.error("There is a typo in: "+e);else if(b&&404==b||a&&a.status&&404==a.status)O.log("Does not exist: "+e);else{var f=b?b:a&&a.status?a.status:null;O.log(f+" when loading "+e)}d(c,{})},dataType:"json",async:c.getAsync})},postMissing:function(a,b,c,d,e){var f={};f[c]=d;var g=[];if("fallback"===K.sendMissingTo&&K.fallbackLng[0]!==!1)for(var h=0;hh;h++)g.push({lng:e[h],url:s(K.resPostPath,{lng:e[h],ns:b})});for(var j=0,k=g.length;k>j;j++){var l=g[j];O.ajax({url:l.url,type:K.sendType,data:f,success:function(){O.log("posted missing key '"+c+"' to: "+l.url);for(var a=c.split("."),e=0,f=G[l.lng][b];a[e];)f=f[a[e]]=e===a.length-1?d:f[a[e]]||{},e++},error:function(){O.log("failed posting missing key '"+c+"' to: "+l.url)},dataType:"json",async:K.postAsync})}}};var K={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:["dev"],fallbackNS:[],detectLngQS:"setLng",detectLngFromLocalStorage:!1,ns:"translation",fallbackOnNull:!0,fallbackOnEmpty:!1,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,indefiniteSuffix:"_indefinite",indefiniteNotFound:["indefinite_not_found",Math.random()].join(""),setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",cookieDomain:void 0,objectTreeKeyHandler:void 0,postProcess:void 0,parseMissingKey:void 0,missingKeyHandler:sync.postMissing,shortcutFunction:"sprintf"},L={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},M={create:function(a,b,c,d){var e;if(c){var f=new Date;f.setTime(f.getTime()+1e3*60*c),e="; expires="+f.toGMTString()}else e="";d=d?"domain="+d+";":"",document.cookie=a+"="+b+e+";"+d+"path=/"},read:function(a){for(var b=a+"=",c=document.cookie.split(";"),d=0;d-1?c.push(a):b("rejecting non-whitelisted language: "+a)};if("string"==typeof a&&a.indexOf("-")>-1){var f=a.split("-");a=K.lowerCaseLng?f[0].toLowerCase()+"-"+f[1].toLowerCase():f[0].toLowerCase()+"-"+f[1].toUpperCase(),"unspecific"!==K.load&&e(a),"current"!==K.load&&e(f[this.getCountyIndexOfLng(a)])}else e(a);for(var g=0;g1)}},af:{name:"Afrikaans",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ak:{name:"Akan",numbers:[1,2],plurals:function(a){return Number(a>1)}},am:{name:"Amharic",numbers:[1,2],plurals:function(a){return Number(a>1)}},an:{name:"Aragonese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ar:{name:"Arabic",numbers:[0,1,2,3,11,100],plurals:function(a){return Number(0===a?0:1==a?1:2==a?2:a%100>=3&&10>=a%100?3:a%100>=11?4:5)}},arn:{name:"Mapudungun",numbers:[1,2],plurals:function(a){return Number(a>1)}},ast:{name:"Asturian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ay:{name:"Aymará",numbers:[1],plurals:function(){return 0}},az:{name:"Azerbaijani",numbers:[1,2],plurals:function(a){return Number(1!=a)}},be:{name:"Belarusian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},bg:{name:"Bulgarian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},bn:{name:"Bengali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},bo:{name:"Tibetan",numbers:[1],plurals:function(){return 0}},br:{name:"Breton",numbers:[1,2],plurals:function(a){return Number(a>1)}},bs:{name:"Bosnian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},ca:{name:"Catalan",numbers:[1,2],plurals:function(a){return Number(1!=a)}},cgg:{name:"Chiga",numbers:[1],plurals:function(){return 0}},cs:{name:"Czech",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)}},csb:{name:"Kashubian",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},cy:{name:"Welsh",numbers:[1,2,3,8],plurals:function(a){return Number(1==a?0:2==a?1:8!=a&&11!=a?2:3)}},da:{name:"Danish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},de:{name:"German",numbers:[1,2],plurals:function(a){return Number(1!=a)}},dz:{name:"Dzongkha",numbers:[1],plurals:function(){return 0}},el:{name:"Greek",numbers:[1,2],plurals:function(a){return Number(1!=a)}},en:{name:"English",numbers:[1,2],plurals:function(a){return Number(1!=a)}},eo:{name:"Esperanto",numbers:[1,2],plurals:function(a){return Number(1!=a)}},es:{name:"Spanish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},es_ar:{name:"Argentinean Spanish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},et:{name:"Estonian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},eu:{name:"Basque",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fa:{name:"Persian",numbers:[1],plurals:function(){return 0}},fi:{name:"Finnish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fil:{name:"Filipino",numbers:[1,2],plurals:function(a){return Number(a>1)}},fo:{name:"Faroese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fr:{name:"French",numbers:[1,2],plurals:function(a){return Number(a>=2)}},fur:{name:"Friulian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},fy:{name:"Frisian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ga:{name:"Irish",numbers:[1,2,3,7,11],plurals:function(a){return Number(1==a?0:2==a?1:7>a?2:11>a?3:4)}},gd:{name:"Scottish Gaelic",numbers:[1,2,3,20],plurals:function(a){return Number(1==a||11==a?0:2==a||12==a?1:a>2&&20>a?2:3)}},gl:{name:"Galician",numbers:[1,2],plurals:function(a){return Number(1!=a)}},gu:{name:"Gujarati",numbers:[1,2],plurals:function(a){return Number(1!=a)}},gun:{name:"Gun",numbers:[1,2],plurals:function(a){return Number(a>1)}},ha:{name:"Hausa",numbers:[1,2],plurals:function(a){return Number(1!=a)}},he:{name:"Hebrew",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hi:{name:"Hindi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hr:{name:"Croatian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},hu:{name:"Hungarian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},hy:{name:"Armenian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ia:{name:"Interlingua",numbers:[1,2],plurals:function(a){return Number(1!=a)}},id:{name:"Indonesian",numbers:[1],plurals:function(){return 0}},is:{name:"Icelandic",numbers:[1,2],plurals:function(a){return Number(1!=a%10||11==a%100)}},it:{name:"Italian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ja:{name:"Japanese",numbers:[1],plurals:function(){return 0}},jbo:{name:"Lojban",numbers:[1],plurals:function(){return 0}},jv:{name:"Javanese",numbers:[0,1],plurals:function(a){return Number(0!==a)}},ka:{name:"Georgian",numbers:[1],plurals:function(){return 0}},kk:{name:"Kazakh",numbers:[1],plurals:function(){return 0}},km:{name:"Khmer",numbers:[1],plurals:function(){return 0}},kn:{name:"Kannada",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ko:{name:"Korean",numbers:[1],plurals:function(){return 0}},ku:{name:"Kurdish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},kw:{name:"Cornish",numbers:[1,2,3,4],plurals:function(a){return Number(1==a?0:2==a?1:3==a?2:3)}},ky:{name:"Kyrgyz",numbers:[1],plurals:function(){return 0}},lb:{name:"Letzeburgesch",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ln:{name:"Lingala",numbers:[1,2],plurals:function(a){return Number(a>1)}},lo:{name:"Lao",numbers:[1],plurals:function(){return 0}},lt:{name:"Lithuanian",numbers:[1,2,10],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&(10>a%100||a%100>=20)?1:2)}},lv:{name:"Latvian",numbers:[1,2,0],plurals:function(a){return Number(1==a%10&&11!=a%100?0:0!==a?1:2)}},mai:{name:"Maithili",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mfe:{name:"Mauritian Creole",numbers:[1,2],plurals:function(a){return Number(a>1)}},mg:{name:"Malagasy",numbers:[1,2],plurals:function(a){return Number(a>1)}},mi:{name:"Maori",numbers:[1,2],plurals:function(a){return Number(a>1)}},mk:{name:"Macedonian",numbers:[1,2],plurals:function(a){return Number(1==a||1==a%10?0:1)}},ml:{name:"Malayalam",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mn:{name:"Mongolian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},mnk:{name:"Mandinka",numbers:[0,1,2],plurals:function(a){return Number(1==a?1:2)}},mr:{name:"Marathi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ms:{name:"Malay",numbers:[1],plurals:function(){return 0}},mt:{name:"Maltese",numbers:[1,2,11,20],plurals:function(a){return Number(1==a?0:0===a||a%100>1&&11>a%100?1:a%100>10&&20>a%100?2:3)}},nah:{name:"Nahuatl",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nap:{name:"Neapolitan",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nb:{name:"Norwegian Bokmal",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ne:{name:"Nepali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nl:{name:"Dutch",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nn:{name:"Norwegian Nynorsk",numbers:[1,2],plurals:function(a){return Number(1!=a)}},no:{name:"Norwegian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},nso:{name:"Northern Sotho",numbers:[1,2],plurals:function(a){return Number(1!=a)}},oc:{name:"Occitan",numbers:[1,2],plurals:function(a){return Number(a>1)}},or:{name:"Oriya",numbers:[2,1],plurals:function(a){return Number(1!=a)}},pa:{name:"Punjabi",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pap:{name:"Papiamento",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pl:{name:"Polish",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},pms:{name:"Piemontese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ps:{name:"Pashto",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pt:{name:"Portuguese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},pt_br:{name:"Brazilian Portuguese",numbers:[1,2],plurals:function(a){return Number(1!=a)}},rm:{name:"Romansh",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ro:{name:"Romanian",numbers:[1,2,20],plurals:function(a){return Number(1==a?0:0===a||a%100>0&&20>a%100?1:2)}},ru:{name:"Russian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},sah:{name:"Yakut",numbers:[1],plurals:function(){return 0}},sco:{name:"Scots",numbers:[1,2],plurals:function(a){return Number(1!=a)}},se:{name:"Northern Sami",numbers:[1,2],plurals:function(a){return Number(1!=a)}},si:{name:"Sinhala",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sk:{name:"Slovak",numbers:[1,2,5],plurals:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)}},sl:{name:"Slovenian",numbers:[5,1,2,3],plurals:function(a){return Number(1==a%100?1:2==a%100?2:3==a%100||4==a%100?3:0)}},so:{name:"Somali",numbers:[1,2],plurals:function(a){return Number(1!=a)}},son:{name:"Songhay",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sq:{name:"Albanian",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sr:{name:"Serbian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},su:{name:"Sundanese",numbers:[1],plurals:function(){return 0}},sv:{name:"Swedish",numbers:[1,2],plurals:function(a){return Number(1!=a)}},sw:{name:"Swahili",numbers:[1,2],plurals:function(a){return Number(1!=a)}},ta:{name:"Tamil",numbers:[1,2],plurals:function(a){return Number(1!=a)}},te:{name:"Telugu",numbers:[1,2],plurals:function(a){return Number(1!=a)}},tg:{name:"Tajik",numbers:[1,2],plurals:function(a){return Number(a>1)}},th:{name:"Thai",numbers:[1],plurals:function(){return 0}},ti:{name:"Tigrinya",numbers:[1,2],plurals:function(a){return Number(a>1)}},tk:{name:"Turkmen",numbers:[1,2],plurals:function(a){return Number(1!=a)}},tr:{name:"Turkish",numbers:[1,2],plurals:function(a){return Number(a>1)}},tt:{name:"Tatar",numbers:[1],plurals:function(){return 0}},ug:{name:"Uyghur",numbers:[1],plurals:function(){return 0}},uk:{name:"Ukrainian",numbers:[1,2,5],plurals:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)}},ur:{name:"Urdu",numbers:[1,2],plurals:function(a){return Number(1!=a)}},uz:{name:"Uzbek",numbers:[1,2],plurals:function(a){return Number(a>1)}},vi:{name:"Vietnamese",numbers:[1],plurals:function(){return 0}},wa:{name:"Walloon",numbers:[1,2],plurals:function(a){return Number(a>1)}},wo:{name:"Wolof",numbers:[1],plurals:function(){return 0}},yo:{name:"Yoruba",numbers:[1,2],plurals:function(a){return Number(1!=a)}},zh:{name:"Chinese",numbers:[1],plurals:function(){return 0}}},addRule:function(a,b){P.rules[a]=b},setCurrentLng:function(a){if(!P.currentRule||P.currentRule.lng!==a){var b=a.split("-");P.currentRule={lng:a,rule:P.rules[b[0]]}}},needsPlural:function(a,b){var c,d=a.split("-");return c=P.currentRule&&P.currentRule.lng===a?P.currentRule.rule:P.rules[d[O.getCountyIndexOfLng(a)]],c&&c.numbers.length<=1?!1:1!==this.get(a,b)},get:function(a,b){function c(b,c){var d;if(d=P.currentRule&&P.currentRule.lng===a?P.currentRule.rule:P.rules[b]){var e;e=d.noAbs?d.plurals(c):d.plurals(Math.abs(c));var f=d.numbers[e];return 2===d.numbers.length&&1===d.numbers[0]&&(2===f?f=-1:1===f&&(f=1)),f}return 1===c?"1":"-1"}var d=a.split("-");return c(d[O.getCountyIndexOfLng(a)],b) +}},Q={},R=function(a,b){Q[a]=b},S=function(){function a(a){return Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}function b(a,b){for(var c=[];b>0;c[--b]=a);return c.join("")}var c=function(){return c.cache.hasOwnProperty(arguments[0])||(c.cache[arguments[0]]=c.parse(arguments[0])),c.format.call(null,c.cache[arguments[0]],arguments)};return c.format=function(c,d){var e,f,g,h,i,j,k,l=1,m=c.length,n="",o=[];for(f=0;m>f;f++)if(n=a(c[f]),"string"===n)o.push(c[f]);else if("array"===n){if(h=c[f],h[2])for(e=d[l],g=0;g=0?"+"+e:e,j=h[4]?"0"==h[4]?"0":h[4].charAt(1):" ",k=h[6]-String(e).length,i=h[6]?b(j,k):"",o.push(h[5]?e+i:i+e)}return o.join("")},c.cache={},c.parse=function(a){for(var b=a,c=[],d=[],e=0;b;){if(null!==(c=/^[^\x25]+/.exec(b)))d.push(c[0]);else if(null!==(c=/^\x25{2}/.exec(b)))d.push("%");else{if(null===(c=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(b)))throw"[sprintf] huh?";if(c[2]){e|=1;var f=[],g=c[2],h=[];if(null===(h=/^([a-z_][a-z_\d]*)/i.exec(g)))throw"[sprintf] huh?";for(f.push(h[1]);""!==(g=g.substring(h[0].length));)if(null!==(h=/^\.([a-z_][a-z_\d]*)/i.exec(g)))f.push(h[1]);else{if(null===(h=/^\[(\d+)\]/.exec(g)))throw"[sprintf] huh?";f.push(h[1])}c[2]=f}else e|=2;if(3===e)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";d.push(c)}b=b.substring(c[0].length)}return d},c}(),T=function(a,b){return b.unshift(a),S.apply(null,b)};return R("sprintf",function(a,b,c){return c.sprintf?"[object Array]"===Object.prototype.toString.apply(c.sprintf)?T(a,c.sprintf):"object"==typeof c.sprintf?S(a,c.sprintf):a:a}),F.init=g,F.setLng=p,F.preload=h,F.addResourceBundle=i,F.addResource=k,F.addResources=l,F.removeResourceBundle=j,F.loadNamespace=n,F.loadNamespaces=o,F.setDefaultNamespace=m,F.t=y,F.translate=y,F.exists=x,F.detectLanguage=O.detectLanguage,F.pluralExtensions=P,F.sync=sync,F.functions=O,F.lng=q,F.addPostProcessor=R,F.options=K,a.i18n=F,a.t=F.t,F}); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd.withJQuery-1.7.5.js b/libs/i18next/release/i18next.amd.withJQuery-1.7.5.js new file mode 100644 index 00000000..48096884 --- /dev/null +++ b/libs/i18next/release/i18next.amd.withJQuery-1.7.5.js @@ -0,0 +1,2103 @@ +// i18next, v1.7.5 +// Copyright (c)2014 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function (root, factory) { + if (typeof exports === 'object') { + + var jquery = require('jquery'); + + module.exports = factory(jquery); + + } else if (typeof define === 'function' && define.amd) { + + define(['jquery'], factory); + + } +}(this, function ($) { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + // Add string trim for IE8. + if (typeof String.prototype.trim !== 'function') { + String.prototype.trim = function() { + return this.replace(/^\s+|\s+$/g, ''); + } + } + + var i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = [] + , initialized = false + , sync = {}; + + sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + f.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + if ((status && status == 200) || (xhr && xhr.status && xhr.status == 200)) { + // file loaded but invalid json, stop waste time ! + f.error('There is a typo in: ' + url); + } else if ((status && status == 404) || (xhr && xhr.status && xhr.status == 404)) { + f.log('Does not exist: ' + url); + } else { + var theStatus = status ? status : ((xhr && xhr.status) ? xhr.status : null); + f.log(theStatus + ' when loading ' + url); + } + + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback' && o.fallbackLng[0] !== false) { + for (var i = 0; i < o.fallbackLng.length; i++) { + urls.push({lng: o.fallbackLng[i], url: applyReplacement(o.resPostPath, { lng: o.fallbackLng[i], ns: ns })}); + } + } else if (o.sendMissingTo === 'current' || (o.sendMissingTo === 'fallback' && o.fallbackLng[0] === false) ) { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + }, + + reload: reload + }; + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: ['dev'], + fallbackNS: [], + detectLngQS: 'setLng', + detectLngFromLocalStorage: false, + ns: 'translation', + fallbackOnNull: true, + fallbackOnEmpty: false, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + defaultVariables: false, + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + indefiniteSuffix: '_indefinite', + indefiniteNotFound: ['indefinite_not_found', Math.random()].join(''), + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + cookieDomain: undefined, + + objectTreeKeyHandler: undefined, + postProcess: undefined, + parseMissingKey: undefined, + missingKeyHandler: sync.postMissing, + + shortcutFunction: 'sprintf' // or: defaultValue + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _deepExtend(target, source) { + for (var prop in source) + if (prop in target) + _deepExtend(target[prop], source[prop]); + else + target[prop] = source[prop]; + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || Object.prototype.toString.apply(object) !== '[object Array]' || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + try { + return JSON.parse(data) + } catch (e) { + f.error('Can not parse JSON. URL: ' + url); + return {}; + } + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + // file: protocol always gives status code 0, so check for data + if (status === 200 || (status === 0 && data.text())) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes,domain) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + domain = (domain)? "domain="+domain+";" : ""; + document.cookie = name+"="+value+expires+";"+domain+"path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes,domain) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + deepExtend: _deepExtend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : (typeof document !== 'undefined' ? _ajax : function() {}), + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + error: function(str) { + if (typeof console !== "undefined") console.error(str); + }, + getCountyIndexOfLng: function(lng) { + var lng_index = 0; + if (lng === 'nb-NO' || lng === 'nn-NO' || lng === 'nb-no' || lng === 'nn-no') lng_index = 1; + return lng_index; + }, + toLanguages: function(lng) { + var log = this.log; + + function applyCase(l) { + var ret = l; + + if (typeof l === 'string' && l.indexOf('-') > -1) { + var parts = l.split('-'); + + ret = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } else { + ret = o.lowerCaseLng ? l.toLowerCase() : l; + } + + return ret; + } + + var languages = []; + var whitelist = o.lngWhitelist || false; + var addLanguage = function(language){ + //reject langs not whitelisted + if(!whitelist || whitelist.indexOf(language) > -1){ + languages.push(language); + }else{ + log('rejecting non-whitelisted language: ' + language); + } + }; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + if (o.load !== 'unspecific') addLanguage(applyCase(lng)); + if (o.load !== 'current') addLanguage(applyCase(parts[this.getCountyIndexOfLng(lng)])); + } else { + addLanguage(applyCase(lng)); + } + + for (var i = 0; i < o.fallbackLng.length; i++) { + if (languages.indexOf(o.fallbackLng[i]) === -1 && o.fallbackLng[i]) languages.push(applyCase(o.fallbackLng[i])); + } + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + }, + regexReplacementEscape: function(strOrFn) { + if (typeof strOrFn === 'string') { + return strOrFn.replace(/\$/g, "$$$$"); + } else { + return strOrFn; + } + }, + localStorage: { + setItem: function(key, value) { + if (window.localStorage) { + try { + window.localStorage.setItem(key, value); + } catch (e) { + f.log('failed to set value for key "' + key + '" to localStorage.'); + } + } + } + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + delete o.fixLng; /* passed in each time */ + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // fallback languages + if (typeof o.fallbackLng == 'string' || typeof o.fallbackLng == 'boolean') { + o.fallbackLng = [o.fallbackLng]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + if (o.useCookie && f.cookie.read(o.cookieName) !== currentLng){ //cookie is unset or invalid + f.cookie.create(o.cookieName, currentLng, o.cookieExpirationTime, o.cookieDomain); + } + if (o.detectLngFromLocalStorage && typeof document !== 'undefined' && window.localStorage) { + f.localStorage.setItem('i18next_lng', currentLng); + } + + var lngTranslate = translate; + if (options.fixLng) { + lngTranslate = function(key, options) { + options = options || {}; + options.lng = options.lng || lngTranslate.lng; + return translate(key, options); + }; + lngTranslate.lng = currentLng; + } + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + initialized = true; + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + initialized = true; + + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources, deep) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + if (deep) { + f.deepExtend(resStore[lng][ns], resources); + } else { + f.extend(resStore[lng][ns], resources); + } + } + + function hasResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + var res = resStore[lng][ns] || {}; + + var hasValues = false; + for(var prop in res) { + if (res.hasOwnProperty(prop)) { + hasValues = true; + } + } + + return hasValues; + } + + function removeResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = {}; + } + + function addResource(lng, ns, key, value) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + var keys = key.split(o.keyseparator); + var x = 0; + var node = resStore[lng][ns]; + var origRef = node; + + while (keys[x]) { + if (x == keys.length - 1) + node[keys[x]] = value; + else { + if (node[keys[x]] == null) + node[keys[x]] = {}; + + node = node[keys[x]]; + } + x++; + } + } + + function addResources(lng, ns, resources) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + for (var m in resources) { + if (typeof resources[m] === 'string') addResource(lng, ns, m, resources[m]); + } + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, options, cb) { + if (typeof options === 'function') { + cb = options; + options = {}; + } else if (!options) { + options = {}; + } + + options.lng = lng; + return init(options, cb); + } + + function lng() { + return currentLng; + } + + function reload(cb) { + resStore = {}; + setLng(currentLng, cb); + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else if (attr === 'prepend') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.prepend($.t(key, optionsToUse)); + } else if (attr === 'append') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.append($.t(key, optionsToUse)); + } else if (attr.indexOf("data-") === 0) { + var dataAttr = attr.substr(("data-").length); + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.data(dataAttr) }, options) : options; + var translated = $.t(key, optionsToUse); + //we change into the data cache + ele.data(dataAttr, translated); + //we change into the dom + ele.attr(attr, translated); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key && typeof key !== 'undefined' && key !== false) key = ele.text() || ele.val(); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + var hash = replacementHash.replace && typeof replacementHash.replace === 'object' ? replacementHash.replace : replacementHash; + f.each(hash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), f.regexReplacementEscape(value)); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(f.escape(value))); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(value)); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + if (index_of_end_of_closing <= index_of_opening) { + f.error('there is an missing closing in following translation value', translated); + return ''; + } + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, f.regexReplacementEscape(translated_token)); + } + return translated; + } + + function hasContext(options) { + return (options.context && (typeof options.context == 'string' || typeof options.context == 'number')); + } + + function needsPlural(options, lng) { + return (options.count !== undefined && typeof options.count != 'string'/* && pluralExtensions.needsPlural(lng, options.count)*/); + } + + function needsIndefiniteArticle(options) { + return (options.indefinite_article !== undefined && typeof options.indefinite_article != 'string' && options.indefinite_article); + } + + function exists(key, options) { + options = options || {}; + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + options = options || {}; + + if (!initialized) { + f.log('i18next not finished initialization. you might have called t function before loading resources finished.') + return options.defaultValue || ''; + }; + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _getDefaultValue(key, options) { + return (options.defaultValue !== undefined) ? options.defaultValue : key; + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(potentialKeys, options) { + if (options && typeof options !== 'object') { + if (o.shortcutFunction === 'sprintf') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else if (o.shortcutFunction === 'defaultValue') { + options = { + defaultValue: options + } + } + } else { + options = options || {}; + } + + if (typeof o.defaultVariables === 'object') { + options = f.extend({}, o.defaultVariables, options); + } + + if (potentialKeys === undefined || potentialKeys === null || potentialKeys === '') return ''; + + if (typeof potentialKeys === 'string') { + potentialKeys = [potentialKeys]; + } + + var key = potentialKeys[0]; + + if (potentialKeys.length > 1) { + for (var i = 0; i < potentialKeys.length; i++) { + key = potentialKeys[i]; + if (exists(key, options)) { + break; + } + } + } + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng, options.fallbackLng) : languages + , ns = options.ns || o.ns.defaultNs + , parts; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing && typeof o.missingKeyHandler === 'function') { + if (options.lng) { + o.missingKeyHandler(lngs[0], ns, key, notFound, lngs); + } else { + o.missingKeyHandler(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found !== undefined && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + // process notFound if function exists + var splitNotFound = notFound; + if (notFound.indexOf(o.nsseparator) > -1) { + parts = notFound.split(o.nsseparator); + splitNotFound = parts[1]; + } + if (splitNotFound === key && o.parseMissingKey) { + notFound = o.parseMissingKey(notFound); + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessor && postProcessors[postProcessor]) { + var val = _getDefaultValue(key, options); + found = postProcessors[postProcessor](val, key, options); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options) { + options = options || {}; + + var optionWithoutCount, translated + , notFound = _getDefaultValue(key, options) + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + // CI mode + if (lngs[0].toLowerCase() === 'cimode') return notFound; + + // passed in lng + if (options.lngs) lngs = options.lngs; + if (options.lng) { + lngs = f.toLanguages(options.lng, options.fallbackLng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options, lngs[0])) { + optionWithoutCount = f.extend({ lngs: [lngs[0]]}, options); + delete optionWithoutCount.count; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey; + if (!pluralExtensions.needsPlural(lngs[0], options.count)) { + pluralKey = ns + o.nsseparator + key; + } else { + pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(lngs[0], options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + } + + translated = translate(pluralKey, optionWithoutCount); + + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } else if (lngs.length > 1) { + // remove failed lng + var clone = lngs.slice(); + clone.shift(); + options = f.extend(options, { lngs: clone }); + // retry with fallbacks + translated = translate(ns + o.nsseparator + key, options); + if (translated != o.pluralNotFound) return translated; + } + } + + if (needsIndefiniteArticle(options)) { + var optionsWithoutIndef = f.extend({}, options); + delete optionsWithoutIndef.indefinite_article; + optionsWithoutIndef.defaultValue = o.indefiniteNotFound; + // If we don't have a count, we want the indefinite, if we do have a count, and needsPlural is false + var indefiniteKey = ns + o.nsseparator + key + (((options.count && !needsPlural(options, lngs[0])) || !options.count) ? o.indefiniteSuffix : ""); + translated = translate(indefiniteKey, optionsWithoutIndef); + if (translated != o.indefiniteNotFound) { + return translated; + } + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + var valueType = Object.prototype.toString.apply(value); + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (valueType === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + if (o.objectTreeKeyHandler && typeof o.objectTreeKeyHandler == 'function') { + value = o.objectTreeKeyHandler(key, value, l, ns, options); + } else { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned an object instead of string.'; + f.log(value); + } + } else if (valueType !== '[object Number]' && valueType !== '[object Function]' && valueType !== '[object RegExp]') { + var copy = (valueType === '[object Array]') ? [] : {}; // apply child translation on a copy + f.each(value, function(m) { + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + }); + value = copy; + } + } + + if (typeof value === 'string' && value.trim() === '' && o.fallbackOnEmpty === true) + value = undefined; + + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length > 0))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + options.isFallbackLookup = false; + } + + return found; + } + function detectLanguage() { + var detectedLng; + var whitelist = o.lngWhitelist || []; + var userLngChoices = []; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var params = query.split('&'); + for (var i=0; i 0) { + var key = params[i].substring(0,pos); + if (key == o.detectLngQS) { + userLngChoices.push(params[i].substring(pos+1)); + } + } + } + })(); + } + + // get from cookie + if (o.useCookie && typeof document !== 'undefined') { + var c = f.cookie.read(o.cookieName); + if (c) userLngChoices.push(c); + } + + // get from localStorage + if (o.detectLngFromLocalStorage && typeof window !== 'undefined' && window.localStorage) { + userLngChoices.push(window.localStorage.getItem('i18next_lng')); + } + + // get from navigator + if (typeof navigator !== 'undefined') { + if (navigator.languages) { // chrome only; not an array, so can't use .push.apply instead of iterating + for (var i=0;i -1) { + var parts = lng.split('-'); + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } + + if (whitelist.length === 0 || whitelist.indexOf(lng) > -1) { + detectedLng = lng; + break; + } + } + })(); + + //fallback + if (!detectedLng){ + detectedLng = o.fallbackLng[0]; + } + + return detectedLng; + } + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + + /* [code, name, numbers, pluralsType] */ + var _rules = [ + ["ach", "Acholi", [1,2], 1], + ["af", "Afrikaans",[1,2], 2], + ["ak", "Akan", [1,2], 1], + ["am", "Amharic", [1,2], 1], + ["an", "Aragonese",[1,2], 2], + ["ar", "Arabic", [0,1,2,3,11,100],5], + ["arn", "Mapudungun",[1,2], 1], + ["ast", "Asturian", [1,2], 2], + ["ay", "Aymará", [1], 3], + ["az", "Azerbaijani",[1,2],2], + ["be", "Belarusian",[1,2,5],4], + ["bg", "Bulgarian",[1,2], 2], + ["bn", "Bengali", [1,2], 2], + ["bo", "Tibetan", [1], 3], + ["br", "Breton", [1,2], 1], + ["bs", "Bosnian", [1,2,5],4], + ["ca", "Catalan", [1,2], 2], + ["cgg", "Chiga", [1], 3], + ["cs", "Czech", [1,2,5],6], + ["csb", "Kashubian",[1,2,5],7], + ["cy", "Welsh", [1,2,3,8],8], + ["da", "Danish", [1,2], 2], + ["de", "German", [1,2], 2], + ["dev", "Development Fallback", [1,2], 2], + ["dz", "Dzongkha", [1], 3], + ["el", "Greek", [1,2], 2], + ["en", "English", [1,2], 2], + ["eo", "Esperanto",[1,2], 2], + ["es", "Spanish", [1,2], 2], + ["es_ar","Argentinean Spanish", [1,2], 2], + ["et", "Estonian", [1,2], 2], + ["eu", "Basque", [1,2], 2], + ["fa", "Persian", [1], 3], + ["fi", "Finnish", [1,2], 2], + ["fil", "Filipino", [1,2], 1], + ["fo", "Faroese", [1,2], 2], + ["fr", "French", [1,2], 9], + ["fur", "Friulian", [1,2], 2], + ["fy", "Frisian", [1,2], 2], + ["ga", "Irish", [1,2,3,7,11],10], + ["gd", "Scottish Gaelic",[1,2,3,20],11], + ["gl", "Galician", [1,2], 2], + ["gu", "Gujarati", [1,2], 2], + ["gun", "Gun", [1,2], 1], + ["ha", "Hausa", [1,2], 2], + ["he", "Hebrew", [1,2], 2], + ["hi", "Hindi", [1,2], 2], + ["hr", "Croatian", [1,2,5],4], + ["hu", "Hungarian",[1,2], 2], + ["hy", "Armenian", [1,2], 2], + ["ia", "Interlingua",[1,2],2], + ["id", "Indonesian",[1], 3], + ["is", "Icelandic",[1,2], 12], + ["it", "Italian", [1,2], 2], + ["ja", "Japanese", [1], 3], + ["jbo", "Lojban", [1], 3], + ["jv", "Javanese", [0,1], 13], + ["ka", "Georgian", [1], 3], + ["kk", "Kazakh", [1], 3], + ["km", "Khmer", [1], 3], + ["kn", "Kannada", [1,2], 2], + ["ko", "Korean", [1], 3], + ["ku", "Kurdish", [1,2], 2], + ["kw", "Cornish", [1,2,3,4],14], + ["ky", "Kyrgyz", [1], 3], + ["lb", "Letzeburgesch",[1,2],2], + ["ln", "Lingala", [1,2], 1], + ["lo", "Lao", [1], 3], + ["lt", "Lithuanian",[1,2,10],15], + ["lv", "Latvian", [1,2,0],16], + ["mai", "Maithili", [1,2], 2], + ["mfe", "Mauritian Creole",[1,2],1], + ["mg", "Malagasy", [1,2], 1], + ["mi", "Maori", [1,2], 1], + ["mk", "Macedonian",[1,2],17], + ["ml", "Malayalam",[1,2], 2], + ["mn", "Mongolian",[1,2], 2], + ["mnk", "Mandinka", [0,1,2],18], + ["mr", "Marathi", [1,2], 2], + ["ms", "Malay", [1], 3], + ["mt", "Maltese", [1,2,11,20],19], + ["nah", "Nahuatl", [1,2], 2], + ["nap", "Neapolitan",[1,2], 2], + ["nb", "Norwegian Bokmal",[1,2],2], + ["ne", "Nepali", [1,2], 2], + ["nl", "Dutch", [1,2], 2], + ["nn", "Norwegian Nynorsk",[1,2],2], + ["no", "Norwegian",[1,2], 2], + ["nso", "Northern Sotho",[1,2],2], + ["oc", "Occitan", [1,2], 1], + ["or", "Oriya", [2,1], 2], + ["pa", "Punjabi", [1,2], 2], + ["pap", "Papiamento",[1,2], 2], + ["pl", "Polish", [1,2,5],7], + ["pms", "Piemontese",[1,2], 2], + ["ps", "Pashto", [1,2], 2], + ["pt", "Portuguese",[1,2], 2], + ["pt_br","Brazilian Portuguese",[1,2], 2], + ["rm", "Romansh", [1,2], 2], + ["ro", "Romanian", [1,2,20],20], + ["ru", "Russian", [1,2,5],4], + ["sah", "Yakut", [1], 3], + ["sco", "Scots", [1,2], 2], + ["se", "Northern Sami",[1,2], 2], + ["si", "Sinhala", [1,2], 2], + ["sk", "Slovak", [1,2,5],6], + ["sl", "Slovenian",[5,1,2,3],21], + ["so", "Somali", [1,2], 2], + ["son", "Songhay", [1,2], 2], + ["sq", "Albanian", [1,2], 2], + ["sr", "Serbian", [1,2,5],4], + ["su", "Sundanese",[1], 3], + ["sv", "Swedish", [1,2], 2], + ["sw", "Swahili", [1,2], 2], + ["ta", "Tamil", [1,2], 2], + ["te", "Telugu", [1,2], 2], + ["tg", "Tajik", [1,2], 1], + ["th", "Thai", [1], 3], + ["ti", "Tigrinya", [1,2], 1], + ["tk", "Turkmen", [1,2], 2], + ["tr", "Turkish", [1,2], 1], + ["tt", "Tatar", [1], 3], + ["ug", "Uyghur", [1], 3], + ["uk", "Ukrainian",[1,2,5],4], + ["ur", "Urdu", [1,2], 2], + ["uz", "Uzbek", [1,2], 1], + ["vi", "Vietnamese",[1], 3], + ["wa", "Walloon", [1,2], 1], + ["wo", "Wolof", [1], 3], + ["yo", "Yoruba", [1,2], 2], + ["zh", "Chinese", [1], 3] + ]; + + var _rulesPluralsTypes = { + 1: function(n) {return Number(n > 1);}, + 2: function(n) {return Number(n != 1);}, + 3: function(n) {return 0;}, + 4: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 5: function(n) {return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5);}, + 6: function(n) {return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2);}, + 7: function(n) {return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 8: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3);}, + 9: function(n) {return Number(n >= 2);}, + 10: function(n) {return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;}, + 11: function(n) {return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3);}, + 12: function(n) {return Number(n%10!=1 || n%100==11);}, + 13: function(n) {return Number(n !== 0);}, + 14: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3);}, + 15: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 16: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2);}, + 17: function(n) {return Number(n==1 || n%10==1 ? 0 : 1);}, + 18: function(n) {return Number(0 ? 0 : n==1 ? 1 : 2);}, + 19: function(n) {return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3);}, + 20: function(n) {return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2);}, + 21: function(n) {return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }; + + var pluralExtensions = { + + rules: (function () { + var l, rules = {}; + for (l=_rules.length; l-- ;) { + rules[_rules[l][0]] = { + name: _rules[l][1], + numbers: _rules[l][2], + plurals: _rulesPluralsTypes[_rules[l][3]] + } + } + return rules; + }()), + + // you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + needsPlural: function(lng, count) { + var parts = lng.split('-'); + + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[parts[f.getCountyIndexOfLng(lng)]]; + } + + if (ext && ext.numbers.length <= 1) { + return false; + } else { + return this.get(lng, count) !== 1; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i; + if (ext.noAbs) { + i = ext.plurals(c); + } else { + i = ext.plurals(Math.abs(c)); + } + + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[f.getCountyIndexOfLng(lng)], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.hasResourceBundle = hasResourceBundle; + i18n.addResource = addResource; + i18n.addResources = addResources; + i18n.removeResourceBundle = removeResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + + $.i18n = i18n; + $.t = i18n.t; + + return i18n; + +})); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd.withJQuery-1.7.5.min.js b/libs/i18next/release/i18next.amd.withJQuery-1.7.5.min.js new file mode 100644 index 00000000..e1dbe014 --- /dev/null +++ b/libs/i18next/release/i18next.amd.withJQuery-1.7.5.min.js @@ -0,0 +1,5 @@ +// i18next, v1.7.5 +// Copyright (c)2014 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +!function(a,b){if("object"==typeof exports){var c=require("jquery");module.exports=b(c)}else"function"==typeof define&&define.amd&&define(["jquery"],b)}(this,function(a){function b(a,b){if(!b||"function"==typeof b)return a;for(var c in b)a[c]=b[c];return a}function c(a,b){for(var d in b)d in a?c(a[d],b[d]):a[d]=b[d];return a}function d(a,b,c){var d,e=0,f=a.length,g=void 0===f||"[object Array]"!==Object.prototype.toString.apply(a)||"function"==typeof a;if(c)if(g){for(d in a)if(b.apply(a[d],c)===!1)break}else for(;f>e&&b.apply(a[e++],c)!==!1;);else if(g){for(d in a)if(b.call(a[d],d,a[d])===!1)break}else for(;f>e&&b.call(a[e],e,a[e++])!==!1;);return a}function e(a){return"string"==typeof a?a.replace(/[&<>"'\/]/g,function(a){return O[a]}):a}function f(a){var b=function(a){if(window.XMLHttpRequest)return a(null,new XMLHttpRequest);if(window.ActiveXObject)try{return a(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(b){return a(null,new ActiveXObject("Microsoft.XMLHTTP"))}return a(new Error)},c=function(a){if("string"==typeof a)return a;var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")},d=function(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;cd?b+=String.fromCharCode(d):d>127&&2048>d?(b+=String.fromCharCode(192|d>>6),b+=String.fromCharCode(128|63&d)):(b+=String.fromCharCode(224|d>>12),b+=String.fromCharCode(128|63&d>>6),b+=String.fromCharCode(128|63&d))}return b},e=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";a=d(a);var c,e,f,g,h,i,j,k="",l=0;do c=a.charCodeAt(l++),e=a.charCodeAt(l++),f=a.charCodeAt(l++),g=c>>2,h=(3&c)<<4|e>>4,i=(15&e)<<2|f>>6,j=63&f,isNaN(e)?i=j=64:isNaN(f)&&(j=64),k+=b.charAt(g)+b.charAt(h)+b.charAt(i)+b.charAt(j),c=e=f="",g=h=i=j="";while(l1&&(d+=d.indexOf("?")>-1?"&"+k:"?"+k),e.jsonp){var l=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=d,l.appendChild(m),void 0}}b(function(b,c){if(b)return h(b);c.open(a,d,e.async);for(var f in j)j.hasOwnProperty(f)&&c.setRequestHeader(f,j[f]);c.onreadystatechange=function(){if(4===c.readyState){var a=c.responseText||"";if(!h)return;h(c.status,{text:function(){return a},json:function(){try{return JSON.parse(a)}catch(b){return R.error("Can not parse JSON. URL: "+d),{}}}})}},c.send(i)})},h={authBasic:function(a,b){g.headers.Authorization="Basic "+e(a+":"+b)},connect:function(a,b,c){return g("CONNECT",a,b,c)},del:function(a,b,c){return g("DELETE",a,b,c)},get:function(a,b,c){return g("GET",a,b,c)},head:function(a,b,c){return g("HEAD",a,b,c)},headers:function(a){g.headers=a||{}},isAllowed:function(a,b,c){this.options(a,function(a,d){c(-1!==d.text().indexOf(b))})},options:function(a,b,c){return g("OPTIONS",a,b,c)},patch:function(a,b,c){return g("PATCH",a,b,c)},post:function(a,b,c){return g("POST",a,b,c)},put:function(a,b,c){return g("PUT",a,b,c)},trace:function(a,b,c){return g("TRACE",a,b,c)}},i=a.type?a.type.toLowerCase():"get";h[i](a.url,a,function(b,c){200===b||0===b&&c.text()?a.success(c.json(),b,null):a.error(c.text(),b,null)})}function g(b,c){"function"==typeof b&&(c=b,b={}),b=b||{},R.extend(N,b),delete N.fixLng,"string"==typeof N.ns&&(N.ns={namespaces:[N.ns],defaultNs:N.ns}),"string"==typeof N.fallbackNS&&(N.fallbackNS=[N.fallbackNS]),("string"==typeof N.fallbackLng||"boolean"==typeof N.fallbackLng)&&(N.fallbackLng=[N.fallbackLng]),N.interpolationPrefixEscaped=R.regexEscape(N.interpolationPrefix),N.interpolationSuffixEscaped=R.regexEscape(N.interpolationSuffix),N.lng||(N.lng=R.detectLanguage()),K=R.toLanguages(N.lng),G=K[0],R.log("currentLng set to: "+G),N.useCookie&&R.cookie.read(N.cookieName)!==G&&R.cookie.create(N.cookieName,G,N.cookieExpirationTime,N.cookieDomain),N.detectLngFromLocalStorage&&"undefined"!=typeof document&&window.localStorage&&R.localStorage.setItem("i18next_lng",G);var d=A;b.fixLng&&(d=function(a,b){return b=b||{},b.lng=b.lng||d.lng,A(a,b)},d.lng=G),U.setCurrentLng(G),a&&N.setJqueryExt&&t();var e;if(a&&a.Deferred&&(e=a.Deferred()),!N.resStore){var f=R.toLanguages(N.lng);"string"==typeof N.preload&&(N.preload=[N.preload]);for(var g=0,h=N.preload.length;h>g;g++)for(var i=R.toLanguages(N.preload[g]),j=0,k=i.length;k>j;j++)f.indexOf(i[j])<0&&f.push(i[j]);return H.sync.load(f,N,function(a,b){I=b,L=!0,c&&c(d),e&&e.resolve(d)}),e?e.promise():void 0}return I=N.resStore,L=!0,c&&c(d),e&&e.resolve(d),e?e.promise():void 0}function h(a,b){"string"==typeof a&&(a=[a]);for(var c=0,d=a.length;d>c;c++)N.preload.indexOf(a[c])<0&&N.preload.push(a[c]);return g(b)}function i(a,b,c,d){"string"!=typeof b?(c=b,b=N.ns.defaultNs):N.ns.namespaces.indexOf(b)<0&&N.ns.namespaces.push(b),I[a]=I[a]||{},I[a][b]=I[a][b]||{},d?R.deepExtend(I[a][b],c):R.extend(I[a][b],c)}function j(a,b){"string"!=typeof b&&(b=N.ns.defaultNs),I[a]=I[a]||{};var c=I[a][b]||{},d=!1;for(var e in c)c.hasOwnProperty(e)&&(d=!0);return d}function k(a,b){"string"!=typeof b&&(b=N.ns.defaultNs),I[a]=I[a]||{},I[a][b]={}}function l(a,b,c,d){"string"!=typeof b?(resource=b,b=N.ns.defaultNs):N.ns.namespaces.indexOf(b)<0&&N.ns.namespaces.push(b),I[a]=I[a]||{},I[a][b]=I[a][b]||{};for(var e=c.split(N.keyseparator),f=0,g=I[a][b];e[f];)f==e.length-1?g[e[f]]=d:(null==g[e[f]]&&(g[e[f]]={}),g=g[e[f]]),f++}function m(a,b,c){"string"!=typeof b?(resource=b,b=N.ns.defaultNs):N.ns.namespaces.indexOf(b)<0&&N.ns.namespaces.push(b);for(var d in c)"string"==typeof c[d]&&l(a,b,d,c[d])}function n(a){N.ns.defaultNs=a}function o(a,b){p([a],b)}function p(a,b){var c={dynamicLoad:N.dynamicLoad,resGetPath:N.resGetPath,getAsync:N.getAsync,customLoad:N.customLoad,ns:{namespaces:a,defaultNs:""}},d=R.toLanguages(N.lng);"string"==typeof N.preload&&(N.preload=[N.preload]);for(var e=0,f=N.preload.length;f>e;e++)for(var g=R.toLanguages(N.preload[e]),h=0,i=g.length;i>h;h++)d.indexOf(g[h])<0&&d.push(g[h]);for(var j=[],k=0,l=d.length;l>k;k++){var m=!1,n=I[d[k]];if(n)for(var o=0,p=a.length;p>o;o++)n[a[o]]||(m=!0);else m=!0;m&&j.push(d[k])}j.length?H.sync._fetch(j,c,function(c,d){var e=a.length*j.length;R.each(a,function(a,c){N.ns.namespaces.indexOf(c)<0&&N.ns.namespaces.push(c),R.each(j,function(a,f){I[f]=I[f]||{},I[f][c]=d[f][c],e--,0===e&&b&&(N.useLocalStorage&&H.sync._storeLocal(I),b())})})}):b&&b()}function q(a,b,c){return"function"==typeof b?(c=b,b={}):b||(b={}),b.lng=a,g(b,c)}function r(){return G}function s(a){I={},q(G,a)}function t(){function b(b,c,d){if(0!==c.length){var e="text";if(0===c.indexOf("[")){var f=c.split("]");c=f[1],e=f[0].substr(1,f[0].length-1)}c.indexOf(";")===c.length-1&&(c=c.substr(0,c.length-2));var g;if("html"===e)g=N.defaultValueFromContent?a.extend({defaultValue:b.html()},d):d,b.html(a.t(c,g));else if("text"===e)g=N.defaultValueFromContent?a.extend({defaultValue:b.text()},d):d,b.text(a.t(c,g));else if("prepend"===e)g=N.defaultValueFromContent?a.extend({defaultValue:b.html()},d):d,b.prepend(a.t(c,g));else if("append"===e)g=N.defaultValueFromContent?a.extend({defaultValue:b.html()},d):d,b.append(a.t(c,g));else if(0===e.indexOf("data-")){var h=e.substr("data-".length);g=N.defaultValueFromContent?a.extend({defaultValue:b.data(h)},d):d;var i=a.t(c,g);b.data(h,i),b.attr(e,i)}else g=N.defaultValueFromContent?a.extend({defaultValue:b.attr(e)},d):d,b.attr(e,a.t(c,g))}}function c(c,d){var e=c.attr(N.selectorAttr);if(e||"undefined"==typeof e||e===!1||(e=c.text()||c.val()),e){var f=c,g=c.data("i18n-target");if(g&&(f=c.find(g)||c),d||N.useDataAttrOptions!==!0||(d=c.data("i18n-options")),d=d||{},e.indexOf(";")>=0){var h=e.split(";");a.each(h,function(a,c){""!==c&&b(f,c,d)})}else b(f,e,d);N.useDataAttrOptions===!0&&c.data("i18n-options",d)}}a.t=a.t||A,a.fn.i18n=function(b){return this.each(function(){c(a(this),b);var d=a(this).find("["+N.selectorAttr+"]");d.each(function(){c(a(this),b)})})}}function u(a,b,c,d){if(!a)return a;if(d=d||b,a.indexOf(d.interpolationPrefix||N.interpolationPrefix)<0)return a;var e=d.interpolationPrefix?R.regexEscape(d.interpolationPrefix):N.interpolationPrefixEscaped,f=d.interpolationSuffix?R.regexEscape(d.interpolationSuffix):N.interpolationSuffixEscaped,g="HTML"+f,h=b.replace&&"object"==typeof b.replace?b.replace:b;return R.each(h,function(b,h){var i=c?c+N.keyseparator+b:b;"object"==typeof h&&null!==h?a=u(a,h,i,d):d.escapeInterpolation||N.escapeInterpolation?(a=a.replace(new RegExp([e,i,g].join(""),"g"),R.regexReplacementEscape(h)),a=a.replace(new RegExp([e,i,f].join(""),"g"),R.regexReplacementEscape(R.escape(h)))):a=a.replace(new RegExp([e,i,f].join(""),"g"),R.regexReplacementEscape(h))}),a}function v(a,b){var c=",",d="{",e="}",f=R.extend({},b);for(delete f.postProcess;-1!=a.indexOf(N.reusePrefix)&&(J++,!(J>N.maxRecursion));){var g=a.lastIndexOf(N.reusePrefix),h=a.indexOf(N.reuseSuffix,g)+N.reuseSuffix.length,i=a.substring(g,h),j=i.replace(N.reusePrefix,"").replace(N.reuseSuffix,"");if(g>=h)return R.error("there is an missing closing in following translation value",a),"";if(-1!=j.indexOf(c)){var k=j.indexOf(c);if(-1!=j.indexOf(d,k)&&-1!=j.indexOf(e,k)){var l=j.indexOf(d,k),m=j.indexOf(e,l)+e.length;try{f=R.extend(f,JSON.parse(j.substring(l,m))),j=j.substring(0,k)}catch(n){}}}var o=D(j,f);a=a.replace(i,R.regexReplacementEscape(o))}return a}function w(a){return a.context&&("string"==typeof a.context||"number"==typeof a.context)}function x(a){return void 0!==a.count&&"string"!=typeof a.count}function y(a){return void 0!==a.indefinite_article&&"string"!=typeof a.indefinite_article&&a.indefinite_article}function z(a,b){b=b||{};var c=B(a,b),d=E(a,b);return void 0!==d||d===c}function A(a,b){return b=b||{},L?(J=0,D.apply(null,arguments)):(R.log("i18next not finished initialization. you might have called t function before loading resources finished."),b.defaultValue||"")}function B(a,b){return void 0!==b.defaultValue?b.defaultValue:a}function C(){for(var a=[],b=1;b1)for(var d=0;d-1&&(e=c.split(N.nsseparator),i=e[0],c=e[1]),void 0===g&&N.sendMissing&&"function"==typeof N.missingKeyHandler&&(b.lng?N.missingKeyHandler(h[0],i,c,f,h):N.missingKeyHandler(N.lng,i,c,f,h));var j=b.postProcess||N.postProcess;void 0!==g&&j&&V[j]&&(g=V[j](g,c,b));var k=f;if(f.indexOf(N.nsseparator)>-1&&(e=f.split(N.nsseparator),k=e[1]),k===c&&N.parseMissingKey&&(f=N.parseMissingKey(f)),void 0===g&&(f=u(f,b),f=v(f,b),j&&V[j])){var l=B(c,b);g=V[j](l,c,b)}return void 0!==g?g:f}function E(a,b){b=b||{};var c,d,e=B(a,b),f=K;if(!I)return e;if("cimode"===f[0].toLowerCase())return e;if(b.lngs&&(f=b.lngs),b.lng&&(f=R.toLanguages(b.lng,b.fallbackLng),!I[f[0]])){var g=N.getAsync;N.getAsync=!1,H.sync.load(f,N,function(a,b){R.extend(I,b),N.getAsync=g})}var h=b.ns||N.ns.defaultNs;if(a.indexOf(N.nsseparator)>-1){var i=a.split(N.nsseparator);h=i[0],a=i[1]}if(w(b)){c=R.extend({},b),delete c.context,c.defaultValue=N.contextNotFound;var j=h+N.nsseparator+a+"_"+b.context;if(d=A(j,c),d!=N.contextNotFound)return u(d,{context:b.context})}if(x(b,f[0])){c=R.extend({lngs:[f[0]]},b),delete c.count,c.defaultValue=N.pluralNotFound;var k;if(U.needsPlural(f[0],b.count)){k=h+N.nsseparator+a+N.pluralSuffix;var l=U.get(f[0],b.count);l>=0?k=k+"_"+l:1===l&&(k=h+N.nsseparator+a)}else k=h+N.nsseparator+a;if(d=A(k,c),d!=N.pluralNotFound)return u(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix});if(f.length>1){var m=f.slice();if(m.shift(),b=R.extend(b,{lngs:m}),d=A(h+N.nsseparator+a,b),d!=N.pluralNotFound)return d}}if(y(b)){var n=R.extend({},b);delete n.indefinite_article,n.defaultValue=N.indefiniteNotFound;var o=h+N.nsseparator+a+(b.count&&!x(b,f[0])||!b.count?N.indefiniteSuffix:"");if(d=A(o,n),d!=N.indefiniteNotFound)return d}for(var p,q=a.split(N.keyseparator),r=0,s=f.length;s>r&&void 0===p;r++){for(var t=f[r],z=0,C=I[t]&&I[t][h];q[z];)C=C&&C[q[z]],z++;if(void 0!==C){var F=Object.prototype.toString.apply(C);if("string"==typeof C)C=u(C,b),C=v(C,b);else if("[object Array]"!==F||N.returnObjectTrees||b.returnObjectTrees){if(null===C&&N.fallbackOnNull===!0)C=void 0;else if(null!==C)if(N.returnObjectTrees||b.returnObjectTrees){if("[object Number]"!==F&&"[object Function]"!==F&&"[object RegExp]"!==F){var G="[object Array]"===F?[]:{};R.each(C,function(c){G[c]=D(h+N.nsseparator+a+N.keyseparator+c,b)}),C=G}}else N.objectTreeKeyHandler&&"function"==typeof N.objectTreeKeyHandler?C=N.objectTreeKeyHandler(a,C,t,h,b):(C="key '"+h+":"+a+" ("+t+")' "+"returned an object instead of string.",R.log(C))}else C=C.join("\n"),C=u(C,b),C=v(C,b);"string"==typeof C&&""===C.trim()&&N.fallbackOnEmpty===!0&&(C=void 0),p=C}}if(void 0===p&&!b.isFallbackLookup&&(N.fallbackToDefaultNS===!0||N.fallbackNS&&N.fallbackNS.length>0)){if(b.isFallbackLookup=!0,N.fallbackNS.length){for(var J=0,L=N.fallbackNS.length;L>J;J++)if(p=E(N.fallbackNS[J]+N.nsseparator+a,b)){var M=p.indexOf(N.nsseparator)>-1?p.split(N.nsseparator)[1]:p,O=e.indexOf(N.nsseparator)>-1?e.split(N.nsseparator)[1]:e;if(M!==O)break}}else p=E(a,b);b.isFallbackLookup=!1}return p}function F(){var a,b=N.lngWhitelist||[],c=[];if("undefined"!=typeof window&&!function(){for(var a=window.location.search.substring(1),b=a.split("&"),d=0;d0){var f=b[d].substring(0,e);f==N.detectLngQS&&c.push(b[d].substring(e+1))}}}(),N.useCookie&&"undefined"!=typeof document){var d=R.cookie.read(N.cookieName);d&&c.push(d)}if(N.detectLngFromLocalStorage&&"undefined"!=typeof window&&window.localStorage&&c.push(window.localStorage.getItem("i18next_lng")),"undefined"!=typeof navigator){if(navigator.languages)for(var e=0;e-1){var f=e.split("-");e=N.lowerCaseLng?f[0].toLowerCase()+"-"+f[1].toLowerCase():f[0].toLowerCase()+"-"+f[1].toUpperCase()}if(0===b.length||b.indexOf(e)>-1){a=e;break}}}(),a||(a=N.fallbackLng[0]),a}Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>0&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&1/0!=d&&d!=-1/0&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=c;arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d))));for(var e=d>=0?Math.min(d,c-1):c-Math.abs(d);e>=0;e--)if(e in b&&b[e]===a)return e;return-1}),"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")});var G,H={},I={},J=0,K=[],L=!1,M={};M={load:function(a,b,c){b.useLocalStorage?M._loadLocal(a,b,function(d,e){for(var f=[],g=0,h=a.length;h>g;g++)e[a[g]]||f.push(a[g]);f.length>0?M._fetch(f,b,function(a,b){R.extend(e,b),M._storeLocal(b),c(null,e)}):c(null,e)}):M._fetch(a,b,function(a,b){c(null,b)})},_loadLocal:function(a,b,c){var d={},e=(new Date).getTime();if(window.localStorage){var f=a.length;R.each(a,function(a,g){var h=window.localStorage.getItem("res_"+g);h&&(h=JSON.parse(h),h.i18nStamp&&h.i18nStamp+b.localStorageExpirationTime>e&&(d[g]=h)),f--,0===f&&c(null,d)})}},_storeLocal:function(a){if(window.localStorage)for(var b in a)a[b].i18nStamp=(new Date).getTime(),R.localStorage.setItem("res_"+b,JSON.stringify(a[b]))},_fetch:function(a,b,c){var d=b.ns,e={};if(b.dynamicLoad){var f=function(a,b){c(null,b)};if("function"==typeof b.customLoad)b.customLoad(a,d.namespaces,b,f);else{var g=u(b.resGetPath,{lng:a.join("+"),ns:d.namespaces.join("+")});R.ajax({url:g,success:function(a){R.log("loaded: "+g),f(null,a)},error:function(a,b,c){R.log("failed loading: "+g),f("failed loading resource.json error: "+c)},dataType:"json",async:b.getAsync})}}else{var h,i=d.namespaces.length*a.length;R.each(d.namespaces,function(d,f){R.each(a,function(a,d){var g=function(a,b){a&&(h=h||[],h.push(a)),e[d]=e[d]||{},e[d][f]=b,i--,0===i&&c(h,e)};"function"==typeof b.customLoad?b.customLoad(d,f,b,g):M._fetchOne(d,f,b,g)})})}},_fetchOne:function(a,b,c,d){var e=u(c.resGetPath,{lng:a,ns:b});R.ajax({url:e,success:function(a){R.log("loaded: "+e),d(null,a)},error:function(a,b,c){if(b&&200==b||a&&a.status&&200==a.status)R.error("There is a typo in: "+e);else if(b&&404==b||a&&a.status&&404==a.status)R.log("Does not exist: "+e);else{var f=b?b:a&&a.status?a.status:null;R.log(f+" when loading "+e)}d(c,{})},dataType:"json",async:c.getAsync})},postMissing:function(a,b,c,d,e){var f={};f[c]=d;var g=[];if("fallback"===N.sendMissingTo&&N.fallbackLng[0]!==!1)for(var h=0;hh;h++)g.push({lng:e[h],url:u(N.resPostPath,{lng:e[h],ns:b})});for(var j=0,k=g.length;k>j;j++){var l=g[j];R.ajax({url:l.url,type:N.sendType,data:f,success:function(){R.log("posted missing key '"+c+"' to: "+l.url);for(var a=c.split("."),e=0,f=I[l.lng][b];a[e];)f=f[a[e]]=e===a.length-1?d:f[a[e]]||{},e++},error:function(){R.log("failed posting missing key '"+c+"' to: "+l.url)},dataType:"json",async:N.postAsync})}},reload:s};var N={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:["dev"],fallbackNS:[],detectLngQS:"setLng",detectLngFromLocalStorage:!1,ns:"translation",fallbackOnNull:!0,fallbackOnEmpty:!1,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",defaultVariables:!1,reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,indefiniteSuffix:"_indefinite",indefiniteNotFound:["indefinite_not_found",Math.random()].join(""),setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",cookieDomain:void 0,objectTreeKeyHandler:void 0,postProcess:void 0,parseMissingKey:void 0,missingKeyHandler:M.postMissing,shortcutFunction:"sprintf"},O={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},P={create:function(a,b,c,d){var e;if(c){var f=new Date;f.setTime(f.getTime()+1e3*60*c),e="; expires="+f.toGMTString()}else e="";d=d?"domain="+d+";":"",document.cookie=a+"="+b+e+";"+d+"path=/"},read:function(a){for(var b=a+"=",c=document.cookie.split(";"),d=0;d-1){var c=a.split("-");b=N.lowerCaseLng?c[0].toLowerCase()+"-"+c[1].toLowerCase():c[0].toLowerCase()+"-"+c[1].toUpperCase()}else b=N.lowerCaseLng?a.toLowerCase():a;return b}var c=this.log,d=[],e=N.lngWhitelist||!1,f=function(a){!e||e.indexOf(a)>-1?d.push(a):c("rejecting non-whitelisted language: "+a)};if("string"==typeof a&&a.indexOf("-")>-1){var g=a.split("-");"unspecific"!==N.load&&f(b(a)),"current"!==N.load&&f(b(g[this.getCountyIndexOfLng(a)]))}else f(b(a));for(var h=0;h1)},2:function(a){return Number(1!=a)},3:function(){return 0},4:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},5:function(a){return Number(0===a?0:1==a?1:2==a?2:a%100>=3&&10>=a%100?3:a%100>=11?4:5)},6:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)},7:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},8:function(a){return Number(1==a?0:2==a?1:8!=a&&11!=a?2:3)},9:function(a){return Number(a>=2)},10:function(a){return Number(1==a?0:2==a?1:7>a?2:11>a?3:4)},11:function(a){return Number(1==a||11==a?0:2==a||12==a?1:a>2&&20>a?2:3)},12:function(a){return Number(1!=a%10||11==a%100)},13:function(a){return Number(0!==a)},14:function(a){return Number(1==a?0:2==a?1:3==a?2:3)},15:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&(10>a%100||a%100>=20)?1:2)},16:function(a){return Number(1==a%10&&11!=a%100?0:0!==a?1:2)},17:function(a){return Number(1==a||1==a%10?0:1)},18:function(a){return Number(1==a?1:2)},19:function(a){return Number(1==a?0:0===a||a%100>1&&11>a%100?1:a%100>10&&20>a%100?2:3)},20:function(a){return Number(1==a?0:0===a||a%100>0&&20>a%100?1:2)},21:function(a){return Number(1==a%100?1:2==a%100?2:3==a%100||4==a%100?3:0)}},U={rules:function(){var a,b={};for(a=S.length;a--;)b[S[a][0]]={name:S[a][1],numbers:S[a][2],plurals:T[S[a][3]]};return b}(),addRule:function(a,b){U.rules[a]=b},setCurrentLng:function(a){if(!U.currentRule||U.currentRule.lng!==a){var b=a.split("-");U.currentRule={lng:a,rule:U.rules[b[0]]}}},needsPlural:function(a,b){var c,d=a.split("-");return c=U.currentRule&&U.currentRule.lng===a?U.currentRule.rule:U.rules[d[R.getCountyIndexOfLng(a)]],c&&c.numbers.length<=1?!1:1!==this.get(a,b)},get:function(a,b){function c(b,c){var d;if(d=U.currentRule&&U.currentRule.lng===a?U.currentRule.rule:U.rules[b]){var e;e=d.noAbs?d.plurals(c):d.plurals(Math.abs(c));var f=d.numbers[e];return 2===d.numbers.length&&1===d.numbers[0]&&(2===f?f=-1:1===f&&(f=1)),f}return 1===c?"1":"-1"}var d=a.split("-");return c(d[R.getCountyIndexOfLng(a)],b)}},V={},W=function(a,b){V[a]=b},X=function(){function a(a){return Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}function b(a,b){for(var c=[];b>0;c[--b]=a);return c.join("")}var c=function(){return c.cache.hasOwnProperty(arguments[0])||(c.cache[arguments[0]]=c.parse(arguments[0])),c.format.call(null,c.cache[arguments[0]],arguments)};return c.format=function(c,d){var e,f,g,h,i,j,k,l=1,m=c.length,n="",o=[];for(f=0;m>f;f++)if(n=a(c[f]),"string"===n)o.push(c[f]);else if("array"===n){if(h=c[f],h[2])for(e=d[l],g=0;g=0?"+"+e:e,j=h[4]?"0"==h[4]?"0":h[4].charAt(1):" ",k=h[6]-String(e).length,i=h[6]?b(j,k):"",o.push(h[5]?e+i:i+e)}return o.join("")},c.cache={},c.parse=function(a){for(var b=a,c=[],d=[],e=0;b;){if(null!==(c=/^[^\x25]+/.exec(b)))d.push(c[0]);else if(null!==(c=/^\x25{2}/.exec(b)))d.push("%");else{if(null===(c=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(b)))throw"[sprintf] huh?";if(c[2]){e|=1;var f=[],g=c[2],h=[];if(null===(h=/^([a-z_][a-z_\d]*)/i.exec(g)))throw"[sprintf] huh?";for(f.push(h[1]);""!==(g=g.substring(h[0].length));)if(null!==(h=/^\.([a-z_][a-z_\d]*)/i.exec(g)))f.push(h[1]);else{if(null===(h=/^\[(\d+)\]/.exec(g)))throw"[sprintf] huh?";f.push(h[1])}c[2]=f}else e|=2;if(3===e)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";d.push(c)}b=b.substring(c[0].length)}return d},c}(),Y=function(a,b){return b.unshift(a),X.apply(null,b)};return W("sprintf",function(a,b,c){return c.sprintf?"[object Array]"===Object.prototype.toString.apply(c.sprintf)?Y(a,c.sprintf):"object"==typeof c.sprintf?X(a,c.sprintf):a:a}),H.init=g,H.setLng=q,H.preload=h,H.addResourceBundle=i,H.hasResourceBundle=j,H.addResource=l,H.addResources=m,H.removeResourceBundle=k,H.loadNamespace=o,H.loadNamespaces=p,H.setDefaultNamespace=n,H.t=A,H.translate=A,H.exists=z,H.detectLanguage=R.detectLanguage,H.pluralExtensions=U,H.sync=M,H.functions=R,H.lng=r,H.addPostProcessor=W,H.options=N,a.i18n=H,a.t=H.t,H}); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd.withJQuery-1.7.7.js b/libs/i18next/release/i18next.amd.withJQuery-1.7.7.js new file mode 100644 index 00000000..1bd9ccd6 --- /dev/null +++ b/libs/i18next/release/i18next.amd.withJQuery-1.7.7.js @@ -0,0 +1,2113 @@ +// i18next, v1.7.7 +// Copyright (c)2014 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function (root, factory) { + if (typeof exports === 'object') { + + var jquery = require('jquery'); + + module.exports = factory(jquery); + + } else if (typeof define === 'function' && define.amd) { + + define(['jquery'], factory); + + } +}(this, function ($) { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + // Add string trim for IE8. + if (typeof String.prototype.trim !== 'function') { + String.prototype.trim = function() { + return this.replace(/^\s+|\s+$/g, ''); + } + } + + var i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = [] + , initialized = false + , sync = {}; + + sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = window.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + f.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + if ((status && status == 200) || (xhr && xhr.status && xhr.status == 200)) { + // file loaded but invalid json, stop waste time ! + f.error('There is a typo in: ' + url); + } else if ((status && status == 404) || (xhr && xhr.status && xhr.status == 404)) { + f.log('Does not exist: ' + url); + } else { + var theStatus = status ? status : ((xhr && xhr.status) ? xhr.status : null); + f.log(theStatus + ' when loading ' + url); + } + + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback' && o.fallbackLng[0] !== false) { + for (var i = 0; i < o.fallbackLng.length; i++) { + urls.push({lng: o.fallbackLng[i], url: applyReplacement(o.resPostPath, { lng: o.fallbackLng[i], ns: ns })}); + } + } else if (o.sendMissingTo === 'current' || (o.sendMissingTo === 'fallback' && o.fallbackLng[0] === false) ) { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + }, + + reload: reload + }; + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: ['dev'], + fallbackNS: [], + detectLngQS: 'setLng', + detectLngFromLocalStorage: false, + ns: 'translation', + fallbackOnNull: true, + fallbackOnEmpty: false, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + defaultVariables: false, + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + indefiniteSuffix: '_indefinite', + indefiniteNotFound: ['indefinite_not_found', Math.random()].join(''), + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + cookieDomain: undefined, + + objectTreeKeyHandler: undefined, + postProcess: undefined, + parseMissingKey: undefined, + missingKeyHandler: sync.postMissing, + + shortcutFunction: 'sprintf' // or: defaultValue + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _deepExtend(target, source) { + for (var prop in source) + if (prop in target) + _deepExtend(target[prop], source[prop]); + else + target[prop] = source[prop]; + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || Object.prototype.toString.apply(object) !== '[object Array]' || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + try { + return JSON.parse(data) + } catch (e) { + f.error('Can not parse JSON. URL: ' + url); + return {}; + } + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + // file: protocol always gives status code 0, so check for data + if (status === 200 || (status === 0 && data.text())) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes,domain) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + domain = (domain)? "domain="+domain+";" : ""; + document.cookie = name+"="+value+expires+";"+domain+"path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes,domain) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + deepExtend: _deepExtend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : (typeof document !== 'undefined' ? _ajax : function() {}), + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + error: function(str) { + if (typeof console !== "undefined") console.error(str); + }, + getCountyIndexOfLng: function(lng) { + var lng_index = 0; + if (lng === 'nb-NO' || lng === 'nn-NO' || lng === 'nb-no' || lng === 'nn-no') lng_index = 1; + return lng_index; + }, + toLanguages: function(lng) { + var log = this.log; + + function applyCase(l) { + var ret = l; + + if (typeof l === 'string' && l.indexOf('-') > -1) { + var parts = l.split('-'); + + ret = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } else { + ret = o.lowerCaseLng ? l.toLowerCase() : l; + } + + return ret; + } + + var languages = []; + var whitelist = o.lngWhitelist || false; + var addLanguage = function(language){ + //reject langs not whitelisted + if(!whitelist || whitelist.indexOf(language) > -1){ + languages.push(language); + }else{ + log('rejecting non-whitelisted language: ' + language); + } + }; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + if (o.load !== 'unspecific') addLanguage(applyCase(lng)); + if (o.load !== 'current') addLanguage(applyCase(parts[this.getCountyIndexOfLng(lng)])); + } else { + addLanguage(applyCase(lng)); + } + + for (var i = 0; i < o.fallbackLng.length; i++) { + if (languages.indexOf(o.fallbackLng[i]) === -1 && o.fallbackLng[i]) languages.push(applyCase(o.fallbackLng[i])); + } + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + }, + regexReplacementEscape: function(strOrFn) { + if (typeof strOrFn === 'string') { + return strOrFn.replace(/\$/g, "$$$$"); + } else { + return strOrFn; + } + }, + localStorage: { + setItem: function(key, value) { + if (window.localStorage) { + try { + window.localStorage.setItem(key, value); + } catch (e) { + f.log('failed to set value for key "' + key + '" to localStorage.'); + } + } + } + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + delete o.fixLng; /* passed in each time */ + + // override functions: .log(), .detectLanguage(), etc + if (o.functions) { + delete o.functions; + f.extend(f, options.functions); + } + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // fallback languages + if (typeof o.fallbackLng == 'string' || typeof o.fallbackLng == 'boolean') { + o.fallbackLng = [o.fallbackLng]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + if (o.useCookie && f.cookie.read(o.cookieName) !== currentLng){ //cookie is unset or invalid + f.cookie.create(o.cookieName, currentLng, o.cookieExpirationTime, o.cookieDomain); + } + if (o.detectLngFromLocalStorage && typeof document !== 'undefined' && window.localStorage) { + f.localStorage.setItem('i18next_lng', currentLng); + } + + var lngTranslate = translate; + if (options.fixLng) { + lngTranslate = function(key, options) { + options = options || {}; + options.lng = options.lng || lngTranslate.lng; + return translate(key, options); + }; + lngTranslate.lng = currentLng; + } + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + initialized = true; + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + initialized = true; + + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources, deep) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + if (deep) { + f.deepExtend(resStore[lng][ns], resources); + } else { + f.extend(resStore[lng][ns], resources); + } + } + + function hasResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + var res = resStore[lng][ns] || {}; + + var hasValues = false; + for(var prop in res) { + if (res.hasOwnProperty(prop)) { + hasValues = true; + } + } + + return hasValues; + } + + function removeResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = {}; + } + + function addResource(lng, ns, key, value) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + var keys = key.split(o.keyseparator); + var x = 0; + var node = resStore[lng][ns]; + var origRef = node; + + while (keys[x]) { + if (x == keys.length - 1) + node[keys[x]] = value; + else { + if (node[keys[x]] == null) + node[keys[x]] = {}; + + node = node[keys[x]]; + } + x++; + } + } + + function addResources(lng, ns, resources) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + for (var m in resources) { + if (typeof resources[m] === 'string') addResource(lng, ns, m, resources[m]); + } + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, options, cb) { + if (typeof options === 'function') { + cb = options; + options = {}; + } else if (!options) { + options = {}; + } + + options.lng = lng; + return init(options, cb); + } + + function lng() { + return currentLng; + } + + function reload(cb) { + resStore = {}; + setLng(currentLng, cb); + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else if (attr === 'prepend') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.prepend($.t(key, optionsToUse)); + } else if (attr === 'append') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.append($.t(key, optionsToUse)); + } else if (attr.indexOf("data-") === 0) { + var dataAttr = attr.substr(("data-").length); + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.data(dataAttr) }, options) : options; + var translated = $.t(key, optionsToUse); + //we change into the data cache + ele.data(dataAttr, translated); + //we change into the dom + ele.attr(attr, translated); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key && typeof key !== 'undefined' && key !== false) key = ele.text() || ele.val(); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + var hash = replacementHash.replace && typeof replacementHash.replace === 'object' ? replacementHash.replace : replacementHash; + f.each(hash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), f.regexReplacementEscape(value)); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(f.escape(value))); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(value)); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + if (index_of_end_of_closing <= index_of_opening) { + f.error('there is an missing closing in following translation value', translated); + return ''; + } + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, f.regexReplacementEscape(translated_token)); + } + return translated; + } + + function hasContext(options) { + return (options.context && (typeof options.context == 'string' || typeof options.context == 'number')); + } + + function needsPlural(options, lng) { + return (options.count !== undefined && typeof options.count != 'string'/* && pluralExtensions.needsPlural(lng, options.count)*/); + } + + function needsIndefiniteArticle(options) { + return (options.indefinite_article !== undefined && typeof options.indefinite_article != 'string' && options.indefinite_article); + } + + function exists(key, options) { + options = options || {}; + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + options = options || {}; + + if (!initialized) { + f.log('i18next not finished initialization. you might have called t function before loading resources finished.') + return options.defaultValue || ''; + }; + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _getDefaultValue(key, options) { + return (options.defaultValue !== undefined) ? options.defaultValue : key; + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(potentialKeys, options) { + if (options && typeof options !== 'object') { + if (o.shortcutFunction === 'sprintf') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else if (o.shortcutFunction === 'defaultValue') { + options = { + defaultValue: options + } + } + } else { + options = options || {}; + } + + if (typeof o.defaultVariables === 'object') { + options = f.extend({}, o.defaultVariables, options); + } + + if (potentialKeys === undefined || potentialKeys === null || potentialKeys === '') return ''; + + if (typeof potentialKeys === 'string') { + potentialKeys = [potentialKeys]; + } + + var key = potentialKeys[0]; + + if (potentialKeys.length > 1) { + for (var i = 0; i < potentialKeys.length; i++) { + key = potentialKeys[i]; + if (exists(key, options)) { + break; + } + } + } + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng, options.fallbackLng) : languages + , ns = options.ns || o.ns.defaultNs + , parts; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing && typeof o.missingKeyHandler === 'function') { + if (options.lng) { + o.missingKeyHandler(lngs[0], ns, key, notFound, lngs); + } else { + o.missingKeyHandler(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessor = options.postProcess || o.postProcess; + if (found !== undefined && postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + } + + // process notFound if function exists + var splitNotFound = notFound; + if (notFound.indexOf(o.nsseparator) > -1) { + parts = notFound.split(o.nsseparator); + splitNotFound = parts[1]; + } + if (splitNotFound === key && o.parseMissingKey) { + notFound = o.parseMissingKey(notFound); + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessor && postProcessors[postProcessor]) { + var val = _getDefaultValue(key, options); + found = postProcessors[postProcessor](val, key, options); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options) { + options = options || {}; + + var optionWithoutCount, translated + , notFound = _getDefaultValue(key, options) + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + // CI mode + if (lngs[0].toLowerCase() === 'cimode') return notFound; + + // passed in lng + if (options.lngs) lngs = options.lngs; + if (options.lng) { + lngs = f.toLanguages(options.lng, options.fallbackLng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options, lngs[0])) { + optionWithoutCount = f.extend({ lngs: [lngs[0]]}, options); + delete optionWithoutCount.count; + delete optionWithoutCount.lng; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey; + if (!pluralExtensions.needsPlural(lngs[0], options.count)) { + pluralKey = ns + o.nsseparator + key; + } else { + pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(lngs[0], options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + } + + translated = translate(pluralKey, optionWithoutCount); + + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } else if (lngs.length > 1) { + // remove failed lng + var clone = lngs.slice(); + clone.shift(); + options = f.extend(options, { lngs: clone }); + delete options.lng; + // retry with fallbacks + translated = translate(ns + o.nsseparator + key, options); + if (translated != o.pluralNotFound) return translated; + } else { + return translated; + } + } + + if (needsIndefiniteArticle(options)) { + var optionsWithoutIndef = f.extend({}, options); + delete optionsWithoutIndef.indefinite_article; + optionsWithoutIndef.defaultValue = o.indefiniteNotFound; + // If we don't have a count, we want the indefinite, if we do have a count, and needsPlural is false + var indefiniteKey = ns + o.nsseparator + key + (((options.count && !needsPlural(options, lngs[0])) || !options.count) ? o.indefiniteSuffix : ""); + translated = translate(indefiniteKey, optionsWithoutIndef); + if (translated != o.indefiniteNotFound) { + return translated; + } + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + var valueType = Object.prototype.toString.apply(value); + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (valueType === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + if (o.objectTreeKeyHandler && typeof o.objectTreeKeyHandler == 'function') { + value = o.objectTreeKeyHandler(key, value, l, ns, options); + } else { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned an object instead of string.'; + f.log(value); + } + } else if (valueType !== '[object Number]' && valueType !== '[object Function]' && valueType !== '[object RegExp]') { + var copy = (valueType === '[object Array]') ? [] : {}; // apply child translation on a copy + f.each(value, function(m) { + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + }); + value = copy; + } + } + + if (typeof value === 'string' && value.trim() === '' && o.fallbackOnEmpty === true) + value = undefined; + + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length > 0))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found || (found==="" && o.fallbackOnEmpty === false)) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + options.isFallbackLookup = false; + } + + return found; + } + function detectLanguage() { + var detectedLng; + var whitelist = o.lngWhitelist || []; + var userLngChoices = []; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var params = query.split('&'); + for (var i=0; i 0) { + var key = params[i].substring(0,pos); + if (key == o.detectLngQS) { + userLngChoices.push(params[i].substring(pos+1)); + } + } + } + })(); + } + + // get from cookie + if (o.useCookie && typeof document !== 'undefined') { + var c = f.cookie.read(o.cookieName); + if (c) userLngChoices.push(c); + } + + // get from localStorage + if (o.detectLngFromLocalStorage && typeof window !== 'undefined' && window.localStorage) { + userLngChoices.push(window.localStorage.getItem('i18next_lng')); + } + + // get from navigator + if (typeof navigator !== 'undefined') { + if (navigator.languages) { // chrome only; not an array, so can't use .push.apply instead of iterating + for (var i=0;i -1) { + var parts = lng.split('-'); + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } + + if (whitelist.length === 0 || whitelist.indexOf(lng) > -1) { + detectedLng = lng; + break; + } + } + })(); + + //fallback + if (!detectedLng){ + detectedLng = o.fallbackLng[0]; + } + + return detectedLng; + } + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + + /* [code, name, numbers, pluralsType] */ + var _rules = [ + ["ach", "Acholi", [1,2], 1], + ["af", "Afrikaans",[1,2], 2], + ["ak", "Akan", [1,2], 1], + ["am", "Amharic", [1,2], 1], + ["an", "Aragonese",[1,2], 2], + ["ar", "Arabic", [0,1,2,3,11,100],5], + ["arn", "Mapudungun",[1,2], 1], + ["ast", "Asturian", [1,2], 2], + ["ay", "Aymará", [1], 3], + ["az", "Azerbaijani",[1,2],2], + ["be", "Belarusian",[1,2,5],4], + ["bg", "Bulgarian",[1,2], 2], + ["bn", "Bengali", [1,2], 2], + ["bo", "Tibetan", [1], 3], + ["br", "Breton", [1,2], 1], + ["bs", "Bosnian", [1,2,5],4], + ["ca", "Catalan", [1,2], 2], + ["cgg", "Chiga", [1], 3], + ["cs", "Czech", [1,2,5],6], + ["csb", "Kashubian",[1,2,5],7], + ["cy", "Welsh", [1,2,3,8],8], + ["da", "Danish", [1,2], 2], + ["de", "German", [1,2], 2], + ["dev", "Development Fallback", [1,2], 2], + ["dz", "Dzongkha", [1], 3], + ["el", "Greek", [1,2], 2], + ["en", "English", [1,2], 2], + ["eo", "Esperanto",[1,2], 2], + ["es", "Spanish", [1,2], 2], + ["es_ar","Argentinean Spanish", [1,2], 2], + ["et", "Estonian", [1,2], 2], + ["eu", "Basque", [1,2], 2], + ["fa", "Persian", [1], 3], + ["fi", "Finnish", [1,2], 2], + ["fil", "Filipino", [1,2], 1], + ["fo", "Faroese", [1,2], 2], + ["fr", "French", [1,2], 9], + ["fur", "Friulian", [1,2], 2], + ["fy", "Frisian", [1,2], 2], + ["ga", "Irish", [1,2,3,7,11],10], + ["gd", "Scottish Gaelic",[1,2,3,20],11], + ["gl", "Galician", [1,2], 2], + ["gu", "Gujarati", [1,2], 2], + ["gun", "Gun", [1,2], 1], + ["ha", "Hausa", [1,2], 2], + ["he", "Hebrew", [1,2], 2], + ["hi", "Hindi", [1,2], 2], + ["hr", "Croatian", [1,2,5],4], + ["hu", "Hungarian",[1,2], 2], + ["hy", "Armenian", [1,2], 2], + ["ia", "Interlingua",[1,2],2], + ["id", "Indonesian",[1], 3], + ["is", "Icelandic",[1,2], 12], + ["it", "Italian", [1,2], 2], + ["ja", "Japanese", [1], 3], + ["jbo", "Lojban", [1], 3], + ["jv", "Javanese", [0,1], 13], + ["ka", "Georgian", [1], 3], + ["kk", "Kazakh", [1], 3], + ["km", "Khmer", [1], 3], + ["kn", "Kannada", [1,2], 2], + ["ko", "Korean", [1], 3], + ["ku", "Kurdish", [1,2], 2], + ["kw", "Cornish", [1,2,3,4],14], + ["ky", "Kyrgyz", [1], 3], + ["lb", "Letzeburgesch",[1,2],2], + ["ln", "Lingala", [1,2], 1], + ["lo", "Lao", [1], 3], + ["lt", "Lithuanian",[1,2,10],15], + ["lv", "Latvian", [1,2,0],16], + ["mai", "Maithili", [1,2], 2], + ["mfe", "Mauritian Creole",[1,2],1], + ["mg", "Malagasy", [1,2], 1], + ["mi", "Maori", [1,2], 1], + ["mk", "Macedonian",[1,2],17], + ["ml", "Malayalam",[1,2], 2], + ["mn", "Mongolian",[1,2], 2], + ["mnk", "Mandinka", [0,1,2],18], + ["mr", "Marathi", [1,2], 2], + ["ms", "Malay", [1], 3], + ["mt", "Maltese", [1,2,11,20],19], + ["nah", "Nahuatl", [1,2], 2], + ["nap", "Neapolitan",[1,2], 2], + ["nb", "Norwegian Bokmal",[1,2],2], + ["ne", "Nepali", [1,2], 2], + ["nl", "Dutch", [1,2], 2], + ["nn", "Norwegian Nynorsk",[1,2],2], + ["no", "Norwegian",[1,2], 2], + ["nso", "Northern Sotho",[1,2],2], + ["oc", "Occitan", [1,2], 1], + ["or", "Oriya", [2,1], 2], + ["pa", "Punjabi", [1,2], 2], + ["pap", "Papiamento",[1,2], 2], + ["pl", "Polish", [1,2,5],7], + ["pms", "Piemontese",[1,2], 2], + ["ps", "Pashto", [1,2], 2], + ["pt", "Portuguese",[1,2], 2], + ["pt_br","Brazilian Portuguese",[1,2], 2], + ["rm", "Romansh", [1,2], 2], + ["ro", "Romanian", [1,2,20],20], + ["ru", "Russian", [1,2,5],4], + ["sah", "Yakut", [1], 3], + ["sco", "Scots", [1,2], 2], + ["se", "Northern Sami",[1,2], 2], + ["si", "Sinhala", [1,2], 2], + ["sk", "Slovak", [1,2,5],6], + ["sl", "Slovenian",[5,1,2,3],21], + ["so", "Somali", [1,2], 2], + ["son", "Songhay", [1,2], 2], + ["sq", "Albanian", [1,2], 2], + ["sr", "Serbian", [1,2,5],4], + ["su", "Sundanese",[1], 3], + ["sv", "Swedish", [1,2], 2], + ["sw", "Swahili", [1,2], 2], + ["ta", "Tamil", [1,2], 2], + ["te", "Telugu", [1,2], 2], + ["tg", "Tajik", [1,2], 1], + ["th", "Thai", [1], 3], + ["ti", "Tigrinya", [1,2], 1], + ["tk", "Turkmen", [1,2], 2], + ["tr", "Turkish", [1,2], 1], + ["tt", "Tatar", [1], 3], + ["ug", "Uyghur", [1], 3], + ["uk", "Ukrainian",[1,2,5],4], + ["ur", "Urdu", [1,2], 2], + ["uz", "Uzbek", [1,2], 1], + ["vi", "Vietnamese",[1], 3], + ["wa", "Walloon", [1,2], 1], + ["wo", "Wolof", [1], 3], + ["yo", "Yoruba", [1,2], 2], + ["zh", "Chinese", [1], 3] + ]; + + var _rulesPluralsTypes = { + 1: function(n) {return Number(n > 1);}, + 2: function(n) {return Number(n != 1);}, + 3: function(n) {return 0;}, + 4: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 5: function(n) {return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5);}, + 6: function(n) {return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2);}, + 7: function(n) {return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 8: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3);}, + 9: function(n) {return Number(n >= 2);}, + 10: function(n) {return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;}, + 11: function(n) {return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3);}, + 12: function(n) {return Number(n%10!=1 || n%100==11);}, + 13: function(n) {return Number(n !== 0);}, + 14: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3);}, + 15: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 16: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2);}, + 17: function(n) {return Number(n==1 || n%10==1 ? 0 : 1);}, + 18: function(n) {return Number(0 ? 0 : n==1 ? 1 : 2);}, + 19: function(n) {return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3);}, + 20: function(n) {return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2);}, + 21: function(n) {return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }; + + var pluralExtensions = { + + rules: (function () { + var l, rules = {}; + for (l=_rules.length; l-- ;) { + rules[_rules[l][0]] = { + name: _rules[l][1], + numbers: _rules[l][2], + plurals: _rulesPluralsTypes[_rules[l][3]] + } + } + return rules; + }()), + + // you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + needsPlural: function(lng, count) { + var parts = lng.split('-'); + + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[parts[f.getCountyIndexOfLng(lng)]]; + } + + if (ext && ext.numbers.length <= 1) { + return false; + } else { + return this.get(lng, count) !== 1; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i; + if (ext.noAbs) { + i = ext.plurals(c); + } else { + i = ext.plurals(Math.abs(c)); + } + + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[f.getCountyIndexOfLng(lng)], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.hasResourceBundle = hasResourceBundle; + i18n.addResource = addResource; + i18n.addResources = addResources; + i18n.removeResourceBundle = removeResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.options = o; + + $.i18n = i18n; + $.t = i18n.t; + + return i18n; + +})); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd.withJQuery-1.7.7.min.js b/libs/i18next/release/i18next.amd.withJQuery-1.7.7.min.js new file mode 100644 index 00000000..8b9964cd --- /dev/null +++ b/libs/i18next/release/i18next.amd.withJQuery-1.7.7.min.js @@ -0,0 +1,5 @@ +// i18next, v1.7.7 +// Copyright (c)2014 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +!function(a,b){if("object"==typeof exports){var c=require("jquery");module.exports=b(c)}else"function"==typeof define&&define.amd&&define(["jquery"],b)}(this,function(a){function b(a,b){if(!b||"function"==typeof b)return a;for(var c in b)a[c]=b[c];return a}function c(a,b){for(var d in b)d in a?c(a[d],b[d]):a[d]=b[d];return a}function d(a,b,c){var d,e=0,f=a.length,g=void 0===f||"[object Array]"!==Object.prototype.toString.apply(a)||"function"==typeof a;if(c)if(g){for(d in a)if(b.apply(a[d],c)===!1)break}else for(;f>e&&b.apply(a[e++],c)!==!1;);else if(g){for(d in a)if(b.call(a[d],d,a[d])===!1)break}else for(;f>e&&b.call(a[e],e,a[e++])!==!1;);return a}function e(a){return"string"==typeof a?a.replace(/[&<>"'\/]/g,function(a){return O[a]}):a}function f(a){var b=function(a){if(window.XMLHttpRequest)return a(null,new XMLHttpRequest);if(window.ActiveXObject)try{return a(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(b){return a(null,new ActiveXObject("Microsoft.XMLHTTP"))}return a(new Error)},c=function(a){if("string"==typeof a)return a;var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")},d=function(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;cd?b+=String.fromCharCode(d):d>127&&2048>d?(b+=String.fromCharCode(192|d>>6),b+=String.fromCharCode(128|63&d)):(b+=String.fromCharCode(224|d>>12),b+=String.fromCharCode(128|63&d>>6),b+=String.fromCharCode(128|63&d))}return b},e=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";a=d(a);var c,e,f,g,h,i,j,k="",l=0;do c=a.charCodeAt(l++),e=a.charCodeAt(l++),f=a.charCodeAt(l++),g=c>>2,h=(3&c)<<4|e>>4,i=(15&e)<<2|f>>6,j=63&f,isNaN(e)?i=j=64:isNaN(f)&&(j=64),k+=b.charAt(g)+b.charAt(h)+b.charAt(i)+b.charAt(j),c=e=f="",g=h=i=j="";while(l1&&(d+=d.indexOf("?")>-1?"&"+k:"?"+k),e.jsonp){var l=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=d,l.appendChild(m),void 0}}b(function(b,c){if(b)return h(b);c.open(a,d,e.async);for(var f in j)j.hasOwnProperty(f)&&c.setRequestHeader(f,j[f]);c.onreadystatechange=function(){if(4===c.readyState){var a=c.responseText||"";if(!h)return;h(c.status,{text:function(){return a},json:function(){try{return JSON.parse(a)}catch(b){return R.error("Can not parse JSON. URL: "+d),{}}}})}},c.send(i)})},h={authBasic:function(a,b){g.headers.Authorization="Basic "+e(a+":"+b)},connect:function(a,b,c){return g("CONNECT",a,b,c)},del:function(a,b,c){return g("DELETE",a,b,c)},get:function(a,b,c){return g("GET",a,b,c)},head:function(a,b,c){return g("HEAD",a,b,c)},headers:function(a){g.headers=a||{}},isAllowed:function(a,b,c){this.options(a,function(a,d){c(-1!==d.text().indexOf(b))})},options:function(a,b,c){return g("OPTIONS",a,b,c)},patch:function(a,b,c){return g("PATCH",a,b,c)},post:function(a,b,c){return g("POST",a,b,c)},put:function(a,b,c){return g("PUT",a,b,c)},trace:function(a,b,c){return g("TRACE",a,b,c)}},i=a.type?a.type.toLowerCase():"get";h[i](a.url,a,function(b,c){200===b||0===b&&c.text()?a.success(c.json(),b,null):a.error(c.text(),b,null)})}function g(b,c){"function"==typeof b&&(c=b,b={}),b=b||{},R.extend(N,b),delete N.fixLng,N.functions&&(delete N.functions,R.extend(R,b.functions)),"string"==typeof N.ns&&(N.ns={namespaces:[N.ns],defaultNs:N.ns}),"string"==typeof N.fallbackNS&&(N.fallbackNS=[N.fallbackNS]),("string"==typeof N.fallbackLng||"boolean"==typeof N.fallbackLng)&&(N.fallbackLng=[N.fallbackLng]),N.interpolationPrefixEscaped=R.regexEscape(N.interpolationPrefix),N.interpolationSuffixEscaped=R.regexEscape(N.interpolationSuffix),N.lng||(N.lng=R.detectLanguage()),K=R.toLanguages(N.lng),G=K[0],R.log("currentLng set to: "+G),N.useCookie&&R.cookie.read(N.cookieName)!==G&&R.cookie.create(N.cookieName,G,N.cookieExpirationTime,N.cookieDomain),N.detectLngFromLocalStorage&&"undefined"!=typeof document&&window.localStorage&&R.localStorage.setItem("i18next_lng",G);var d=A;b.fixLng&&(d=function(a,b){return b=b||{},b.lng=b.lng||d.lng,A(a,b)},d.lng=G),U.setCurrentLng(G),a&&N.setJqueryExt&&t();var e;if(a&&a.Deferred&&(e=a.Deferred()),!N.resStore){var f=R.toLanguages(N.lng);"string"==typeof N.preload&&(N.preload=[N.preload]);for(var g=0,h=N.preload.length;h>g;g++)for(var i=R.toLanguages(N.preload[g]),j=0,k=i.length;k>j;j++)f.indexOf(i[j])<0&&f.push(i[j]);return H.sync.load(f,N,function(a,b){I=b,L=!0,c&&c(d),e&&e.resolve(d)}),e?e.promise():void 0}return I=N.resStore,L=!0,c&&c(d),e&&e.resolve(d),e?e.promise():void 0}function h(a,b){"string"==typeof a&&(a=[a]);for(var c=0,d=a.length;d>c;c++)N.preload.indexOf(a[c])<0&&N.preload.push(a[c]);return g(b)}function i(a,b,c,d){"string"!=typeof b?(c=b,b=N.ns.defaultNs):N.ns.namespaces.indexOf(b)<0&&N.ns.namespaces.push(b),I[a]=I[a]||{},I[a][b]=I[a][b]||{},d?R.deepExtend(I[a][b],c):R.extend(I[a][b],c)}function j(a,b){"string"!=typeof b&&(b=N.ns.defaultNs),I[a]=I[a]||{};var c=I[a][b]||{},d=!1;for(var e in c)c.hasOwnProperty(e)&&(d=!0);return d}function k(a,b){"string"!=typeof b&&(b=N.ns.defaultNs),I[a]=I[a]||{},I[a][b]={}}function l(a,b,c,d){"string"!=typeof b?(resource=b,b=N.ns.defaultNs):N.ns.namespaces.indexOf(b)<0&&N.ns.namespaces.push(b),I[a]=I[a]||{},I[a][b]=I[a][b]||{};for(var e=c.split(N.keyseparator),f=0,g=I[a][b];e[f];)f==e.length-1?g[e[f]]=d:(null==g[e[f]]&&(g[e[f]]={}),g=g[e[f]]),f++}function m(a,b,c){"string"!=typeof b?(resource=b,b=N.ns.defaultNs):N.ns.namespaces.indexOf(b)<0&&N.ns.namespaces.push(b);for(var d in c)"string"==typeof c[d]&&l(a,b,d,c[d])}function n(a){N.ns.defaultNs=a}function o(a,b){p([a],b)}function p(a,b){var c={dynamicLoad:N.dynamicLoad,resGetPath:N.resGetPath,getAsync:N.getAsync,customLoad:N.customLoad,ns:{namespaces:a,defaultNs:""}},d=R.toLanguages(N.lng);"string"==typeof N.preload&&(N.preload=[N.preload]);for(var e=0,f=N.preload.length;f>e;e++)for(var g=R.toLanguages(N.preload[e]),h=0,i=g.length;i>h;h++)d.indexOf(g[h])<0&&d.push(g[h]);for(var j=[],k=0,l=d.length;l>k;k++){var m=!1,n=I[d[k]];if(n)for(var o=0,p=a.length;p>o;o++)n[a[o]]||(m=!0);else m=!0;m&&j.push(d[k])}j.length?H.sync._fetch(j,c,function(c,d){var e=a.length*j.length;R.each(a,function(a,c){N.ns.namespaces.indexOf(c)<0&&N.ns.namespaces.push(c),R.each(j,function(a,f){I[f]=I[f]||{},I[f][c]=d[f][c],e--,0===e&&b&&(N.useLocalStorage&&H.sync._storeLocal(I),b())})})}):b&&b()}function q(a,b,c){return"function"==typeof b?(c=b,b={}):b||(b={}),b.lng=a,g(b,c)}function r(){return G}function s(a){I={},q(G,a)}function t(){function b(b,c,d){if(0!==c.length){var e="text";if(0===c.indexOf("[")){var f=c.split("]");c=f[1],e=f[0].substr(1,f[0].length-1)}c.indexOf(";")===c.length-1&&(c=c.substr(0,c.length-2));var g;if("html"===e)g=N.defaultValueFromContent?a.extend({defaultValue:b.html()},d):d,b.html(a.t(c,g));else if("text"===e)g=N.defaultValueFromContent?a.extend({defaultValue:b.text()},d):d,b.text(a.t(c,g));else if("prepend"===e)g=N.defaultValueFromContent?a.extend({defaultValue:b.html()},d):d,b.prepend(a.t(c,g));else if("append"===e)g=N.defaultValueFromContent?a.extend({defaultValue:b.html()},d):d,b.append(a.t(c,g));else if(0===e.indexOf("data-")){var h=e.substr("data-".length);g=N.defaultValueFromContent?a.extend({defaultValue:b.data(h)},d):d;var i=a.t(c,g);b.data(h,i),b.attr(e,i)}else g=N.defaultValueFromContent?a.extend({defaultValue:b.attr(e)},d):d,b.attr(e,a.t(c,g))}}function c(c,d){var e=c.attr(N.selectorAttr);if(e||"undefined"==typeof e||e===!1||(e=c.text()||c.val()),e){var f=c,g=c.data("i18n-target");if(g&&(f=c.find(g)||c),d||N.useDataAttrOptions!==!0||(d=c.data("i18n-options")),d=d||{},e.indexOf(";")>=0){var h=e.split(";");a.each(h,function(a,c){""!==c&&b(f,c,d)})}else b(f,e,d);N.useDataAttrOptions===!0&&c.data("i18n-options",d)}}a.t=a.t||A,a.fn.i18n=function(b){return this.each(function(){c(a(this),b);var d=a(this).find("["+N.selectorAttr+"]");d.each(function(){c(a(this),b)})})}}function u(a,b,c,d){if(!a)return a;if(d=d||b,a.indexOf(d.interpolationPrefix||N.interpolationPrefix)<0)return a;var e=d.interpolationPrefix?R.regexEscape(d.interpolationPrefix):N.interpolationPrefixEscaped,f=d.interpolationSuffix?R.regexEscape(d.interpolationSuffix):N.interpolationSuffixEscaped,g="HTML"+f,h=b.replace&&"object"==typeof b.replace?b.replace:b;return R.each(h,function(b,h){var i=c?c+N.keyseparator+b:b;"object"==typeof h&&null!==h?a=u(a,h,i,d):d.escapeInterpolation||N.escapeInterpolation?(a=a.replace(new RegExp([e,i,g].join(""),"g"),R.regexReplacementEscape(h)),a=a.replace(new RegExp([e,i,f].join(""),"g"),R.regexReplacementEscape(R.escape(h)))):a=a.replace(new RegExp([e,i,f].join(""),"g"),R.regexReplacementEscape(h))}),a}function v(a,b){var c=",",d="{",e="}",f=R.extend({},b);for(delete f.postProcess;-1!=a.indexOf(N.reusePrefix)&&(J++,!(J>N.maxRecursion));){var g=a.lastIndexOf(N.reusePrefix),h=a.indexOf(N.reuseSuffix,g)+N.reuseSuffix.length,i=a.substring(g,h),j=i.replace(N.reusePrefix,"").replace(N.reuseSuffix,"");if(g>=h)return R.error("there is an missing closing in following translation value",a),"";if(-1!=j.indexOf(c)){var k=j.indexOf(c);if(-1!=j.indexOf(d,k)&&-1!=j.indexOf(e,k)){var l=j.indexOf(d,k),m=j.indexOf(e,l)+e.length;try{f=R.extend(f,JSON.parse(j.substring(l,m))),j=j.substring(0,k)}catch(n){}}}var o=D(j,f);a=a.replace(i,R.regexReplacementEscape(o))}return a}function w(a){return a.context&&("string"==typeof a.context||"number"==typeof a.context)}function x(a){return void 0!==a.count&&"string"!=typeof a.count}function y(a){return void 0!==a.indefinite_article&&"string"!=typeof a.indefinite_article&&a.indefinite_article}function z(a,b){b=b||{};var c=B(a,b),d=E(a,b);return void 0!==d||d===c}function A(a,b){return b=b||{},L?(J=0,D.apply(null,arguments)):(R.log("i18next not finished initialization. you might have called t function before loading resources finished."),b.defaultValue||"")}function B(a,b){return void 0!==b.defaultValue?b.defaultValue:a}function C(){for(var a=[],b=1;b1)for(var d=0;d-1&&(e=c.split(N.nsseparator),i=e[0],c=e[1]),void 0===g&&N.sendMissing&&"function"==typeof N.missingKeyHandler&&(b.lng?N.missingKeyHandler(h[0],i,c,f,h):N.missingKeyHandler(N.lng,i,c,f,h));var j=b.postProcess||N.postProcess;void 0!==g&&j&&V[j]&&(g=V[j](g,c,b));var k=f;if(f.indexOf(N.nsseparator)>-1&&(e=f.split(N.nsseparator),k=e[1]),k===c&&N.parseMissingKey&&(f=N.parseMissingKey(f)),void 0===g&&(f=u(f,b),f=v(f,b),j&&V[j])){var l=B(c,b);g=V[j](l,c,b)}return void 0!==g?g:f}function E(a,b){b=b||{};var c,d,e=B(a,b),f=K;if(!I)return e;if("cimode"===f[0].toLowerCase())return e;if(b.lngs&&(f=b.lngs),b.lng&&(f=R.toLanguages(b.lng,b.fallbackLng),!I[f[0]])){var g=N.getAsync;N.getAsync=!1,H.sync.load(f,N,function(a,b){R.extend(I,b),N.getAsync=g})}var h=b.ns||N.ns.defaultNs;if(a.indexOf(N.nsseparator)>-1){var i=a.split(N.nsseparator);h=i[0],a=i[1]}if(w(b)){c=R.extend({},b),delete c.context,c.defaultValue=N.contextNotFound;var j=h+N.nsseparator+a+"_"+b.context;if(d=A(j,c),d!=N.contextNotFound)return u(d,{context:b.context})}if(x(b,f[0])){c=R.extend({lngs:[f[0]]},b),delete c.count,delete c.lng,c.defaultValue=N.pluralNotFound;var k;if(U.needsPlural(f[0],b.count)){k=h+N.nsseparator+a+N.pluralSuffix;var l=U.get(f[0],b.count);l>=0?k=k+"_"+l:1===l&&(k=h+N.nsseparator+a)}else k=h+N.nsseparator+a;if(d=A(k,c),d!=N.pluralNotFound)return u(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix});if(!(f.length>1))return d;var m=f.slice();if(m.shift(),b=R.extend(b,{lngs:m}),delete b.lng,d=A(h+N.nsseparator+a,b),d!=N.pluralNotFound)return d}if(y(b)){var n=R.extend({},b);delete n.indefinite_article,n.defaultValue=N.indefiniteNotFound;var o=h+N.nsseparator+a+(b.count&&!x(b,f[0])||!b.count?N.indefiniteSuffix:"");if(d=A(o,n),d!=N.indefiniteNotFound)return d}for(var p,q=a.split(N.keyseparator),r=0,s=f.length;s>r&&void 0===p;r++){for(var t=f[r],z=0,C=I[t]&&I[t][h];q[z];)C=C&&C[q[z]],z++;if(void 0!==C){var F=Object.prototype.toString.apply(C);if("string"==typeof C)C=u(C,b),C=v(C,b);else if("[object Array]"!==F||N.returnObjectTrees||b.returnObjectTrees){if(null===C&&N.fallbackOnNull===!0)C=void 0;else if(null!==C)if(N.returnObjectTrees||b.returnObjectTrees){if("[object Number]"!==F&&"[object Function]"!==F&&"[object RegExp]"!==F){var G="[object Array]"===F?[]:{};R.each(C,function(c){G[c]=D(h+N.nsseparator+a+N.keyseparator+c,b)}),C=G}}else N.objectTreeKeyHandler&&"function"==typeof N.objectTreeKeyHandler?C=N.objectTreeKeyHandler(a,C,t,h,b):(C="key '"+h+":"+a+" ("+t+")' "+"returned an object instead of string.",R.log(C))}else C=C.join("\n"),C=u(C,b),C=v(C,b);"string"==typeof C&&""===C.trim()&&N.fallbackOnEmpty===!0&&(C=void 0),p=C}}if(void 0===p&&!b.isFallbackLookup&&(N.fallbackToDefaultNS===!0||N.fallbackNS&&N.fallbackNS.length>0)){if(b.isFallbackLookup=!0,N.fallbackNS.length){for(var J=0,L=N.fallbackNS.length;L>J;J++)if(p=E(N.fallbackNS[J]+N.nsseparator+a,b),p||""===p&&N.fallbackOnEmpty===!1){var M=p.indexOf(N.nsseparator)>-1?p.split(N.nsseparator)[1]:p,O=e.indexOf(N.nsseparator)>-1?e.split(N.nsseparator)[1]:e;if(M!==O)break}}else p=E(a,b);b.isFallbackLookup=!1}return p}function F(){var a,b=N.lngWhitelist||[],c=[];if("undefined"!=typeof window&&!function(){for(var a=window.location.search.substring(1),b=a.split("&"),d=0;d0){var f=b[d].substring(0,e);f==N.detectLngQS&&c.push(b[d].substring(e+1))}}}(),N.useCookie&&"undefined"!=typeof document){var d=R.cookie.read(N.cookieName);d&&c.push(d)}if(N.detectLngFromLocalStorage&&"undefined"!=typeof window&&window.localStorage&&c.push(window.localStorage.getItem("i18next_lng")),"undefined"!=typeof navigator){if(navigator.languages)for(var e=0;e-1){var f=e.split("-");e=N.lowerCaseLng?f[0].toLowerCase()+"-"+f[1].toLowerCase():f[0].toLowerCase()+"-"+f[1].toUpperCase()}if(0===b.length||b.indexOf(e)>-1){a=e;break}}}(),a||(a=N.fallbackLng[0]),a}Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>0&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&1/0!=d&&d!=-1/0&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=c;arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d))));for(var e=d>=0?Math.min(d,c-1):c-Math.abs(d);e>=0;e--)if(e in b&&b[e]===a)return e;return-1}),"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")});var G,H={},I={},J=0,K=[],L=!1,M={};M={load:function(a,b,c){b.useLocalStorage?M._loadLocal(a,b,function(d,e){for(var f=[],g=0,h=a.length;h>g;g++)e[a[g]]||f.push(a[g]);f.length>0?M._fetch(f,b,function(a,b){R.extend(e,b),M._storeLocal(b),c(null,e)}):c(null,e)}):M._fetch(a,b,function(a,b){c(null,b)})},_loadLocal:function(a,b,c){var d={},e=(new Date).getTime();if(window.localStorage){var f=a.length;R.each(a,function(a,g){var h=window.localStorage.getItem("res_"+g);h&&(h=JSON.parse(h),h.i18nStamp&&h.i18nStamp+b.localStorageExpirationTime>e&&(d[g]=h)),f--,0===f&&c(null,d)})}},_storeLocal:function(a){if(window.localStorage)for(var b in a)a[b].i18nStamp=(new Date).getTime(),R.localStorage.setItem("res_"+b,JSON.stringify(a[b]))},_fetch:function(a,b,c){var d=b.ns,e={};if(b.dynamicLoad){var f=function(a,b){c(null,b)};if("function"==typeof b.customLoad)b.customLoad(a,d.namespaces,b,f);else{var g=u(b.resGetPath,{lng:a.join("+"),ns:d.namespaces.join("+")});R.ajax({url:g,success:function(a){R.log("loaded: "+g),f(null,a)},error:function(a,b,c){R.log("failed loading: "+g),f("failed loading resource.json error: "+c)},dataType:"json",async:b.getAsync})}}else{var h,i=d.namespaces.length*a.length;R.each(d.namespaces,function(d,f){R.each(a,function(a,d){var g=function(a,b){a&&(h=h||[],h.push(a)),e[d]=e[d]||{},e[d][f]=b,i--,0===i&&c(h,e)};"function"==typeof b.customLoad?b.customLoad(d,f,b,g):M._fetchOne(d,f,b,g)})})}},_fetchOne:function(a,b,c,d){var e=u(c.resGetPath,{lng:a,ns:b});R.ajax({url:e,success:function(a){R.log("loaded: "+e),d(null,a)},error:function(a,b,c){if(b&&200==b||a&&a.status&&200==a.status)R.error("There is a typo in: "+e);else if(b&&404==b||a&&a.status&&404==a.status)R.log("Does not exist: "+e);else{var f=b?b:a&&a.status?a.status:null;R.log(f+" when loading "+e)}d(c,{})},dataType:"json",async:c.getAsync})},postMissing:function(a,b,c,d,e){var f={};f[c]=d;var g=[];if("fallback"===N.sendMissingTo&&N.fallbackLng[0]!==!1)for(var h=0;hh;h++)g.push({lng:e[h],url:u(N.resPostPath,{lng:e[h],ns:b})});for(var j=0,k=g.length;k>j;j++){var l=g[j];R.ajax({url:l.url,type:N.sendType,data:f,success:function(){R.log("posted missing key '"+c+"' to: "+l.url);for(var a=c.split("."),e=0,f=I[l.lng][b];a[e];)f=f[a[e]]=e===a.length-1?d:f[a[e]]||{},e++},error:function(){R.log("failed posting missing key '"+c+"' to: "+l.url)},dataType:"json",async:N.postAsync})}},reload:s};var N={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:["dev"],fallbackNS:[],detectLngQS:"setLng",detectLngFromLocalStorage:!1,ns:"translation",fallbackOnNull:!0,fallbackOnEmpty:!1,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",defaultVariables:!1,reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,indefiniteSuffix:"_indefinite",indefiniteNotFound:["indefinite_not_found",Math.random()].join(""),setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",cookieDomain:void 0,objectTreeKeyHandler:void 0,postProcess:void 0,parseMissingKey:void 0,missingKeyHandler:M.postMissing,shortcutFunction:"sprintf"},O={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},P={create:function(a,b,c,d){var e;if(c){var f=new Date;f.setTime(f.getTime()+1e3*60*c),e="; expires="+f.toGMTString()}else e="";d=d?"domain="+d+";":"",document.cookie=a+"="+b+e+";"+d+"path=/"},read:function(a){for(var b=a+"=",c=document.cookie.split(";"),d=0;d-1){var c=a.split("-");b=N.lowerCaseLng?c[0].toLowerCase()+"-"+c[1].toLowerCase():c[0].toLowerCase()+"-"+c[1].toUpperCase()}else b=N.lowerCaseLng?a.toLowerCase():a;return b}var c=this.log,d=[],e=N.lngWhitelist||!1,f=function(a){!e||e.indexOf(a)>-1?d.push(a):c("rejecting non-whitelisted language: "+a)};if("string"==typeof a&&a.indexOf("-")>-1){var g=a.split("-");"unspecific"!==N.load&&f(b(a)),"current"!==N.load&&f(b(g[this.getCountyIndexOfLng(a)]))}else f(b(a));for(var h=0;h1)},2:function(a){return Number(1!=a)},3:function(){return 0},4:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},5:function(a){return Number(0===a?0:1==a?1:2==a?2:a%100>=3&&10>=a%100?3:a%100>=11?4:5)},6:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)},7:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},8:function(a){return Number(1==a?0:2==a?1:8!=a&&11!=a?2:3)},9:function(a){return Number(a>=2)},10:function(a){return Number(1==a?0:2==a?1:7>a?2:11>a?3:4)},11:function(a){return Number(1==a||11==a?0:2==a||12==a?1:a>2&&20>a?2:3)},12:function(a){return Number(1!=a%10||11==a%100)},13:function(a){return Number(0!==a)},14:function(a){return Number(1==a?0:2==a?1:3==a?2:3)},15:function(a){return Number(1==a%10&&11!=a%100?0:a%10>=2&&(10>a%100||a%100>=20)?1:2)},16:function(a){return Number(1==a%10&&11!=a%100?0:0!==a?1:2)},17:function(a){return Number(1==a||1==a%10?0:1)},18:function(a){return Number(1==a?1:2)},19:function(a){return Number(1==a?0:0===a||a%100>1&&11>a%100?1:a%100>10&&20>a%100?2:3)},20:function(a){return Number(1==a?0:0===a||a%100>0&&20>a%100?1:2)},21:function(a){return Number(1==a%100?1:2==a%100?2:3==a%100||4==a%100?3:0)}},U={rules:function(){var a,b={};for(a=S.length;a--;)b[S[a][0]]={name:S[a][1],numbers:S[a][2],plurals:T[S[a][3]]};return b}(),addRule:function(a,b){U.rules[a]=b},setCurrentLng:function(a){if(!U.currentRule||U.currentRule.lng!==a){var b=a.split("-");U.currentRule={lng:a,rule:U.rules[b[0]]}}},needsPlural:function(a,b){var c,d=a.split("-");return c=U.currentRule&&U.currentRule.lng===a?U.currentRule.rule:U.rules[d[R.getCountyIndexOfLng(a)]],c&&c.numbers.length<=1?!1:1!==this.get(a,b)},get:function(a,b){function c(b,c){var d;if(d=U.currentRule&&U.currentRule.lng===a?U.currentRule.rule:U.rules[b]){var e;e=d.noAbs?d.plurals(c):d.plurals(Math.abs(c));var f=d.numbers[e];return 2===d.numbers.length&&1===d.numbers[0]&&(2===f?f=-1:1===f&&(f=1)),f}return 1===c?"1":"-1"}var d=a.split("-");return c(d[R.getCountyIndexOfLng(a)],b)}},V={},W=function(a,b){V[a]=b},X=function(){function a(a){return Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}function b(a,b){for(var c=[];b>0;c[--b]=a);return c.join("")}var c=function(){return c.cache.hasOwnProperty(arguments[0])||(c.cache[arguments[0]]=c.parse(arguments[0])),c.format.call(null,c.cache[arguments[0]],arguments)};return c.format=function(c,d){var e,f,g,h,i,j,k,l=1,m=c.length,n="",o=[];for(f=0;m>f;f++)if(n=a(c[f]),"string"===n)o.push(c[f]);else if("array"===n){if(h=c[f],h[2])for(e=d[l],g=0;g=0?"+"+e:e,j=h[4]?"0"==h[4]?"0":h[4].charAt(1):" ",k=h[6]-String(e).length,i=h[6]?b(j,k):"",o.push(h[5]?e+i:i+e)}return o.join("")},c.cache={},c.parse=function(a){for(var b=a,c=[],d=[],e=0;b;){if(null!==(c=/^[^\x25]+/.exec(b)))d.push(c[0]);else if(null!==(c=/^\x25{2}/.exec(b)))d.push("%");else{if(null===(c=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(b)))throw"[sprintf] huh?";if(c[2]){e|=1;var f=[],g=c[2],h=[];if(null===(h=/^([a-z_][a-z_\d]*)/i.exec(g)))throw"[sprintf] huh?";for(f.push(h[1]);""!==(g=g.substring(h[0].length));)if(null!==(h=/^\.([a-z_][a-z_\d]*)/i.exec(g)))f.push(h[1]);else{if(null===(h=/^\[(\d+)\]/.exec(g)))throw"[sprintf] huh?";f.push(h[1])}c[2]=f}else e|=2;if(3===e)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";d.push(c)}b=b.substring(c[0].length)}return d},c}(),Y=function(a,b){return b.unshift(a),X.apply(null,b)};return W("sprintf",function(a,b,c){return c.sprintf?"[object Array]"===Object.prototype.toString.apply(c.sprintf)?Y(a,c.sprintf):"object"==typeof c.sprintf?X(a,c.sprintf):a:a}),H.init=g,H.setLng=q,H.preload=h,H.addResourceBundle=i,H.hasResourceBundle=j,H.addResource=l,H.addResources=m,H.removeResourceBundle=k,H.loadNamespace=o,H.loadNamespaces=p,H.setDefaultNamespace=n,H.t=A,H.translate=A,H.exists=z,H.detectLanguage=R.detectLanguage,H.pluralExtensions=U,H.sync=M,H.functions=R,H.lng=r,H.addPostProcessor=W,H.options=N,a.i18n=H,a.t=H.t,H}); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd.withJQuery-1.8.0.js b/libs/i18next/release/i18next.amd.withJQuery-1.8.0.js new file mode 100644 index 00000000..97c66e7e --- /dev/null +++ b/libs/i18next/release/i18next.amd.withJQuery-1.8.0.js @@ -0,0 +1,2177 @@ +// i18next, v1.8.0 +// Copyright (c)2015 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function (root, factory) { + if (typeof exports === 'object') { + + var jquery = require('jquery'); + + module.exports = factory(jquery); + + } else if (typeof define === 'function' && define.amd) { + + define(['jquery'], factory); + + } +}(this, function ($) { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + // Add string trim for IE8. + if (typeof String.prototype.trim !== 'function') { + String.prototype.trim = function() { + return this.replace(/^\s+|\s+$/g, ''); + } + } + + var i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = [] + , initialized = false + , sync = {}; + + sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = f.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + f.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + if ((status && status == 200) || (xhr && xhr.status && xhr.status == 200)) { + // file loaded but invalid json, stop waste time ! + f.error('There is a typo in: ' + url); + } else if ((status && status == 404) || (xhr && xhr.status && xhr.status == 404)) { + f.log('Does not exist: ' + url); + } else { + var theStatus = status ? status : ((xhr && xhr.status) ? xhr.status : null); + f.log(theStatus + ' when loading ' + url); + } + + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback' && o.fallbackLng[0] !== false) { + for (var i = 0; i < o.fallbackLng.length; i++) { + urls.push({lng: o.fallbackLng[i], url: applyReplacement(o.resPostPath, { lng: o.fallbackLng[i], ns: ns })}); + } + } else if (o.sendMissingTo === 'current' || (o.sendMissingTo === 'fallback' && o.fallbackLng[0] === false) ) { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + }, + + reload: reload + }; + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: ['dev'], + fallbackNS: [], + detectLngQS: 'setLng', + detectLngFromLocalStorage: false, + ns: 'translation', + fallbackOnNull: true, + fallbackOnEmpty: false, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + defaultVariables: false, + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + indefiniteSuffix: '_indefinite', + indefiniteNotFound: ['indefinite_not_found', Math.random()].join(''), + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + cookieDomain: undefined, + + objectTreeKeyHandler: undefined, + postProcess: undefined, + parseMissingKey: undefined, + missingKeyHandler: sync.postMissing, + + shortcutFunction: 'sprintf' // or: defaultValue + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _deepExtend(target, source) { + for (var prop in source) + if (prop in target) + _deepExtend(target[prop], source[prop]); + else + target[prop] = source[prop]; + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || Object.prototype.toString.apply(object) !== '[object Array]' || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + try { + return JSON.parse(data) + } catch (e) { + f.error('Can not parse JSON. URL: ' + url); + return {}; + } + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + // file: protocol always gives status code 0, so check for data + if (status === 200 || (status === 0 && data.text())) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes,domain) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + domain = (domain)? "domain="+domain+";" : ""; + document.cookie = name+"="+value+expires+";"+domain+"path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes,domain) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + deepExtend: _deepExtend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : (typeof document !== 'undefined' ? _ajax : function() {}), + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + error: function(str) { + if (typeof console !== "undefined") console.error(str); + }, + getCountyIndexOfLng: function(lng) { + var lng_index = 0; + if (lng === 'nb-NO' || lng === 'nn-NO' || lng === 'nb-no' || lng === 'nn-no') lng_index = 1; + return lng_index; + }, + toLanguages: function(lng) { + var log = this.log; + + function applyCase(l) { + var ret = l; + + if (typeof l === 'string' && l.indexOf('-') > -1) { + var parts = l.split('-'); + + ret = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } else { + ret = o.lowerCaseLng ? l.toLowerCase() : l; + } + + return ret; + } + + var languages = []; + var whitelist = o.lngWhitelist || false; + var addLanguage = function(language){ + //reject langs not whitelisted + if(!whitelist || whitelist.indexOf(language) > -1){ + languages.push(language); + }else{ + log('rejecting non-whitelisted language: ' + language); + } + }; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + if (o.load !== 'unspecific') addLanguage(applyCase(lng)); + if (o.load !== 'current') addLanguage(applyCase(parts[this.getCountyIndexOfLng(lng)])); + } else { + addLanguage(applyCase(lng)); + } + + for (var i = 0; i < o.fallbackLng.length; i++) { + if (languages.indexOf(o.fallbackLng[i]) === -1 && o.fallbackLng[i]) languages.push(applyCase(o.fallbackLng[i])); + } + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + }, + regexReplacementEscape: function(strOrFn) { + if (typeof strOrFn === 'string') { + return strOrFn.replace(/\$/g, "$$$$"); + } else { + return strOrFn; + } + }, + localStorage: { + setItem: function(key, value) { + if (window.localStorage) { + try { + window.localStorage.setItem(key, value); + } catch (e) { + f.log('failed to set value for key "' + key + '" to localStorage.'); + } + } + }, + getItem: function(key, value) { + if (window.localStorage) { + try { + return window.localStorage.getItem(key, value); + } catch (e) { + f.log('failed to get value for key "' + key + '" from localStorage.'); + return undefined; + } + } + } + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + delete o.fixLng; /* passed in each time */ + + // override functions: .log(), .detectLanguage(), etc + if (o.functions) { + delete o.functions; + f.extend(f, options.functions); + } + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // fallback languages + if (typeof o.fallbackLng == 'string' || typeof o.fallbackLng == 'boolean') { + o.fallbackLng = [o.fallbackLng]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + if (o.useCookie && f.cookie.read(o.cookieName) !== currentLng){ //cookie is unset or invalid + f.cookie.create(o.cookieName, currentLng, o.cookieExpirationTime, o.cookieDomain); + } + if (o.detectLngFromLocalStorage && typeof document !== 'undefined' && window.localStorage) { + f.localStorage.setItem('i18next_lng', currentLng); + } + + var lngTranslate = translate; + if (options.fixLng) { + lngTranslate = function(key, options) { + options = options || {}; + options.lng = options.lng || lngTranslate.lng; + return translate(key, options); + }; + lngTranslate.lng = currentLng; + } + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + initialized = true; + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + initialized = true; + + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources, deep) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + if (deep) { + f.deepExtend(resStore[lng][ns], resources); + } else { + f.extend(resStore[lng][ns], resources); + } + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function hasResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + var res = resStore[lng][ns] || {}; + + var hasValues = false; + for(var prop in res) { + if (res.hasOwnProperty(prop)) { + hasValues = true; + } + } + + return hasValues; + } + + function getResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + return f.extend({}, resStore[lng][ns]); + } + + function removeResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = {}; + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function addResource(lng, ns, key, value) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + var keys = key.split(o.keyseparator); + var x = 0; + var node = resStore[lng][ns]; + var origRef = node; + + while (keys[x]) { + if (x == keys.length - 1) + node[keys[x]] = value; + else { + if (node[keys[x]] == null) + node[keys[x]] = {}; + + node = node[keys[x]]; + } + x++; + } + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function addResources(lng, ns, resources) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + for (var m in resources) { + if (typeof resources[m] === 'string') addResource(lng, ns, m, resources[m]); + } + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, options, cb) { + if (typeof options === 'function') { + cb = options; + options = {}; + } else if (!options) { + options = {}; + } + + options.lng = lng; + return init(options, cb); + } + + function lng() { + return currentLng; + } + + function reload(cb) { + resStore = {}; + setLng(currentLng, cb); + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else if (attr === 'prepend') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.prepend($.t(key, optionsToUse)); + } else if (attr === 'append') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.append($.t(key, optionsToUse)); + } else if (attr.indexOf("data-") === 0) { + var dataAttr = attr.substr(("data-").length); + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.data(dataAttr) }, options) : options; + var translated = $.t(key, optionsToUse); + //we change into the data cache + ele.data(dataAttr, translated); + //we change into the dom + ele.attr(attr, translated); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key && typeof key !== 'undefined' && key !== false) key = ele.text() || ele.val(); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + var hash = replacementHash.replace && typeof replacementHash.replace === 'object' ? replacementHash.replace : replacementHash; + f.each(hash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), f.regexReplacementEscape(value)); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(f.escape(value))); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(value)); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + if (index_of_end_of_closing <= index_of_opening) { + f.error('there is an missing closing in following translation value', translated); + return ''; + } + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, f.regexReplacementEscape(translated_token)); + } + return translated; + } + + function hasContext(options) { + return (options.context && (typeof options.context == 'string' || typeof options.context == 'number')); + } + + function needsPlural(options, lng) { + return (options.count !== undefined && typeof options.count != 'string'/* && pluralExtensions.needsPlural(lng, options.count)*/); + } + + function needsIndefiniteArticle(options) { + return (options.indefinite_article !== undefined && typeof options.indefinite_article != 'string' && options.indefinite_article); + } + + function exists(key, options) { + options = options || {}; + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + options = options || {}; + + if (!initialized) { + f.log('i18next not finished initialization. you might have called t function before loading resources finished.') + return options.defaultValue || ''; + }; + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _getDefaultValue(key, options) { + return (options.defaultValue !== undefined) ? options.defaultValue : key; + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(potentialKeys, options) { + if (options && typeof options !== 'object') { + if (o.shortcutFunction === 'sprintf') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else if (o.shortcutFunction === 'defaultValue') { + options = { + defaultValue: options + } + } + } else { + options = options || {}; + } + + if (typeof o.defaultVariables === 'object') { + options = f.extend({}, o.defaultVariables, options); + } + + if (potentialKeys === undefined || potentialKeys === null || potentialKeys === '') return ''; + + if (typeof potentialKeys === 'number') { + potentialKeys = String(potentialKeys); + } + + if (typeof potentialKeys === 'string') { + potentialKeys = [potentialKeys]; + } + + var key = potentialKeys[0]; + + if (potentialKeys.length > 1) { + for (var i = 0; i < potentialKeys.length; i++) { + key = potentialKeys[i]; + if (exists(key, options)) { + break; + } + } + } + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng, options.fallbackLng) : languages + , ns = options.ns || o.ns.defaultNs + , parts; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing && typeof o.missingKeyHandler === 'function') { + if (options.lng) { + o.missingKeyHandler(lngs[0], ns, key, notFound, lngs); + } else { + o.missingKeyHandler(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessorsToApply; + if (typeof o.postProcess === 'string' && o.postProcess !== '') { + postProcessorsToApply = [o.postProcess]; + } else if (typeof o.postProcess === 'array' || typeof o.postProcess === 'object') { + postProcessorsToApply = o.postProcess; + } else { + postProcessorsToApply = []; + } + + if (typeof options.postProcess === 'string' && options.postProcess !== '') { + postProcessorsToApply = postProcessorsToApply.concat([options.postProcess]); + } else if (typeof options.postProcess === 'array' || typeof options.postProcess === 'object') { + postProcessorsToApply = postProcessorsToApply.concat(options.postProcess); + } + + if (found !== undefined && postProcessorsToApply.length) { + postProcessorsToApply.forEach(function(postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + }); + } + + // process notFound if function exists + var splitNotFound = notFound; + if (notFound.indexOf(o.nsseparator) > -1) { + parts = notFound.split(o.nsseparator); + splitNotFound = parts[1]; + } + if (splitNotFound === key && o.parseMissingKey) { + notFound = o.parseMissingKey(notFound); + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessorsToApply.length) { + var val = _getDefaultValue(key, options); + postProcessorsToApply.forEach(function(postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](val, key, options); + } + }); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options) { + options = options || {}; + + var optionWithoutCount, translated + , notFound = _getDefaultValue(key, options) + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + // CI mode + if (lngs[0].toLowerCase() === 'cimode') return notFound; + + // passed in lng + if (options.lngs) lngs = options.lngs; + if (options.lng) { + lngs = f.toLanguages(options.lng, options.fallbackLng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options, lngs[0])) { + optionWithoutCount = f.extend({ lngs: [lngs[0]]}, options); + delete optionWithoutCount.count; + optionWithoutCount._origLng = optionWithoutCount._origLng || optionWithoutCount.lng || lngs[0]; + delete optionWithoutCount.lng; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey; + if (!pluralExtensions.needsPlural(lngs[0], options.count)) { + pluralKey = ns + o.nsseparator + key; + } else { + pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(lngs[0], options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + } + + translated = translate(pluralKey, optionWithoutCount); + + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } else if (lngs.length > 1) { + // remove failed lng + var clone = lngs.slice(); + clone.shift(); + options = f.extend(options, { lngs: clone }); + options._origLng = optionWithoutCount._origLng; + delete options.lng; + // retry with fallbacks + translated = translate(ns + o.nsseparator + key, options); + if (translated != o.pluralNotFound) return translated; + } else { + optionWithoutCount.lng = optionWithoutCount._origLng; + delete optionWithoutCount._origLng; + translated = translate(ns + o.nsseparator + key, optionWithoutCount); + + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); + } + } + + if (needsIndefiniteArticle(options)) { + var optionsWithoutIndef = f.extend({}, options); + delete optionsWithoutIndef.indefinite_article; + optionsWithoutIndef.defaultValue = o.indefiniteNotFound; + // If we don't have a count, we want the indefinite, if we do have a count, and needsPlural is false + var indefiniteKey = ns + o.nsseparator + key + (((options.count && !needsPlural(options, lngs[0])) || !options.count) ? o.indefiniteSuffix : ""); + translated = translate(indefiniteKey, optionsWithoutIndef); + if (translated != o.indefiniteNotFound) { + return translated; + } + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + var valueType = Object.prototype.toString.apply(value); + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (valueType === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + if (o.objectTreeKeyHandler && typeof o.objectTreeKeyHandler == 'function') { + value = o.objectTreeKeyHandler(key, value, l, ns, options); + } else { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned an object instead of string.'; + f.log(value); + } + } else if (valueType !== '[object Number]' && valueType !== '[object Function]' && valueType !== '[object RegExp]') { + var copy = (valueType === '[object Array]') ? [] : {}; // apply child translation on a copy + f.each(value, function(m) { + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + }); + value = copy; + } + } + + if (typeof value === 'string' && value.trim() === '' && o.fallbackOnEmpty === true) + value = undefined; + + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length > 0))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found || (found==="" && o.fallbackOnEmpty === false)) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + options.isFallbackLookup = false; + } + + return found; + } + function detectLanguage() { + var detectedLng; + var whitelist = o.lngWhitelist || []; + var userLngChoices = []; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var params = query.split('&'); + for (var i=0; i 0) { + var key = params[i].substring(0,pos); + if (key == o.detectLngQS) { + userLngChoices.push(params[i].substring(pos+1)); + } + } + } + })(); + } + + // get from cookie + if (o.useCookie && typeof document !== 'undefined') { + var c = f.cookie.read(o.cookieName); + if (c) userLngChoices.push(c); + } + + // get from localStorage + if (o.detectLngFromLocalStorage && typeof window !== 'undefined' && window.localStorage) { + userLngChoices.push(f.localStorage.getItem('i18next_lng')); + } + + // get from navigator + if (typeof navigator !== 'undefined') { + if (navigator.languages) { // chrome only; not an array, so can't use .push.apply instead of iterating + for (var i=0;i -1) { + var parts = lng.split('-'); + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } + + if (whitelist.length === 0 || whitelist.indexOf(lng) > -1) { + detectedLng = lng; + break; + } + } + })(); + + //fallback + if (!detectedLng){ + detectedLng = o.fallbackLng[0]; + } + + return detectedLng; + } + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + + /* [code, name, numbers, pluralsType] */ + var _rules = [ + ["ach", "Acholi", [1,2], 1], + ["af", "Afrikaans",[1,2], 2], + ["ak", "Akan", [1,2], 1], + ["am", "Amharic", [1,2], 1], + ["an", "Aragonese",[1,2], 2], + ["ar", "Arabic", [0,1,2,3,11,100],5], + ["arn", "Mapudungun",[1,2], 1], + ["ast", "Asturian", [1,2], 2], + ["ay", "Aymará", [1], 3], + ["az", "Azerbaijani",[1,2],2], + ["be", "Belarusian",[1,2,5],4], + ["bg", "Bulgarian",[1,2], 2], + ["bn", "Bengali", [1,2], 2], + ["bo", "Tibetan", [1], 3], + ["br", "Breton", [1,2], 1], + ["bs", "Bosnian", [1,2,5],4], + ["ca", "Catalan", [1,2], 2], + ["cgg", "Chiga", [1], 3], + ["cs", "Czech", [1,2,5],6], + ["csb", "Kashubian",[1,2,5],7], + ["cy", "Welsh", [1,2,3,8],8], + ["da", "Danish", [1,2], 2], + ["de", "German", [1,2], 2], + ["dev", "Development Fallback", [1,2], 2], + ["dz", "Dzongkha", [1], 3], + ["el", "Greek", [1,2], 2], + ["en", "English", [1,2], 2], + ["eo", "Esperanto",[1,2], 2], + ["es", "Spanish", [1,2], 2], + ["es_ar","Argentinean Spanish", [1,2], 2], + ["et", "Estonian", [1,2], 2], + ["eu", "Basque", [1,2], 2], + ["fa", "Persian", [1], 3], + ["fi", "Finnish", [1,2], 2], + ["fil", "Filipino", [1,2], 1], + ["fo", "Faroese", [1,2], 2], + ["fr", "French", [1,2], 9], + ["fur", "Friulian", [1,2], 2], + ["fy", "Frisian", [1,2], 2], + ["ga", "Irish", [1,2,3,7,11],10], + ["gd", "Scottish Gaelic",[1,2,3,20],11], + ["gl", "Galician", [1,2], 2], + ["gu", "Gujarati", [1,2], 2], + ["gun", "Gun", [1,2], 1], + ["ha", "Hausa", [1,2], 2], + ["he", "Hebrew", [1,2], 2], + ["hi", "Hindi", [1,2], 2], + ["hr", "Croatian", [1,2,5],4], + ["hu", "Hungarian",[1,2], 2], + ["hy", "Armenian", [1,2], 2], + ["ia", "Interlingua",[1,2],2], + ["id", "Indonesian",[1], 3], + ["is", "Icelandic",[1,2], 12], + ["it", "Italian", [1,2], 2], + ["ja", "Japanese", [1], 3], + ["jbo", "Lojban", [1], 3], + ["jv", "Javanese", [0,1], 13], + ["ka", "Georgian", [1], 3], + ["kk", "Kazakh", [1], 3], + ["km", "Khmer", [1], 3], + ["kn", "Kannada", [1,2], 2], + ["ko", "Korean", [1], 3], + ["ku", "Kurdish", [1,2], 2], + ["kw", "Cornish", [1,2,3,4],14], + ["ky", "Kyrgyz", [1], 3], + ["lb", "Letzeburgesch",[1,2],2], + ["ln", "Lingala", [1,2], 1], + ["lo", "Lao", [1], 3], + ["lt", "Lithuanian",[1,2,10],15], + ["lv", "Latvian", [1,2,0],16], + ["mai", "Maithili", [1,2], 2], + ["mfe", "Mauritian Creole",[1,2],1], + ["mg", "Malagasy", [1,2], 1], + ["mi", "Maori", [1,2], 1], + ["mk", "Macedonian",[1,2],17], + ["ml", "Malayalam",[1,2], 2], + ["mn", "Mongolian",[1,2], 2], + ["mnk", "Mandinka", [0,1,2],18], + ["mr", "Marathi", [1,2], 2], + ["ms", "Malay", [1], 3], + ["mt", "Maltese", [1,2,11,20],19], + ["nah", "Nahuatl", [1,2], 2], + ["nap", "Neapolitan",[1,2], 2], + ["nb", "Norwegian Bokmal",[1,2],2], + ["ne", "Nepali", [1,2], 2], + ["nl", "Dutch", [1,2], 2], + ["nn", "Norwegian Nynorsk",[1,2],2], + ["no", "Norwegian",[1,2], 2], + ["nso", "Northern Sotho",[1,2],2], + ["oc", "Occitan", [1,2], 1], + ["or", "Oriya", [2,1], 2], + ["pa", "Punjabi", [1,2], 2], + ["pap", "Papiamento",[1,2], 2], + ["pl", "Polish", [1,2,5],7], + ["pms", "Piemontese",[1,2], 2], + ["ps", "Pashto", [1,2], 2], + ["pt", "Portuguese",[1,2], 2], + ["pt_br","Brazilian Portuguese",[1,2], 2], + ["rm", "Romansh", [1,2], 2], + ["ro", "Romanian", [1,2,20],20], + ["ru", "Russian", [1,2,5],4], + ["sah", "Yakut", [1], 3], + ["sco", "Scots", [1,2], 2], + ["se", "Northern Sami",[1,2], 2], + ["si", "Sinhala", [1,2], 2], + ["sk", "Slovak", [1,2,5],6], + ["sl", "Slovenian",[5,1,2,3],21], + ["so", "Somali", [1,2], 2], + ["son", "Songhay", [1,2], 2], + ["sq", "Albanian", [1,2], 2], + ["sr", "Serbian", [1,2,5],4], + ["su", "Sundanese",[1], 3], + ["sv", "Swedish", [1,2], 2], + ["sw", "Swahili", [1,2], 2], + ["ta", "Tamil", [1,2], 2], + ["te", "Telugu", [1,2], 2], + ["tg", "Tajik", [1,2], 1], + ["th", "Thai", [1], 3], + ["ti", "Tigrinya", [1,2], 1], + ["tk", "Turkmen", [1,2], 2], + ["tr", "Turkish", [1,2], 1], + ["tt", "Tatar", [1], 3], + ["ug", "Uyghur", [1], 3], + ["uk", "Ukrainian",[1,2,5],4], + ["ur", "Urdu", [1,2], 2], + ["uz", "Uzbek", [1,2], 1], + ["vi", "Vietnamese",[1], 3], + ["wa", "Walloon", [1,2], 1], + ["wo", "Wolof", [1], 3], + ["yo", "Yoruba", [1,2], 2], + ["zh", "Chinese", [1], 3] + ]; + + var _rulesPluralsTypes = { + 1: function(n) {return Number(n > 1);}, + 2: function(n) {return Number(n != 1);}, + 3: function(n) {return 0;}, + 4: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 5: function(n) {return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5);}, + 6: function(n) {return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2);}, + 7: function(n) {return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 8: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3);}, + 9: function(n) {return Number(n >= 2);}, + 10: function(n) {return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;}, + 11: function(n) {return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3);}, + 12: function(n) {return Number(n%10!=1 || n%100==11);}, + 13: function(n) {return Number(n !== 0);}, + 14: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3);}, + 15: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 16: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2);}, + 17: function(n) {return Number(n==1 || n%10==1 ? 0 : 1);}, + 18: function(n) {return Number(0 ? 0 : n==1 ? 1 : 2);}, + 19: function(n) {return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3);}, + 20: function(n) {return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2);}, + 21: function(n) {return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }; + + var pluralExtensions = { + + rules: (function () { + var l, rules = {}; + for (l=_rules.length; l-- ;) { + rules[_rules[l][0]] = { + name: _rules[l][1], + numbers: _rules[l][2], + plurals: _rulesPluralsTypes[_rules[l][3]] + } + } + return rules; + }()), + + // you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + needsPlural: function(lng, count) { + var parts = lng.split('-'); + + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[parts[f.getCountyIndexOfLng(lng)]]; + } + + if (ext && ext.numbers.length <= 1) { + return false; + } else { + return this.get(lng, count) !== 1; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i; + if (ext.noAbs) { + i = ext.plurals(c); + } else { + i = ext.plurals(Math.abs(c)); + } + + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[f.getCountyIndexOfLng(lng)], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.hasResourceBundle = hasResourceBundle; + i18n.getResourceBundle = getResourceBundle; + i18n.addResource = addResource; + i18n.addResources = addResources; + i18n.removeResourceBundle = removeResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.applyReplacement = f.applyReplacement; + i18n.options = o; + + $.i18n = i18n; + $.t = i18n.t; + + return i18n; + +})); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd.withJQuery-1.8.0.min.js b/libs/i18next/release/i18next.amd.withJQuery-1.8.0.min.js new file mode 100644 index 00000000..f23545b7 --- /dev/null +++ b/libs/i18next/release/i18next.amd.withJQuery-1.8.0.min.js @@ -0,0 +1,5 @@ +// i18next, v1.8.0 +// Copyright (c)2015 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +!function(a,b){if("object"==typeof exports){var c=require("jquery");module.exports=b(c)}else"function"==typeof define&&define.amd&&define(["jquery"],b)}(this,function(a){function b(a,b){if(!b||"function"==typeof b)return a;for(var c in b)a[c]=b[c];return a}function c(a,b){for(var d in b)d in a?c(a[d],b[d]):a[d]=b[d];return a}function d(a,b,c){var d,e=0,f=a.length,g=void 0===f||"[object Array]"!==Object.prototype.toString.apply(a)||"function"==typeof a;if(c)if(g){for(d in a)if(b.apply(a[d],c)===!1)break}else for(;f>e&&b.apply(a[e++],c)!==!1;);else if(g){for(d in a)if(b.call(a[d],d,a[d])===!1)break}else for(;f>e&&b.call(a[e],e,a[e++])!==!1;);return a}function e(a){return"string"==typeof a?a.replace(/[&<>"'\/]/g,function(a){return P[a]}):a}function f(a){var b=function(a){if(window.XMLHttpRequest)return a(null,new XMLHttpRequest);if(window.ActiveXObject)try{return a(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(b){return a(null,new ActiveXObject("Microsoft.XMLHTTP"))}return a(new Error)},c=function(a){if("string"==typeof a)return a;var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")},d=function(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;cd?b+=String.fromCharCode(d):d>127&&2048>d?(b+=String.fromCharCode(d>>6|192),b+=String.fromCharCode(63&d|128)):(b+=String.fromCharCode(d>>12|224),b+=String.fromCharCode(d>>6&63|128),b+=String.fromCharCode(63&d|128))}return b},e=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";a=d(a);var c,e,f,g,h,i,j,k="",l=0;do c=a.charCodeAt(l++),e=a.charCodeAt(l++),f=a.charCodeAt(l++),g=c>>2,h=(3&c)<<4|e>>4,i=(15&e)<<2|f>>6,j=63&f,isNaN(e)?i=j=64:isNaN(f)&&(j=64),k+=b.charAt(g)+b.charAt(h)+b.charAt(i)+b.charAt(j),c=e=f="",g=h=i=j="";while(l1&&(d+=d.indexOf("?")>-1?"&"+k:"?"+k),e.jsonp){var l=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=d,void l.appendChild(m)}}b(function(b,c){if(b)return h(b);c.open(a,d,e.async);for(var f in j)j.hasOwnProperty(f)&&c.setRequestHeader(f,j[f]);c.onreadystatechange=function(){if(4===c.readyState){var a=c.responseText||"";if(!h)return;h(c.status,{text:function(){return a},json:function(){try{return JSON.parse(a)}catch(b){return S.error("Can not parse JSON. URL: "+d),{}}}})}},c.send(i)})},h={authBasic:function(a,b){g.headers.Authorization="Basic "+e(a+":"+b)},connect:function(a,b,c){return g("CONNECT",a,b,c)},del:function(a,b,c){return g("DELETE",a,b,c)},get:function(a,b,c){return g("GET",a,b,c)},head:function(a,b,c){return g("HEAD",a,b,c)},headers:function(a){g.headers=a||{}},isAllowed:function(a,b,c){this.options(a,function(a,d){c(-1!==d.text().indexOf(b))})},options:function(a,b,c){return g("OPTIONS",a,b,c)},patch:function(a,b,c){return g("PATCH",a,b,c)},post:function(a,b,c){return g("POST",a,b,c)},put:function(a,b,c){return g("PUT",a,b,c)},trace:function(a,b,c){return g("TRACE",a,b,c)}},i=a.type?a.type.toLowerCase():"get";h[i](a.url,a,function(b,c){200===b||0===b&&c.text()?a.success(c.json(),b,null):a.error(c.text(),b,null)})}function g(b,c){"function"==typeof b&&(c=b,b={}),b=b||{},S.extend(O,b),delete O.fixLng,O.functions&&(delete O.functions,S.extend(S,b.functions)),"string"==typeof O.ns&&(O.ns={namespaces:[O.ns],defaultNs:O.ns}),"string"==typeof O.fallbackNS&&(O.fallbackNS=[O.fallbackNS]),("string"==typeof O.fallbackLng||"boolean"==typeof O.fallbackLng)&&(O.fallbackLng=[O.fallbackLng]),O.interpolationPrefixEscaped=S.regexEscape(O.interpolationPrefix),O.interpolationSuffixEscaped=S.regexEscape(O.interpolationSuffix),O.lng||(O.lng=S.detectLanguage()),L=S.toLanguages(O.lng),H=L[0],S.log("currentLng set to: "+H),O.useCookie&&S.cookie.read(O.cookieName)!==H&&S.cookie.create(O.cookieName,H,O.cookieExpirationTime,O.cookieDomain),O.detectLngFromLocalStorage&&"undefined"!=typeof document&&window.localStorage&&S.localStorage.setItem("i18next_lng",H);var d=B;b.fixLng&&(d=function(a,b){return b=b||{},b.lng=b.lng||d.lng,B(a,b)},d.lng=H),V.setCurrentLng(H),a&&O.setJqueryExt&&u();var e;if(a&&a.Deferred&&(e=a.Deferred()),!O.resStore){var f=S.toLanguages(O.lng);"string"==typeof O.preload&&(O.preload=[O.preload]);for(var g=0,h=O.preload.length;h>g;g++)for(var i=S.toLanguages(O.preload[g]),j=0,k=i.length;k>j;j++)f.indexOf(i[j])<0&&f.push(i[j]);return I.sync.load(f,O,function(a,b){J=b,M=!0,c&&c(d),e&&e.resolve(d)}),e?e.promise():void 0}return J=O.resStore,M=!0,c&&c(d),e&&e.resolve(d),e?e.promise():void 0}function h(a,b){"string"==typeof a&&(a=[a]);for(var c=0,d=a.length;d>c;c++)O.preload.indexOf(a[c])<0&&O.preload.push(a[c]);return g(b)}function i(a,b,c,d){"string"!=typeof b?(c=b,b=O.ns.defaultNs):O.ns.namespaces.indexOf(b)<0&&O.ns.namespaces.push(b),J[a]=J[a]||{},J[a][b]=J[a][b]||{},d?S.deepExtend(J[a][b],c):S.extend(J[a][b],c),O.useLocalStorage&&N._storeLocal(J)}function j(a,b){"string"!=typeof b&&(b=O.ns.defaultNs),J[a]=J[a]||{};var c=J[a][b]||{},d=!1;for(var e in c)c.hasOwnProperty(e)&&(d=!0);return d}function k(a,b){return"string"!=typeof b&&(b=O.ns.defaultNs),J[a]=J[a]||{},S.extend({},J[a][b])}function l(a,b){"string"!=typeof b&&(b=O.ns.defaultNs),J[a]=J[a]||{},J[a][b]={},O.useLocalStorage&&N._storeLocal(J)}function m(a,b,c,d){"string"!=typeof b?(resource=b,b=O.ns.defaultNs):O.ns.namespaces.indexOf(b)<0&&O.ns.namespaces.push(b),J[a]=J[a]||{},J[a][b]=J[a][b]||{};for(var e=c.split(O.keyseparator),f=0,g=J[a][b];e[f];)f==e.length-1?g[e[f]]=d:(null==g[e[f]]&&(g[e[f]]={}),g=g[e[f]]),f++;O.useLocalStorage&&N._storeLocal(J)}function n(a,b,c){"string"!=typeof b?(resource=b,b=O.ns.defaultNs):O.ns.namespaces.indexOf(b)<0&&O.ns.namespaces.push(b);for(var d in c)"string"==typeof c[d]&&m(a,b,d,c[d])}function o(a){O.ns.defaultNs=a}function p(a,b){q([a],b)}function q(a,b){var c={dynamicLoad:O.dynamicLoad,resGetPath:O.resGetPath,getAsync:O.getAsync,customLoad:O.customLoad,ns:{namespaces:a,defaultNs:""}},d=S.toLanguages(O.lng);"string"==typeof O.preload&&(O.preload=[O.preload]);for(var e=0,f=O.preload.length;f>e;e++)for(var g=S.toLanguages(O.preload[e]),h=0,i=g.length;i>h;h++)d.indexOf(g[h])<0&&d.push(g[h]);for(var j=[],k=0,l=d.length;l>k;k++){var m=!1,n=J[d[k]];if(n)for(var o=0,p=a.length;p>o;o++)n[a[o]]||(m=!0);else m=!0;m&&j.push(d[k])}j.length?I.sync._fetch(j,c,function(c,d){var e=a.length*j.length;S.each(a,function(a,c){O.ns.namespaces.indexOf(c)<0&&O.ns.namespaces.push(c),S.each(j,function(a,f){J[f]=J[f]||{},J[f][c]=d[f][c],e--,0===e&&b&&(O.useLocalStorage&&I.sync._storeLocal(J),b())})})}):b&&b()}function r(a,b,c){return"function"==typeof b?(c=b,b={}):b||(b={}),b.lng=a,g(b,c)}function s(){return H}function t(a){J={},r(H,a)}function u(){function b(b,c,d){if(0!==c.length){var e="text";if(0===c.indexOf("[")){var f=c.split("]");c=f[1],e=f[0].substr(1,f[0].length-1)}c.indexOf(";")===c.length-1&&(c=c.substr(0,c.length-2));var g;if("html"===e)g=O.defaultValueFromContent?a.extend({defaultValue:b.html()},d):d,b.html(a.t(c,g));else if("text"===e)g=O.defaultValueFromContent?a.extend({defaultValue:b.text()},d):d,b.text(a.t(c,g));else if("prepend"===e)g=O.defaultValueFromContent?a.extend({defaultValue:b.html()},d):d,b.prepend(a.t(c,g));else if("append"===e)g=O.defaultValueFromContent?a.extend({defaultValue:b.html()},d):d,b.append(a.t(c,g));else if(0===e.indexOf("data-")){var h=e.substr("data-".length);g=O.defaultValueFromContent?a.extend({defaultValue:b.data(h)},d):d;var i=a.t(c,g);b.data(h,i),b.attr(e,i)}else g=O.defaultValueFromContent?a.extend({defaultValue:b.attr(e)},d):d,b.attr(e,a.t(c,g))}}function c(c,d){var e=c.attr(O.selectorAttr);if(e||"undefined"==typeof e||e===!1||(e=c.text()||c.val()),e){var f=c,g=c.data("i18n-target");if(g&&(f=c.find(g)||c),d||O.useDataAttrOptions!==!0||(d=c.data("i18n-options")),d=d||{},e.indexOf(";")>=0){var h=e.split(";");a.each(h,function(a,c){""!==c&&b(f,c,d)})}else b(f,e,d);O.useDataAttrOptions===!0&&c.data("i18n-options",d)}}a.t=a.t||B,a.fn.i18n=function(b){return this.each(function(){c(a(this),b);var d=a(this).find("["+O.selectorAttr+"]");d.each(function(){c(a(this),b)})})}}function v(a,b,c,d){if(!a)return a;if(d=d||b,a.indexOf(d.interpolationPrefix||O.interpolationPrefix)<0)return a;var e=d.interpolationPrefix?S.regexEscape(d.interpolationPrefix):O.interpolationPrefixEscaped,f=d.interpolationSuffix?S.regexEscape(d.interpolationSuffix):O.interpolationSuffixEscaped,g="HTML"+f,h=b.replace&&"object"==typeof b.replace?b.replace:b;return S.each(h,function(b,h){var i=c?c+O.keyseparator+b:b;"object"==typeof h&&null!==h?a=v(a,h,i,d):d.escapeInterpolation||O.escapeInterpolation?(a=a.replace(new RegExp([e,i,g].join(""),"g"),S.regexReplacementEscape(h)),a=a.replace(new RegExp([e,i,f].join(""),"g"),S.regexReplacementEscape(S.escape(h)))):a=a.replace(new RegExp([e,i,f].join(""),"g"),S.regexReplacementEscape(h))}),a}function w(a,b){var c=",",d="{",e="}",f=S.extend({},b);for(delete f.postProcess;-1!=a.indexOf(O.reusePrefix)&&(K++,!(K>O.maxRecursion));){var g=a.lastIndexOf(O.reusePrefix),h=a.indexOf(O.reuseSuffix,g)+O.reuseSuffix.length,i=a.substring(g,h),j=i.replace(O.reusePrefix,"").replace(O.reuseSuffix,"");if(g>=h)return S.error("there is an missing closing in following translation value",a),"";if(-1!=j.indexOf(c)){var k=j.indexOf(c);if(-1!=j.indexOf(d,k)&&-1!=j.indexOf(e,k)){var l=j.indexOf(d,k),m=j.indexOf(e,l)+e.length;try{f=S.extend(f,JSON.parse(j.substring(l,m))),j=j.substring(0,k)}catch(n){}}}var o=E(j,f);a=a.replace(i,S.regexReplacementEscape(o))}return a}function x(a){return a.context&&("string"==typeof a.context||"number"==typeof a.context)}function y(a){return void 0!==a.count&&"string"!=typeof a.count}function z(a){return void 0!==a.indefinite_article&&"string"!=typeof a.indefinite_article&&a.indefinite_article}function A(a,b){b=b||{};var c=C(a,b),d=F(a,b);return void 0!==d||d===c}function B(a,b){return b=b||{},M?(K=0,E.apply(null,arguments)):(S.log("i18next not finished initialization. you might have called t function before loading resources finished."),b.defaultValue||"")}function C(a,b){return void 0!==b.defaultValue?b.defaultValue:a}function D(){for(var a=[],b=1;b1)for(var d=0;d-1&&(e=c.split(O.nsseparator),i=e[0],c=e[1]),void 0===g&&O.sendMissing&&"function"==typeof O.missingKeyHandler&&(b.lng?O.missingKeyHandler(h[0],i,c,f,h):O.missingKeyHandler(O.lng,i,c,f,h));var j;j="string"==typeof O.postProcess&&""!==O.postProcess?[O.postProcess]:"array"==typeof O.postProcess||"object"==typeof O.postProcess?O.postProcess:[],"string"==typeof b.postProcess&&""!==b.postProcess?j=j.concat([b.postProcess]):("array"==typeof b.postProcess||"object"==typeof b.postProcess)&&(j=j.concat(b.postProcess)),void 0!==g&&j.length&&j.forEach(function(a){W[a]&&(g=W[a](g,c,b))});var k=f;if(f.indexOf(O.nsseparator)>-1&&(e=f.split(O.nsseparator),k=e[1]),k===c&&O.parseMissingKey&&(f=O.parseMissingKey(f)),void 0===g&&(f=v(f,b),f=w(f,b),j.length)){var l=C(c,b);j.forEach(function(a){W[a]&&(g=W[a](l,c,b))})}return void 0!==g?g:f}function F(a,b){b=b||{};var c,d,e=C(a,b),f=L;if(!J)return e;if("cimode"===f[0].toLowerCase())return e;if(b.lngs&&(f=b.lngs),b.lng&&(f=S.toLanguages(b.lng,b.fallbackLng),!J[f[0]])){var g=O.getAsync;O.getAsync=!1,I.sync.load(f,O,function(a,b){S.extend(J,b),O.getAsync=g})}var h=b.ns||O.ns.defaultNs;if(a.indexOf(O.nsseparator)>-1){var i=a.split(O.nsseparator);h=i[0],a=i[1]}if(x(b)){c=S.extend({},b),delete c.context,c.defaultValue=O.contextNotFound;var j=h+O.nsseparator+a+"_"+b.context;if(d=B(j,c),d!=O.contextNotFound)return v(d,{context:b.context})}if(y(b,f[0])){c=S.extend({lngs:[f[0]]},b),delete c.count,c._origLng=c._origLng||c.lng||f[0],delete c.lng,c.defaultValue=O.pluralNotFound;var k;if(V.needsPlural(f[0],b.count)){k=h+O.nsseparator+a+O.pluralSuffix;var l=V.get(f[0],b.count);l>=0?k=k+"_"+l:1===l&&(k=h+O.nsseparator+a)}else k=h+O.nsseparator+a;if(d=B(k,c),d!=O.pluralNotFound)return v(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix});if(!(f.length>1))return c.lng=c._origLng,delete c._origLng,d=B(h+O.nsseparator+a,c),v(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix});var m=f.slice();if(m.shift(),b=S.extend(b,{lngs:m}),b._origLng=c._origLng,delete b.lng,d=B(h+O.nsseparator+a,b),d!=O.pluralNotFound)return d}if(z(b)){var n=S.extend({},b);delete n.indefinite_article,n.defaultValue=O.indefiniteNotFound;var o=h+O.nsseparator+a+(b.count&&!y(b,f[0])||!b.count?O.indefiniteSuffix:"");if(d=B(o,n),d!=O.indefiniteNotFound)return d}for(var p,q=a.split(O.keyseparator),r=0,s=f.length;s>r&&void 0===p;r++){for(var t=f[r],u=0,A=J[t]&&J[t][h];q[u];)A=A&&A[q[u]],u++;if(void 0!==A){var D=Object.prototype.toString.apply(A);if("string"==typeof A)A=v(A,b),A=w(A,b);else if("[object Array]"!==D||O.returnObjectTrees||b.returnObjectTrees){if(null===A&&O.fallbackOnNull===!0)A=void 0;else if(null!==A)if(O.returnObjectTrees||b.returnObjectTrees){if("[object Number]"!==D&&"[object Function]"!==D&&"[object RegExp]"!==D){var G="[object Array]"===D?[]:{};S.each(A,function(c){G[c]=E(h+O.nsseparator+a+O.keyseparator+c,b)}),A=G}}else O.objectTreeKeyHandler&&"function"==typeof O.objectTreeKeyHandler?A=O.objectTreeKeyHandler(a,A,t,h,b):(A="key '"+h+":"+a+" ("+t+")' returned an object instead of string.",S.log(A))}else A=A.join("\n"),A=v(A,b),A=w(A,b);"string"==typeof A&&""===A.trim()&&O.fallbackOnEmpty===!0&&(A=void 0),p=A}}if(void 0===p&&!b.isFallbackLookup&&(O.fallbackToDefaultNS===!0||O.fallbackNS&&O.fallbackNS.length>0)){if(b.isFallbackLookup=!0,O.fallbackNS.length){for(var H=0,K=O.fallbackNS.length;K>H;H++)if(p=F(O.fallbackNS[H]+O.nsseparator+a,b),p||""===p&&O.fallbackOnEmpty===!1){var M=p.indexOf(O.nsseparator)>-1?p.split(O.nsseparator)[1]:p,N=e.indexOf(O.nsseparator)>-1?e.split(O.nsseparator)[1]:e;if(M!==N)break}}else p=F(a,b);b.isFallbackLookup=!1}return p}function G(){var a,b=O.lngWhitelist||[],c=[];if("undefined"!=typeof window&&!function(){for(var a=window.location.search.substring(1),b=a.split("&"),d=0;d0){var f=b[d].substring(0,e);f==O.detectLngQS&&c.push(b[d].substring(e+1))}}}(),O.useCookie&&"undefined"!=typeof document){var d=S.cookie.read(O.cookieName);d&&c.push(d)}if(O.detectLngFromLocalStorage&&"undefined"!=typeof window&&window.localStorage&&c.push(S.localStorage.getItem("i18next_lng")),"undefined"!=typeof navigator){if(navigator.languages)for(var e=0;e-1){var f=e.split("-");e=O.lowerCaseLng?f[0].toLowerCase()+"-"+f[1].toLowerCase():f[0].toLowerCase()+"-"+f[1].toUpperCase()}if(0===b.length||b.indexOf(e)>-1){a=e;break}}}(),a||(a=O.fallbackLng[0]),a}Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>0&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=c;arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d))));for(var e=d>=0?Math.min(d,c-1):c-Math.abs(d);e>=0;e--)if(e in b&&b[e]===a)return e;return-1}),"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")});var H,I={},J={},K=0,L=[],M=!1,N={};N={load:function(a,b,c){b.useLocalStorage?N._loadLocal(a,b,function(d,e){for(var f=[],g=0,h=a.length;h>g;g++)e[a[g]]||f.push(a[g]);f.length>0?N._fetch(f,b,function(a,b){S.extend(e,b),N._storeLocal(b),c(null,e)}):c(null,e)}):N._fetch(a,b,function(a,b){c(null,b)})},_loadLocal:function(a,b,c){var d={},e=(new Date).getTime();if(window.localStorage){var f=a.length;S.each(a,function(a,g){var h=S.localStorage.getItem("res_"+g);h&&(h=JSON.parse(h),h.i18nStamp&&h.i18nStamp+b.localStorageExpirationTime>e&&(d[g]=h)),f--,0===f&&c(null,d)})}},_storeLocal:function(a){if(window.localStorage)for(var b in a)a[b].i18nStamp=(new Date).getTime(),S.localStorage.setItem("res_"+b,JSON.stringify(a[b]))},_fetch:function(a,b,c){var d=b.ns,e={};if(b.dynamicLoad){var f=function(a,b){c(null,b)};if("function"==typeof b.customLoad)b.customLoad(a,d.namespaces,b,f);else{var g=v(b.resGetPath,{lng:a.join("+"),ns:d.namespaces.join("+")});S.ajax({url:g,success:function(a){S.log("loaded: "+g),f(null,a)},error:function(a,b,c){S.log("failed loading: "+g),f("failed loading resource.json error: "+c)},dataType:"json",async:b.getAsync})}}else{var h,i=d.namespaces.length*a.length;S.each(d.namespaces,function(d,f){S.each(a,function(a,d){var g=function(a,b){a&&(h=h||[],h.push(a)),e[d]=e[d]||{},e[d][f]=b,i--,0===i&&c(h,e)};"function"==typeof b.customLoad?b.customLoad(d,f,b,g):N._fetchOne(d,f,b,g)})})}},_fetchOne:function(a,b,c,d){var e=v(c.resGetPath,{lng:a,ns:b});S.ajax({url:e,success:function(a){S.log("loaded: "+e),d(null,a)},error:function(a,b,c){if(b&&200==b||a&&a.status&&200==a.status)S.error("There is a typo in: "+e);else if(b&&404==b||a&&a.status&&404==a.status)S.log("Does not exist: "+e);else{var f=b?b:a&&a.status?a.status:null;S.log(f+" when loading "+e)}d(c,{})},dataType:"json",async:c.getAsync})},postMissing:function(a,b,c,d,e){var f={};f[c]=d;var g=[];if("fallback"===O.sendMissingTo&&O.fallbackLng[0]!==!1)for(var h=0;hh;h++)g.push({lng:e[h],url:v(O.resPostPath,{lng:e[h],ns:b})});for(var j=0,k=g.length;k>j;j++){var l=g[j];S.ajax({url:l.url,type:O.sendType,data:f,success:function(){S.log("posted missing key '"+c+"' to: "+l.url);for(var a=c.split("."),e=0,f=J[l.lng][b];a[e];)f=f[a[e]]=e===a.length-1?d:f[a[e]]||{},e++},error:function(){S.log("failed posting missing key '"+c+"' to: "+l.url)},dataType:"json",async:O.postAsync})}},reload:t};var O={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:["dev"],fallbackNS:[],detectLngQS:"setLng",detectLngFromLocalStorage:!1,ns:"translation",fallbackOnNull:!0,fallbackOnEmpty:!1,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",defaultVariables:!1,reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,indefiniteSuffix:"_indefinite",indefiniteNotFound:["indefinite_not_found",Math.random()].join(""),setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",cookieDomain:void 0,objectTreeKeyHandler:void 0,postProcess:void 0,parseMissingKey:void 0,missingKeyHandler:N.postMissing,shortcutFunction:"sprintf"},P={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},Q={create:function(a,b,c,d){var e;if(c){var f=new Date;f.setTime(f.getTime()+60*c*1e3),e="; expires="+f.toGMTString()}else e="";d=d?"domain="+d+";":"",document.cookie=a+"="+b+e+";"+d+"path=/"},read:function(a){for(var b=a+"=",c=document.cookie.split(";"),d=0;d-1){var c=a.split("-");b=O.lowerCaseLng?c[0].toLowerCase()+"-"+c[1].toLowerCase():c[0].toLowerCase()+"-"+c[1].toUpperCase()}else b=O.lowerCaseLng?a.toLowerCase():a;return b}var c=this.log,d=[],e=O.lngWhitelist||!1,f=function(a){!e||e.indexOf(a)>-1?d.push(a):c("rejecting non-whitelisted language: "+a)};if("string"==typeof a&&a.indexOf("-")>-1){var g=a.split("-");"unspecific"!==O.load&&f(b(a)),"current"!==O.load&&f(b(g[this.getCountyIndexOfLng(a)]))}else f(b(a));for(var h=0;h1)},2:function(a){return Number(1!=a)},3:function(){return 0},4:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},5:function(a){return Number(0===a?0:1==a?1:2==a?2:a%100>=3&&10>=a%100?3:a%100>=11?4:5)},6:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)},7:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},8:function(a){return Number(1==a?0:2==a?1:8!=a&&11!=a?2:3)},9:function(a){return Number(a>=2)},10:function(a){return Number(1==a?0:2==a?1:7>a?2:11>a?3:4)},11:function(a){return Number(1==a||11==a?0:2==a||12==a?1:a>2&&20>a?2:3)},12:function(a){return Number(a%10!=1||a%100==11)},13:function(a){return Number(0!==a)},14:function(a){return Number(1==a?0:2==a?1:3==a?2:3)},15:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&(10>a%100||a%100>=20)?1:2)},16:function(a){return Number(a%10==1&&a%100!=11?0:0!==a?1:2)},17:function(a){return Number(1==a||a%10==1?0:1)},18:function(a){return Number(1==a?1:2)},19:function(a){return Number(1==a?0:0===a||a%100>1&&11>a%100?1:a%100>10&&20>a%100?2:3)},20:function(a){return Number(1==a?0:0===a||a%100>0&&20>a%100?1:2)},21:function(a){return Number(a%100==1?1:a%100==2?2:a%100==3||a%100==4?3:0)}},V={rules:function(){var a,b={};for(a=T.length;a--;)b[T[a][0]]={name:T[a][1],numbers:T[a][2],plurals:U[T[a][3]]};return b}(),addRule:function(a,b){V.rules[a]=b},setCurrentLng:function(a){if(!V.currentRule||V.currentRule.lng!==a){var b=a.split("-");V.currentRule={lng:a,rule:V.rules[b[0]]}}},needsPlural:function(a,b){var c,d=a.split("-");return c=V.currentRule&&V.currentRule.lng===a?V.currentRule.rule:V.rules[d[S.getCountyIndexOfLng(a)]],c&&c.numbers.length<=1?!1:1!==this.get(a,b)},get:function(a,b){function c(b,c){var d;if(d=V.currentRule&&V.currentRule.lng===a?V.currentRule.rule:V.rules[b]){var e;e=d.plurals(d.noAbs?c:Math.abs(c));var f=d.numbers[e];return 2===d.numbers.length&&1===d.numbers[0]&&(2===f?f=-1:1===f&&(f=1)),f}return 1===c?"1":"-1"}var d=a.split("-");return c(d[S.getCountyIndexOfLng(a)],b)}},W={},X=function(a,b){W[a]=b},Y=function(){function a(a){return Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}function b(a,b){for(var c=[];b>0;c[--b]=a);return c.join("")}var c=function(){return c.cache.hasOwnProperty(arguments[0])||(c.cache[arguments[0]]=c.parse(arguments[0])),c.format.call(null,c.cache[arguments[0]],arguments)};return c.format=function(c,d){var e,f,g,h,i,j,k,l=1,m=c.length,n="",o=[];for(f=0;m>f;f++)if(n=a(c[f]),"string"===n)o.push(c[f]);else if("array"===n){if(h=c[f],h[2])for(e=d[l],g=0;g=0?"+"+e:e,j=h[4]?"0"==h[4]?"0":h[4].charAt(1):" ",k=h[6]-String(e).length,i=h[6]?b(j,k):"",o.push(h[5]?e+i:i+e)}return o.join("")},c.cache={},c.parse=function(a){for(var b=a,c=[],d=[],e=0;b;){if(null!==(c=/^[^\x25]+/.exec(b)))d.push(c[0]);else if(null!==(c=/^\x25{2}/.exec(b)))d.push("%");else{if(null===(c=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(b)))throw"[sprintf] huh?";if(c[2]){e|=1;var f=[],g=c[2],h=[];if(null===(h=/^([a-z_][a-z_\d]*)/i.exec(g)))throw"[sprintf] huh?";for(f.push(h[1]);""!==(g=g.substring(h[0].length));)if(null!==(h=/^\.([a-z_][a-z_\d]*)/i.exec(g)))f.push(h[1]);else{if(null===(h=/^\[(\d+)\]/.exec(g)))throw"[sprintf] huh?";f.push(h[1])}c[2]=f}else e|=2;if(3===e)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";d.push(c)}b=b.substring(c[0].length)}return d},c}(),Z=function(a,b){return b.unshift(a),Y.apply(null,b)};return X("sprintf",function(a,b,c){return c.sprintf?"[object Array]"===Object.prototype.toString.apply(c.sprintf)?Z(a,c.sprintf):"object"==typeof c.sprintf?Y(a,c.sprintf):a:a}),I.init=g,I.setLng=r,I.preload=h,I.addResourceBundle=i,I.hasResourceBundle=j,I.getResourceBundle=k,I.addResource=m,I.addResources=n,I.removeResourceBundle=l,I.loadNamespace=p,I.loadNamespaces=q,I.setDefaultNamespace=o,I.t=B,I.translate=B,I.exists=A,I.detectLanguage=S.detectLanguage,I.pluralExtensions=V,I.sync=N,I.functions=S,I.lng=s,I.addPostProcessor=X,I.applyReplacement=S.applyReplacement,I.options=O,a.i18n=I,a.t=I.t,I}); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd.withJQuery-1.8.1.js b/libs/i18next/release/i18next.amd.withJQuery-1.8.1.js new file mode 100644 index 00000000..dbc3d328 --- /dev/null +++ b/libs/i18next/release/i18next.amd.withJQuery-1.8.1.js @@ -0,0 +1,2177 @@ +// i18next, v1.8.1 +// Copyright (c)2015 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function (root, factory) { + if (typeof exports === 'object') { + + var jquery = require('jquery'); + + module.exports = factory(jquery); + + } else if (typeof define === 'function' && define.amd) { + + define(['jquery'], factory); + + } +}(this, function ($) { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + // Add string trim for IE8. + if (typeof String.prototype.trim !== 'function') { + String.prototype.trim = function() { + return this.replace(/^\s+|\s+$/g, ''); + } + } + + var i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = [] + , initialized = false + , sync = {}; + + sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = f.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + f.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + if ((status && status == 200) || (xhr && xhr.status && xhr.status == 200)) { + // file loaded but invalid json, stop waste time ! + f.error('There is a typo in: ' + url); + } else if ((status && status == 404) || (xhr && xhr.status && xhr.status == 404)) { + f.log('Does not exist: ' + url); + } else { + var theStatus = status ? status : ((xhr && xhr.status) ? xhr.status : null); + f.log(theStatus + ' when loading ' + url); + } + + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback' && o.fallbackLng[0] !== false) { + for (var i = 0; i < o.fallbackLng.length; i++) { + urls.push({lng: o.fallbackLng[i], url: applyReplacement(o.resPostPath, { lng: o.fallbackLng[i], ns: ns })}); + } + } else if (o.sendMissingTo === 'current' || (o.sendMissingTo === 'fallback' && o.fallbackLng[0] === false) ) { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + }, + + reload: reload + }; + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: ['dev'], + fallbackNS: [], + detectLngQS: 'setLng', + detectLngFromLocalStorage: false, + ns: 'translation', + fallbackOnNull: true, + fallbackOnEmpty: false, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + defaultVariables: false, + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + indefiniteSuffix: '_indefinite', + indefiniteNotFound: ['indefinite_not_found', Math.random()].join(''), + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + cookieDomain: undefined, + + objectTreeKeyHandler: undefined, + postProcess: undefined, + parseMissingKey: undefined, + missingKeyHandler: sync.postMissing, + + shortcutFunction: 'sprintf' // or: defaultValue + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _deepExtend(target, source) { + for (var prop in source) + if (prop in target) + _deepExtend(target[prop], source[prop]); + else + target[prop] = source[prop]; + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || Object.prototype.toString.apply(object) !== '[object Array]' || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + try { + return JSON.parse(data) + } catch (e) { + f.error('Can not parse JSON. URL: ' + url); + return {}; + } + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + // file: protocol always gives status code 0, so check for data + if (status === 200 || (status === 0 && data.text())) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes,domain) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + domain = (domain)? "domain="+domain+";" : ""; + document.cookie = name+"="+value+expires+";"+domain+"path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes,domain) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + deepExtend: _deepExtend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : (typeof document !== 'undefined' ? _ajax : function() {}), + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + error: function(str) { + if (typeof console !== "undefined") console.error(str); + }, + getCountyIndexOfLng: function(lng) { + var lng_index = 0; + if (lng === 'nb-NO' || lng === 'nn-NO' || lng === 'nb-no' || lng === 'nn-no') lng_index = 1; + return lng_index; + }, + toLanguages: function(lng) { + var log = this.log; + + function applyCase(l) { + var ret = l; + + if (typeof l === 'string' && l.indexOf('-') > -1) { + var parts = l.split('-'); + + ret = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } else { + ret = o.lowerCaseLng ? l.toLowerCase() : l; + } + + return ret; + } + + var languages = []; + var whitelist = o.lngWhitelist || false; + var addLanguage = function(language){ + //reject langs not whitelisted + if(!whitelist || whitelist.indexOf(language) > -1){ + languages.push(language); + }else{ + log('rejecting non-whitelisted language: ' + language); + } + }; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + if (o.load !== 'unspecific') addLanguage(applyCase(lng)); + if (o.load !== 'current') addLanguage(applyCase(parts[this.getCountyIndexOfLng(lng)])); + } else { + addLanguage(applyCase(lng)); + } + + for (var i = 0; i < o.fallbackLng.length; i++) { + if (languages.indexOf(o.fallbackLng[i]) === -1 && o.fallbackLng[i]) languages.push(applyCase(o.fallbackLng[i])); + } + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + }, + regexReplacementEscape: function(strOrFn) { + if (typeof strOrFn === 'string') { + return strOrFn.replace(/\$/g, "$$$$"); + } else { + return strOrFn; + } + }, + localStorage: { + setItem: function(key, value) { + if (window.localStorage) { + try { + window.localStorage.setItem(key, value); + } catch (e) { + f.log('failed to set value for key "' + key + '" to localStorage.'); + } + } + }, + getItem: function(key, value) { + if (window.localStorage) { + try { + return window.localStorage.getItem(key, value); + } catch (e) { + f.log('failed to get value for key "' + key + '" from localStorage.'); + return undefined; + } + } + } + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + delete o.fixLng; /* passed in each time */ + + // override functions: .log(), .detectLanguage(), etc + if (o.functions) { + delete o.functions; + f.extend(f, options.functions); + } + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // fallback languages + if (typeof o.fallbackLng == 'string' || typeof o.fallbackLng == 'boolean') { + o.fallbackLng = [o.fallbackLng]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + if (o.useCookie && f.cookie.read(o.cookieName) !== currentLng){ //cookie is unset or invalid + f.cookie.create(o.cookieName, currentLng, o.cookieExpirationTime, o.cookieDomain); + } + if (o.detectLngFromLocalStorage && typeof document !== 'undefined' && window.localStorage) { + f.localStorage.setItem('i18next_lng', currentLng); + } + + var lngTranslate = translate; + if (options.fixLng) { + lngTranslate = function(key, options) { + options = options || {}; + options.lng = options.lng || lngTranslate.lng; + return translate(key, options); + }; + lngTranslate.lng = currentLng; + } + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + initialized = true; + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + initialized = true; + + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources, deep) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + if (deep) { + f.deepExtend(resStore[lng][ns], resources); + } else { + f.extend(resStore[lng][ns], resources); + } + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function hasResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + var res = resStore[lng][ns] || {}; + + var hasValues = false; + for(var prop in res) { + if (res.hasOwnProperty(prop)) { + hasValues = true; + } + } + + return hasValues; + } + + function getResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + return f.extend({}, resStore[lng][ns]); + } + + function removeResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = {}; + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function addResource(lng, ns, key, value) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + var keys = key.split(o.keyseparator); + var x = 0; + var node = resStore[lng][ns]; + var origRef = node; + + while (keys[x]) { + if (x == keys.length - 1) + node[keys[x]] = value; + else { + if (node[keys[x]] == null) + node[keys[x]] = {}; + + node = node[keys[x]]; + } + x++; + } + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function addResources(lng, ns, resources) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + for (var m in resources) { + if (typeof resources[m] === 'string') addResource(lng, ns, m, resources[m]); + } + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, options, cb) { + if (typeof options === 'function') { + cb = options; + options = {}; + } else if (!options) { + options = {}; + } + + options.lng = lng; + return init(options, cb); + } + + function lng() { + return currentLng; + } + + function reload(cb) { + resStore = {}; + setLng(currentLng, cb); + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else if (attr === 'prepend') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.prepend($.t(key, optionsToUse)); + } else if (attr === 'append') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.append($.t(key, optionsToUse)); + } else if (attr.indexOf("data-") === 0) { + var dataAttr = attr.substr(("data-").length); + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.data(dataAttr) }, options) : options; + var translated = $.t(key, optionsToUse); + //we change into the data cache + ele.data(dataAttr, translated); + //we change into the dom + ele.attr(attr, translated); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key && typeof key !== 'undefined' && key !== false) key = ele.text() || ele.val(); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + var hash = replacementHash.replace && typeof replacementHash.replace === 'object' ? replacementHash.replace : replacementHash; + f.each(hash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), f.regexReplacementEscape(value)); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(f.escape(value))); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(value)); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + if (index_of_end_of_closing <= index_of_opening) { + f.error('there is an missing closing in following translation value', translated); + return ''; + } + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, f.regexReplacementEscape(translated_token)); + } + return translated; + } + + function hasContext(options) { + return (options.context && (typeof options.context == 'string' || typeof options.context == 'number')); + } + + function needsPlural(options, lng) { + return (options.count !== undefined && typeof options.count != 'string'/* && pluralExtensions.needsPlural(lng, options.count)*/); + } + + function needsIndefiniteArticle(options) { + return (options.indefinite_article !== undefined && typeof options.indefinite_article != 'string' && options.indefinite_article); + } + + function exists(key, options) { + options = options || {}; + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + options = options || {}; + + if (!initialized) { + f.log('i18next not finished initialization. you might have called t function before loading resources finished.') + return options.defaultValue || ''; + }; + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _getDefaultValue(key, options) { + return (options.defaultValue !== undefined) ? options.defaultValue : key; + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(potentialKeys, options) { + if (options && typeof options !== 'object') { + if (o.shortcutFunction === 'sprintf') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else if (o.shortcutFunction === 'defaultValue') { + options = { + defaultValue: options + } + } + } else { + options = options || {}; + } + + if (typeof o.defaultVariables === 'object') { + options = f.extend({}, o.defaultVariables, options); + } + + if (potentialKeys === undefined || potentialKeys === null || potentialKeys === '') return ''; + + if (typeof potentialKeys === 'number') { + potentialKeys = String(potentialKeys); + } + + if (typeof potentialKeys === 'string') { + potentialKeys = [potentialKeys]; + } + + var key = potentialKeys[0]; + + if (potentialKeys.length > 1) { + for (var i = 0; i < potentialKeys.length; i++) { + key = potentialKeys[i]; + if (exists(key, options)) { + break; + } + } + } + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng, options.fallbackLng) : languages + , ns = options.ns || o.ns.defaultNs + , parts; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing && typeof o.missingKeyHandler === 'function') { + if (options.lng) { + o.missingKeyHandler(lngs[0], ns, key, notFound, lngs); + } else { + o.missingKeyHandler(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessorsToApply; + if (typeof o.postProcess === 'string' && o.postProcess !== '') { + postProcessorsToApply = [o.postProcess]; + } else if (typeof o.postProcess === 'array' || typeof o.postProcess === 'object') { + postProcessorsToApply = o.postProcess; + } else { + postProcessorsToApply = []; + } + + if (typeof options.postProcess === 'string' && options.postProcess !== '') { + postProcessorsToApply = postProcessorsToApply.concat([options.postProcess]); + } else if (typeof options.postProcess === 'array' || typeof options.postProcess === 'object') { + postProcessorsToApply = postProcessorsToApply.concat(options.postProcess); + } + + if (found !== undefined && postProcessorsToApply.length) { + postProcessorsToApply.forEach(function(postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + }); + } + + // process notFound if function exists + var splitNotFound = notFound; + if (notFound.indexOf(o.nsseparator) > -1) { + parts = notFound.split(o.nsseparator); + splitNotFound = parts[1]; + } + if (splitNotFound === key && o.parseMissingKey) { + notFound = o.parseMissingKey(notFound); + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessorsToApply.length) { + var val = _getDefaultValue(key, options); + postProcessorsToApply.forEach(function(postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](val, key, options); + } + }); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options) { + options = options || {}; + + var optionWithoutCount, translated + , notFound = _getDefaultValue(key, options) + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + // CI mode + if (lngs[0].toLowerCase() === 'cimode') return notFound; + + // passed in lng + if (options.lngs) lngs = options.lngs; + if (options.lng) { + lngs = f.toLanguages(options.lng, options.fallbackLng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options, lngs[0])) { + optionWithoutCount = f.extend({ lngs: [lngs[0]]}, options); + delete optionWithoutCount.count; + optionWithoutCount._origLng = optionWithoutCount._origLng || optionWithoutCount.lng || lngs[0]; + delete optionWithoutCount.lng; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey; + if (!pluralExtensions.needsPlural(lngs[0], options.count)) { + pluralKey = ns + o.nsseparator + key; + } else { + pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(lngs[0], options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + } + + translated = translate(pluralKey, optionWithoutCount); + + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } else if (lngs.length > 1) { + // remove failed lng + var clone = lngs.slice(); + clone.shift(); + options = f.extend(options, { lngs: clone }); + options._origLng = optionWithoutCount._origLng; + delete options.lng; + // retry with fallbacks + translated = translate(ns + o.nsseparator + key, options); + if (translated != o.pluralNotFound) return translated; + } else { + optionWithoutCount.lng = optionWithoutCount._origLng; + delete optionWithoutCount._origLng; + translated = translate(ns + o.nsseparator + key, optionWithoutCount); + + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); + } + } + + if (needsIndefiniteArticle(options)) { + var optionsWithoutIndef = f.extend({}, options); + delete optionsWithoutIndef.indefinite_article; + optionsWithoutIndef.defaultValue = o.indefiniteNotFound; + // If we don't have a count, we want the indefinite, if we do have a count, and needsPlural is false + var indefiniteKey = ns + o.nsseparator + key + (((options.count && !needsPlural(options, lngs[0])) || !options.count) ? o.indefiniteSuffix : ""); + translated = translate(indefiniteKey, optionsWithoutIndef); + if (translated != o.indefiniteNotFound) { + return translated; + } + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + var valueType = Object.prototype.toString.apply(value); + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (valueType === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + if (o.objectTreeKeyHandler && typeof o.objectTreeKeyHandler == 'function') { + value = o.objectTreeKeyHandler(key, value, l, ns, options); + } else { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned an object instead of string.'; + f.log(value); + } + } else if (valueType !== '[object Number]' && valueType !== '[object Function]' && valueType !== '[object RegExp]') { + var copy = (valueType === '[object Array]') ? [] : {}; // apply child translation on a copy + f.each(value, function(m) { + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + }); + value = copy; + } + } + + if (typeof value === 'string' && value.trim() === '' && o.fallbackOnEmpty === true) + value = undefined; + + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length > 0))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found || (found==="" && o.fallbackOnEmpty === false)) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + options.isFallbackLookup = false; + } + + return found; + } + function detectLanguage() { + var detectedLng; + var whitelist = o.lngWhitelist || []; + var userLngChoices = []; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var params = query.split('&'); + for (var i=0; i 0) { + var key = params[i].substring(0,pos); + if (key == o.detectLngQS) { + userLngChoices.push(params[i].substring(pos+1)); + } + } + } + })(); + } + + // get from cookie + if (o.useCookie && typeof document !== 'undefined') { + var c = f.cookie.read(o.cookieName); + if (c) userLngChoices.push(c); + } + + // get from localStorage + if (o.detectLngFromLocalStorage && typeof window !== 'undefined' && window.localStorage) { + userLngChoices.push(f.localStorage.getItem('i18next_lng')); + } + + // get from navigator + if (typeof navigator !== 'undefined') { + if (navigator.languages) { // chrome only; not an array, so can't use .push.apply instead of iterating + for (var i=0;i -1) { + var parts = lng.split('-'); + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } + + if (whitelist.length === 0 || whitelist.indexOf(lng) > -1) { + detectedLng = lng; + break; + } + } + })(); + + //fallback + if (!detectedLng){ + detectedLng = o.fallbackLng[0]; + } + + return detectedLng; + } + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + + /* [code, name, numbers, pluralsType] */ + var _rules = [ + ["ach", "Acholi", [1,2], 1], + ["af", "Afrikaans",[1,2], 2], + ["ak", "Akan", [1,2], 1], + ["am", "Amharic", [1,2], 1], + ["an", "Aragonese",[1,2], 2], + ["ar", "Arabic", [0,1,2,3,11,100],5], + ["arn", "Mapudungun",[1,2], 1], + ["ast", "Asturian", [1,2], 2], + ["ay", "Aymará", [1], 3], + ["az", "Azerbaijani",[1,2],2], + ["be", "Belarusian",[1,2,5],4], + ["bg", "Bulgarian",[1,2], 2], + ["bn", "Bengali", [1,2], 2], + ["bo", "Tibetan", [1], 3], + ["br", "Breton", [1,2], 1], + ["bs", "Bosnian", [1,2,5],4], + ["ca", "Catalan", [1,2], 2], + ["cgg", "Chiga", [1], 3], + ["cs", "Czech", [1,2,5],6], + ["csb", "Kashubian",[1,2,5],7], + ["cy", "Welsh", [1,2,3,8],8], + ["da", "Danish", [1,2], 2], + ["de", "German", [1,2], 2], + ["dev", "Development Fallback", [1,2], 2], + ["dz", "Dzongkha", [1], 3], + ["el", "Greek", [1,2], 2], + ["en", "English", [1,2], 2], + ["eo", "Esperanto",[1,2], 2], + ["es", "Spanish", [1,2], 2], + ["es_ar","Argentinean Spanish", [1,2], 2], + ["et", "Estonian", [1,2], 2], + ["eu", "Basque", [1,2], 2], + ["fa", "Persian", [1], 3], + ["fi", "Finnish", [1,2], 2], + ["fil", "Filipino", [1,2], 1], + ["fo", "Faroese", [1,2], 2], + ["fr", "French", [1,2], 9], + ["fur", "Friulian", [1,2], 2], + ["fy", "Frisian", [1,2], 2], + ["ga", "Irish", [1,2,3,7,11],10], + ["gd", "Scottish Gaelic",[1,2,3,20],11], + ["gl", "Galician", [1,2], 2], + ["gu", "Gujarati", [1,2], 2], + ["gun", "Gun", [1,2], 1], + ["ha", "Hausa", [1,2], 2], + ["he", "Hebrew", [1,2], 2], + ["hi", "Hindi", [1,2], 2], + ["hr", "Croatian", [1,2,5],4], + ["hu", "Hungarian",[1,2], 2], + ["hy", "Armenian", [1,2], 2], + ["ia", "Interlingua",[1,2],2], + ["id", "Indonesian",[1], 3], + ["is", "Icelandic",[1,2], 12], + ["it", "Italian", [1,2], 2], + ["ja", "Japanese", [1], 3], + ["jbo", "Lojban", [1], 3], + ["jv", "Javanese", [0,1], 13], + ["ka", "Georgian", [1], 3], + ["kk", "Kazakh", [1], 3], + ["km", "Khmer", [1], 3], + ["kn", "Kannada", [1,2], 2], + ["ko", "Korean", [1], 3], + ["ku", "Kurdish", [1,2], 2], + ["kw", "Cornish", [1,2,3,4],14], + ["ky", "Kyrgyz", [1], 3], + ["lb", "Letzeburgesch",[1,2],2], + ["ln", "Lingala", [1,2], 1], + ["lo", "Lao", [1], 3], + ["lt", "Lithuanian",[1,2,10],15], + ["lv", "Latvian", [1,2,0],16], + ["mai", "Maithili", [1,2], 2], + ["mfe", "Mauritian Creole",[1,2],1], + ["mg", "Malagasy", [1,2], 1], + ["mi", "Maori", [1,2], 1], + ["mk", "Macedonian",[1,2],17], + ["ml", "Malayalam",[1,2], 2], + ["mn", "Mongolian",[1,2], 2], + ["mnk", "Mandinka", [0,1,2],18], + ["mr", "Marathi", [1,2], 2], + ["ms", "Malay", [1], 3], + ["mt", "Maltese", [1,2,11,20],19], + ["nah", "Nahuatl", [1,2], 2], + ["nap", "Neapolitan",[1,2], 2], + ["nb", "Norwegian Bokmal",[1,2],2], + ["ne", "Nepali", [1,2], 2], + ["nl", "Dutch", [1,2], 2], + ["nn", "Norwegian Nynorsk",[1,2],2], + ["no", "Norwegian",[1,2], 2], + ["nso", "Northern Sotho",[1,2],2], + ["oc", "Occitan", [1,2], 1], + ["or", "Oriya", [2,1], 2], + ["pa", "Punjabi", [1,2], 2], + ["pap", "Papiamento",[1,2], 2], + ["pl", "Polish", [1,2,5],7], + ["pms", "Piemontese",[1,2], 2], + ["ps", "Pashto", [1,2], 2], + ["pt", "Portuguese",[1,2], 2], + ["pt_br","Brazilian Portuguese",[1,2], 2], + ["rm", "Romansh", [1,2], 2], + ["ro", "Romanian", [1,2,20],20], + ["ru", "Russian", [1,2,5],4], + ["sah", "Yakut", [1], 3], + ["sco", "Scots", [1,2], 2], + ["se", "Northern Sami",[1,2], 2], + ["si", "Sinhala", [1,2], 2], + ["sk", "Slovak", [1,2,5],6], + ["sl", "Slovenian",[5,1,2,3],21], + ["so", "Somali", [1,2], 2], + ["son", "Songhay", [1,2], 2], + ["sq", "Albanian", [1,2], 2], + ["sr", "Serbian", [1,2,5],4], + ["su", "Sundanese",[1], 3], + ["sv", "Swedish", [1,2], 2], + ["sw", "Swahili", [1,2], 2], + ["ta", "Tamil", [1,2], 2], + ["te", "Telugu", [1,2], 2], + ["tg", "Tajik", [1,2], 1], + ["th", "Thai", [1], 3], + ["ti", "Tigrinya", [1,2], 1], + ["tk", "Turkmen", [1,2], 2], + ["tr", "Turkish", [1,2], 1], + ["tt", "Tatar", [1], 3], + ["ug", "Uyghur", [1], 3], + ["uk", "Ukrainian",[1,2,5],4], + ["ur", "Urdu", [1,2], 2], + ["uz", "Uzbek", [1,2], 1], + ["vi", "Vietnamese",[1], 3], + ["wa", "Walloon", [1,2], 1], + ["wo", "Wolof", [1], 3], + ["yo", "Yoruba", [1,2], 2], + ["zh", "Chinese", [1], 3] + ]; + + var _rulesPluralsTypes = { + 1: function(n) {return Number(n > 1);}, + 2: function(n) {return Number(n != 1);}, + 3: function(n) {return 0;}, + 4: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 5: function(n) {return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5);}, + 6: function(n) {return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2);}, + 7: function(n) {return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 8: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3);}, + 9: function(n) {return Number(n >= 2);}, + 10: function(n) {return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;}, + 11: function(n) {return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3);}, + 12: function(n) {return Number(n%10!=1 || n%100==11);}, + 13: function(n) {return Number(n !== 0);}, + 14: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3);}, + 15: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 16: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2);}, + 17: function(n) {return Number(n==1 || n%10==1 ? 0 : 1);}, + 18: function(n) {return Number(0 ? 0 : n==1 ? 1 : 2);}, + 19: function(n) {return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3);}, + 20: function(n) {return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2);}, + 21: function(n) {return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }; + + var pluralExtensions = { + + rules: (function () { + var l, rules = {}; + for (l=_rules.length; l-- ;) { + rules[_rules[l][0]] = { + name: _rules[l][1], + numbers: _rules[l][2], + plurals: _rulesPluralsTypes[_rules[l][3]] + } + } + return rules; + }()), + + // you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + needsPlural: function(lng, count) { + var parts = lng.split('-'); + + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[parts[f.getCountyIndexOfLng(lng)]]; + } + + if (ext && ext.numbers.length <= 1) { + return false; + } else { + return this.get(lng, count) !== 1; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i; + if (ext.noAbs) { + i = ext.plurals(c); + } else { + i = ext.plurals(Math.abs(c)); + } + + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[f.getCountyIndexOfLng(lng)], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.hasResourceBundle = hasResourceBundle; + i18n.getResourceBundle = getResourceBundle; + i18n.addResource = addResource; + i18n.addResources = addResources; + i18n.removeResourceBundle = removeResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.applyReplacement = f.applyReplacement; + i18n.options = o; + + $.i18n = i18n; + $.t = i18n.t; + + return i18n; + +})); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd.withJQuery-1.8.1.min.js b/libs/i18next/release/i18next.amd.withJQuery-1.8.1.min.js new file mode 100644 index 00000000..ebeaefd9 --- /dev/null +++ b/libs/i18next/release/i18next.amd.withJQuery-1.8.1.min.js @@ -0,0 +1,5 @@ +// i18next, v1.8.1 +// Copyright (c)2015 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +!function(a,b){if("object"==typeof exports){var c=require("jquery");module.exports=b(c)}else"function"==typeof define&&define.amd&&define(["jquery"],b)}(this,function(a){function b(a,b){if(!b||"function"==typeof b)return a;for(var c in b)a[c]=b[c];return a}function c(a,b){for(var d in b)d in a?c(a[d],b[d]):a[d]=b[d];return a}function d(a,b,c){var d,e=0,f=a.length,g=void 0===f||"[object Array]"!==Object.prototype.toString.apply(a)||"function"==typeof a;if(c)if(g){for(d in a)if(b.apply(a[d],c)===!1)break}else for(;f>e&&b.apply(a[e++],c)!==!1;);else if(g){for(d in a)if(b.call(a[d],d,a[d])===!1)break}else for(;f>e&&b.call(a[e],e,a[e++])!==!1;);return a}function e(a){return"string"==typeof a?a.replace(/[&<>"'\/]/g,function(a){return P[a]}):a}function f(a){var b=function(a){if(window.XMLHttpRequest)return a(null,new XMLHttpRequest);if(window.ActiveXObject)try{return a(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(b){return a(null,new ActiveXObject("Microsoft.XMLHTTP"))}return a(new Error)},c=function(a){if("string"==typeof a)return a;var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")},d=function(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;cd?b+=String.fromCharCode(d):d>127&&2048>d?(b+=String.fromCharCode(d>>6|192),b+=String.fromCharCode(63&d|128)):(b+=String.fromCharCode(d>>12|224),b+=String.fromCharCode(d>>6&63|128),b+=String.fromCharCode(63&d|128))}return b},e=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";a=d(a);var c,e,f,g,h,i,j,k="",l=0;do c=a.charCodeAt(l++),e=a.charCodeAt(l++),f=a.charCodeAt(l++),g=c>>2,h=(3&c)<<4|e>>4,i=(15&e)<<2|f>>6,j=63&f,isNaN(e)?i=j=64:isNaN(f)&&(j=64),k+=b.charAt(g)+b.charAt(h)+b.charAt(i)+b.charAt(j),c=e=f="",g=h=i=j="";while(l1&&(d+=d.indexOf("?")>-1?"&"+k:"?"+k),e.jsonp){var l=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=d,void l.appendChild(m)}}b(function(b,c){if(b)return h(b);c.open(a,d,e.async);for(var f in j)j.hasOwnProperty(f)&&c.setRequestHeader(f,j[f]);c.onreadystatechange=function(){if(4===c.readyState){var a=c.responseText||"";if(!h)return;h(c.status,{text:function(){return a},json:function(){try{return JSON.parse(a)}catch(b){return S.error("Can not parse JSON. URL: "+d),{}}}})}},c.send(i)})},h={authBasic:function(a,b){g.headers.Authorization="Basic "+e(a+":"+b)},connect:function(a,b,c){return g("CONNECT",a,b,c)},del:function(a,b,c){return g("DELETE",a,b,c)},get:function(a,b,c){return g("GET",a,b,c)},head:function(a,b,c){return g("HEAD",a,b,c)},headers:function(a){g.headers=a||{}},isAllowed:function(a,b,c){this.options(a,function(a,d){c(-1!==d.text().indexOf(b))})},options:function(a,b,c){return g("OPTIONS",a,b,c)},patch:function(a,b,c){return g("PATCH",a,b,c)},post:function(a,b,c){return g("POST",a,b,c)},put:function(a,b,c){return g("PUT",a,b,c)},trace:function(a,b,c){return g("TRACE",a,b,c)}},i=a.type?a.type.toLowerCase():"get";h[i](a.url,a,function(b,c){200===b||0===b&&c.text()?a.success(c.json(),b,null):a.error(c.text(),b,null)})}function g(b,c){"function"==typeof b&&(c=b,b={}),b=b||{},S.extend(O,b),delete O.fixLng,O.functions&&(delete O.functions,S.extend(S,b.functions)),"string"==typeof O.ns&&(O.ns={namespaces:[O.ns],defaultNs:O.ns}),"string"==typeof O.fallbackNS&&(O.fallbackNS=[O.fallbackNS]),("string"==typeof O.fallbackLng||"boolean"==typeof O.fallbackLng)&&(O.fallbackLng=[O.fallbackLng]),O.interpolationPrefixEscaped=S.regexEscape(O.interpolationPrefix),O.interpolationSuffixEscaped=S.regexEscape(O.interpolationSuffix),O.lng||(O.lng=S.detectLanguage()),L=S.toLanguages(O.lng),H=L[0],S.log("currentLng set to: "+H),O.useCookie&&S.cookie.read(O.cookieName)!==H&&S.cookie.create(O.cookieName,H,O.cookieExpirationTime,O.cookieDomain),O.detectLngFromLocalStorage&&"undefined"!=typeof document&&window.localStorage&&S.localStorage.setItem("i18next_lng",H);var d=B;b.fixLng&&(d=function(a,b){return b=b||{},b.lng=b.lng||d.lng,B(a,b)},d.lng=H),V.setCurrentLng(H),a&&O.setJqueryExt&&u();var e;if(a&&a.Deferred&&(e=a.Deferred()),!O.resStore){var f=S.toLanguages(O.lng);"string"==typeof O.preload&&(O.preload=[O.preload]);for(var g=0,h=O.preload.length;h>g;g++)for(var i=S.toLanguages(O.preload[g]),j=0,k=i.length;k>j;j++)f.indexOf(i[j])<0&&f.push(i[j]);return I.sync.load(f,O,function(a,b){J=b,M=!0,c&&c(d),e&&e.resolve(d)}),e?e.promise():void 0}return J=O.resStore,M=!0,c&&c(d),e&&e.resolve(d),e?e.promise():void 0}function h(a,b){"string"==typeof a&&(a=[a]);for(var c=0,d=a.length;d>c;c++)O.preload.indexOf(a[c])<0&&O.preload.push(a[c]);return g(b)}function i(a,b,c,d){"string"!=typeof b?(c=b,b=O.ns.defaultNs):O.ns.namespaces.indexOf(b)<0&&O.ns.namespaces.push(b),J[a]=J[a]||{},J[a][b]=J[a][b]||{},d?S.deepExtend(J[a][b],c):S.extend(J[a][b],c),O.useLocalStorage&&N._storeLocal(J)}function j(a,b){"string"!=typeof b&&(b=O.ns.defaultNs),J[a]=J[a]||{};var c=J[a][b]||{},d=!1;for(var e in c)c.hasOwnProperty(e)&&(d=!0);return d}function k(a,b){return"string"!=typeof b&&(b=O.ns.defaultNs),J[a]=J[a]||{},S.extend({},J[a][b])}function l(a,b){"string"!=typeof b&&(b=O.ns.defaultNs),J[a]=J[a]||{},J[a][b]={},O.useLocalStorage&&N._storeLocal(J)}function m(a,b,c,d){"string"!=typeof b?(resource=b,b=O.ns.defaultNs):O.ns.namespaces.indexOf(b)<0&&O.ns.namespaces.push(b),J[a]=J[a]||{},J[a][b]=J[a][b]||{};for(var e=c.split(O.keyseparator),f=0,g=J[a][b];e[f];)f==e.length-1?g[e[f]]=d:(null==g[e[f]]&&(g[e[f]]={}),g=g[e[f]]),f++;O.useLocalStorage&&N._storeLocal(J)}function n(a,b,c){"string"!=typeof b?(resource=b,b=O.ns.defaultNs):O.ns.namespaces.indexOf(b)<0&&O.ns.namespaces.push(b);for(var d in c)"string"==typeof c[d]&&m(a,b,d,c[d])}function o(a){O.ns.defaultNs=a}function p(a,b){q([a],b)}function q(a,b){var c={dynamicLoad:O.dynamicLoad,resGetPath:O.resGetPath,getAsync:O.getAsync,customLoad:O.customLoad,ns:{namespaces:a,defaultNs:""}},d=S.toLanguages(O.lng);"string"==typeof O.preload&&(O.preload=[O.preload]);for(var e=0,f=O.preload.length;f>e;e++)for(var g=S.toLanguages(O.preload[e]),h=0,i=g.length;i>h;h++)d.indexOf(g[h])<0&&d.push(g[h]);for(var j=[],k=0,l=d.length;l>k;k++){var m=!1,n=J[d[k]];if(n)for(var o=0,p=a.length;p>o;o++)n[a[o]]||(m=!0);else m=!0;m&&j.push(d[k])}j.length?I.sync._fetch(j,c,function(c,d){var e=a.length*j.length;S.each(a,function(a,c){O.ns.namespaces.indexOf(c)<0&&O.ns.namespaces.push(c),S.each(j,function(a,f){J[f]=J[f]||{},J[f][c]=d[f][c],e--,0===e&&b&&(O.useLocalStorage&&I.sync._storeLocal(J),b())})})}):b&&b()}function r(a,b,c){return"function"==typeof b?(c=b,b={}):b||(b={}),b.lng=a,g(b,c)}function s(){return H}function t(a){J={},r(H,a)}function u(){function b(b,c,d){if(0!==c.length){var e="text";if(0===c.indexOf("[")){var f=c.split("]");c=f[1],e=f[0].substr(1,f[0].length-1)}c.indexOf(";")===c.length-1&&(c=c.substr(0,c.length-2));var g;if("html"===e)g=O.defaultValueFromContent?a.extend({defaultValue:b.html()},d):d,b.html(a.t(c,g));else if("text"===e)g=O.defaultValueFromContent?a.extend({defaultValue:b.text()},d):d,b.text(a.t(c,g));else if("prepend"===e)g=O.defaultValueFromContent?a.extend({defaultValue:b.html()},d):d,b.prepend(a.t(c,g));else if("append"===e)g=O.defaultValueFromContent?a.extend({defaultValue:b.html()},d):d,b.append(a.t(c,g));else if(0===e.indexOf("data-")){var h=e.substr("data-".length);g=O.defaultValueFromContent?a.extend({defaultValue:b.data(h)},d):d;var i=a.t(c,g);b.data(h,i),b.attr(e,i)}else g=O.defaultValueFromContent?a.extend({defaultValue:b.attr(e)},d):d,b.attr(e,a.t(c,g))}}function c(c,d){var e=c.attr(O.selectorAttr);if(e||"undefined"==typeof e||e===!1||(e=c.text()||c.val()),e){var f=c,g=c.data("i18n-target");if(g&&(f=c.find(g)||c),d||O.useDataAttrOptions!==!0||(d=c.data("i18n-options")),d=d||{},e.indexOf(";")>=0){var h=e.split(";");a.each(h,function(a,c){""!==c&&b(f,c,d)})}else b(f,e,d);O.useDataAttrOptions===!0&&c.data("i18n-options",d)}}a.t=a.t||B,a.fn.i18n=function(b){return this.each(function(){c(a(this),b);var d=a(this).find("["+O.selectorAttr+"]");d.each(function(){c(a(this),b)})})}}function v(a,b,c,d){if(!a)return a;if(d=d||b,a.indexOf(d.interpolationPrefix||O.interpolationPrefix)<0)return a;var e=d.interpolationPrefix?S.regexEscape(d.interpolationPrefix):O.interpolationPrefixEscaped,f=d.interpolationSuffix?S.regexEscape(d.interpolationSuffix):O.interpolationSuffixEscaped,g="HTML"+f,h=b.replace&&"object"==typeof b.replace?b.replace:b;return S.each(h,function(b,h){var i=c?c+O.keyseparator+b:b;"object"==typeof h&&null!==h?a=v(a,h,i,d):d.escapeInterpolation||O.escapeInterpolation?(a=a.replace(new RegExp([e,i,g].join(""),"g"),S.regexReplacementEscape(h)),a=a.replace(new RegExp([e,i,f].join(""),"g"),S.regexReplacementEscape(S.escape(h)))):a=a.replace(new RegExp([e,i,f].join(""),"g"),S.regexReplacementEscape(h))}),a}function w(a,b){var c=",",d="{",e="}",f=S.extend({},b);for(delete f.postProcess;-1!=a.indexOf(O.reusePrefix)&&(K++,!(K>O.maxRecursion));){var g=a.lastIndexOf(O.reusePrefix),h=a.indexOf(O.reuseSuffix,g)+O.reuseSuffix.length,i=a.substring(g,h),j=i.replace(O.reusePrefix,"").replace(O.reuseSuffix,"");if(g>=h)return S.error("there is an missing closing in following translation value",a),"";if(-1!=j.indexOf(c)){var k=j.indexOf(c);if(-1!=j.indexOf(d,k)&&-1!=j.indexOf(e,k)){var l=j.indexOf(d,k),m=j.indexOf(e,l)+e.length;try{f=S.extend(f,JSON.parse(j.substring(l,m))),j=j.substring(0,k)}catch(n){}}}var o=E(j,f);a=a.replace(i,S.regexReplacementEscape(o))}return a}function x(a){return a.context&&("string"==typeof a.context||"number"==typeof a.context)}function y(a){return void 0!==a.count&&"string"!=typeof a.count}function z(a){return void 0!==a.indefinite_article&&"string"!=typeof a.indefinite_article&&a.indefinite_article}function A(a,b){b=b||{};var c=C(a,b),d=F(a,b);return void 0!==d||d===c}function B(a,b){return b=b||{},M?(K=0,E.apply(null,arguments)):(S.log("i18next not finished initialization. you might have called t function before loading resources finished."),b.defaultValue||"")}function C(a,b){return void 0!==b.defaultValue?b.defaultValue:a}function D(){for(var a=[],b=1;b1)for(var d=0;d-1&&(e=c.split(O.nsseparator),i=e[0],c=e[1]),void 0===g&&O.sendMissing&&"function"==typeof O.missingKeyHandler&&(b.lng?O.missingKeyHandler(h[0],i,c,f,h):O.missingKeyHandler(O.lng,i,c,f,h));var j;j="string"==typeof O.postProcess&&""!==O.postProcess?[O.postProcess]:"array"==typeof O.postProcess||"object"==typeof O.postProcess?O.postProcess:[],"string"==typeof b.postProcess&&""!==b.postProcess?j=j.concat([b.postProcess]):("array"==typeof b.postProcess||"object"==typeof b.postProcess)&&(j=j.concat(b.postProcess)),void 0!==g&&j.length&&j.forEach(function(a){W[a]&&(g=W[a](g,c,b))});var k=f;if(f.indexOf(O.nsseparator)>-1&&(e=f.split(O.nsseparator),k=e[1]),k===c&&O.parseMissingKey&&(f=O.parseMissingKey(f)),void 0===g&&(f=v(f,b),f=w(f,b),j.length)){var l=C(c,b);j.forEach(function(a){W[a]&&(g=W[a](l,c,b))})}return void 0!==g?g:f}function F(a,b){b=b||{};var c,d,e=C(a,b),f=L;if(!J)return e;if("cimode"===f[0].toLowerCase())return e;if(b.lngs&&(f=b.lngs),b.lng&&(f=S.toLanguages(b.lng,b.fallbackLng),!J[f[0]])){var g=O.getAsync;O.getAsync=!1,I.sync.load(f,O,function(a,b){S.extend(J,b),O.getAsync=g})}var h=b.ns||O.ns.defaultNs;if(a.indexOf(O.nsseparator)>-1){var i=a.split(O.nsseparator);h=i[0],a=i[1]}if(x(b)){c=S.extend({},b),delete c.context,c.defaultValue=O.contextNotFound;var j=h+O.nsseparator+a+"_"+b.context;if(d=B(j,c),d!=O.contextNotFound)return v(d,{context:b.context})}if(y(b,f[0])){c=S.extend({lngs:[f[0]]},b),delete c.count,c._origLng=c._origLng||c.lng||f[0],delete c.lng,c.defaultValue=O.pluralNotFound;var k;if(V.needsPlural(f[0],b.count)){k=h+O.nsseparator+a+O.pluralSuffix;var l=V.get(f[0],b.count);l>=0?k=k+"_"+l:1===l&&(k=h+O.nsseparator+a)}else k=h+O.nsseparator+a;if(d=B(k,c),d!=O.pluralNotFound)return v(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix});if(!(f.length>1))return c.lng=c._origLng,delete c._origLng,d=B(h+O.nsseparator+a,c),v(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix});var m=f.slice();if(m.shift(),b=S.extend(b,{lngs:m}),b._origLng=c._origLng,delete b.lng,d=B(h+O.nsseparator+a,b),d!=O.pluralNotFound)return d}if(z(b)){var n=S.extend({},b);delete n.indefinite_article,n.defaultValue=O.indefiniteNotFound;var o=h+O.nsseparator+a+(b.count&&!y(b,f[0])||!b.count?O.indefiniteSuffix:"");if(d=B(o,n),d!=O.indefiniteNotFound)return d}for(var p,q=a.split(O.keyseparator),r=0,s=f.length;s>r&&void 0===p;r++){for(var t=f[r],u=0,A=J[t]&&J[t][h];q[u];)A=A&&A[q[u]],u++;if(void 0!==A){var D=Object.prototype.toString.apply(A);if("string"==typeof A)A=v(A,b),A=w(A,b);else if("[object Array]"!==D||O.returnObjectTrees||b.returnObjectTrees){if(null===A&&O.fallbackOnNull===!0)A=void 0;else if(null!==A)if(O.returnObjectTrees||b.returnObjectTrees){if("[object Number]"!==D&&"[object Function]"!==D&&"[object RegExp]"!==D){var G="[object Array]"===D?[]:{};S.each(A,function(c){G[c]=E(h+O.nsseparator+a+O.keyseparator+c,b)}),A=G}}else O.objectTreeKeyHandler&&"function"==typeof O.objectTreeKeyHandler?A=O.objectTreeKeyHandler(a,A,t,h,b):(A="key '"+h+":"+a+" ("+t+")' returned an object instead of string.",S.log(A))}else A=A.join("\n"),A=v(A,b),A=w(A,b);"string"==typeof A&&""===A.trim()&&O.fallbackOnEmpty===!0&&(A=void 0),p=A}}if(void 0===p&&!b.isFallbackLookup&&(O.fallbackToDefaultNS===!0||O.fallbackNS&&O.fallbackNS.length>0)){if(b.isFallbackLookup=!0,O.fallbackNS.length){for(var H=0,K=O.fallbackNS.length;K>H;H++)if(p=F(O.fallbackNS[H]+O.nsseparator+a,b),p||""===p&&O.fallbackOnEmpty===!1){var M=p.indexOf(O.nsseparator)>-1?p.split(O.nsseparator)[1]:p,N=e.indexOf(O.nsseparator)>-1?e.split(O.nsseparator)[1]:e;if(M!==N)break}}else p=F(a,b);b.isFallbackLookup=!1}return p}function G(){var a,b=O.lngWhitelist||[],c=[];if("undefined"!=typeof window&&!function(){for(var a=window.location.search.substring(1),b=a.split("&"),d=0;d0){var f=b[d].substring(0,e);f==O.detectLngQS&&c.push(b[d].substring(e+1))}}}(),O.useCookie&&"undefined"!=typeof document){var d=S.cookie.read(O.cookieName);d&&c.push(d)}if(O.detectLngFromLocalStorage&&"undefined"!=typeof window&&window.localStorage&&c.push(S.localStorage.getItem("i18next_lng")),"undefined"!=typeof navigator){if(navigator.languages)for(var e=0;e-1){var f=e.split("-");e=O.lowerCaseLng?f[0].toLowerCase()+"-"+f[1].toLowerCase():f[0].toLowerCase()+"-"+f[1].toUpperCase()}if(0===b.length||b.indexOf(e)>-1){a=e;break}}}(),a||(a=O.fallbackLng[0]),a}Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>0&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=c;arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d))));for(var e=d>=0?Math.min(d,c-1):c-Math.abs(d);e>=0;e--)if(e in b&&b[e]===a)return e;return-1}),"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")});var H,I={},J={},K=0,L=[],M=!1,N={};N={load:function(a,b,c){b.useLocalStorage?N._loadLocal(a,b,function(d,e){for(var f=[],g=0,h=a.length;h>g;g++)e[a[g]]||f.push(a[g]);f.length>0?N._fetch(f,b,function(a,b){S.extend(e,b),N._storeLocal(b),c(null,e)}):c(null,e)}):N._fetch(a,b,function(a,b){c(null,b)})},_loadLocal:function(a,b,c){var d={},e=(new Date).getTime();if(window.localStorage){var f=a.length;S.each(a,function(a,g){var h=S.localStorage.getItem("res_"+g);h&&(h=JSON.parse(h),h.i18nStamp&&h.i18nStamp+b.localStorageExpirationTime>e&&(d[g]=h)),f--,0===f&&c(null,d)})}},_storeLocal:function(a){if(window.localStorage)for(var b in a)a[b].i18nStamp=(new Date).getTime(),S.localStorage.setItem("res_"+b,JSON.stringify(a[b]))},_fetch:function(a,b,c){var d=b.ns,e={};if(b.dynamicLoad){var f=function(a,b){c(null,b)};if("function"==typeof b.customLoad)b.customLoad(a,d.namespaces,b,f);else{var g=v(b.resGetPath,{lng:a.join("+"),ns:d.namespaces.join("+")});S.ajax({url:g,success:function(a){S.log("loaded: "+g),f(null,a)},error:function(a,b,c){S.log("failed loading: "+g),f("failed loading resource.json error: "+c)},dataType:"json",async:b.getAsync})}}else{var h,i=d.namespaces.length*a.length;S.each(d.namespaces,function(d,f){S.each(a,function(a,d){var g=function(a,b){a&&(h=h||[],h.push(a)),e[d]=e[d]||{},e[d][f]=b,i--,0===i&&c(h,e)};"function"==typeof b.customLoad?b.customLoad(d,f,b,g):N._fetchOne(d,f,b,g)})})}},_fetchOne:function(a,b,c,d){var e=v(c.resGetPath,{lng:a,ns:b});S.ajax({url:e,success:function(a){S.log("loaded: "+e),d(null,a)},error:function(a,b,c){if(b&&200==b||a&&a.status&&200==a.status)S.error("There is a typo in: "+e);else if(b&&404==b||a&&a.status&&404==a.status)S.log("Does not exist: "+e);else{var f=b?b:a&&a.status?a.status:null;S.log(f+" when loading "+e)}d(c,{})},dataType:"json",async:c.getAsync})},postMissing:function(a,b,c,d,e){var f={};f[c]=d;var g=[];if("fallback"===O.sendMissingTo&&O.fallbackLng[0]!==!1)for(var h=0;hh;h++)g.push({lng:e[h],url:v(O.resPostPath,{lng:e[h],ns:b})});for(var j=0,k=g.length;k>j;j++){var l=g[j];S.ajax({url:l.url,type:O.sendType,data:f,success:function(){S.log("posted missing key '"+c+"' to: "+l.url);for(var a=c.split("."),e=0,f=J[l.lng][b];a[e];)f=f[a[e]]=e===a.length-1?d:f[a[e]]||{},e++},error:function(){S.log("failed posting missing key '"+c+"' to: "+l.url)},dataType:"json",async:O.postAsync})}},reload:t};var O={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:["dev"],fallbackNS:[],detectLngQS:"setLng",detectLngFromLocalStorage:!1,ns:"translation",fallbackOnNull:!0,fallbackOnEmpty:!1,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",defaultVariables:!1,reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,indefiniteSuffix:"_indefinite",indefiniteNotFound:["indefinite_not_found",Math.random()].join(""),setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",cookieDomain:void 0,objectTreeKeyHandler:void 0,postProcess:void 0,parseMissingKey:void 0,missingKeyHandler:N.postMissing,shortcutFunction:"sprintf"},P={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},Q={create:function(a,b,c,d){var e;if(c){var f=new Date;f.setTime(f.getTime()+60*c*1e3),e="; expires="+f.toGMTString()}else e="";d=d?"domain="+d+";":"",document.cookie=a+"="+b+e+";"+d+"path=/"},read:function(a){for(var b=a+"=",c=document.cookie.split(";"),d=0;d-1){var c=a.split("-");b=O.lowerCaseLng?c[0].toLowerCase()+"-"+c[1].toLowerCase():c[0].toLowerCase()+"-"+c[1].toUpperCase()}else b=O.lowerCaseLng?a.toLowerCase():a;return b}var c=this.log,d=[],e=O.lngWhitelist||!1,f=function(a){!e||e.indexOf(a)>-1?d.push(a):c("rejecting non-whitelisted language: "+a)};if("string"==typeof a&&a.indexOf("-")>-1){var g=a.split("-");"unspecific"!==O.load&&f(b(a)),"current"!==O.load&&f(b(g[this.getCountyIndexOfLng(a)]))}else f(b(a));for(var h=0;h1)},2:function(a){return Number(1!=a)},3:function(){return 0},4:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},5:function(a){return Number(0===a?0:1==a?1:2==a?2:a%100>=3&&10>=a%100?3:a%100>=11?4:5)},6:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)},7:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},8:function(a){return Number(1==a?0:2==a?1:8!=a&&11!=a?2:3)},9:function(a){return Number(a>=2)},10:function(a){return Number(1==a?0:2==a?1:7>a?2:11>a?3:4)},11:function(a){return Number(1==a||11==a?0:2==a||12==a?1:a>2&&20>a?2:3)},12:function(a){return Number(a%10!=1||a%100==11)},13:function(a){return Number(0!==a)},14:function(a){return Number(1==a?0:2==a?1:3==a?2:3)},15:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&(10>a%100||a%100>=20)?1:2)},16:function(a){return Number(a%10==1&&a%100!=11?0:0!==a?1:2)},17:function(a){return Number(1==a||a%10==1?0:1)},18:function(a){return Number(1==a?1:2)},19:function(a){return Number(1==a?0:0===a||a%100>1&&11>a%100?1:a%100>10&&20>a%100?2:3)},20:function(a){return Number(1==a?0:0===a||a%100>0&&20>a%100?1:2)},21:function(a){return Number(a%100==1?1:a%100==2?2:a%100==3||a%100==4?3:0)}},V={rules:function(){var a,b={};for(a=T.length;a--;)b[T[a][0]]={name:T[a][1],numbers:T[a][2],plurals:U[T[a][3]]};return b}(),addRule:function(a,b){V.rules[a]=b},setCurrentLng:function(a){if(!V.currentRule||V.currentRule.lng!==a){var b=a.split("-");V.currentRule={lng:a,rule:V.rules[b[0]]}}},needsPlural:function(a,b){var c,d=a.split("-");return c=V.currentRule&&V.currentRule.lng===a?V.currentRule.rule:V.rules[d[S.getCountyIndexOfLng(a)]],c&&c.numbers.length<=1?!1:1!==this.get(a,b)},get:function(a,b){function c(b,c){var d;if(d=V.currentRule&&V.currentRule.lng===a?V.currentRule.rule:V.rules[b]){var e;e=d.plurals(d.noAbs?c:Math.abs(c));var f=d.numbers[e];return 2===d.numbers.length&&1===d.numbers[0]&&(2===f?f=-1:1===f&&(f=1)),f}return 1===c?"1":"-1"}var d=a.split("-");return c(d[S.getCountyIndexOfLng(a)],b)}},W={},X=function(a,b){W[a]=b},Y=function(){function a(a){return Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}function b(a,b){for(var c=[];b>0;c[--b]=a);return c.join("")}var c=function(){return c.cache.hasOwnProperty(arguments[0])||(c.cache[arguments[0]]=c.parse(arguments[0])),c.format.call(null,c.cache[arguments[0]],arguments)};return c.format=function(c,d){var e,f,g,h,i,j,k,l=1,m=c.length,n="",o=[];for(f=0;m>f;f++)if(n=a(c[f]),"string"===n)o.push(c[f]);else if("array"===n){if(h=c[f],h[2])for(e=d[l],g=0;g=0?"+"+e:e,j=h[4]?"0"==h[4]?"0":h[4].charAt(1):" ",k=h[6]-String(e).length,i=h[6]?b(j,k):"",o.push(h[5]?e+i:i+e)}return o.join("")},c.cache={},c.parse=function(a){for(var b=a,c=[],d=[],e=0;b;){if(null!==(c=/^[^\x25]+/.exec(b)))d.push(c[0]);else if(null!==(c=/^\x25{2}/.exec(b)))d.push("%");else{if(null===(c=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(b)))throw"[sprintf] huh?";if(c[2]){e|=1;var f=[],g=c[2],h=[];if(null===(h=/^([a-z_][a-z_\d]*)/i.exec(g)))throw"[sprintf] huh?";for(f.push(h[1]);""!==(g=g.substring(h[0].length));)if(null!==(h=/^\.([a-z_][a-z_\d]*)/i.exec(g)))f.push(h[1]);else{if(null===(h=/^\[(\d+)\]/.exec(g)))throw"[sprintf] huh?";f.push(h[1])}c[2]=f}else e|=2;if(3===e)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";d.push(c)}b=b.substring(c[0].length)}return d},c}(),Z=function(a,b){return b.unshift(a),Y.apply(null,b)};return X("sprintf",function(a,b,c){return c.sprintf?"[object Array]"===Object.prototype.toString.apply(c.sprintf)?Z(a,c.sprintf):"object"==typeof c.sprintf?Y(a,c.sprintf):a:a}),I.init=g,I.setLng=r,I.preload=h,I.addResourceBundle=i,I.hasResourceBundle=j,I.getResourceBundle=k,I.addResource=m,I.addResources=n,I.removeResourceBundle=l,I.loadNamespace=p,I.loadNamespaces=q,I.setDefaultNamespace=o,I.t=B,I.translate=B,I.exists=A,I.detectLanguage=S.detectLanguage,I.pluralExtensions=V,I.sync=N,I.functions=S,I.lng=s,I.addPostProcessor=X,I.applyReplacement=S.applyReplacement,I.options=O,a.i18n=I,a.t=I.t,I}); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd.withJQuery-1.8.2.js b/libs/i18next/release/i18next.amd.withJQuery-1.8.2.js new file mode 100644 index 00000000..46e8f4f2 --- /dev/null +++ b/libs/i18next/release/i18next.amd.withJQuery-1.8.2.js @@ -0,0 +1,2180 @@ +// i18next, v1.8.2 +// Copyright (c)2015 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function (root, factory) { + if (typeof exports === 'object') { + + var jquery = require('jquery'); + + module.exports = factory(jquery); + + } else if (typeof define === 'function' && define.amd) { + + define(['jquery'], factory); + + } +}(this, function ($) { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + // Add string trim for IE8. + if (typeof String.prototype.trim !== 'function') { + String.prototype.trim = function() { + return this.replace(/^\s+|\s+$/g, ''); + } + } + + var i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = [] + , initialized = false + , sync = {}; + + sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = f.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + f.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + if ((status && status == 200) || (xhr && xhr.status && xhr.status == 200)) { + // file loaded but invalid json, stop waste time ! + f.error('There is a typo in: ' + url); + } else if ((status && status == 404) || (xhr && xhr.status && xhr.status == 404)) { + f.log('Does not exist: ' + url); + } else { + var theStatus = status ? status : ((xhr && xhr.status) ? xhr.status : null); + f.log(theStatus + ' when loading ' + url); + } + + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback' && o.fallbackLng[0] !== false) { + for (var i = 0; i < o.fallbackLng.length; i++) { + urls.push({lng: o.fallbackLng[i], url: applyReplacement(o.resPostPath, { lng: o.fallbackLng[i], ns: ns })}); + } + } else if (o.sendMissingTo === 'current' || (o.sendMissingTo === 'fallback' && o.fallbackLng[0] === false) ) { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + }, + + reload: reload + }; + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: ['dev'], + fallbackNS: [], + detectLngQS: 'setLng', + detectLngFromLocalStorage: false, + ns: { + namespaces: ['translation'], + defaultNs: 'translation' + }, + fallbackOnNull: true, + fallbackOnEmpty: false, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + defaultVariables: false, + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + indefiniteSuffix: '_indefinite', + indefiniteNotFound: ['indefinite_not_found', Math.random()].join(''), + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + cookieDomain: undefined, + + objectTreeKeyHandler: undefined, + postProcess: undefined, + parseMissingKey: undefined, + missingKeyHandler: sync.postMissing, + + shortcutFunction: 'sprintf' // or: defaultValue + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _deepExtend(target, source) { + for (var prop in source) + if (prop in target) + _deepExtend(target[prop], source[prop]); + else + target[prop] = source[prop]; + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || Object.prototype.toString.apply(object) !== '[object Array]' || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + try { + return JSON.parse(data) + } catch (e) { + f.error('Can not parse JSON. URL: ' + url); + return {}; + } + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + // file: protocol always gives status code 0, so check for data + if (status === 200 || (status === 0 && data.text())) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes,domain) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + domain = (domain)? "domain="+domain+";" : ""; + document.cookie = name+"="+value+expires+";"+domain+"path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes,domain) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + deepExtend: _deepExtend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : (typeof document !== 'undefined' ? _ajax : function() {}), + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + error: function(str) { + if (typeof console !== "undefined") console.error(str); + }, + getCountyIndexOfLng: function(lng) { + var lng_index = 0; + if (lng === 'nb-NO' || lng === 'nn-NO' || lng === 'nb-no' || lng === 'nn-no') lng_index = 1; + return lng_index; + }, + toLanguages: function(lng) { + var log = this.log; + + function applyCase(l) { + var ret = l; + + if (typeof l === 'string' && l.indexOf('-') > -1) { + var parts = l.split('-'); + + ret = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } else { + ret = o.lowerCaseLng ? l.toLowerCase() : l; + } + + return ret; + } + + var languages = []; + var whitelist = o.lngWhitelist || false; + var addLanguage = function(language){ + //reject langs not whitelisted + if(!whitelist || whitelist.indexOf(language) > -1){ + languages.push(language); + }else{ + log('rejecting non-whitelisted language: ' + language); + } + }; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + if (o.load !== 'unspecific') addLanguage(applyCase(lng)); + if (o.load !== 'current') addLanguage(applyCase(parts[this.getCountyIndexOfLng(lng)])); + } else { + addLanguage(applyCase(lng)); + } + + for (var i = 0; i < o.fallbackLng.length; i++) { + if (languages.indexOf(o.fallbackLng[i]) === -1 && o.fallbackLng[i]) languages.push(applyCase(o.fallbackLng[i])); + } + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + }, + regexReplacementEscape: function(strOrFn) { + if (typeof strOrFn === 'string') { + return strOrFn.replace(/\$/g, "$$$$"); + } else { + return strOrFn; + } + }, + localStorage: { + setItem: function(key, value) { + if (window.localStorage) { + try { + window.localStorage.setItem(key, value); + } catch (e) { + f.log('failed to set value for key "' + key + '" to localStorage.'); + } + } + }, + getItem: function(key, value) { + if (window.localStorage) { + try { + return window.localStorage.getItem(key, value); + } catch (e) { + f.log('failed to get value for key "' + key + '" from localStorage.'); + return undefined; + } + } + } + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + delete o.fixLng; /* passed in each time */ + + // override functions: .log(), .detectLanguage(), etc + if (o.functions) { + delete o.functions; + f.extend(f, options.functions); + } + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // fallback languages + if (typeof o.fallbackLng == 'string' || typeof o.fallbackLng == 'boolean') { + o.fallbackLng = [o.fallbackLng]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + if (o.useCookie && f.cookie.read(o.cookieName) !== currentLng){ //cookie is unset or invalid + f.cookie.create(o.cookieName, currentLng, o.cookieExpirationTime, o.cookieDomain); + } + if (o.detectLngFromLocalStorage && typeof document !== 'undefined' && window.localStorage) { + f.localStorage.setItem('i18next_lng', currentLng); + } + + var lngTranslate = translate; + if (options.fixLng) { + lngTranslate = function(key, options) { + options = options || {}; + options.lng = options.lng || lngTranslate.lng; + return translate(key, options); + }; + lngTranslate.lng = currentLng; + } + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + initialized = true; + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + initialized = true; + + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources, deep) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + if (deep) { + f.deepExtend(resStore[lng][ns], resources); + } else { + f.extend(resStore[lng][ns], resources); + } + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function hasResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + var res = resStore[lng][ns] || {}; + + var hasValues = false; + for(var prop in res) { + if (res.hasOwnProperty(prop)) { + hasValues = true; + } + } + + return hasValues; + } + + function getResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + return f.extend({}, resStore[lng][ns]); + } + + function removeResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = {}; + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function addResource(lng, ns, key, value) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + var keys = key.split(o.keyseparator); + var x = 0; + var node = resStore[lng][ns]; + var origRef = node; + + while (keys[x]) { + if (x == keys.length - 1) + node[keys[x]] = value; + else { + if (node[keys[x]] == null) + node[keys[x]] = {}; + + node = node[keys[x]]; + } + x++; + } + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function addResources(lng, ns, resources) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + for (var m in resources) { + if (typeof resources[m] === 'string') addResource(lng, ns, m, resources[m]); + } + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, options, cb) { + if (typeof options === 'function') { + cb = options; + options = {}; + } else if (!options) { + options = {}; + } + + options.lng = lng; + return init(options, cb); + } + + function lng() { + return currentLng; + } + + function reload(cb) { + resStore = {}; + setLng(currentLng, cb); + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else if (attr === 'prepend') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.prepend($.t(key, optionsToUse)); + } else if (attr === 'append') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.append($.t(key, optionsToUse)); + } else if (attr.indexOf("data-") === 0) { + var dataAttr = attr.substr(("data-").length); + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.data(dataAttr) }, options) : options; + var translated = $.t(key, optionsToUse); + //we change into the data cache + ele.data(dataAttr, translated); + //we change into the dom + ele.attr(attr, translated); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key && typeof key !== 'undefined' && key !== false) key = ele.text() || ele.val(); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + var hash = replacementHash.replace && typeof replacementHash.replace === 'object' ? replacementHash.replace : replacementHash; + f.each(hash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), f.regexReplacementEscape(value)); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(f.escape(value))); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(value)); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + if (index_of_end_of_closing <= index_of_opening) { + f.error('there is an missing closing in following translation value', translated); + return ''; + } + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, f.regexReplacementEscape(translated_token)); + } + return translated; + } + + function hasContext(options) { + return (options.context && (typeof options.context == 'string' || typeof options.context == 'number')); + } + + function needsPlural(options, lng) { + return (options.count !== undefined && typeof options.count != 'string'/* && pluralExtensions.needsPlural(lng, options.count)*/); + } + + function needsIndefiniteArticle(options) { + return (options.indefinite_article !== undefined && typeof options.indefinite_article != 'string' && options.indefinite_article); + } + + function exists(key, options) { + options = options || {}; + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + options = options || {}; + + if (!initialized) { + f.log('i18next not finished initialization. you might have called t function before loading resources finished.') + return options.defaultValue || ''; + }; + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _getDefaultValue(key, options) { + return (options.defaultValue !== undefined) ? options.defaultValue : key; + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(potentialKeys, options) { + if (options && typeof options !== 'object') { + if (o.shortcutFunction === 'sprintf') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else if (o.shortcutFunction === 'defaultValue') { + options = { + defaultValue: options + } + } + } else { + options = options || {}; + } + + if (typeof o.defaultVariables === 'object') { + options = f.extend({}, o.defaultVariables, options); + } + + if (potentialKeys === undefined || potentialKeys === null || potentialKeys === '') return ''; + + if (typeof potentialKeys === 'number') { + potentialKeys = String(potentialKeys); + } + + if (typeof potentialKeys === 'string') { + potentialKeys = [potentialKeys]; + } + + var key = potentialKeys[0]; + + if (potentialKeys.length > 1) { + for (var i = 0; i < potentialKeys.length; i++) { + key = potentialKeys[i]; + if (exists(key, options)) { + break; + } + } + } + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng, options.fallbackLng) : languages + , ns = options.ns || o.ns.defaultNs + , parts; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing && typeof o.missingKeyHandler === 'function') { + if (options.lng) { + o.missingKeyHandler(lngs[0], ns, key, notFound, lngs); + } else { + o.missingKeyHandler(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessorsToApply; + if (typeof o.postProcess === 'string' && o.postProcess !== '') { + postProcessorsToApply = [o.postProcess]; + } else if (typeof o.postProcess === 'array' || typeof o.postProcess === 'object') { + postProcessorsToApply = o.postProcess; + } else { + postProcessorsToApply = []; + } + + if (typeof options.postProcess === 'string' && options.postProcess !== '') { + postProcessorsToApply = postProcessorsToApply.concat([options.postProcess]); + } else if (typeof options.postProcess === 'array' || typeof options.postProcess === 'object') { + postProcessorsToApply = postProcessorsToApply.concat(options.postProcess); + } + + if (found !== undefined && postProcessorsToApply.length) { + postProcessorsToApply.forEach(function(postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + }); + } + + // process notFound if function exists + var splitNotFound = notFound; + if (notFound.indexOf(o.nsseparator) > -1) { + parts = notFound.split(o.nsseparator); + splitNotFound = parts[1]; + } + if (splitNotFound === key && o.parseMissingKey) { + notFound = o.parseMissingKey(notFound); + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessorsToApply.length) { + var val = _getDefaultValue(key, options); + postProcessorsToApply.forEach(function(postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](val, key, options); + } + }); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options) { + options = options || {}; + + var optionWithoutCount, translated + , notFound = _getDefaultValue(key, options) + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + // CI mode + if (lngs[0].toLowerCase() === 'cimode') return notFound; + + // passed in lng + if (options.lngs) lngs = options.lngs; + if (options.lng) { + lngs = f.toLanguages(options.lng, options.fallbackLng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options, lngs[0])) { + optionWithoutCount = f.extend({ lngs: [lngs[0]]}, options); + delete optionWithoutCount.count; + optionWithoutCount._origLng = optionWithoutCount._origLng || optionWithoutCount.lng || lngs[0]; + delete optionWithoutCount.lng; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey; + if (!pluralExtensions.needsPlural(lngs[0], options.count)) { + pluralKey = ns + o.nsseparator + key; + } else { + pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(lngs[0], options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + } + + translated = translate(pluralKey, optionWithoutCount); + + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } else if (lngs.length > 1) { + // remove failed lng + var clone = lngs.slice(); + clone.shift(); + options = f.extend(options, { lngs: clone }); + options._origLng = optionWithoutCount._origLng; + delete options.lng; + // retry with fallbacks + translated = translate(ns + o.nsseparator + key, options); + if (translated != o.pluralNotFound) return translated; + } else { + optionWithoutCount.lng = optionWithoutCount._origLng; + delete optionWithoutCount._origLng; + translated = translate(ns + o.nsseparator + key, optionWithoutCount); + + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); + } + } + + if (needsIndefiniteArticle(options)) { + var optionsWithoutIndef = f.extend({}, options); + delete optionsWithoutIndef.indefinite_article; + optionsWithoutIndef.defaultValue = o.indefiniteNotFound; + // If we don't have a count, we want the indefinite, if we do have a count, and needsPlural is false + var indefiniteKey = ns + o.nsseparator + key + (((options.count && !needsPlural(options, lngs[0])) || !options.count) ? o.indefiniteSuffix : ""); + translated = translate(indefiniteKey, optionsWithoutIndef); + if (translated != o.indefiniteNotFound) { + return translated; + } + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + var valueType = Object.prototype.toString.apply(value); + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (valueType === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + if (o.objectTreeKeyHandler && typeof o.objectTreeKeyHandler == 'function') { + value = o.objectTreeKeyHandler(key, value, l, ns, options); + } else { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned an object instead of string.'; + f.log(value); + } + } else if (valueType !== '[object Number]' && valueType !== '[object Function]' && valueType !== '[object RegExp]') { + var copy = (valueType === '[object Array]') ? [] : {}; // apply child translation on a copy + f.each(value, function(m) { + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + }); + value = copy; + } + } + + if (typeof value === 'string' && value.trim() === '' && o.fallbackOnEmpty === true) + value = undefined; + + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length > 0))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found || (found==="" && o.fallbackOnEmpty === false)) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + options.isFallbackLookup = false; + } + + return found; + } + function detectLanguage() { + var detectedLng; + var whitelist = o.lngWhitelist || []; + var userLngChoices = []; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var params = query.split('&'); + for (var i=0; i 0) { + var key = params[i].substring(0,pos); + if (key == o.detectLngQS) { + userLngChoices.push(params[i].substring(pos+1)); + } + } + } + })(); + } + + // get from cookie + if (o.useCookie && typeof document !== 'undefined') { + var c = f.cookie.read(o.cookieName); + if (c) userLngChoices.push(c); + } + + // get from localStorage + if (o.detectLngFromLocalStorage && typeof window !== 'undefined' && window.localStorage) { + userLngChoices.push(f.localStorage.getItem('i18next_lng')); + } + + // get from navigator + if (typeof navigator !== 'undefined') { + if (navigator.languages) { // chrome only; not an array, so can't use .push.apply instead of iterating + for (var i=0;i -1) { + var parts = lng.split('-'); + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } + + if (whitelist.length === 0 || whitelist.indexOf(lng) > -1) { + detectedLng = lng; + break; + } + } + })(); + + //fallback + if (!detectedLng){ + detectedLng = o.fallbackLng[0]; + } + + return detectedLng; + } + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + + /* [code, name, numbers, pluralsType] */ + var _rules = [ + ["ach", "Acholi", [1,2], 1], + ["af", "Afrikaans",[1,2], 2], + ["ak", "Akan", [1,2], 1], + ["am", "Amharic", [1,2], 1], + ["an", "Aragonese",[1,2], 2], + ["ar", "Arabic", [0,1,2,3,11,100],5], + ["arn", "Mapudungun",[1,2], 1], + ["ast", "Asturian", [1,2], 2], + ["ay", "Aymará", [1], 3], + ["az", "Azerbaijani",[1,2],2], + ["be", "Belarusian",[1,2,5],4], + ["bg", "Bulgarian",[1,2], 2], + ["bn", "Bengali", [1,2], 2], + ["bo", "Tibetan", [1], 3], + ["br", "Breton", [1,2], 1], + ["bs", "Bosnian", [1,2,5],4], + ["ca", "Catalan", [1,2], 2], + ["cgg", "Chiga", [1], 3], + ["cs", "Czech", [1,2,5],6], + ["csb", "Kashubian",[1,2,5],7], + ["cy", "Welsh", [1,2,3,8],8], + ["da", "Danish", [1,2], 2], + ["de", "German", [1,2], 2], + ["dev", "Development Fallback", [1,2], 2], + ["dz", "Dzongkha", [1], 3], + ["el", "Greek", [1,2], 2], + ["en", "English", [1,2], 2], + ["eo", "Esperanto",[1,2], 2], + ["es", "Spanish", [1,2], 2], + ["es_ar","Argentinean Spanish", [1,2], 2], + ["et", "Estonian", [1,2], 2], + ["eu", "Basque", [1,2], 2], + ["fa", "Persian", [1], 3], + ["fi", "Finnish", [1,2], 2], + ["fil", "Filipino", [1,2], 1], + ["fo", "Faroese", [1,2], 2], + ["fr", "French", [1,2], 9], + ["fur", "Friulian", [1,2], 2], + ["fy", "Frisian", [1,2], 2], + ["ga", "Irish", [1,2,3,7,11],10], + ["gd", "Scottish Gaelic",[1,2,3,20],11], + ["gl", "Galician", [1,2], 2], + ["gu", "Gujarati", [1,2], 2], + ["gun", "Gun", [1,2], 1], + ["ha", "Hausa", [1,2], 2], + ["he", "Hebrew", [1,2], 2], + ["hi", "Hindi", [1,2], 2], + ["hr", "Croatian", [1,2,5],4], + ["hu", "Hungarian",[1,2], 2], + ["hy", "Armenian", [1,2], 2], + ["ia", "Interlingua",[1,2],2], + ["id", "Indonesian",[1], 3], + ["is", "Icelandic",[1,2], 12], + ["it", "Italian", [1,2], 2], + ["ja", "Japanese", [1], 3], + ["jbo", "Lojban", [1], 3], + ["jv", "Javanese", [0,1], 13], + ["ka", "Georgian", [1], 3], + ["kk", "Kazakh", [1], 3], + ["km", "Khmer", [1], 3], + ["kn", "Kannada", [1,2], 2], + ["ko", "Korean", [1], 3], + ["ku", "Kurdish", [1,2], 2], + ["kw", "Cornish", [1,2,3,4],14], + ["ky", "Kyrgyz", [1], 3], + ["lb", "Letzeburgesch",[1,2],2], + ["ln", "Lingala", [1,2], 1], + ["lo", "Lao", [1], 3], + ["lt", "Lithuanian",[1,2,10],15], + ["lv", "Latvian", [1,2,0],16], + ["mai", "Maithili", [1,2], 2], + ["mfe", "Mauritian Creole",[1,2],1], + ["mg", "Malagasy", [1,2], 1], + ["mi", "Maori", [1,2], 1], + ["mk", "Macedonian",[1,2],17], + ["ml", "Malayalam",[1,2], 2], + ["mn", "Mongolian",[1,2], 2], + ["mnk", "Mandinka", [0,1,2],18], + ["mr", "Marathi", [1,2], 2], + ["ms", "Malay", [1], 3], + ["mt", "Maltese", [1,2,11,20],19], + ["nah", "Nahuatl", [1,2], 2], + ["nap", "Neapolitan",[1,2], 2], + ["nb", "Norwegian Bokmal",[1,2],2], + ["ne", "Nepali", [1,2], 2], + ["nl", "Dutch", [1,2], 2], + ["nn", "Norwegian Nynorsk",[1,2],2], + ["no", "Norwegian",[1,2], 2], + ["nso", "Northern Sotho",[1,2],2], + ["oc", "Occitan", [1,2], 1], + ["or", "Oriya", [2,1], 2], + ["pa", "Punjabi", [1,2], 2], + ["pap", "Papiamento",[1,2], 2], + ["pl", "Polish", [1,2,5],7], + ["pms", "Piemontese",[1,2], 2], + ["ps", "Pashto", [1,2], 2], + ["pt", "Portuguese",[1,2], 2], + ["pt_br","Brazilian Portuguese",[1,2], 2], + ["rm", "Romansh", [1,2], 2], + ["ro", "Romanian", [1,2,20],20], + ["ru", "Russian", [1,2,5],4], + ["sah", "Yakut", [1], 3], + ["sco", "Scots", [1,2], 2], + ["se", "Northern Sami",[1,2], 2], + ["si", "Sinhala", [1,2], 2], + ["sk", "Slovak", [1,2,5],6], + ["sl", "Slovenian",[5,1,2,3],21], + ["so", "Somali", [1,2], 2], + ["son", "Songhay", [1,2], 2], + ["sq", "Albanian", [1,2], 2], + ["sr", "Serbian", [1,2,5],4], + ["su", "Sundanese",[1], 3], + ["sv", "Swedish", [1,2], 2], + ["sw", "Swahili", [1,2], 2], + ["ta", "Tamil", [1,2], 2], + ["te", "Telugu", [1,2], 2], + ["tg", "Tajik", [1,2], 1], + ["th", "Thai", [1], 3], + ["ti", "Tigrinya", [1,2], 1], + ["tk", "Turkmen", [1,2], 2], + ["tr", "Turkish", [1,2], 1], + ["tt", "Tatar", [1], 3], + ["ug", "Uyghur", [1], 3], + ["uk", "Ukrainian",[1,2,5],4], + ["ur", "Urdu", [1,2], 2], + ["uz", "Uzbek", [1,2], 1], + ["vi", "Vietnamese",[1], 3], + ["wa", "Walloon", [1,2], 1], + ["wo", "Wolof", [1], 3], + ["yo", "Yoruba", [1,2], 2], + ["zh", "Chinese", [1], 3] + ]; + + var _rulesPluralsTypes = { + 1: function(n) {return Number(n > 1);}, + 2: function(n) {return Number(n != 1);}, + 3: function(n) {return 0;}, + 4: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 5: function(n) {return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5);}, + 6: function(n) {return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2);}, + 7: function(n) {return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 8: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3);}, + 9: function(n) {return Number(n >= 2);}, + 10: function(n) {return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;}, + 11: function(n) {return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3);}, + 12: function(n) {return Number(n%10!=1 || n%100==11);}, + 13: function(n) {return Number(n !== 0);}, + 14: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3);}, + 15: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 16: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2);}, + 17: function(n) {return Number(n==1 || n%10==1 ? 0 : 1);}, + 18: function(n) {return Number(0 ? 0 : n==1 ? 1 : 2);}, + 19: function(n) {return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3);}, + 20: function(n) {return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2);}, + 21: function(n) {return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }; + + var pluralExtensions = { + + rules: (function () { + var l, rules = {}; + for (l=_rules.length; l-- ;) { + rules[_rules[l][0]] = { + name: _rules[l][1], + numbers: _rules[l][2], + plurals: _rulesPluralsTypes[_rules[l][3]] + } + } + return rules; + }()), + + // you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + needsPlural: function(lng, count) { + var parts = lng.split('-'); + + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[parts[f.getCountyIndexOfLng(lng)]]; + } + + if (ext && ext.numbers.length <= 1) { + return false; + } else { + return this.get(lng, count) !== 1; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i; + if (ext.noAbs) { + i = ext.plurals(c); + } else { + i = ext.plurals(Math.abs(c)); + } + + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[f.getCountyIndexOfLng(lng)], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.hasResourceBundle = hasResourceBundle; + i18n.getResourceBundle = getResourceBundle; + i18n.addResource = addResource; + i18n.addResources = addResources; + i18n.removeResourceBundle = removeResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.applyReplacement = f.applyReplacement; + i18n.options = o; + + $.i18n = i18n; + $.t = i18n.t; + + return i18n; + +})); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd.withJQuery-1.8.2.min.js b/libs/i18next/release/i18next.amd.withJQuery-1.8.2.min.js new file mode 100644 index 00000000..0f9273f2 --- /dev/null +++ b/libs/i18next/release/i18next.amd.withJQuery-1.8.2.min.js @@ -0,0 +1,5 @@ +// i18next, v1.8.2 +// Copyright (c)2015 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +!function(a,b){if("object"==typeof exports){var c=require("jquery");module.exports=b(c)}else"function"==typeof define&&define.amd&&define(["jquery"],b)}(this,function(a){function b(a,b){if(!b||"function"==typeof b)return a;for(var c in b)a[c]=b[c];return a}function c(a,b){for(var d in b)d in a?c(a[d],b[d]):a[d]=b[d];return a}function d(a,b,c){var d,e=0,f=a.length,g=void 0===f||"[object Array]"!==Object.prototype.toString.apply(a)||"function"==typeof a;if(c)if(g){for(d in a)if(b.apply(a[d],c)===!1)break}else for(;f>e&&b.apply(a[e++],c)!==!1;);else if(g){for(d in a)if(b.call(a[d],d,a[d])===!1)break}else for(;f>e&&b.call(a[e],e,a[e++])!==!1;);return a}function e(a){return"string"==typeof a?a.replace(/[&<>"'\/]/g,function(a){return P[a]}):a}function f(a){var b=function(a){if(window.XMLHttpRequest)return a(null,new XMLHttpRequest);if(window.ActiveXObject)try{return a(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(b){return a(null,new ActiveXObject("Microsoft.XMLHTTP"))}return a(new Error)},c=function(a){if("string"==typeof a)return a;var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")},d=function(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;cd?b+=String.fromCharCode(d):d>127&&2048>d?(b+=String.fromCharCode(d>>6|192),b+=String.fromCharCode(63&d|128)):(b+=String.fromCharCode(d>>12|224),b+=String.fromCharCode(d>>6&63|128),b+=String.fromCharCode(63&d|128))}return b},e=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";a=d(a);var c,e,f,g,h,i,j,k="",l=0;do c=a.charCodeAt(l++),e=a.charCodeAt(l++),f=a.charCodeAt(l++),g=c>>2,h=(3&c)<<4|e>>4,i=(15&e)<<2|f>>6,j=63&f,isNaN(e)?i=j=64:isNaN(f)&&(j=64),k+=b.charAt(g)+b.charAt(h)+b.charAt(i)+b.charAt(j),c=e=f="",g=h=i=j="";while(l1&&(d+=d.indexOf("?")>-1?"&"+k:"?"+k),e.jsonp){var l=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=d,void l.appendChild(m)}}b(function(b,c){if(b)return h(b);c.open(a,d,e.async);for(var f in j)j.hasOwnProperty(f)&&c.setRequestHeader(f,j[f]);c.onreadystatechange=function(){if(4===c.readyState){var a=c.responseText||"";if(!h)return;h(c.status,{text:function(){return a},json:function(){try{return JSON.parse(a)}catch(b){return S.error("Can not parse JSON. URL: "+d),{}}}})}},c.send(i)})},h={authBasic:function(a,b){g.headers.Authorization="Basic "+e(a+":"+b)},connect:function(a,b,c){return g("CONNECT",a,b,c)},del:function(a,b,c){return g("DELETE",a,b,c)},get:function(a,b,c){return g("GET",a,b,c)},head:function(a,b,c){return g("HEAD",a,b,c)},headers:function(a){g.headers=a||{}},isAllowed:function(a,b,c){this.options(a,function(a,d){c(-1!==d.text().indexOf(b))})},options:function(a,b,c){return g("OPTIONS",a,b,c)},patch:function(a,b,c){return g("PATCH",a,b,c)},post:function(a,b,c){return g("POST",a,b,c)},put:function(a,b,c){return g("PUT",a,b,c)},trace:function(a,b,c){return g("TRACE",a,b,c)}},i=a.type?a.type.toLowerCase():"get";h[i](a.url,a,function(b,c){200===b||0===b&&c.text()?a.success(c.json(),b,null):a.error(c.text(),b,null)})}function g(b,c){"function"==typeof b&&(c=b,b={}),b=b||{},S.extend(O,b),delete O.fixLng,O.functions&&(delete O.functions,S.extend(S,b.functions)),"string"==typeof O.ns&&(O.ns={namespaces:[O.ns],defaultNs:O.ns}),"string"==typeof O.fallbackNS&&(O.fallbackNS=[O.fallbackNS]),("string"==typeof O.fallbackLng||"boolean"==typeof O.fallbackLng)&&(O.fallbackLng=[O.fallbackLng]),O.interpolationPrefixEscaped=S.regexEscape(O.interpolationPrefix),O.interpolationSuffixEscaped=S.regexEscape(O.interpolationSuffix),O.lng||(O.lng=S.detectLanguage()),L=S.toLanguages(O.lng),H=L[0],S.log("currentLng set to: "+H),O.useCookie&&S.cookie.read(O.cookieName)!==H&&S.cookie.create(O.cookieName,H,O.cookieExpirationTime,O.cookieDomain),O.detectLngFromLocalStorage&&"undefined"!=typeof document&&window.localStorage&&S.localStorage.setItem("i18next_lng",H);var d=B;b.fixLng&&(d=function(a,b){return b=b||{},b.lng=b.lng||d.lng,B(a,b)},d.lng=H),V.setCurrentLng(H),a&&O.setJqueryExt&&u();var e;if(a&&a.Deferred&&(e=a.Deferred()),!O.resStore){var f=S.toLanguages(O.lng);"string"==typeof O.preload&&(O.preload=[O.preload]);for(var g=0,h=O.preload.length;h>g;g++)for(var i=S.toLanguages(O.preload[g]),j=0,k=i.length;k>j;j++)f.indexOf(i[j])<0&&f.push(i[j]);return I.sync.load(f,O,function(a,b){J=b,M=!0,c&&c(d),e&&e.resolve(d)}),e?e.promise():void 0}return J=O.resStore,M=!0,c&&c(d),e&&e.resolve(d),e?e.promise():void 0}function h(a,b){"string"==typeof a&&(a=[a]);for(var c=0,d=a.length;d>c;c++)O.preload.indexOf(a[c])<0&&O.preload.push(a[c]);return g(b)}function i(a,b,c,d){"string"!=typeof b?(c=b,b=O.ns.defaultNs):O.ns.namespaces.indexOf(b)<0&&O.ns.namespaces.push(b),J[a]=J[a]||{},J[a][b]=J[a][b]||{},d?S.deepExtend(J[a][b],c):S.extend(J[a][b],c),O.useLocalStorage&&N._storeLocal(J)}function j(a,b){"string"!=typeof b&&(b=O.ns.defaultNs),J[a]=J[a]||{};var c=J[a][b]||{},d=!1;for(var e in c)c.hasOwnProperty(e)&&(d=!0);return d}function k(a,b){return"string"!=typeof b&&(b=O.ns.defaultNs),J[a]=J[a]||{},S.extend({},J[a][b])}function l(a,b){"string"!=typeof b&&(b=O.ns.defaultNs),J[a]=J[a]||{},J[a][b]={},O.useLocalStorage&&N._storeLocal(J)}function m(a,b,c,d){"string"!=typeof b?(resource=b,b=O.ns.defaultNs):O.ns.namespaces.indexOf(b)<0&&O.ns.namespaces.push(b),J[a]=J[a]||{},J[a][b]=J[a][b]||{};for(var e=c.split(O.keyseparator),f=0,g=J[a][b];e[f];)f==e.length-1?g[e[f]]=d:(null==g[e[f]]&&(g[e[f]]={}),g=g[e[f]]),f++;O.useLocalStorage&&N._storeLocal(J)}function n(a,b,c){"string"!=typeof b?(resource=b,b=O.ns.defaultNs):O.ns.namespaces.indexOf(b)<0&&O.ns.namespaces.push(b);for(var d in c)"string"==typeof c[d]&&m(a,b,d,c[d])}function o(a){O.ns.defaultNs=a}function p(a,b){q([a],b)}function q(a,b){var c={dynamicLoad:O.dynamicLoad,resGetPath:O.resGetPath,getAsync:O.getAsync,customLoad:O.customLoad,ns:{namespaces:a,defaultNs:""}},d=S.toLanguages(O.lng);"string"==typeof O.preload&&(O.preload=[O.preload]);for(var e=0,f=O.preload.length;f>e;e++)for(var g=S.toLanguages(O.preload[e]),h=0,i=g.length;i>h;h++)d.indexOf(g[h])<0&&d.push(g[h]);for(var j=[],k=0,l=d.length;l>k;k++){var m=!1,n=J[d[k]];if(n)for(var o=0,p=a.length;p>o;o++)n[a[o]]||(m=!0);else m=!0;m&&j.push(d[k])}j.length?I.sync._fetch(j,c,function(c,d){var e=a.length*j.length;S.each(a,function(a,c){O.ns.namespaces.indexOf(c)<0&&O.ns.namespaces.push(c),S.each(j,function(a,f){J[f]=J[f]||{},J[f][c]=d[f][c],e--,0===e&&b&&(O.useLocalStorage&&I.sync._storeLocal(J),b())})})}):b&&b()}function r(a,b,c){return"function"==typeof b?(c=b,b={}):b||(b={}),b.lng=a,g(b,c)}function s(){return H}function t(a){J={},r(H,a)}function u(){function b(b,c,d){if(0!==c.length){var e="text";if(0===c.indexOf("[")){var f=c.split("]");c=f[1],e=f[0].substr(1,f[0].length-1)}c.indexOf(";")===c.length-1&&(c=c.substr(0,c.length-2));var g;if("html"===e)g=O.defaultValueFromContent?a.extend({defaultValue:b.html()},d):d,b.html(a.t(c,g));else if("text"===e)g=O.defaultValueFromContent?a.extend({defaultValue:b.text()},d):d,b.text(a.t(c,g));else if("prepend"===e)g=O.defaultValueFromContent?a.extend({defaultValue:b.html()},d):d,b.prepend(a.t(c,g));else if("append"===e)g=O.defaultValueFromContent?a.extend({defaultValue:b.html()},d):d,b.append(a.t(c,g));else if(0===e.indexOf("data-")){var h=e.substr("data-".length);g=O.defaultValueFromContent?a.extend({defaultValue:b.data(h)},d):d;var i=a.t(c,g);b.data(h,i),b.attr(e,i)}else g=O.defaultValueFromContent?a.extend({defaultValue:b.attr(e)},d):d,b.attr(e,a.t(c,g))}}function c(c,d){var e=c.attr(O.selectorAttr);if(e||"undefined"==typeof e||e===!1||(e=c.text()||c.val()),e){var f=c,g=c.data("i18n-target");if(g&&(f=c.find(g)||c),d||O.useDataAttrOptions!==!0||(d=c.data("i18n-options")),d=d||{},e.indexOf(";")>=0){var h=e.split(";");a.each(h,function(a,c){""!==c&&b(f,c,d)})}else b(f,e,d);O.useDataAttrOptions===!0&&c.data("i18n-options",d)}}a.t=a.t||B,a.fn.i18n=function(b){return this.each(function(){c(a(this),b);var d=a(this).find("["+O.selectorAttr+"]");d.each(function(){c(a(this),b)})})}}function v(a,b,c,d){if(!a)return a;if(d=d||b,a.indexOf(d.interpolationPrefix||O.interpolationPrefix)<0)return a;var e=d.interpolationPrefix?S.regexEscape(d.interpolationPrefix):O.interpolationPrefixEscaped,f=d.interpolationSuffix?S.regexEscape(d.interpolationSuffix):O.interpolationSuffixEscaped,g="HTML"+f,h=b.replace&&"object"==typeof b.replace?b.replace:b;return S.each(h,function(b,h){var i=c?c+O.keyseparator+b:b;"object"==typeof h&&null!==h?a=v(a,h,i,d):d.escapeInterpolation||O.escapeInterpolation?(a=a.replace(new RegExp([e,i,g].join(""),"g"),S.regexReplacementEscape(h)),a=a.replace(new RegExp([e,i,f].join(""),"g"),S.regexReplacementEscape(S.escape(h)))):a=a.replace(new RegExp([e,i,f].join(""),"g"),S.regexReplacementEscape(h))}),a}function w(a,b){var c=",",d="{",e="}",f=S.extend({},b);for(delete f.postProcess;-1!=a.indexOf(O.reusePrefix)&&(K++,!(K>O.maxRecursion));){var g=a.lastIndexOf(O.reusePrefix),h=a.indexOf(O.reuseSuffix,g)+O.reuseSuffix.length,i=a.substring(g,h),j=i.replace(O.reusePrefix,"").replace(O.reuseSuffix,"");if(g>=h)return S.error("there is an missing closing in following translation value",a),"";if(-1!=j.indexOf(c)){var k=j.indexOf(c);if(-1!=j.indexOf(d,k)&&-1!=j.indexOf(e,k)){var l=j.indexOf(d,k),m=j.indexOf(e,l)+e.length;try{f=S.extend(f,JSON.parse(j.substring(l,m))),j=j.substring(0,k)}catch(n){}}}var o=E(j,f);a=a.replace(i,S.regexReplacementEscape(o))}return a}function x(a){return a.context&&("string"==typeof a.context||"number"==typeof a.context)}function y(a){return void 0!==a.count&&"string"!=typeof a.count}function z(a){return void 0!==a.indefinite_article&&"string"!=typeof a.indefinite_article&&a.indefinite_article}function A(a,b){b=b||{};var c=C(a,b),d=F(a,b);return void 0!==d||d===c}function B(a,b){return b=b||{},M?(K=0,E.apply(null,arguments)):(S.log("i18next not finished initialization. you might have called t function before loading resources finished."),b.defaultValue||"")}function C(a,b){return void 0!==b.defaultValue?b.defaultValue:a}function D(){for(var a=[],b=1;b1)for(var d=0;d-1&&(e=c.split(O.nsseparator),i=e[0],c=e[1]),void 0===g&&O.sendMissing&&"function"==typeof O.missingKeyHandler&&(b.lng?O.missingKeyHandler(h[0],i,c,f,h):O.missingKeyHandler(O.lng,i,c,f,h));var j;j="string"==typeof O.postProcess&&""!==O.postProcess?[O.postProcess]:"array"==typeof O.postProcess||"object"==typeof O.postProcess?O.postProcess:[],"string"==typeof b.postProcess&&""!==b.postProcess?j=j.concat([b.postProcess]):("array"==typeof b.postProcess||"object"==typeof b.postProcess)&&(j=j.concat(b.postProcess)),void 0!==g&&j.length&&j.forEach(function(a){W[a]&&(g=W[a](g,c,b))});var k=f;if(f.indexOf(O.nsseparator)>-1&&(e=f.split(O.nsseparator),k=e[1]),k===c&&O.parseMissingKey&&(f=O.parseMissingKey(f)),void 0===g&&(f=v(f,b),f=w(f,b),j.length)){var l=C(c,b);j.forEach(function(a){W[a]&&(g=W[a](l,c,b))})}return void 0!==g?g:f}function F(a,b){b=b||{};var c,d,e=C(a,b),f=L;if(!J)return e;if("cimode"===f[0].toLowerCase())return e;if(b.lngs&&(f=b.lngs),b.lng&&(f=S.toLanguages(b.lng,b.fallbackLng),!J[f[0]])){var g=O.getAsync;O.getAsync=!1,I.sync.load(f,O,function(a,b){S.extend(J,b),O.getAsync=g})}var h=b.ns||O.ns.defaultNs;if(a.indexOf(O.nsseparator)>-1){var i=a.split(O.nsseparator);h=i[0],a=i[1]}if(x(b)){c=S.extend({},b),delete c.context,c.defaultValue=O.contextNotFound;var j=h+O.nsseparator+a+"_"+b.context;if(d=B(j,c),d!=O.contextNotFound)return v(d,{context:b.context})}if(y(b,f[0])){c=S.extend({lngs:[f[0]]},b),delete c.count,c._origLng=c._origLng||c.lng||f[0],delete c.lng,c.defaultValue=O.pluralNotFound;var k;if(V.needsPlural(f[0],b.count)){k=h+O.nsseparator+a+O.pluralSuffix;var l=V.get(f[0],b.count);l>=0?k=k+"_"+l:1===l&&(k=h+O.nsseparator+a)}else k=h+O.nsseparator+a;if(d=B(k,c),d!=O.pluralNotFound)return v(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix});if(!(f.length>1))return c.lng=c._origLng,delete c._origLng,d=B(h+O.nsseparator+a,c),v(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix});var m=f.slice();if(m.shift(),b=S.extend(b,{lngs:m}),b._origLng=c._origLng,delete b.lng,d=B(h+O.nsseparator+a,b),d!=O.pluralNotFound)return d}if(z(b)){var n=S.extend({},b);delete n.indefinite_article,n.defaultValue=O.indefiniteNotFound;var o=h+O.nsseparator+a+(b.count&&!y(b,f[0])||!b.count?O.indefiniteSuffix:"");if(d=B(o,n),d!=O.indefiniteNotFound)return d}for(var p,q=a.split(O.keyseparator),r=0,s=f.length;s>r&&void 0===p;r++){for(var t=f[r],u=0,A=J[t]&&J[t][h];q[u];)A=A&&A[q[u]],u++;if(void 0!==A){var D=Object.prototype.toString.apply(A);if("string"==typeof A)A=v(A,b),A=w(A,b);else if("[object Array]"!==D||O.returnObjectTrees||b.returnObjectTrees){if(null===A&&O.fallbackOnNull===!0)A=void 0;else if(null!==A)if(O.returnObjectTrees||b.returnObjectTrees){if("[object Number]"!==D&&"[object Function]"!==D&&"[object RegExp]"!==D){var G="[object Array]"===D?[]:{};S.each(A,function(c){G[c]=E(h+O.nsseparator+a+O.keyseparator+c,b)}),A=G}}else O.objectTreeKeyHandler&&"function"==typeof O.objectTreeKeyHandler?A=O.objectTreeKeyHandler(a,A,t,h,b):(A="key '"+h+":"+a+" ("+t+")' returned an object instead of string.",S.log(A))}else A=A.join("\n"),A=v(A,b),A=w(A,b);"string"==typeof A&&""===A.trim()&&O.fallbackOnEmpty===!0&&(A=void 0),p=A}}if(void 0===p&&!b.isFallbackLookup&&(O.fallbackToDefaultNS===!0||O.fallbackNS&&O.fallbackNS.length>0)){if(b.isFallbackLookup=!0,O.fallbackNS.length){for(var H=0,K=O.fallbackNS.length;K>H;H++)if(p=F(O.fallbackNS[H]+O.nsseparator+a,b),p||""===p&&O.fallbackOnEmpty===!1){var M=p.indexOf(O.nsseparator)>-1?p.split(O.nsseparator)[1]:p,N=e.indexOf(O.nsseparator)>-1?e.split(O.nsseparator)[1]:e;if(M!==N)break}}else p=F(a,b);b.isFallbackLookup=!1}return p}function G(){var a,b=O.lngWhitelist||[],c=[];if("undefined"!=typeof window&&!function(){for(var a=window.location.search.substring(1),b=a.split("&"),d=0;d0){var f=b[d].substring(0,e);f==O.detectLngQS&&c.push(b[d].substring(e+1))}}}(),O.useCookie&&"undefined"!=typeof document){var d=S.cookie.read(O.cookieName);d&&c.push(d)}if(O.detectLngFromLocalStorage&&"undefined"!=typeof window&&window.localStorage&&c.push(S.localStorage.getItem("i18next_lng")),"undefined"!=typeof navigator){if(navigator.languages)for(var e=0;e-1){var f=e.split("-");e=O.lowerCaseLng?f[0].toLowerCase()+"-"+f[1].toLowerCase():f[0].toLowerCase()+"-"+f[1].toUpperCase()}if(0===b.length||b.indexOf(e)>-1){a=e;break}}}(),a||(a=O.fallbackLng[0]),a}Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>0&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=c;arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d))));for(var e=d>=0?Math.min(d,c-1):c-Math.abs(d);e>=0;e--)if(e in b&&b[e]===a)return e;return-1}),"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")});var H,I={},J={},K=0,L=[],M=!1,N={};N={load:function(a,b,c){b.useLocalStorage?N._loadLocal(a,b,function(d,e){for(var f=[],g=0,h=a.length;h>g;g++)e[a[g]]||f.push(a[g]);f.length>0?N._fetch(f,b,function(a,b){S.extend(e,b),N._storeLocal(b),c(null,e)}):c(null,e)}):N._fetch(a,b,function(a,b){c(null,b)})},_loadLocal:function(a,b,c){var d={},e=(new Date).getTime();if(window.localStorage){var f=a.length;S.each(a,function(a,g){var h=S.localStorage.getItem("res_"+g);h&&(h=JSON.parse(h),h.i18nStamp&&h.i18nStamp+b.localStorageExpirationTime>e&&(d[g]=h)),f--,0===f&&c(null,d)})}},_storeLocal:function(a){if(window.localStorage)for(var b in a)a[b].i18nStamp=(new Date).getTime(),S.localStorage.setItem("res_"+b,JSON.stringify(a[b]))},_fetch:function(a,b,c){var d=b.ns,e={};if(b.dynamicLoad){var f=function(a,b){c(null,b)};if("function"==typeof b.customLoad)b.customLoad(a,d.namespaces,b,f);else{var g=v(b.resGetPath,{lng:a.join("+"),ns:d.namespaces.join("+")});S.ajax({url:g,success:function(a){S.log("loaded: "+g),f(null,a)},error:function(a,b,c){S.log("failed loading: "+g),f("failed loading resource.json error: "+c)},dataType:"json",async:b.getAsync})}}else{var h,i=d.namespaces.length*a.length;S.each(d.namespaces,function(d,f){S.each(a,function(a,d){var g=function(a,b){a&&(h=h||[],h.push(a)),e[d]=e[d]||{},e[d][f]=b,i--,0===i&&c(h,e)};"function"==typeof b.customLoad?b.customLoad(d,f,b,g):N._fetchOne(d,f,b,g)})})}},_fetchOne:function(a,b,c,d){var e=v(c.resGetPath,{lng:a,ns:b});S.ajax({url:e,success:function(a){S.log("loaded: "+e),d(null,a)},error:function(a,b,c){if(b&&200==b||a&&a.status&&200==a.status)S.error("There is a typo in: "+e);else if(b&&404==b||a&&a.status&&404==a.status)S.log("Does not exist: "+e);else{var f=b?b:a&&a.status?a.status:null;S.log(f+" when loading "+e)}d(c,{})},dataType:"json",async:c.getAsync})},postMissing:function(a,b,c,d,e){var f={};f[c]=d;var g=[];if("fallback"===O.sendMissingTo&&O.fallbackLng[0]!==!1)for(var h=0;hh;h++)g.push({lng:e[h],url:v(O.resPostPath,{lng:e[h],ns:b})});for(var j=0,k=g.length;k>j;j++){var l=g[j];S.ajax({url:l.url,type:O.sendType,data:f,success:function(){S.log("posted missing key '"+c+"' to: "+l.url);for(var a=c.split("."),e=0,f=J[l.lng][b];a[e];)f=f[a[e]]=e===a.length-1?d:f[a[e]]||{},e++},error:function(){S.log("failed posting missing key '"+c+"' to: "+l.url)},dataType:"json",async:O.postAsync})}},reload:t};var O={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:["dev"],fallbackNS:[],detectLngQS:"setLng",detectLngFromLocalStorage:!1,ns:{namespaces:["translation"],defaultNs:"translation"},fallbackOnNull:!0,fallbackOnEmpty:!1,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",defaultVariables:!1,reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,indefiniteSuffix:"_indefinite",indefiniteNotFound:["indefinite_not_found",Math.random()].join(""),setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",cookieDomain:void 0,objectTreeKeyHandler:void 0,postProcess:void 0,parseMissingKey:void 0,missingKeyHandler:N.postMissing,shortcutFunction:"sprintf"},P={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},Q={create:function(a,b,c,d){var e;if(c){var f=new Date;f.setTime(f.getTime()+60*c*1e3),e="; expires="+f.toGMTString()}else e="";d=d?"domain="+d+";":"",document.cookie=a+"="+b+e+";"+d+"path=/"},read:function(a){for(var b=a+"=",c=document.cookie.split(";"),d=0;d-1){var c=a.split("-");b=O.lowerCaseLng?c[0].toLowerCase()+"-"+c[1].toLowerCase():c[0].toLowerCase()+"-"+c[1].toUpperCase()}else b=O.lowerCaseLng?a.toLowerCase():a;return b}var c=this.log,d=[],e=O.lngWhitelist||!1,f=function(a){!e||e.indexOf(a)>-1?d.push(a):c("rejecting non-whitelisted language: "+a)};if("string"==typeof a&&a.indexOf("-")>-1){var g=a.split("-");"unspecific"!==O.load&&f(b(a)),"current"!==O.load&&f(b(g[this.getCountyIndexOfLng(a)]))}else f(b(a));for(var h=0;h1)},2:function(a){return Number(1!=a)},3:function(){return 0},4:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},5:function(a){return Number(0===a?0:1==a?1:2==a?2:a%100>=3&&10>=a%100?3:a%100>=11?4:5)},6:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)},7:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},8:function(a){return Number(1==a?0:2==a?1:8!=a&&11!=a?2:3)},9:function(a){return Number(a>=2)},10:function(a){return Number(1==a?0:2==a?1:7>a?2:11>a?3:4)},11:function(a){return Number(1==a||11==a?0:2==a||12==a?1:a>2&&20>a?2:3)},12:function(a){return Number(a%10!=1||a%100==11)},13:function(a){return Number(0!==a)},14:function(a){return Number(1==a?0:2==a?1:3==a?2:3)},15:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&(10>a%100||a%100>=20)?1:2)},16:function(a){return Number(a%10==1&&a%100!=11?0:0!==a?1:2)},17:function(a){return Number(1==a||a%10==1?0:1)},18:function(a){return Number(1==a?1:2)},19:function(a){return Number(1==a?0:0===a||a%100>1&&11>a%100?1:a%100>10&&20>a%100?2:3)},20:function(a){return Number(1==a?0:0===a||a%100>0&&20>a%100?1:2)},21:function(a){return Number(a%100==1?1:a%100==2?2:a%100==3||a%100==4?3:0)}},V={rules:function(){var a,b={};for(a=T.length;a--;)b[T[a][0]]={name:T[a][1],numbers:T[a][2],plurals:U[T[a][3]]};return b}(),addRule:function(a,b){V.rules[a]=b},setCurrentLng:function(a){if(!V.currentRule||V.currentRule.lng!==a){var b=a.split("-");V.currentRule={lng:a,rule:V.rules[b[0]]}}},needsPlural:function(a,b){var c,d=a.split("-");return c=V.currentRule&&V.currentRule.lng===a?V.currentRule.rule:V.rules[d[S.getCountyIndexOfLng(a)]],c&&c.numbers.length<=1?!1:1!==this.get(a,b)},get:function(a,b){function c(b,c){var d;if(d=V.currentRule&&V.currentRule.lng===a?V.currentRule.rule:V.rules[b]){var e;e=d.plurals(d.noAbs?c:Math.abs(c));var f=d.numbers[e];return 2===d.numbers.length&&1===d.numbers[0]&&(2===f?f=-1:1===f&&(f=1)),f}return 1===c?"1":"-1"}var d=a.split("-");return c(d[S.getCountyIndexOfLng(a)],b)}},W={},X=function(a,b){W[a]=b},Y=function(){function a(a){return Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}function b(a,b){for(var c=[];b>0;c[--b]=a);return c.join("")}var c=function(){return c.cache.hasOwnProperty(arguments[0])||(c.cache[arguments[0]]=c.parse(arguments[0])),c.format.call(null,c.cache[arguments[0]],arguments)};return c.format=function(c,d){var e,f,g,h,i,j,k,l=1,m=c.length,n="",o=[];for(f=0;m>f;f++)if(n=a(c[f]),"string"===n)o.push(c[f]);else if("array"===n){if(h=c[f],h[2])for(e=d[l],g=0;g=0?"+"+e:e,j=h[4]?"0"==h[4]?"0":h[4].charAt(1):" ",k=h[6]-String(e).length,i=h[6]?b(j,k):"",o.push(h[5]?e+i:i+e)}return o.join("")},c.cache={},c.parse=function(a){for(var b=a,c=[],d=[],e=0;b;){if(null!==(c=/^[^\x25]+/.exec(b)))d.push(c[0]);else if(null!==(c=/^\x25{2}/.exec(b)))d.push("%");else{if(null===(c=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(b)))throw"[sprintf] huh?";if(c[2]){e|=1;var f=[],g=c[2],h=[];if(null===(h=/^([a-z_][a-z_\d]*)/i.exec(g)))throw"[sprintf] huh?";for(f.push(h[1]);""!==(g=g.substring(h[0].length));)if(null!==(h=/^\.([a-z_][a-z_\d]*)/i.exec(g)))f.push(h[1]);else{if(null===(h=/^\[(\d+)\]/.exec(g)))throw"[sprintf] huh?";f.push(h[1])}c[2]=f}else e|=2;if(3===e)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";d.push(c)}b=b.substring(c[0].length)}return d},c}(),Z=function(a,b){return b.unshift(a),Y.apply(null,b)};return X("sprintf",function(a,b,c){return c.sprintf?"[object Array]"===Object.prototype.toString.apply(c.sprintf)?Z(a,c.sprintf):"object"==typeof c.sprintf?Y(a,c.sprintf):a:a}),I.init=g,I.setLng=r,I.preload=h,I.addResourceBundle=i,I.hasResourceBundle=j,I.getResourceBundle=k,I.addResource=m,I.addResources=n,I.removeResourceBundle=l,I.loadNamespace=p,I.loadNamespaces=q,I.setDefaultNamespace=o,I.t=B,I.translate=B,I.exists=A,I.detectLanguage=S.detectLanguage,I.pluralExtensions=V,I.sync=N,I.functions=S,I.lng=s,I.addPostProcessor=X,I.applyReplacement=S.applyReplacement,I.options=O,a.i18n=I,a.t=I.t,I}); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd.withJQuery-latest.js b/libs/i18next/release/i18next.amd.withJQuery-latest.js new file mode 100644 index 00000000..46e8f4f2 --- /dev/null +++ b/libs/i18next/release/i18next.amd.withJQuery-latest.js @@ -0,0 +1,2180 @@ +// i18next, v1.8.2 +// Copyright (c)2015 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function (root, factory) { + if (typeof exports === 'object') { + + var jquery = require('jquery'); + + module.exports = factory(jquery); + + } else if (typeof define === 'function' && define.amd) { + + define(['jquery'], factory); + + } +}(this, function ($) { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + // Add string trim for IE8. + if (typeof String.prototype.trim !== 'function') { + String.prototype.trim = function() { + return this.replace(/^\s+|\s+$/g, ''); + } + } + + var i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = [] + , initialized = false + , sync = {}; + + sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = f.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + f.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + if ((status && status == 200) || (xhr && xhr.status && xhr.status == 200)) { + // file loaded but invalid json, stop waste time ! + f.error('There is a typo in: ' + url); + } else if ((status && status == 404) || (xhr && xhr.status && xhr.status == 404)) { + f.log('Does not exist: ' + url); + } else { + var theStatus = status ? status : ((xhr && xhr.status) ? xhr.status : null); + f.log(theStatus + ' when loading ' + url); + } + + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback' && o.fallbackLng[0] !== false) { + for (var i = 0; i < o.fallbackLng.length; i++) { + urls.push({lng: o.fallbackLng[i], url: applyReplacement(o.resPostPath, { lng: o.fallbackLng[i], ns: ns })}); + } + } else if (o.sendMissingTo === 'current' || (o.sendMissingTo === 'fallback' && o.fallbackLng[0] === false) ) { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + }, + + reload: reload + }; + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: ['dev'], + fallbackNS: [], + detectLngQS: 'setLng', + detectLngFromLocalStorage: false, + ns: { + namespaces: ['translation'], + defaultNs: 'translation' + }, + fallbackOnNull: true, + fallbackOnEmpty: false, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + defaultVariables: false, + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + indefiniteSuffix: '_indefinite', + indefiniteNotFound: ['indefinite_not_found', Math.random()].join(''), + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + cookieDomain: undefined, + + objectTreeKeyHandler: undefined, + postProcess: undefined, + parseMissingKey: undefined, + missingKeyHandler: sync.postMissing, + + shortcutFunction: 'sprintf' // or: defaultValue + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _deepExtend(target, source) { + for (var prop in source) + if (prop in target) + _deepExtend(target[prop], source[prop]); + else + target[prop] = source[prop]; + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || Object.prototype.toString.apply(object) !== '[object Array]' || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + try { + return JSON.parse(data) + } catch (e) { + f.error('Can not parse JSON. URL: ' + url); + return {}; + } + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + // file: protocol always gives status code 0, so check for data + if (status === 200 || (status === 0 && data.text())) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes,domain) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + domain = (domain)? "domain="+domain+";" : ""; + document.cookie = name+"="+value+expires+";"+domain+"path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes,domain) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + deepExtend: _deepExtend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : (typeof document !== 'undefined' ? _ajax : function() {}), + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + error: function(str) { + if (typeof console !== "undefined") console.error(str); + }, + getCountyIndexOfLng: function(lng) { + var lng_index = 0; + if (lng === 'nb-NO' || lng === 'nn-NO' || lng === 'nb-no' || lng === 'nn-no') lng_index = 1; + return lng_index; + }, + toLanguages: function(lng) { + var log = this.log; + + function applyCase(l) { + var ret = l; + + if (typeof l === 'string' && l.indexOf('-') > -1) { + var parts = l.split('-'); + + ret = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } else { + ret = o.lowerCaseLng ? l.toLowerCase() : l; + } + + return ret; + } + + var languages = []; + var whitelist = o.lngWhitelist || false; + var addLanguage = function(language){ + //reject langs not whitelisted + if(!whitelist || whitelist.indexOf(language) > -1){ + languages.push(language); + }else{ + log('rejecting non-whitelisted language: ' + language); + } + }; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + if (o.load !== 'unspecific') addLanguage(applyCase(lng)); + if (o.load !== 'current') addLanguage(applyCase(parts[this.getCountyIndexOfLng(lng)])); + } else { + addLanguage(applyCase(lng)); + } + + for (var i = 0; i < o.fallbackLng.length; i++) { + if (languages.indexOf(o.fallbackLng[i]) === -1 && o.fallbackLng[i]) languages.push(applyCase(o.fallbackLng[i])); + } + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + }, + regexReplacementEscape: function(strOrFn) { + if (typeof strOrFn === 'string') { + return strOrFn.replace(/\$/g, "$$$$"); + } else { + return strOrFn; + } + }, + localStorage: { + setItem: function(key, value) { + if (window.localStorage) { + try { + window.localStorage.setItem(key, value); + } catch (e) { + f.log('failed to set value for key "' + key + '" to localStorage.'); + } + } + }, + getItem: function(key, value) { + if (window.localStorage) { + try { + return window.localStorage.getItem(key, value); + } catch (e) { + f.log('failed to get value for key "' + key + '" from localStorage.'); + return undefined; + } + } + } + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + delete o.fixLng; /* passed in each time */ + + // override functions: .log(), .detectLanguage(), etc + if (o.functions) { + delete o.functions; + f.extend(f, options.functions); + } + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // fallback languages + if (typeof o.fallbackLng == 'string' || typeof o.fallbackLng == 'boolean') { + o.fallbackLng = [o.fallbackLng]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + if (o.useCookie && f.cookie.read(o.cookieName) !== currentLng){ //cookie is unset or invalid + f.cookie.create(o.cookieName, currentLng, o.cookieExpirationTime, o.cookieDomain); + } + if (o.detectLngFromLocalStorage && typeof document !== 'undefined' && window.localStorage) { + f.localStorage.setItem('i18next_lng', currentLng); + } + + var lngTranslate = translate; + if (options.fixLng) { + lngTranslate = function(key, options) { + options = options || {}; + options.lng = options.lng || lngTranslate.lng; + return translate(key, options); + }; + lngTranslate.lng = currentLng; + } + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + initialized = true; + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + initialized = true; + + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources, deep) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + if (deep) { + f.deepExtend(resStore[lng][ns], resources); + } else { + f.extend(resStore[lng][ns], resources); + } + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function hasResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + var res = resStore[lng][ns] || {}; + + var hasValues = false; + for(var prop in res) { + if (res.hasOwnProperty(prop)) { + hasValues = true; + } + } + + return hasValues; + } + + function getResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + return f.extend({}, resStore[lng][ns]); + } + + function removeResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = {}; + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function addResource(lng, ns, key, value) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + var keys = key.split(o.keyseparator); + var x = 0; + var node = resStore[lng][ns]; + var origRef = node; + + while (keys[x]) { + if (x == keys.length - 1) + node[keys[x]] = value; + else { + if (node[keys[x]] == null) + node[keys[x]] = {}; + + node = node[keys[x]]; + } + x++; + } + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function addResources(lng, ns, resources) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + for (var m in resources) { + if (typeof resources[m] === 'string') addResource(lng, ns, m, resources[m]); + } + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, options, cb) { + if (typeof options === 'function') { + cb = options; + options = {}; + } else if (!options) { + options = {}; + } + + options.lng = lng; + return init(options, cb); + } + + function lng() { + return currentLng; + } + + function reload(cb) { + resStore = {}; + setLng(currentLng, cb); + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else if (attr === 'prepend') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.prepend($.t(key, optionsToUse)); + } else if (attr === 'append') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.append($.t(key, optionsToUse)); + } else if (attr.indexOf("data-") === 0) { + var dataAttr = attr.substr(("data-").length); + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.data(dataAttr) }, options) : options; + var translated = $.t(key, optionsToUse); + //we change into the data cache + ele.data(dataAttr, translated); + //we change into the dom + ele.attr(attr, translated); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key && typeof key !== 'undefined' && key !== false) key = ele.text() || ele.val(); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + var hash = replacementHash.replace && typeof replacementHash.replace === 'object' ? replacementHash.replace : replacementHash; + f.each(hash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), f.regexReplacementEscape(value)); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(f.escape(value))); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(value)); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + if (index_of_end_of_closing <= index_of_opening) { + f.error('there is an missing closing in following translation value', translated); + return ''; + } + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, f.regexReplacementEscape(translated_token)); + } + return translated; + } + + function hasContext(options) { + return (options.context && (typeof options.context == 'string' || typeof options.context == 'number')); + } + + function needsPlural(options, lng) { + return (options.count !== undefined && typeof options.count != 'string'/* && pluralExtensions.needsPlural(lng, options.count)*/); + } + + function needsIndefiniteArticle(options) { + return (options.indefinite_article !== undefined && typeof options.indefinite_article != 'string' && options.indefinite_article); + } + + function exists(key, options) { + options = options || {}; + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + options = options || {}; + + if (!initialized) { + f.log('i18next not finished initialization. you might have called t function before loading resources finished.') + return options.defaultValue || ''; + }; + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _getDefaultValue(key, options) { + return (options.defaultValue !== undefined) ? options.defaultValue : key; + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(potentialKeys, options) { + if (options && typeof options !== 'object') { + if (o.shortcutFunction === 'sprintf') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else if (o.shortcutFunction === 'defaultValue') { + options = { + defaultValue: options + } + } + } else { + options = options || {}; + } + + if (typeof o.defaultVariables === 'object') { + options = f.extend({}, o.defaultVariables, options); + } + + if (potentialKeys === undefined || potentialKeys === null || potentialKeys === '') return ''; + + if (typeof potentialKeys === 'number') { + potentialKeys = String(potentialKeys); + } + + if (typeof potentialKeys === 'string') { + potentialKeys = [potentialKeys]; + } + + var key = potentialKeys[0]; + + if (potentialKeys.length > 1) { + for (var i = 0; i < potentialKeys.length; i++) { + key = potentialKeys[i]; + if (exists(key, options)) { + break; + } + } + } + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng, options.fallbackLng) : languages + , ns = options.ns || o.ns.defaultNs + , parts; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing && typeof o.missingKeyHandler === 'function') { + if (options.lng) { + o.missingKeyHandler(lngs[0], ns, key, notFound, lngs); + } else { + o.missingKeyHandler(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessorsToApply; + if (typeof o.postProcess === 'string' && o.postProcess !== '') { + postProcessorsToApply = [o.postProcess]; + } else if (typeof o.postProcess === 'array' || typeof o.postProcess === 'object') { + postProcessorsToApply = o.postProcess; + } else { + postProcessorsToApply = []; + } + + if (typeof options.postProcess === 'string' && options.postProcess !== '') { + postProcessorsToApply = postProcessorsToApply.concat([options.postProcess]); + } else if (typeof options.postProcess === 'array' || typeof options.postProcess === 'object') { + postProcessorsToApply = postProcessorsToApply.concat(options.postProcess); + } + + if (found !== undefined && postProcessorsToApply.length) { + postProcessorsToApply.forEach(function(postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + }); + } + + // process notFound if function exists + var splitNotFound = notFound; + if (notFound.indexOf(o.nsseparator) > -1) { + parts = notFound.split(o.nsseparator); + splitNotFound = parts[1]; + } + if (splitNotFound === key && o.parseMissingKey) { + notFound = o.parseMissingKey(notFound); + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessorsToApply.length) { + var val = _getDefaultValue(key, options); + postProcessorsToApply.forEach(function(postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](val, key, options); + } + }); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options) { + options = options || {}; + + var optionWithoutCount, translated + , notFound = _getDefaultValue(key, options) + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + // CI mode + if (lngs[0].toLowerCase() === 'cimode') return notFound; + + // passed in lng + if (options.lngs) lngs = options.lngs; + if (options.lng) { + lngs = f.toLanguages(options.lng, options.fallbackLng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options, lngs[0])) { + optionWithoutCount = f.extend({ lngs: [lngs[0]]}, options); + delete optionWithoutCount.count; + optionWithoutCount._origLng = optionWithoutCount._origLng || optionWithoutCount.lng || lngs[0]; + delete optionWithoutCount.lng; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey; + if (!pluralExtensions.needsPlural(lngs[0], options.count)) { + pluralKey = ns + o.nsseparator + key; + } else { + pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(lngs[0], options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + } + + translated = translate(pluralKey, optionWithoutCount); + + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } else if (lngs.length > 1) { + // remove failed lng + var clone = lngs.slice(); + clone.shift(); + options = f.extend(options, { lngs: clone }); + options._origLng = optionWithoutCount._origLng; + delete options.lng; + // retry with fallbacks + translated = translate(ns + o.nsseparator + key, options); + if (translated != o.pluralNotFound) return translated; + } else { + optionWithoutCount.lng = optionWithoutCount._origLng; + delete optionWithoutCount._origLng; + translated = translate(ns + o.nsseparator + key, optionWithoutCount); + + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); + } + } + + if (needsIndefiniteArticle(options)) { + var optionsWithoutIndef = f.extend({}, options); + delete optionsWithoutIndef.indefinite_article; + optionsWithoutIndef.defaultValue = o.indefiniteNotFound; + // If we don't have a count, we want the indefinite, if we do have a count, and needsPlural is false + var indefiniteKey = ns + o.nsseparator + key + (((options.count && !needsPlural(options, lngs[0])) || !options.count) ? o.indefiniteSuffix : ""); + translated = translate(indefiniteKey, optionsWithoutIndef); + if (translated != o.indefiniteNotFound) { + return translated; + } + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + var valueType = Object.prototype.toString.apply(value); + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (valueType === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + if (o.objectTreeKeyHandler && typeof o.objectTreeKeyHandler == 'function') { + value = o.objectTreeKeyHandler(key, value, l, ns, options); + } else { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned an object instead of string.'; + f.log(value); + } + } else if (valueType !== '[object Number]' && valueType !== '[object Function]' && valueType !== '[object RegExp]') { + var copy = (valueType === '[object Array]') ? [] : {}; // apply child translation on a copy + f.each(value, function(m) { + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + }); + value = copy; + } + } + + if (typeof value === 'string' && value.trim() === '' && o.fallbackOnEmpty === true) + value = undefined; + + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length > 0))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found || (found==="" && o.fallbackOnEmpty === false)) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + options.isFallbackLookup = false; + } + + return found; + } + function detectLanguage() { + var detectedLng; + var whitelist = o.lngWhitelist || []; + var userLngChoices = []; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var params = query.split('&'); + for (var i=0; i 0) { + var key = params[i].substring(0,pos); + if (key == o.detectLngQS) { + userLngChoices.push(params[i].substring(pos+1)); + } + } + } + })(); + } + + // get from cookie + if (o.useCookie && typeof document !== 'undefined') { + var c = f.cookie.read(o.cookieName); + if (c) userLngChoices.push(c); + } + + // get from localStorage + if (o.detectLngFromLocalStorage && typeof window !== 'undefined' && window.localStorage) { + userLngChoices.push(f.localStorage.getItem('i18next_lng')); + } + + // get from navigator + if (typeof navigator !== 'undefined') { + if (navigator.languages) { // chrome only; not an array, so can't use .push.apply instead of iterating + for (var i=0;i -1) { + var parts = lng.split('-'); + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } + + if (whitelist.length === 0 || whitelist.indexOf(lng) > -1) { + detectedLng = lng; + break; + } + } + })(); + + //fallback + if (!detectedLng){ + detectedLng = o.fallbackLng[0]; + } + + return detectedLng; + } + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + + /* [code, name, numbers, pluralsType] */ + var _rules = [ + ["ach", "Acholi", [1,2], 1], + ["af", "Afrikaans",[1,2], 2], + ["ak", "Akan", [1,2], 1], + ["am", "Amharic", [1,2], 1], + ["an", "Aragonese",[1,2], 2], + ["ar", "Arabic", [0,1,2,3,11,100],5], + ["arn", "Mapudungun",[1,2], 1], + ["ast", "Asturian", [1,2], 2], + ["ay", "Aymará", [1], 3], + ["az", "Azerbaijani",[1,2],2], + ["be", "Belarusian",[1,2,5],4], + ["bg", "Bulgarian",[1,2], 2], + ["bn", "Bengali", [1,2], 2], + ["bo", "Tibetan", [1], 3], + ["br", "Breton", [1,2], 1], + ["bs", "Bosnian", [1,2,5],4], + ["ca", "Catalan", [1,2], 2], + ["cgg", "Chiga", [1], 3], + ["cs", "Czech", [1,2,5],6], + ["csb", "Kashubian",[1,2,5],7], + ["cy", "Welsh", [1,2,3,8],8], + ["da", "Danish", [1,2], 2], + ["de", "German", [1,2], 2], + ["dev", "Development Fallback", [1,2], 2], + ["dz", "Dzongkha", [1], 3], + ["el", "Greek", [1,2], 2], + ["en", "English", [1,2], 2], + ["eo", "Esperanto",[1,2], 2], + ["es", "Spanish", [1,2], 2], + ["es_ar","Argentinean Spanish", [1,2], 2], + ["et", "Estonian", [1,2], 2], + ["eu", "Basque", [1,2], 2], + ["fa", "Persian", [1], 3], + ["fi", "Finnish", [1,2], 2], + ["fil", "Filipino", [1,2], 1], + ["fo", "Faroese", [1,2], 2], + ["fr", "French", [1,2], 9], + ["fur", "Friulian", [1,2], 2], + ["fy", "Frisian", [1,2], 2], + ["ga", "Irish", [1,2,3,7,11],10], + ["gd", "Scottish Gaelic",[1,2,3,20],11], + ["gl", "Galician", [1,2], 2], + ["gu", "Gujarati", [1,2], 2], + ["gun", "Gun", [1,2], 1], + ["ha", "Hausa", [1,2], 2], + ["he", "Hebrew", [1,2], 2], + ["hi", "Hindi", [1,2], 2], + ["hr", "Croatian", [1,2,5],4], + ["hu", "Hungarian",[1,2], 2], + ["hy", "Armenian", [1,2], 2], + ["ia", "Interlingua",[1,2],2], + ["id", "Indonesian",[1], 3], + ["is", "Icelandic",[1,2], 12], + ["it", "Italian", [1,2], 2], + ["ja", "Japanese", [1], 3], + ["jbo", "Lojban", [1], 3], + ["jv", "Javanese", [0,1], 13], + ["ka", "Georgian", [1], 3], + ["kk", "Kazakh", [1], 3], + ["km", "Khmer", [1], 3], + ["kn", "Kannada", [1,2], 2], + ["ko", "Korean", [1], 3], + ["ku", "Kurdish", [1,2], 2], + ["kw", "Cornish", [1,2,3,4],14], + ["ky", "Kyrgyz", [1], 3], + ["lb", "Letzeburgesch",[1,2],2], + ["ln", "Lingala", [1,2], 1], + ["lo", "Lao", [1], 3], + ["lt", "Lithuanian",[1,2,10],15], + ["lv", "Latvian", [1,2,0],16], + ["mai", "Maithili", [1,2], 2], + ["mfe", "Mauritian Creole",[1,2],1], + ["mg", "Malagasy", [1,2], 1], + ["mi", "Maori", [1,2], 1], + ["mk", "Macedonian",[1,2],17], + ["ml", "Malayalam",[1,2], 2], + ["mn", "Mongolian",[1,2], 2], + ["mnk", "Mandinka", [0,1,2],18], + ["mr", "Marathi", [1,2], 2], + ["ms", "Malay", [1], 3], + ["mt", "Maltese", [1,2,11,20],19], + ["nah", "Nahuatl", [1,2], 2], + ["nap", "Neapolitan",[1,2], 2], + ["nb", "Norwegian Bokmal",[1,2],2], + ["ne", "Nepali", [1,2], 2], + ["nl", "Dutch", [1,2], 2], + ["nn", "Norwegian Nynorsk",[1,2],2], + ["no", "Norwegian",[1,2], 2], + ["nso", "Northern Sotho",[1,2],2], + ["oc", "Occitan", [1,2], 1], + ["or", "Oriya", [2,1], 2], + ["pa", "Punjabi", [1,2], 2], + ["pap", "Papiamento",[1,2], 2], + ["pl", "Polish", [1,2,5],7], + ["pms", "Piemontese",[1,2], 2], + ["ps", "Pashto", [1,2], 2], + ["pt", "Portuguese",[1,2], 2], + ["pt_br","Brazilian Portuguese",[1,2], 2], + ["rm", "Romansh", [1,2], 2], + ["ro", "Romanian", [1,2,20],20], + ["ru", "Russian", [1,2,5],4], + ["sah", "Yakut", [1], 3], + ["sco", "Scots", [1,2], 2], + ["se", "Northern Sami",[1,2], 2], + ["si", "Sinhala", [1,2], 2], + ["sk", "Slovak", [1,2,5],6], + ["sl", "Slovenian",[5,1,2,3],21], + ["so", "Somali", [1,2], 2], + ["son", "Songhay", [1,2], 2], + ["sq", "Albanian", [1,2], 2], + ["sr", "Serbian", [1,2,5],4], + ["su", "Sundanese",[1], 3], + ["sv", "Swedish", [1,2], 2], + ["sw", "Swahili", [1,2], 2], + ["ta", "Tamil", [1,2], 2], + ["te", "Telugu", [1,2], 2], + ["tg", "Tajik", [1,2], 1], + ["th", "Thai", [1], 3], + ["ti", "Tigrinya", [1,2], 1], + ["tk", "Turkmen", [1,2], 2], + ["tr", "Turkish", [1,2], 1], + ["tt", "Tatar", [1], 3], + ["ug", "Uyghur", [1], 3], + ["uk", "Ukrainian",[1,2,5],4], + ["ur", "Urdu", [1,2], 2], + ["uz", "Uzbek", [1,2], 1], + ["vi", "Vietnamese",[1], 3], + ["wa", "Walloon", [1,2], 1], + ["wo", "Wolof", [1], 3], + ["yo", "Yoruba", [1,2], 2], + ["zh", "Chinese", [1], 3] + ]; + + var _rulesPluralsTypes = { + 1: function(n) {return Number(n > 1);}, + 2: function(n) {return Number(n != 1);}, + 3: function(n) {return 0;}, + 4: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 5: function(n) {return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5);}, + 6: function(n) {return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2);}, + 7: function(n) {return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 8: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3);}, + 9: function(n) {return Number(n >= 2);}, + 10: function(n) {return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;}, + 11: function(n) {return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3);}, + 12: function(n) {return Number(n%10!=1 || n%100==11);}, + 13: function(n) {return Number(n !== 0);}, + 14: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3);}, + 15: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 16: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2);}, + 17: function(n) {return Number(n==1 || n%10==1 ? 0 : 1);}, + 18: function(n) {return Number(0 ? 0 : n==1 ? 1 : 2);}, + 19: function(n) {return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3);}, + 20: function(n) {return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2);}, + 21: function(n) {return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }; + + var pluralExtensions = { + + rules: (function () { + var l, rules = {}; + for (l=_rules.length; l-- ;) { + rules[_rules[l][0]] = { + name: _rules[l][1], + numbers: _rules[l][2], + plurals: _rulesPluralsTypes[_rules[l][3]] + } + } + return rules; + }()), + + // you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + needsPlural: function(lng, count) { + var parts = lng.split('-'); + + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[parts[f.getCountyIndexOfLng(lng)]]; + } + + if (ext && ext.numbers.length <= 1) { + return false; + } else { + return this.get(lng, count) !== 1; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i; + if (ext.noAbs) { + i = ext.plurals(c); + } else { + i = ext.plurals(Math.abs(c)); + } + + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[f.getCountyIndexOfLng(lng)], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.hasResourceBundle = hasResourceBundle; + i18n.getResourceBundle = getResourceBundle; + i18n.addResource = addResource; + i18n.addResources = addResources; + i18n.removeResourceBundle = removeResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.applyReplacement = f.applyReplacement; + i18n.options = o; + + $.i18n = i18n; + $.t = i18n.t; + + return i18n; + +})); \ No newline at end of file diff --git a/libs/i18next/release/i18next.amd.withJQuery-latest.min.js b/libs/i18next/release/i18next.amd.withJQuery-latest.min.js new file mode 100644 index 00000000..0f9273f2 --- /dev/null +++ b/libs/i18next/release/i18next.amd.withJQuery-latest.min.js @@ -0,0 +1,5 @@ +// i18next, v1.8.2 +// Copyright (c)2015 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +!function(a,b){if("object"==typeof exports){var c=require("jquery");module.exports=b(c)}else"function"==typeof define&&define.amd&&define(["jquery"],b)}(this,function(a){function b(a,b){if(!b||"function"==typeof b)return a;for(var c in b)a[c]=b[c];return a}function c(a,b){for(var d in b)d in a?c(a[d],b[d]):a[d]=b[d];return a}function d(a,b,c){var d,e=0,f=a.length,g=void 0===f||"[object Array]"!==Object.prototype.toString.apply(a)||"function"==typeof a;if(c)if(g){for(d in a)if(b.apply(a[d],c)===!1)break}else for(;f>e&&b.apply(a[e++],c)!==!1;);else if(g){for(d in a)if(b.call(a[d],d,a[d])===!1)break}else for(;f>e&&b.call(a[e],e,a[e++])!==!1;);return a}function e(a){return"string"==typeof a?a.replace(/[&<>"'\/]/g,function(a){return P[a]}):a}function f(a){var b=function(a){if(window.XMLHttpRequest)return a(null,new XMLHttpRequest);if(window.ActiveXObject)try{return a(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(b){return a(null,new ActiveXObject("Microsoft.XMLHTTP"))}return a(new Error)},c=function(a){if("string"==typeof a)return a;var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")},d=function(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;cd?b+=String.fromCharCode(d):d>127&&2048>d?(b+=String.fromCharCode(d>>6|192),b+=String.fromCharCode(63&d|128)):(b+=String.fromCharCode(d>>12|224),b+=String.fromCharCode(d>>6&63|128),b+=String.fromCharCode(63&d|128))}return b},e=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";a=d(a);var c,e,f,g,h,i,j,k="",l=0;do c=a.charCodeAt(l++),e=a.charCodeAt(l++),f=a.charCodeAt(l++),g=c>>2,h=(3&c)<<4|e>>4,i=(15&e)<<2|f>>6,j=63&f,isNaN(e)?i=j=64:isNaN(f)&&(j=64),k+=b.charAt(g)+b.charAt(h)+b.charAt(i)+b.charAt(j),c=e=f="",g=h=i=j="";while(l1&&(d+=d.indexOf("?")>-1?"&"+k:"?"+k),e.jsonp){var l=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=d,void l.appendChild(m)}}b(function(b,c){if(b)return h(b);c.open(a,d,e.async);for(var f in j)j.hasOwnProperty(f)&&c.setRequestHeader(f,j[f]);c.onreadystatechange=function(){if(4===c.readyState){var a=c.responseText||"";if(!h)return;h(c.status,{text:function(){return a},json:function(){try{return JSON.parse(a)}catch(b){return S.error("Can not parse JSON. URL: "+d),{}}}})}},c.send(i)})},h={authBasic:function(a,b){g.headers.Authorization="Basic "+e(a+":"+b)},connect:function(a,b,c){return g("CONNECT",a,b,c)},del:function(a,b,c){return g("DELETE",a,b,c)},get:function(a,b,c){return g("GET",a,b,c)},head:function(a,b,c){return g("HEAD",a,b,c)},headers:function(a){g.headers=a||{}},isAllowed:function(a,b,c){this.options(a,function(a,d){c(-1!==d.text().indexOf(b))})},options:function(a,b,c){return g("OPTIONS",a,b,c)},patch:function(a,b,c){return g("PATCH",a,b,c)},post:function(a,b,c){return g("POST",a,b,c)},put:function(a,b,c){return g("PUT",a,b,c)},trace:function(a,b,c){return g("TRACE",a,b,c)}},i=a.type?a.type.toLowerCase():"get";h[i](a.url,a,function(b,c){200===b||0===b&&c.text()?a.success(c.json(),b,null):a.error(c.text(),b,null)})}function g(b,c){"function"==typeof b&&(c=b,b={}),b=b||{},S.extend(O,b),delete O.fixLng,O.functions&&(delete O.functions,S.extend(S,b.functions)),"string"==typeof O.ns&&(O.ns={namespaces:[O.ns],defaultNs:O.ns}),"string"==typeof O.fallbackNS&&(O.fallbackNS=[O.fallbackNS]),("string"==typeof O.fallbackLng||"boolean"==typeof O.fallbackLng)&&(O.fallbackLng=[O.fallbackLng]),O.interpolationPrefixEscaped=S.regexEscape(O.interpolationPrefix),O.interpolationSuffixEscaped=S.regexEscape(O.interpolationSuffix),O.lng||(O.lng=S.detectLanguage()),L=S.toLanguages(O.lng),H=L[0],S.log("currentLng set to: "+H),O.useCookie&&S.cookie.read(O.cookieName)!==H&&S.cookie.create(O.cookieName,H,O.cookieExpirationTime,O.cookieDomain),O.detectLngFromLocalStorage&&"undefined"!=typeof document&&window.localStorage&&S.localStorage.setItem("i18next_lng",H);var d=B;b.fixLng&&(d=function(a,b){return b=b||{},b.lng=b.lng||d.lng,B(a,b)},d.lng=H),V.setCurrentLng(H),a&&O.setJqueryExt&&u();var e;if(a&&a.Deferred&&(e=a.Deferred()),!O.resStore){var f=S.toLanguages(O.lng);"string"==typeof O.preload&&(O.preload=[O.preload]);for(var g=0,h=O.preload.length;h>g;g++)for(var i=S.toLanguages(O.preload[g]),j=0,k=i.length;k>j;j++)f.indexOf(i[j])<0&&f.push(i[j]);return I.sync.load(f,O,function(a,b){J=b,M=!0,c&&c(d),e&&e.resolve(d)}),e?e.promise():void 0}return J=O.resStore,M=!0,c&&c(d),e&&e.resolve(d),e?e.promise():void 0}function h(a,b){"string"==typeof a&&(a=[a]);for(var c=0,d=a.length;d>c;c++)O.preload.indexOf(a[c])<0&&O.preload.push(a[c]);return g(b)}function i(a,b,c,d){"string"!=typeof b?(c=b,b=O.ns.defaultNs):O.ns.namespaces.indexOf(b)<0&&O.ns.namespaces.push(b),J[a]=J[a]||{},J[a][b]=J[a][b]||{},d?S.deepExtend(J[a][b],c):S.extend(J[a][b],c),O.useLocalStorage&&N._storeLocal(J)}function j(a,b){"string"!=typeof b&&(b=O.ns.defaultNs),J[a]=J[a]||{};var c=J[a][b]||{},d=!1;for(var e in c)c.hasOwnProperty(e)&&(d=!0);return d}function k(a,b){return"string"!=typeof b&&(b=O.ns.defaultNs),J[a]=J[a]||{},S.extend({},J[a][b])}function l(a,b){"string"!=typeof b&&(b=O.ns.defaultNs),J[a]=J[a]||{},J[a][b]={},O.useLocalStorage&&N._storeLocal(J)}function m(a,b,c,d){"string"!=typeof b?(resource=b,b=O.ns.defaultNs):O.ns.namespaces.indexOf(b)<0&&O.ns.namespaces.push(b),J[a]=J[a]||{},J[a][b]=J[a][b]||{};for(var e=c.split(O.keyseparator),f=0,g=J[a][b];e[f];)f==e.length-1?g[e[f]]=d:(null==g[e[f]]&&(g[e[f]]={}),g=g[e[f]]),f++;O.useLocalStorage&&N._storeLocal(J)}function n(a,b,c){"string"!=typeof b?(resource=b,b=O.ns.defaultNs):O.ns.namespaces.indexOf(b)<0&&O.ns.namespaces.push(b);for(var d in c)"string"==typeof c[d]&&m(a,b,d,c[d])}function o(a){O.ns.defaultNs=a}function p(a,b){q([a],b)}function q(a,b){var c={dynamicLoad:O.dynamicLoad,resGetPath:O.resGetPath,getAsync:O.getAsync,customLoad:O.customLoad,ns:{namespaces:a,defaultNs:""}},d=S.toLanguages(O.lng);"string"==typeof O.preload&&(O.preload=[O.preload]);for(var e=0,f=O.preload.length;f>e;e++)for(var g=S.toLanguages(O.preload[e]),h=0,i=g.length;i>h;h++)d.indexOf(g[h])<0&&d.push(g[h]);for(var j=[],k=0,l=d.length;l>k;k++){var m=!1,n=J[d[k]];if(n)for(var o=0,p=a.length;p>o;o++)n[a[o]]||(m=!0);else m=!0;m&&j.push(d[k])}j.length?I.sync._fetch(j,c,function(c,d){var e=a.length*j.length;S.each(a,function(a,c){O.ns.namespaces.indexOf(c)<0&&O.ns.namespaces.push(c),S.each(j,function(a,f){J[f]=J[f]||{},J[f][c]=d[f][c],e--,0===e&&b&&(O.useLocalStorage&&I.sync._storeLocal(J),b())})})}):b&&b()}function r(a,b,c){return"function"==typeof b?(c=b,b={}):b||(b={}),b.lng=a,g(b,c)}function s(){return H}function t(a){J={},r(H,a)}function u(){function b(b,c,d){if(0!==c.length){var e="text";if(0===c.indexOf("[")){var f=c.split("]");c=f[1],e=f[0].substr(1,f[0].length-1)}c.indexOf(";")===c.length-1&&(c=c.substr(0,c.length-2));var g;if("html"===e)g=O.defaultValueFromContent?a.extend({defaultValue:b.html()},d):d,b.html(a.t(c,g));else if("text"===e)g=O.defaultValueFromContent?a.extend({defaultValue:b.text()},d):d,b.text(a.t(c,g));else if("prepend"===e)g=O.defaultValueFromContent?a.extend({defaultValue:b.html()},d):d,b.prepend(a.t(c,g));else if("append"===e)g=O.defaultValueFromContent?a.extend({defaultValue:b.html()},d):d,b.append(a.t(c,g));else if(0===e.indexOf("data-")){var h=e.substr("data-".length);g=O.defaultValueFromContent?a.extend({defaultValue:b.data(h)},d):d;var i=a.t(c,g);b.data(h,i),b.attr(e,i)}else g=O.defaultValueFromContent?a.extend({defaultValue:b.attr(e)},d):d,b.attr(e,a.t(c,g))}}function c(c,d){var e=c.attr(O.selectorAttr);if(e||"undefined"==typeof e||e===!1||(e=c.text()||c.val()),e){var f=c,g=c.data("i18n-target");if(g&&(f=c.find(g)||c),d||O.useDataAttrOptions!==!0||(d=c.data("i18n-options")),d=d||{},e.indexOf(";")>=0){var h=e.split(";");a.each(h,function(a,c){""!==c&&b(f,c,d)})}else b(f,e,d);O.useDataAttrOptions===!0&&c.data("i18n-options",d)}}a.t=a.t||B,a.fn.i18n=function(b){return this.each(function(){c(a(this),b);var d=a(this).find("["+O.selectorAttr+"]");d.each(function(){c(a(this),b)})})}}function v(a,b,c,d){if(!a)return a;if(d=d||b,a.indexOf(d.interpolationPrefix||O.interpolationPrefix)<0)return a;var e=d.interpolationPrefix?S.regexEscape(d.interpolationPrefix):O.interpolationPrefixEscaped,f=d.interpolationSuffix?S.regexEscape(d.interpolationSuffix):O.interpolationSuffixEscaped,g="HTML"+f,h=b.replace&&"object"==typeof b.replace?b.replace:b;return S.each(h,function(b,h){var i=c?c+O.keyseparator+b:b;"object"==typeof h&&null!==h?a=v(a,h,i,d):d.escapeInterpolation||O.escapeInterpolation?(a=a.replace(new RegExp([e,i,g].join(""),"g"),S.regexReplacementEscape(h)),a=a.replace(new RegExp([e,i,f].join(""),"g"),S.regexReplacementEscape(S.escape(h)))):a=a.replace(new RegExp([e,i,f].join(""),"g"),S.regexReplacementEscape(h))}),a}function w(a,b){var c=",",d="{",e="}",f=S.extend({},b);for(delete f.postProcess;-1!=a.indexOf(O.reusePrefix)&&(K++,!(K>O.maxRecursion));){var g=a.lastIndexOf(O.reusePrefix),h=a.indexOf(O.reuseSuffix,g)+O.reuseSuffix.length,i=a.substring(g,h),j=i.replace(O.reusePrefix,"").replace(O.reuseSuffix,"");if(g>=h)return S.error("there is an missing closing in following translation value",a),"";if(-1!=j.indexOf(c)){var k=j.indexOf(c);if(-1!=j.indexOf(d,k)&&-1!=j.indexOf(e,k)){var l=j.indexOf(d,k),m=j.indexOf(e,l)+e.length;try{f=S.extend(f,JSON.parse(j.substring(l,m))),j=j.substring(0,k)}catch(n){}}}var o=E(j,f);a=a.replace(i,S.regexReplacementEscape(o))}return a}function x(a){return a.context&&("string"==typeof a.context||"number"==typeof a.context)}function y(a){return void 0!==a.count&&"string"!=typeof a.count}function z(a){return void 0!==a.indefinite_article&&"string"!=typeof a.indefinite_article&&a.indefinite_article}function A(a,b){b=b||{};var c=C(a,b),d=F(a,b);return void 0!==d||d===c}function B(a,b){return b=b||{},M?(K=0,E.apply(null,arguments)):(S.log("i18next not finished initialization. you might have called t function before loading resources finished."),b.defaultValue||"")}function C(a,b){return void 0!==b.defaultValue?b.defaultValue:a}function D(){for(var a=[],b=1;b1)for(var d=0;d-1&&(e=c.split(O.nsseparator),i=e[0],c=e[1]),void 0===g&&O.sendMissing&&"function"==typeof O.missingKeyHandler&&(b.lng?O.missingKeyHandler(h[0],i,c,f,h):O.missingKeyHandler(O.lng,i,c,f,h));var j;j="string"==typeof O.postProcess&&""!==O.postProcess?[O.postProcess]:"array"==typeof O.postProcess||"object"==typeof O.postProcess?O.postProcess:[],"string"==typeof b.postProcess&&""!==b.postProcess?j=j.concat([b.postProcess]):("array"==typeof b.postProcess||"object"==typeof b.postProcess)&&(j=j.concat(b.postProcess)),void 0!==g&&j.length&&j.forEach(function(a){W[a]&&(g=W[a](g,c,b))});var k=f;if(f.indexOf(O.nsseparator)>-1&&(e=f.split(O.nsseparator),k=e[1]),k===c&&O.parseMissingKey&&(f=O.parseMissingKey(f)),void 0===g&&(f=v(f,b),f=w(f,b),j.length)){var l=C(c,b);j.forEach(function(a){W[a]&&(g=W[a](l,c,b))})}return void 0!==g?g:f}function F(a,b){b=b||{};var c,d,e=C(a,b),f=L;if(!J)return e;if("cimode"===f[0].toLowerCase())return e;if(b.lngs&&(f=b.lngs),b.lng&&(f=S.toLanguages(b.lng,b.fallbackLng),!J[f[0]])){var g=O.getAsync;O.getAsync=!1,I.sync.load(f,O,function(a,b){S.extend(J,b),O.getAsync=g})}var h=b.ns||O.ns.defaultNs;if(a.indexOf(O.nsseparator)>-1){var i=a.split(O.nsseparator);h=i[0],a=i[1]}if(x(b)){c=S.extend({},b),delete c.context,c.defaultValue=O.contextNotFound;var j=h+O.nsseparator+a+"_"+b.context;if(d=B(j,c),d!=O.contextNotFound)return v(d,{context:b.context})}if(y(b,f[0])){c=S.extend({lngs:[f[0]]},b),delete c.count,c._origLng=c._origLng||c.lng||f[0],delete c.lng,c.defaultValue=O.pluralNotFound;var k;if(V.needsPlural(f[0],b.count)){k=h+O.nsseparator+a+O.pluralSuffix;var l=V.get(f[0],b.count);l>=0?k=k+"_"+l:1===l&&(k=h+O.nsseparator+a)}else k=h+O.nsseparator+a;if(d=B(k,c),d!=O.pluralNotFound)return v(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix});if(!(f.length>1))return c.lng=c._origLng,delete c._origLng,d=B(h+O.nsseparator+a,c),v(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix});var m=f.slice();if(m.shift(),b=S.extend(b,{lngs:m}),b._origLng=c._origLng,delete b.lng,d=B(h+O.nsseparator+a,b),d!=O.pluralNotFound)return d}if(z(b)){var n=S.extend({},b);delete n.indefinite_article,n.defaultValue=O.indefiniteNotFound;var o=h+O.nsseparator+a+(b.count&&!y(b,f[0])||!b.count?O.indefiniteSuffix:"");if(d=B(o,n),d!=O.indefiniteNotFound)return d}for(var p,q=a.split(O.keyseparator),r=0,s=f.length;s>r&&void 0===p;r++){for(var t=f[r],u=0,A=J[t]&&J[t][h];q[u];)A=A&&A[q[u]],u++;if(void 0!==A){var D=Object.prototype.toString.apply(A);if("string"==typeof A)A=v(A,b),A=w(A,b);else if("[object Array]"!==D||O.returnObjectTrees||b.returnObjectTrees){if(null===A&&O.fallbackOnNull===!0)A=void 0;else if(null!==A)if(O.returnObjectTrees||b.returnObjectTrees){if("[object Number]"!==D&&"[object Function]"!==D&&"[object RegExp]"!==D){var G="[object Array]"===D?[]:{};S.each(A,function(c){G[c]=E(h+O.nsseparator+a+O.keyseparator+c,b)}),A=G}}else O.objectTreeKeyHandler&&"function"==typeof O.objectTreeKeyHandler?A=O.objectTreeKeyHandler(a,A,t,h,b):(A="key '"+h+":"+a+" ("+t+")' returned an object instead of string.",S.log(A))}else A=A.join("\n"),A=v(A,b),A=w(A,b);"string"==typeof A&&""===A.trim()&&O.fallbackOnEmpty===!0&&(A=void 0),p=A}}if(void 0===p&&!b.isFallbackLookup&&(O.fallbackToDefaultNS===!0||O.fallbackNS&&O.fallbackNS.length>0)){if(b.isFallbackLookup=!0,O.fallbackNS.length){for(var H=0,K=O.fallbackNS.length;K>H;H++)if(p=F(O.fallbackNS[H]+O.nsseparator+a,b),p||""===p&&O.fallbackOnEmpty===!1){var M=p.indexOf(O.nsseparator)>-1?p.split(O.nsseparator)[1]:p,N=e.indexOf(O.nsseparator)>-1?e.split(O.nsseparator)[1]:e;if(M!==N)break}}else p=F(a,b);b.isFallbackLookup=!1}return p}function G(){var a,b=O.lngWhitelist||[],c=[];if("undefined"!=typeof window&&!function(){for(var a=window.location.search.substring(1),b=a.split("&"),d=0;d0){var f=b[d].substring(0,e);f==O.detectLngQS&&c.push(b[d].substring(e+1))}}}(),O.useCookie&&"undefined"!=typeof document){var d=S.cookie.read(O.cookieName);d&&c.push(d)}if(O.detectLngFromLocalStorage&&"undefined"!=typeof window&&window.localStorage&&c.push(S.localStorage.getItem("i18next_lng")),"undefined"!=typeof navigator){if(navigator.languages)for(var e=0;e-1){var f=e.split("-");e=O.lowerCaseLng?f[0].toLowerCase()+"-"+f[1].toLowerCase():f[0].toLowerCase()+"-"+f[1].toUpperCase()}if(0===b.length||b.indexOf(e)>-1){a=e;break}}}(),a||(a=O.fallbackLng[0]),a}Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>0&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=c;arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d))));for(var e=d>=0?Math.min(d,c-1):c-Math.abs(d);e>=0;e--)if(e in b&&b[e]===a)return e;return-1}),"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")});var H,I={},J={},K=0,L=[],M=!1,N={};N={load:function(a,b,c){b.useLocalStorage?N._loadLocal(a,b,function(d,e){for(var f=[],g=0,h=a.length;h>g;g++)e[a[g]]||f.push(a[g]);f.length>0?N._fetch(f,b,function(a,b){S.extend(e,b),N._storeLocal(b),c(null,e)}):c(null,e)}):N._fetch(a,b,function(a,b){c(null,b)})},_loadLocal:function(a,b,c){var d={},e=(new Date).getTime();if(window.localStorage){var f=a.length;S.each(a,function(a,g){var h=S.localStorage.getItem("res_"+g);h&&(h=JSON.parse(h),h.i18nStamp&&h.i18nStamp+b.localStorageExpirationTime>e&&(d[g]=h)),f--,0===f&&c(null,d)})}},_storeLocal:function(a){if(window.localStorage)for(var b in a)a[b].i18nStamp=(new Date).getTime(),S.localStorage.setItem("res_"+b,JSON.stringify(a[b]))},_fetch:function(a,b,c){var d=b.ns,e={};if(b.dynamicLoad){var f=function(a,b){c(null,b)};if("function"==typeof b.customLoad)b.customLoad(a,d.namespaces,b,f);else{var g=v(b.resGetPath,{lng:a.join("+"),ns:d.namespaces.join("+")});S.ajax({url:g,success:function(a){S.log("loaded: "+g),f(null,a)},error:function(a,b,c){S.log("failed loading: "+g),f("failed loading resource.json error: "+c)},dataType:"json",async:b.getAsync})}}else{var h,i=d.namespaces.length*a.length;S.each(d.namespaces,function(d,f){S.each(a,function(a,d){var g=function(a,b){a&&(h=h||[],h.push(a)),e[d]=e[d]||{},e[d][f]=b,i--,0===i&&c(h,e)};"function"==typeof b.customLoad?b.customLoad(d,f,b,g):N._fetchOne(d,f,b,g)})})}},_fetchOne:function(a,b,c,d){var e=v(c.resGetPath,{lng:a,ns:b});S.ajax({url:e,success:function(a){S.log("loaded: "+e),d(null,a)},error:function(a,b,c){if(b&&200==b||a&&a.status&&200==a.status)S.error("There is a typo in: "+e);else if(b&&404==b||a&&a.status&&404==a.status)S.log("Does not exist: "+e);else{var f=b?b:a&&a.status?a.status:null;S.log(f+" when loading "+e)}d(c,{})},dataType:"json",async:c.getAsync})},postMissing:function(a,b,c,d,e){var f={};f[c]=d;var g=[];if("fallback"===O.sendMissingTo&&O.fallbackLng[0]!==!1)for(var h=0;hh;h++)g.push({lng:e[h],url:v(O.resPostPath,{lng:e[h],ns:b})});for(var j=0,k=g.length;k>j;j++){var l=g[j];S.ajax({url:l.url,type:O.sendType,data:f,success:function(){S.log("posted missing key '"+c+"' to: "+l.url);for(var a=c.split("."),e=0,f=J[l.lng][b];a[e];)f=f[a[e]]=e===a.length-1?d:f[a[e]]||{},e++},error:function(){S.log("failed posting missing key '"+c+"' to: "+l.url)},dataType:"json",async:O.postAsync})}},reload:t};var O={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:["dev"],fallbackNS:[],detectLngQS:"setLng",detectLngFromLocalStorage:!1,ns:{namespaces:["translation"],defaultNs:"translation"},fallbackOnNull:!0,fallbackOnEmpty:!1,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",defaultVariables:!1,reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,indefiniteSuffix:"_indefinite",indefiniteNotFound:["indefinite_not_found",Math.random()].join(""),setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",cookieDomain:void 0,objectTreeKeyHandler:void 0,postProcess:void 0,parseMissingKey:void 0,missingKeyHandler:N.postMissing,shortcutFunction:"sprintf"},P={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},Q={create:function(a,b,c,d){var e;if(c){var f=new Date;f.setTime(f.getTime()+60*c*1e3),e="; expires="+f.toGMTString()}else e="";d=d?"domain="+d+";":"",document.cookie=a+"="+b+e+";"+d+"path=/"},read:function(a){for(var b=a+"=",c=document.cookie.split(";"),d=0;d-1){var c=a.split("-");b=O.lowerCaseLng?c[0].toLowerCase()+"-"+c[1].toLowerCase():c[0].toLowerCase()+"-"+c[1].toUpperCase()}else b=O.lowerCaseLng?a.toLowerCase():a;return b}var c=this.log,d=[],e=O.lngWhitelist||!1,f=function(a){!e||e.indexOf(a)>-1?d.push(a):c("rejecting non-whitelisted language: "+a)};if("string"==typeof a&&a.indexOf("-")>-1){var g=a.split("-");"unspecific"!==O.load&&f(b(a)),"current"!==O.load&&f(b(g[this.getCountyIndexOfLng(a)]))}else f(b(a));for(var h=0;h1)},2:function(a){return Number(1!=a)},3:function(){return 0},4:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},5:function(a){return Number(0===a?0:1==a?1:2==a?2:a%100>=3&&10>=a%100?3:a%100>=11?4:5)},6:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)},7:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},8:function(a){return Number(1==a?0:2==a?1:8!=a&&11!=a?2:3)},9:function(a){return Number(a>=2)},10:function(a){return Number(1==a?0:2==a?1:7>a?2:11>a?3:4)},11:function(a){return Number(1==a||11==a?0:2==a||12==a?1:a>2&&20>a?2:3)},12:function(a){return Number(a%10!=1||a%100==11)},13:function(a){return Number(0!==a)},14:function(a){return Number(1==a?0:2==a?1:3==a?2:3)},15:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&(10>a%100||a%100>=20)?1:2)},16:function(a){return Number(a%10==1&&a%100!=11?0:0!==a?1:2)},17:function(a){return Number(1==a||a%10==1?0:1)},18:function(a){return Number(1==a?1:2)},19:function(a){return Number(1==a?0:0===a||a%100>1&&11>a%100?1:a%100>10&&20>a%100?2:3)},20:function(a){return Number(1==a?0:0===a||a%100>0&&20>a%100?1:2)},21:function(a){return Number(a%100==1?1:a%100==2?2:a%100==3||a%100==4?3:0)}},V={rules:function(){var a,b={};for(a=T.length;a--;)b[T[a][0]]={name:T[a][1],numbers:T[a][2],plurals:U[T[a][3]]};return b}(),addRule:function(a,b){V.rules[a]=b},setCurrentLng:function(a){if(!V.currentRule||V.currentRule.lng!==a){var b=a.split("-");V.currentRule={lng:a,rule:V.rules[b[0]]}}},needsPlural:function(a,b){var c,d=a.split("-");return c=V.currentRule&&V.currentRule.lng===a?V.currentRule.rule:V.rules[d[S.getCountyIndexOfLng(a)]],c&&c.numbers.length<=1?!1:1!==this.get(a,b)},get:function(a,b){function c(b,c){var d;if(d=V.currentRule&&V.currentRule.lng===a?V.currentRule.rule:V.rules[b]){var e;e=d.plurals(d.noAbs?c:Math.abs(c));var f=d.numbers[e];return 2===d.numbers.length&&1===d.numbers[0]&&(2===f?f=-1:1===f&&(f=1)),f}return 1===c?"1":"-1"}var d=a.split("-");return c(d[S.getCountyIndexOfLng(a)],b)}},W={},X=function(a,b){W[a]=b},Y=function(){function a(a){return Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}function b(a,b){for(var c=[];b>0;c[--b]=a);return c.join("")}var c=function(){return c.cache.hasOwnProperty(arguments[0])||(c.cache[arguments[0]]=c.parse(arguments[0])),c.format.call(null,c.cache[arguments[0]],arguments)};return c.format=function(c,d){var e,f,g,h,i,j,k,l=1,m=c.length,n="",o=[];for(f=0;m>f;f++)if(n=a(c[f]),"string"===n)o.push(c[f]);else if("array"===n){if(h=c[f],h[2])for(e=d[l],g=0;g=0?"+"+e:e,j=h[4]?"0"==h[4]?"0":h[4].charAt(1):" ",k=h[6]-String(e).length,i=h[6]?b(j,k):"",o.push(h[5]?e+i:i+e)}return o.join("")},c.cache={},c.parse=function(a){for(var b=a,c=[],d=[],e=0;b;){if(null!==(c=/^[^\x25]+/.exec(b)))d.push(c[0]);else if(null!==(c=/^\x25{2}/.exec(b)))d.push("%");else{if(null===(c=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(b)))throw"[sprintf] huh?";if(c[2]){e|=1;var f=[],g=c[2],h=[];if(null===(h=/^([a-z_][a-z_\d]*)/i.exec(g)))throw"[sprintf] huh?";for(f.push(h[1]);""!==(g=g.substring(h[0].length));)if(null!==(h=/^\.([a-z_][a-z_\d]*)/i.exec(g)))f.push(h[1]);else{if(null===(h=/^\[(\d+)\]/.exec(g)))throw"[sprintf] huh?";f.push(h[1])}c[2]=f}else e|=2;if(3===e)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";d.push(c)}b=b.substring(c[0].length)}return d},c}(),Z=function(a,b){return b.unshift(a),Y.apply(null,b)};return X("sprintf",function(a,b,c){return c.sprintf?"[object Array]"===Object.prototype.toString.apply(c.sprintf)?Z(a,c.sprintf):"object"==typeof c.sprintf?Y(a,c.sprintf):a:a}),I.init=g,I.setLng=r,I.preload=h,I.addResourceBundle=i,I.hasResourceBundle=j,I.getResourceBundle=k,I.addResource=m,I.addResources=n,I.removeResourceBundle=l,I.loadNamespace=p,I.loadNamespaces=q,I.setDefaultNamespace=o,I.t=B,I.translate=B,I.exists=A,I.detectLanguage=S.detectLanguage,I.pluralExtensions=V,I.sync=N,I.functions=S,I.lng=s,I.addPostProcessor=X,I.applyReplacement=S.applyReplacement,I.options=O,a.i18n=I,a.t=I.t,I}); \ No newline at end of file diff --git a/libs/i18next/release/i18next.commonjs.withJQuery-1.8.0.js b/libs/i18next/release/i18next.commonjs.withJQuery-1.8.0.js new file mode 100644 index 00000000..fc738701 --- /dev/null +++ b/libs/i18next/release/i18next.commonjs.withJQuery-1.8.0.js @@ -0,0 +1,4 @@ +// i18next, v1.8.0 +// Copyright (c)2015 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com diff --git a/libs/i18next/release/i18next.commonjs.withJQuery-1.8.0.min.js b/libs/i18next/release/i18next.commonjs.withJQuery-1.8.0.min.js new file mode 100644 index 00000000..fc738701 --- /dev/null +++ b/libs/i18next/release/i18next.commonjs.withJQuery-1.8.0.min.js @@ -0,0 +1,4 @@ +// i18next, v1.8.0 +// Copyright (c)2015 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com diff --git a/libs/i18next/release/i18next.commonjs.withJQuery-1.8.1.js b/libs/i18next/release/i18next.commonjs.withJQuery-1.8.1.js new file mode 100644 index 00000000..d340e1f6 --- /dev/null +++ b/libs/i18next/release/i18next.commonjs.withJQuery-1.8.1.js @@ -0,0 +1,2183 @@ +// i18next, v1.8.1 +// Copyright (c)2015 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function(root) { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + // Add string trim for IE8. + if (typeof String.prototype.trim !== 'function') { + String.prototype.trim = function() { + return this.replace(/^\s+|\s+$/g, ''); + } + } + + var $ = root.jQuery || root.Zepto + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = [] + , initialized = false + , sync = {}; + + + + // Export the i18next object for **CommonJS**. + // If we're not in CommonJS, add `i18n` to the + // global object or to jquery. + if (typeof module !== 'undefined' && module.exports) { + module.exports = i18n; + if (!$) { + try { + $ = require('jquery'); + } catch(e) { + // just ignore + } + } + + } else { + root.i18n = root.i18n || i18n; + } + + if ($) { + $.i18n = $.i18n || i18n; + } + sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = f.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + f.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + if ((status && status == 200) || (xhr && xhr.status && xhr.status == 200)) { + // file loaded but invalid json, stop waste time ! + f.error('There is a typo in: ' + url); + } else if ((status && status == 404) || (xhr && xhr.status && xhr.status == 404)) { + f.log('Does not exist: ' + url); + } else { + var theStatus = status ? status : ((xhr && xhr.status) ? xhr.status : null); + f.log(theStatus + ' when loading ' + url); + } + + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback' && o.fallbackLng[0] !== false) { + for (var i = 0; i < o.fallbackLng.length; i++) { + urls.push({lng: o.fallbackLng[i], url: applyReplacement(o.resPostPath, { lng: o.fallbackLng[i], ns: ns })}); + } + } else if (o.sendMissingTo === 'current' || (o.sendMissingTo === 'fallback' && o.fallbackLng[0] === false) ) { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + }, + + reload: reload + }; + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: ['dev'], + fallbackNS: [], + detectLngQS: 'setLng', + detectLngFromLocalStorage: false, + ns: 'translation', + fallbackOnNull: true, + fallbackOnEmpty: false, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + defaultVariables: false, + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + indefiniteSuffix: '_indefinite', + indefiniteNotFound: ['indefinite_not_found', Math.random()].join(''), + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + cookieDomain: undefined, + + objectTreeKeyHandler: undefined, + postProcess: undefined, + parseMissingKey: undefined, + missingKeyHandler: sync.postMissing, + + shortcutFunction: 'sprintf' // or: defaultValue + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _deepExtend(target, source) { + for (var prop in source) + if (prop in target) + _deepExtend(target[prop], source[prop]); + else + target[prop] = source[prop]; + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || Object.prototype.toString.apply(object) !== '[object Array]' || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + try { + return JSON.parse(data) + } catch (e) { + f.error('Can not parse JSON. URL: ' + url); + return {}; + } + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + // file: protocol always gives status code 0, so check for data + if (status === 200 || (status === 0 && data.text())) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes,domain) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + domain = (domain)? "domain="+domain+";" : ""; + document.cookie = name+"="+value+expires+";"+domain+"path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes,domain) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + deepExtend: _deepExtend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : (typeof document !== 'undefined' ? _ajax : function() {}), + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + error: function(str) { + if (typeof console !== "undefined") console.error(str); + }, + getCountyIndexOfLng: function(lng) { + var lng_index = 0; + if (lng === 'nb-NO' || lng === 'nn-NO' || lng === 'nb-no' || lng === 'nn-no') lng_index = 1; + return lng_index; + }, + toLanguages: function(lng) { + var log = this.log; + + function applyCase(l) { + var ret = l; + + if (typeof l === 'string' && l.indexOf('-') > -1) { + var parts = l.split('-'); + + ret = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } else { + ret = o.lowerCaseLng ? l.toLowerCase() : l; + } + + return ret; + } + + var languages = []; + var whitelist = o.lngWhitelist || false; + var addLanguage = function(language){ + //reject langs not whitelisted + if(!whitelist || whitelist.indexOf(language) > -1){ + languages.push(language); + }else{ + log('rejecting non-whitelisted language: ' + language); + } + }; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + if (o.load !== 'unspecific') addLanguage(applyCase(lng)); + if (o.load !== 'current') addLanguage(applyCase(parts[this.getCountyIndexOfLng(lng)])); + } else { + addLanguage(applyCase(lng)); + } + + for (var i = 0; i < o.fallbackLng.length; i++) { + if (languages.indexOf(o.fallbackLng[i]) === -1 && o.fallbackLng[i]) languages.push(applyCase(o.fallbackLng[i])); + } + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + }, + regexReplacementEscape: function(strOrFn) { + if (typeof strOrFn === 'string') { + return strOrFn.replace(/\$/g, "$$$$"); + } else { + return strOrFn; + } + }, + localStorage: { + setItem: function(key, value) { + if (window.localStorage) { + try { + window.localStorage.setItem(key, value); + } catch (e) { + f.log('failed to set value for key "' + key + '" to localStorage.'); + } + } + }, + getItem: function(key, value) { + if (window.localStorage) { + try { + return window.localStorage.getItem(key, value); + } catch (e) { + f.log('failed to get value for key "' + key + '" from localStorage.'); + return undefined; + } + } + } + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + delete o.fixLng; /* passed in each time */ + + // override functions: .log(), .detectLanguage(), etc + if (o.functions) { + delete o.functions; + f.extend(f, options.functions); + } + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // fallback languages + if (typeof o.fallbackLng == 'string' || typeof o.fallbackLng == 'boolean') { + o.fallbackLng = [o.fallbackLng]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + if (o.useCookie && f.cookie.read(o.cookieName) !== currentLng){ //cookie is unset or invalid + f.cookie.create(o.cookieName, currentLng, o.cookieExpirationTime, o.cookieDomain); + } + if (o.detectLngFromLocalStorage && typeof document !== 'undefined' && window.localStorage) { + f.localStorage.setItem('i18next_lng', currentLng); + } + + var lngTranslate = translate; + if (options.fixLng) { + lngTranslate = function(key, options) { + options = options || {}; + options.lng = options.lng || lngTranslate.lng; + return translate(key, options); + }; + lngTranslate.lng = currentLng; + } + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + initialized = true; + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + initialized = true; + + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources, deep) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + if (deep) { + f.deepExtend(resStore[lng][ns], resources); + } else { + f.extend(resStore[lng][ns], resources); + } + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function hasResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + var res = resStore[lng][ns] || {}; + + var hasValues = false; + for(var prop in res) { + if (res.hasOwnProperty(prop)) { + hasValues = true; + } + } + + return hasValues; + } + + function getResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + return f.extend({}, resStore[lng][ns]); + } + + function removeResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = {}; + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function addResource(lng, ns, key, value) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + var keys = key.split(o.keyseparator); + var x = 0; + var node = resStore[lng][ns]; + var origRef = node; + + while (keys[x]) { + if (x == keys.length - 1) + node[keys[x]] = value; + else { + if (node[keys[x]] == null) + node[keys[x]] = {}; + + node = node[keys[x]]; + } + x++; + } + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function addResources(lng, ns, resources) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + for (var m in resources) { + if (typeof resources[m] === 'string') addResource(lng, ns, m, resources[m]); + } + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, options, cb) { + if (typeof options === 'function') { + cb = options; + options = {}; + } else if (!options) { + options = {}; + } + + options.lng = lng; + return init(options, cb); + } + + function lng() { + return currentLng; + } + + function reload(cb) { + resStore = {}; + setLng(currentLng, cb); + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else if (attr === 'prepend') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.prepend($.t(key, optionsToUse)); + } else if (attr === 'append') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.append($.t(key, optionsToUse)); + } else if (attr.indexOf("data-") === 0) { + var dataAttr = attr.substr(("data-").length); + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.data(dataAttr) }, options) : options; + var translated = $.t(key, optionsToUse); + //we change into the data cache + ele.data(dataAttr, translated); + //we change into the dom + ele.attr(attr, translated); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key && typeof key !== 'undefined' && key !== false) key = ele.text() || ele.val(); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + var hash = replacementHash.replace && typeof replacementHash.replace === 'object' ? replacementHash.replace : replacementHash; + f.each(hash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), f.regexReplacementEscape(value)); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(f.escape(value))); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(value)); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + if (index_of_end_of_closing <= index_of_opening) { + f.error('there is an missing closing in following translation value', translated); + return ''; + } + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, f.regexReplacementEscape(translated_token)); + } + return translated; + } + + function hasContext(options) { + return (options.context && (typeof options.context == 'string' || typeof options.context == 'number')); + } + + function needsPlural(options, lng) { + return (options.count !== undefined && typeof options.count != 'string'/* && pluralExtensions.needsPlural(lng, options.count)*/); + } + + function needsIndefiniteArticle(options) { + return (options.indefinite_article !== undefined && typeof options.indefinite_article != 'string' && options.indefinite_article); + } + + function exists(key, options) { + options = options || {}; + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + options = options || {}; + + if (!initialized) { + f.log('i18next not finished initialization. you might have called t function before loading resources finished.') + return options.defaultValue || ''; + }; + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _getDefaultValue(key, options) { + return (options.defaultValue !== undefined) ? options.defaultValue : key; + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(potentialKeys, options) { + if (options && typeof options !== 'object') { + if (o.shortcutFunction === 'sprintf') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else if (o.shortcutFunction === 'defaultValue') { + options = { + defaultValue: options + } + } + } else { + options = options || {}; + } + + if (typeof o.defaultVariables === 'object') { + options = f.extend({}, o.defaultVariables, options); + } + + if (potentialKeys === undefined || potentialKeys === null || potentialKeys === '') return ''; + + if (typeof potentialKeys === 'number') { + potentialKeys = String(potentialKeys); + } + + if (typeof potentialKeys === 'string') { + potentialKeys = [potentialKeys]; + } + + var key = potentialKeys[0]; + + if (potentialKeys.length > 1) { + for (var i = 0; i < potentialKeys.length; i++) { + key = potentialKeys[i]; + if (exists(key, options)) { + break; + } + } + } + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng, options.fallbackLng) : languages + , ns = options.ns || o.ns.defaultNs + , parts; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing && typeof o.missingKeyHandler === 'function') { + if (options.lng) { + o.missingKeyHandler(lngs[0], ns, key, notFound, lngs); + } else { + o.missingKeyHandler(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessorsToApply; + if (typeof o.postProcess === 'string' && o.postProcess !== '') { + postProcessorsToApply = [o.postProcess]; + } else if (typeof o.postProcess === 'array' || typeof o.postProcess === 'object') { + postProcessorsToApply = o.postProcess; + } else { + postProcessorsToApply = []; + } + + if (typeof options.postProcess === 'string' && options.postProcess !== '') { + postProcessorsToApply = postProcessorsToApply.concat([options.postProcess]); + } else if (typeof options.postProcess === 'array' || typeof options.postProcess === 'object') { + postProcessorsToApply = postProcessorsToApply.concat(options.postProcess); + } + + if (found !== undefined && postProcessorsToApply.length) { + postProcessorsToApply.forEach(function(postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + }); + } + + // process notFound if function exists + var splitNotFound = notFound; + if (notFound.indexOf(o.nsseparator) > -1) { + parts = notFound.split(o.nsseparator); + splitNotFound = parts[1]; + } + if (splitNotFound === key && o.parseMissingKey) { + notFound = o.parseMissingKey(notFound); + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessorsToApply.length) { + var val = _getDefaultValue(key, options); + postProcessorsToApply.forEach(function(postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](val, key, options); + } + }); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options) { + options = options || {}; + + var optionWithoutCount, translated + , notFound = _getDefaultValue(key, options) + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + // CI mode + if (lngs[0].toLowerCase() === 'cimode') return notFound; + + // passed in lng + if (options.lngs) lngs = options.lngs; + if (options.lng) { + lngs = f.toLanguages(options.lng, options.fallbackLng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options, lngs[0])) { + optionWithoutCount = f.extend({ lngs: [lngs[0]]}, options); + delete optionWithoutCount.count; + optionWithoutCount._origLng = optionWithoutCount._origLng || optionWithoutCount.lng || lngs[0]; + delete optionWithoutCount.lng; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey; + if (!pluralExtensions.needsPlural(lngs[0], options.count)) { + pluralKey = ns + o.nsseparator + key; + } else { + pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(lngs[0], options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + } + + translated = translate(pluralKey, optionWithoutCount); + + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } else if (lngs.length > 1) { + // remove failed lng + var clone = lngs.slice(); + clone.shift(); + options = f.extend(options, { lngs: clone }); + options._origLng = optionWithoutCount._origLng; + delete options.lng; + // retry with fallbacks + translated = translate(ns + o.nsseparator + key, options); + if (translated != o.pluralNotFound) return translated; + } else { + optionWithoutCount.lng = optionWithoutCount._origLng; + delete optionWithoutCount._origLng; + translated = translate(ns + o.nsseparator + key, optionWithoutCount); + + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); + } + } + + if (needsIndefiniteArticle(options)) { + var optionsWithoutIndef = f.extend({}, options); + delete optionsWithoutIndef.indefinite_article; + optionsWithoutIndef.defaultValue = o.indefiniteNotFound; + // If we don't have a count, we want the indefinite, if we do have a count, and needsPlural is false + var indefiniteKey = ns + o.nsseparator + key + (((options.count && !needsPlural(options, lngs[0])) || !options.count) ? o.indefiniteSuffix : ""); + translated = translate(indefiniteKey, optionsWithoutIndef); + if (translated != o.indefiniteNotFound) { + return translated; + } + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + var valueType = Object.prototype.toString.apply(value); + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (valueType === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + if (o.objectTreeKeyHandler && typeof o.objectTreeKeyHandler == 'function') { + value = o.objectTreeKeyHandler(key, value, l, ns, options); + } else { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned an object instead of string.'; + f.log(value); + } + } else if (valueType !== '[object Number]' && valueType !== '[object Function]' && valueType !== '[object RegExp]') { + var copy = (valueType === '[object Array]') ? [] : {}; // apply child translation on a copy + f.each(value, function(m) { + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + }); + value = copy; + } + } + + if (typeof value === 'string' && value.trim() === '' && o.fallbackOnEmpty === true) + value = undefined; + + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length > 0))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found || (found==="" && o.fallbackOnEmpty === false)) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + options.isFallbackLookup = false; + } + + return found; + } + function detectLanguage() { + var detectedLng; + var whitelist = o.lngWhitelist || []; + var userLngChoices = []; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var params = query.split('&'); + for (var i=0; i 0) { + var key = params[i].substring(0,pos); + if (key == o.detectLngQS) { + userLngChoices.push(params[i].substring(pos+1)); + } + } + } + })(); + } + + // get from cookie + if (o.useCookie && typeof document !== 'undefined') { + var c = f.cookie.read(o.cookieName); + if (c) userLngChoices.push(c); + } + + // get from localStorage + if (o.detectLngFromLocalStorage && typeof window !== 'undefined' && window.localStorage) { + userLngChoices.push(f.localStorage.getItem('i18next_lng')); + } + + // get from navigator + if (typeof navigator !== 'undefined') { + if (navigator.languages) { // chrome only; not an array, so can't use .push.apply instead of iterating + for (var i=0;i -1) { + var parts = lng.split('-'); + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } + + if (whitelist.length === 0 || whitelist.indexOf(lng) > -1) { + detectedLng = lng; + break; + } + } + })(); + + //fallback + if (!detectedLng){ + detectedLng = o.fallbackLng[0]; + } + + return detectedLng; + } + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + + /* [code, name, numbers, pluralsType] */ + var _rules = [ + ["ach", "Acholi", [1,2], 1], + ["af", "Afrikaans",[1,2], 2], + ["ak", "Akan", [1,2], 1], + ["am", "Amharic", [1,2], 1], + ["an", "Aragonese",[1,2], 2], + ["ar", "Arabic", [0,1,2,3,11,100],5], + ["arn", "Mapudungun",[1,2], 1], + ["ast", "Asturian", [1,2], 2], + ["ay", "Aymará", [1], 3], + ["az", "Azerbaijani",[1,2],2], + ["be", "Belarusian",[1,2,5],4], + ["bg", "Bulgarian",[1,2], 2], + ["bn", "Bengali", [1,2], 2], + ["bo", "Tibetan", [1], 3], + ["br", "Breton", [1,2], 1], + ["bs", "Bosnian", [1,2,5],4], + ["ca", "Catalan", [1,2], 2], + ["cgg", "Chiga", [1], 3], + ["cs", "Czech", [1,2,5],6], + ["csb", "Kashubian",[1,2,5],7], + ["cy", "Welsh", [1,2,3,8],8], + ["da", "Danish", [1,2], 2], + ["de", "German", [1,2], 2], + ["dev", "Development Fallback", [1,2], 2], + ["dz", "Dzongkha", [1], 3], + ["el", "Greek", [1,2], 2], + ["en", "English", [1,2], 2], + ["eo", "Esperanto",[1,2], 2], + ["es", "Spanish", [1,2], 2], + ["es_ar","Argentinean Spanish", [1,2], 2], + ["et", "Estonian", [1,2], 2], + ["eu", "Basque", [1,2], 2], + ["fa", "Persian", [1], 3], + ["fi", "Finnish", [1,2], 2], + ["fil", "Filipino", [1,2], 1], + ["fo", "Faroese", [1,2], 2], + ["fr", "French", [1,2], 9], + ["fur", "Friulian", [1,2], 2], + ["fy", "Frisian", [1,2], 2], + ["ga", "Irish", [1,2,3,7,11],10], + ["gd", "Scottish Gaelic",[1,2,3,20],11], + ["gl", "Galician", [1,2], 2], + ["gu", "Gujarati", [1,2], 2], + ["gun", "Gun", [1,2], 1], + ["ha", "Hausa", [1,2], 2], + ["he", "Hebrew", [1,2], 2], + ["hi", "Hindi", [1,2], 2], + ["hr", "Croatian", [1,2,5],4], + ["hu", "Hungarian",[1,2], 2], + ["hy", "Armenian", [1,2], 2], + ["ia", "Interlingua",[1,2],2], + ["id", "Indonesian",[1], 3], + ["is", "Icelandic",[1,2], 12], + ["it", "Italian", [1,2], 2], + ["ja", "Japanese", [1], 3], + ["jbo", "Lojban", [1], 3], + ["jv", "Javanese", [0,1], 13], + ["ka", "Georgian", [1], 3], + ["kk", "Kazakh", [1], 3], + ["km", "Khmer", [1], 3], + ["kn", "Kannada", [1,2], 2], + ["ko", "Korean", [1], 3], + ["ku", "Kurdish", [1,2], 2], + ["kw", "Cornish", [1,2,3,4],14], + ["ky", "Kyrgyz", [1], 3], + ["lb", "Letzeburgesch",[1,2],2], + ["ln", "Lingala", [1,2], 1], + ["lo", "Lao", [1], 3], + ["lt", "Lithuanian",[1,2,10],15], + ["lv", "Latvian", [1,2,0],16], + ["mai", "Maithili", [1,2], 2], + ["mfe", "Mauritian Creole",[1,2],1], + ["mg", "Malagasy", [1,2], 1], + ["mi", "Maori", [1,2], 1], + ["mk", "Macedonian",[1,2],17], + ["ml", "Malayalam",[1,2], 2], + ["mn", "Mongolian",[1,2], 2], + ["mnk", "Mandinka", [0,1,2],18], + ["mr", "Marathi", [1,2], 2], + ["ms", "Malay", [1], 3], + ["mt", "Maltese", [1,2,11,20],19], + ["nah", "Nahuatl", [1,2], 2], + ["nap", "Neapolitan",[1,2], 2], + ["nb", "Norwegian Bokmal",[1,2],2], + ["ne", "Nepali", [1,2], 2], + ["nl", "Dutch", [1,2], 2], + ["nn", "Norwegian Nynorsk",[1,2],2], + ["no", "Norwegian",[1,2], 2], + ["nso", "Northern Sotho",[1,2],2], + ["oc", "Occitan", [1,2], 1], + ["or", "Oriya", [2,1], 2], + ["pa", "Punjabi", [1,2], 2], + ["pap", "Papiamento",[1,2], 2], + ["pl", "Polish", [1,2,5],7], + ["pms", "Piemontese",[1,2], 2], + ["ps", "Pashto", [1,2], 2], + ["pt", "Portuguese",[1,2], 2], + ["pt_br","Brazilian Portuguese",[1,2], 2], + ["rm", "Romansh", [1,2], 2], + ["ro", "Romanian", [1,2,20],20], + ["ru", "Russian", [1,2,5],4], + ["sah", "Yakut", [1], 3], + ["sco", "Scots", [1,2], 2], + ["se", "Northern Sami",[1,2], 2], + ["si", "Sinhala", [1,2], 2], + ["sk", "Slovak", [1,2,5],6], + ["sl", "Slovenian",[5,1,2,3],21], + ["so", "Somali", [1,2], 2], + ["son", "Songhay", [1,2], 2], + ["sq", "Albanian", [1,2], 2], + ["sr", "Serbian", [1,2,5],4], + ["su", "Sundanese",[1], 3], + ["sv", "Swedish", [1,2], 2], + ["sw", "Swahili", [1,2], 2], + ["ta", "Tamil", [1,2], 2], + ["te", "Telugu", [1,2], 2], + ["tg", "Tajik", [1,2], 1], + ["th", "Thai", [1], 3], + ["ti", "Tigrinya", [1,2], 1], + ["tk", "Turkmen", [1,2], 2], + ["tr", "Turkish", [1,2], 1], + ["tt", "Tatar", [1], 3], + ["ug", "Uyghur", [1], 3], + ["uk", "Ukrainian",[1,2,5],4], + ["ur", "Urdu", [1,2], 2], + ["uz", "Uzbek", [1,2], 1], + ["vi", "Vietnamese",[1], 3], + ["wa", "Walloon", [1,2], 1], + ["wo", "Wolof", [1], 3], + ["yo", "Yoruba", [1,2], 2], + ["zh", "Chinese", [1], 3] + ]; + + var _rulesPluralsTypes = { + 1: function(n) {return Number(n > 1);}, + 2: function(n) {return Number(n != 1);}, + 3: function(n) {return 0;}, + 4: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 5: function(n) {return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5);}, + 6: function(n) {return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2);}, + 7: function(n) {return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 8: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3);}, + 9: function(n) {return Number(n >= 2);}, + 10: function(n) {return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;}, + 11: function(n) {return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3);}, + 12: function(n) {return Number(n%10!=1 || n%100==11);}, + 13: function(n) {return Number(n !== 0);}, + 14: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3);}, + 15: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 16: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2);}, + 17: function(n) {return Number(n==1 || n%10==1 ? 0 : 1);}, + 18: function(n) {return Number(0 ? 0 : n==1 ? 1 : 2);}, + 19: function(n) {return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3);}, + 20: function(n) {return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2);}, + 21: function(n) {return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }; + + var pluralExtensions = { + + rules: (function () { + var l, rules = {}; + for (l=_rules.length; l-- ;) { + rules[_rules[l][0]] = { + name: _rules[l][1], + numbers: _rules[l][2], + plurals: _rulesPluralsTypes[_rules[l][3]] + } + } + return rules; + }()), + + // you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + needsPlural: function(lng, count) { + var parts = lng.split('-'); + + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[parts[f.getCountyIndexOfLng(lng)]]; + } + + if (ext && ext.numbers.length <= 1) { + return false; + } else { + return this.get(lng, count) !== 1; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i; + if (ext.noAbs) { + i = ext.plurals(c); + } else { + i = ext.plurals(Math.abs(c)); + } + + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[f.getCountyIndexOfLng(lng)], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.hasResourceBundle = hasResourceBundle; + i18n.getResourceBundle = getResourceBundle; + i18n.addResource = addResource; + i18n.addResources = addResources; + i18n.removeResourceBundle = removeResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.applyReplacement = f.applyReplacement; + i18n.options = o; + +})(typeof exports === 'undefined' ? window : exports); \ No newline at end of file diff --git a/libs/i18next/release/i18next.commonjs.withJQuery-1.8.1.min.js b/libs/i18next/release/i18next.commonjs.withJQuery-1.8.1.min.js new file mode 100644 index 00000000..5f24ea55 --- /dev/null +++ b/libs/i18next/release/i18next.commonjs.withJQuery-1.8.1.min.js @@ -0,0 +1,5 @@ +// i18next, v1.8.1 +// Copyright (c)2015 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +!function(a){function b(a,b){if(!b||"function"==typeof b)return a;for(var c in b)a[c]=b[c];return a}function c(a,b){for(var d in b)d in a?c(a[d],b[d]):a[d]=b[d];return a}function d(a,b,c){var d,e=0,f=a.length,g=void 0===f||"[object Array]"!==Object.prototype.toString.apply(a)||"function"==typeof a;if(c)if(g){for(d in a)if(b.apply(a[d],c)===!1)break}else for(;f>e&&b.apply(a[e++],c)!==!1;);else if(g){for(d in a)if(b.call(a[d],d,a[d])===!1)break}else for(;f>e&&b.call(a[e],e,a[e++])!==!1;);return a}function e(a){return"string"==typeof a?a.replace(/[&<>"'\/]/g,function(a){return R[a]}):a}function f(a){var b=function(a){if(window.XMLHttpRequest)return a(null,new XMLHttpRequest);if(window.ActiveXObject)try{return a(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(b){return a(null,new ActiveXObject("Microsoft.XMLHTTP"))}return a(new Error)},c=function(a){if("string"==typeof a)return a;var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")},d=function(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;cd?b+=String.fromCharCode(d):d>127&&2048>d?(b+=String.fromCharCode(d>>6|192),b+=String.fromCharCode(63&d|128)):(b+=String.fromCharCode(d>>12|224),b+=String.fromCharCode(d>>6&63|128),b+=String.fromCharCode(63&d|128))}return b},e=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";a=d(a);var c,e,f,g,h,i,j,k="",l=0;do c=a.charCodeAt(l++),e=a.charCodeAt(l++),f=a.charCodeAt(l++),g=c>>2,h=(3&c)<<4|e>>4,i=(15&e)<<2|f>>6,j=63&f,isNaN(e)?i=j=64:isNaN(f)&&(j=64),k+=b.charAt(g)+b.charAt(h)+b.charAt(i)+b.charAt(j),c=e=f="",g=h=i=j="";while(l1&&(d+=d.indexOf("?")>-1?"&"+k:"?"+k),e.jsonp){var l=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=d,void l.appendChild(m)}}b(function(b,c){if(b)return h(b);c.open(a,d,e.async);for(var f in j)j.hasOwnProperty(f)&&c.setRequestHeader(f,j[f]);c.onreadystatechange=function(){if(4===c.readyState){var a=c.responseText||"";if(!h)return;h(c.status,{text:function(){return a},json:function(){try{return JSON.parse(a)}catch(b){return U.error("Can not parse JSON. URL: "+d),{}}}})}},c.send(i)})},h={authBasic:function(a,b){g.headers.Authorization="Basic "+e(a+":"+b)},connect:function(a,b,c){return g("CONNECT",a,b,c)},del:function(a,b,c){return g("DELETE",a,b,c)},get:function(a,b,c){return g("GET",a,b,c)},head:function(a,b,c){return g("HEAD",a,b,c)},headers:function(a){g.headers=a||{}},isAllowed:function(a,b,c){this.options(a,function(a,d){c(-1!==d.text().indexOf(b))})},options:function(a,b,c){return g("OPTIONS",a,b,c)},patch:function(a,b,c){return g("PATCH",a,b,c)},post:function(a,b,c){return g("POST",a,b,c)},put:function(a,b,c){return g("PUT",a,b,c)},trace:function(a,b,c){return g("TRACE",a,b,c)}},i=a.type?a.type.toLowerCase():"get";h[i](a.url,a,function(b,c){200===b||0===b&&c.text()?a.success(c.json(),b,null):a.error(c.text(),b,null)})}function g(a,b){"function"==typeof a&&(b=a,a={}),a=a||{},U.extend(Q,a),delete Q.fixLng,Q.functions&&(delete Q.functions,U.extend(U,a.functions)),"string"==typeof Q.ns&&(Q.ns={namespaces:[Q.ns],defaultNs:Q.ns}),"string"==typeof Q.fallbackNS&&(Q.fallbackNS=[Q.fallbackNS]),("string"==typeof Q.fallbackLng||"boolean"==typeof Q.fallbackLng)&&(Q.fallbackLng=[Q.fallbackLng]),Q.interpolationPrefixEscaped=U.regexEscape(Q.interpolationPrefix),Q.interpolationSuffixEscaped=U.regexEscape(Q.interpolationSuffix),Q.lng||(Q.lng=U.detectLanguage()),M=U.toLanguages(Q.lng),H=M[0],U.log("currentLng set to: "+H),Q.useCookie&&U.cookie.read(Q.cookieName)!==H&&U.cookie.create(Q.cookieName,H,Q.cookieExpirationTime,Q.cookieDomain),Q.detectLngFromLocalStorage&&"undefined"!=typeof document&&window.localStorage&&U.localStorage.setItem("i18next_lng",H);var c=B;a.fixLng&&(c=function(a,b){return b=b||{},b.lng=b.lng||c.lng,B(a,b)},c.lng=H),X.setCurrentLng(H),I&&Q.setJqueryExt&&u();var d;if(I&&I.Deferred&&(d=I.Deferred()),!Q.resStore){var e=U.toLanguages(Q.lng);"string"==typeof Q.preload&&(Q.preload=[Q.preload]);for(var f=0,g=Q.preload.length;g>f;f++)for(var h=U.toLanguages(Q.preload[f]),i=0,j=h.length;j>i;i++)e.indexOf(h[i])<0&&e.push(h[i]);return J.sync.load(e,Q,function(a,e){K=e,N=!0,b&&b(c),d&&d.resolve(c)}),d?d.promise():void 0}return K=Q.resStore,N=!0,b&&b(c),d&&d.resolve(c),d?d.promise():void 0}function h(a,b){"string"==typeof a&&(a=[a]);for(var c=0,d=a.length;d>c;c++)Q.preload.indexOf(a[c])<0&&Q.preload.push(a[c]);return g(b)}function i(a,b,c,d){"string"!=typeof b?(c=b,b=Q.ns.defaultNs):Q.ns.namespaces.indexOf(b)<0&&Q.ns.namespaces.push(b),K[a]=K[a]||{},K[a][b]=K[a][b]||{},d?U.deepExtend(K[a][b],c):U.extend(K[a][b],c),Q.useLocalStorage&&O._storeLocal(K)}function j(a,b){"string"!=typeof b&&(b=Q.ns.defaultNs),K[a]=K[a]||{};var c=K[a][b]||{},d=!1;for(var e in c)c.hasOwnProperty(e)&&(d=!0);return d}function k(a,b){return"string"!=typeof b&&(b=Q.ns.defaultNs),K[a]=K[a]||{},U.extend({},K[a][b])}function l(a,b){"string"!=typeof b&&(b=Q.ns.defaultNs),K[a]=K[a]||{},K[a][b]={},Q.useLocalStorage&&O._storeLocal(K)}function m(a,b,c,d){"string"!=typeof b?(resource=b,b=Q.ns.defaultNs):Q.ns.namespaces.indexOf(b)<0&&Q.ns.namespaces.push(b),K[a]=K[a]||{},K[a][b]=K[a][b]||{};for(var e=c.split(Q.keyseparator),f=0,g=K[a][b];e[f];)f==e.length-1?g[e[f]]=d:(null==g[e[f]]&&(g[e[f]]={}),g=g[e[f]]),f++;Q.useLocalStorage&&O._storeLocal(K)}function n(a,b,c){"string"!=typeof b?(resource=b,b=Q.ns.defaultNs):Q.ns.namespaces.indexOf(b)<0&&Q.ns.namespaces.push(b);for(var d in c)"string"==typeof c[d]&&m(a,b,d,c[d])}function o(a){Q.ns.defaultNs=a}function p(a,b){q([a],b)}function q(a,b){var c={dynamicLoad:Q.dynamicLoad,resGetPath:Q.resGetPath,getAsync:Q.getAsync,customLoad:Q.customLoad,ns:{namespaces:a,defaultNs:""}},d=U.toLanguages(Q.lng);"string"==typeof Q.preload&&(Q.preload=[Q.preload]);for(var e=0,f=Q.preload.length;f>e;e++)for(var g=U.toLanguages(Q.preload[e]),h=0,i=g.length;i>h;h++)d.indexOf(g[h])<0&&d.push(g[h]);for(var j=[],k=0,l=d.length;l>k;k++){var m=!1,n=K[d[k]];if(n)for(var o=0,p=a.length;p>o;o++)n[a[o]]||(m=!0);else m=!0;m&&j.push(d[k])}j.length?J.sync._fetch(j,c,function(c,d){var e=a.length*j.length;U.each(a,function(a,c){Q.ns.namespaces.indexOf(c)<0&&Q.ns.namespaces.push(c),U.each(j,function(a,f){K[f]=K[f]||{},K[f][c]=d[f][c],e--,0===e&&b&&(Q.useLocalStorage&&J.sync._storeLocal(K),b())})})}):b&&b()}function r(a,b,c){return"function"==typeof b?(c=b,b={}):b||(b={}),b.lng=a,g(b,c)}function s(){return H}function t(a){K={},r(H,a)}function u(){function a(a,b,c){if(0!==b.length){var d="text";if(0===b.indexOf("[")){var e=b.split("]");b=e[1],d=e[0].substr(1,e[0].length-1)}b.indexOf(";")===b.length-1&&(b=b.substr(0,b.length-2));var f;if("html"===d)f=Q.defaultValueFromContent?I.extend({defaultValue:a.html()},c):c,a.html(I.t(b,f));else if("text"===d)f=Q.defaultValueFromContent?I.extend({defaultValue:a.text()},c):c,a.text(I.t(b,f));else if("prepend"===d)f=Q.defaultValueFromContent?I.extend({defaultValue:a.html()},c):c,a.prepend(I.t(b,f));else if("append"===d)f=Q.defaultValueFromContent?I.extend({defaultValue:a.html()},c):c,a.append(I.t(b,f));else if(0===d.indexOf("data-")){var g=d.substr("data-".length);f=Q.defaultValueFromContent?I.extend({defaultValue:a.data(g)},c):c;var h=I.t(b,f);a.data(g,h),a.attr(d,h)}else f=Q.defaultValueFromContent?I.extend({defaultValue:a.attr(d)},c):c,a.attr(d,I.t(b,f))}}function b(b,c){var d=b.attr(Q.selectorAttr);if(d||"undefined"==typeof d||d===!1||(d=b.text()||b.val()),d){var e=b,f=b.data("i18n-target");if(f&&(e=b.find(f)||b),c||Q.useDataAttrOptions!==!0||(c=b.data("i18n-options")),c=c||{},d.indexOf(";")>=0){var g=d.split(";");I.each(g,function(b,d){""!==d&&a(e,d,c)})}else a(e,d,c);Q.useDataAttrOptions===!0&&b.data("i18n-options",c)}}I.t=I.t||B,I.fn.i18n=function(a){return this.each(function(){b(I(this),a);var c=I(this).find("["+Q.selectorAttr+"]");c.each(function(){b(I(this),a)})})}}function v(a,b,c,d){if(!a)return a;if(d=d||b,a.indexOf(d.interpolationPrefix||Q.interpolationPrefix)<0)return a;var e=d.interpolationPrefix?U.regexEscape(d.interpolationPrefix):Q.interpolationPrefixEscaped,f=d.interpolationSuffix?U.regexEscape(d.interpolationSuffix):Q.interpolationSuffixEscaped,g="HTML"+f,h=b.replace&&"object"==typeof b.replace?b.replace:b;return U.each(h,function(b,h){var i=c?c+Q.keyseparator+b:b;"object"==typeof h&&null!==h?a=v(a,h,i,d):d.escapeInterpolation||Q.escapeInterpolation?(a=a.replace(new RegExp([e,i,g].join(""),"g"),U.regexReplacementEscape(h)),a=a.replace(new RegExp([e,i,f].join(""),"g"),U.regexReplacementEscape(U.escape(h)))):a=a.replace(new RegExp([e,i,f].join(""),"g"),U.regexReplacementEscape(h))}),a}function w(a,b){var c=",",d="{",e="}",f=U.extend({},b);for(delete f.postProcess;-1!=a.indexOf(Q.reusePrefix)&&(L++,!(L>Q.maxRecursion));){var g=a.lastIndexOf(Q.reusePrefix),h=a.indexOf(Q.reuseSuffix,g)+Q.reuseSuffix.length,i=a.substring(g,h),j=i.replace(Q.reusePrefix,"").replace(Q.reuseSuffix,"");if(g>=h)return U.error("there is an missing closing in following translation value",a),"";if(-1!=j.indexOf(c)){var k=j.indexOf(c);if(-1!=j.indexOf(d,k)&&-1!=j.indexOf(e,k)){var l=j.indexOf(d,k),m=j.indexOf(e,l)+e.length;try{f=U.extend(f,JSON.parse(j.substring(l,m))),j=j.substring(0,k)}catch(n){}}}var o=E(j,f);a=a.replace(i,U.regexReplacementEscape(o))}return a}function x(a){return a.context&&("string"==typeof a.context||"number"==typeof a.context)}function y(a){return void 0!==a.count&&"string"!=typeof a.count}function z(a){return void 0!==a.indefinite_article&&"string"!=typeof a.indefinite_article&&a.indefinite_article}function A(a,b){b=b||{};var c=C(a,b),d=F(a,b);return void 0!==d||d===c}function B(a,b){return b=b||{},N?(L=0,E.apply(null,arguments)):(U.log("i18next not finished initialization. you might have called t function before loading resources finished."),b.defaultValue||"")}function C(a,b){return void 0!==b.defaultValue?b.defaultValue:a}function D(){for(var a=[],b=1;b1)for(var d=0;d-1&&(e=c.split(Q.nsseparator),i=e[0],c=e[1]),void 0===g&&Q.sendMissing&&"function"==typeof Q.missingKeyHandler&&(b.lng?Q.missingKeyHandler(h[0],i,c,f,h):Q.missingKeyHandler(Q.lng,i,c,f,h));var j;j="string"==typeof Q.postProcess&&""!==Q.postProcess?[Q.postProcess]:"array"==typeof Q.postProcess||"object"==typeof Q.postProcess?Q.postProcess:[],"string"==typeof b.postProcess&&""!==b.postProcess?j=j.concat([b.postProcess]):("array"==typeof b.postProcess||"object"==typeof b.postProcess)&&(j=j.concat(b.postProcess)),void 0!==g&&j.length&&j.forEach(function(a){Y[a]&&(g=Y[a](g,c,b))});var k=f;if(f.indexOf(Q.nsseparator)>-1&&(e=f.split(Q.nsseparator),k=e[1]),k===c&&Q.parseMissingKey&&(f=Q.parseMissingKey(f)),void 0===g&&(f=v(f,b),f=w(f,b),j.length)){var l=C(c,b);j.forEach(function(a){Y[a]&&(g=Y[a](l,c,b))})}return void 0!==g?g:f}function F(a,b){b=b||{};var c,d,e=C(a,b),f=M;if(!K)return e;if("cimode"===f[0].toLowerCase())return e;if(b.lngs&&(f=b.lngs),b.lng&&(f=U.toLanguages(b.lng,b.fallbackLng),!K[f[0]])){var g=Q.getAsync;Q.getAsync=!1,J.sync.load(f,Q,function(a,b){U.extend(K,b),Q.getAsync=g})}var h=b.ns||Q.ns.defaultNs;if(a.indexOf(Q.nsseparator)>-1){var i=a.split(Q.nsseparator);h=i[0],a=i[1]}if(x(b)){c=U.extend({},b),delete c.context,c.defaultValue=Q.contextNotFound;var j=h+Q.nsseparator+a+"_"+b.context;if(d=B(j,c),d!=Q.contextNotFound)return v(d,{context:b.context})}if(y(b,f[0])){c=U.extend({lngs:[f[0]]},b),delete c.count,c._origLng=c._origLng||c.lng||f[0],delete c.lng,c.defaultValue=Q.pluralNotFound;var k;if(X.needsPlural(f[0],b.count)){k=h+Q.nsseparator+a+Q.pluralSuffix;var l=X.get(f[0],b.count);l>=0?k=k+"_"+l:1===l&&(k=h+Q.nsseparator+a)}else k=h+Q.nsseparator+a;if(d=B(k,c),d!=Q.pluralNotFound)return v(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix});if(!(f.length>1))return c.lng=c._origLng,delete c._origLng,d=B(h+Q.nsseparator+a,c),v(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix});var m=f.slice();if(m.shift(),b=U.extend(b,{lngs:m}),b._origLng=c._origLng,delete b.lng,d=B(h+Q.nsseparator+a,b),d!=Q.pluralNotFound)return d}if(z(b)){var n=U.extend({},b);delete n.indefinite_article,n.defaultValue=Q.indefiniteNotFound;var o=h+Q.nsseparator+a+(b.count&&!y(b,f[0])||!b.count?Q.indefiniteSuffix:"");if(d=B(o,n),d!=Q.indefiniteNotFound)return d}for(var p,q=a.split(Q.keyseparator),r=0,s=f.length;s>r&&void 0===p;r++){for(var t=f[r],u=0,A=K[t]&&K[t][h];q[u];)A=A&&A[q[u]],u++;if(void 0!==A){var D=Object.prototype.toString.apply(A);if("string"==typeof A)A=v(A,b),A=w(A,b);else if("[object Array]"!==D||Q.returnObjectTrees||b.returnObjectTrees){if(null===A&&Q.fallbackOnNull===!0)A=void 0;else if(null!==A)if(Q.returnObjectTrees||b.returnObjectTrees){if("[object Number]"!==D&&"[object Function]"!==D&&"[object RegExp]"!==D){var G="[object Array]"===D?[]:{};U.each(A,function(c){G[c]=E(h+Q.nsseparator+a+Q.keyseparator+c,b)}),A=G}}else Q.objectTreeKeyHandler&&"function"==typeof Q.objectTreeKeyHandler?A=Q.objectTreeKeyHandler(a,A,t,h,b):(A="key '"+h+":"+a+" ("+t+")' returned an object instead of string.",U.log(A))}else A=A.join("\n"),A=v(A,b),A=w(A,b);"string"==typeof A&&""===A.trim()&&Q.fallbackOnEmpty===!0&&(A=void 0),p=A}}if(void 0===p&&!b.isFallbackLookup&&(Q.fallbackToDefaultNS===!0||Q.fallbackNS&&Q.fallbackNS.length>0)){if(b.isFallbackLookup=!0,Q.fallbackNS.length){for(var H=0,I=Q.fallbackNS.length;I>H;H++)if(p=F(Q.fallbackNS[H]+Q.nsseparator+a,b),p||""===p&&Q.fallbackOnEmpty===!1){var L=p.indexOf(Q.nsseparator)>-1?p.split(Q.nsseparator)[1]:p,N=e.indexOf(Q.nsseparator)>-1?e.split(Q.nsseparator)[1]:e;if(L!==N)break}}else p=F(a,b);b.isFallbackLookup=!1}return p}function G(){var a,b=Q.lngWhitelist||[],c=[];if("undefined"!=typeof window&&!function(){for(var a=window.location.search.substring(1),b=a.split("&"),d=0;d0){var f=b[d].substring(0,e);f==Q.detectLngQS&&c.push(b[d].substring(e+1))}}}(),Q.useCookie&&"undefined"!=typeof document){var d=U.cookie.read(Q.cookieName);d&&c.push(d)}if(Q.detectLngFromLocalStorage&&"undefined"!=typeof window&&window.localStorage&&c.push(U.localStorage.getItem("i18next_lng")),"undefined"!=typeof navigator){if(navigator.languages)for(var e=0;e-1){var f=e.split("-");e=Q.lowerCaseLng?f[0].toLowerCase()+"-"+f[1].toLowerCase():f[0].toLowerCase()+"-"+f[1].toUpperCase()}if(0===b.length||b.indexOf(e)>-1){a=e;break}}}(),a||(a=Q.fallbackLng[0]),a}Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>0&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=c;arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d))));for(var e=d>=0?Math.min(d,c-1):c-Math.abs(d);e>=0;e--)if(e in b&&b[e]===a)return e;return-1}),"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")});var H,I=a.jQuery||a.Zepto,J={},K={},L=0,M=[],N=!1,O={};if("undefined"!=typeof module&&module.exports){if(module.exports=J,!I)try{I=require("jquery")}catch(P){}}else a.i18n=a.i18n||J;I&&(I.i18n=I.i18n||J),O={load:function(a,b,c){b.useLocalStorage?O._loadLocal(a,b,function(d,e){for(var f=[],g=0,h=a.length;h>g;g++)e[a[g]]||f.push(a[g]);f.length>0?O._fetch(f,b,function(a,b){U.extend(e,b),O._storeLocal(b),c(null,e)}):c(null,e)}):O._fetch(a,b,function(a,b){c(null,b)})},_loadLocal:function(a,b,c){var d={},e=(new Date).getTime();if(window.localStorage){var f=a.length;U.each(a,function(a,g){var h=U.localStorage.getItem("res_"+g);h&&(h=JSON.parse(h),h.i18nStamp&&h.i18nStamp+b.localStorageExpirationTime>e&&(d[g]=h)),f--,0===f&&c(null,d)})}},_storeLocal:function(a){if(window.localStorage)for(var b in a)a[b].i18nStamp=(new Date).getTime(),U.localStorage.setItem("res_"+b,JSON.stringify(a[b]))},_fetch:function(a,b,c){var d=b.ns,e={};if(b.dynamicLoad){var f=function(a,b){c(null,b)};if("function"==typeof b.customLoad)b.customLoad(a,d.namespaces,b,f);else{var g=v(b.resGetPath,{lng:a.join("+"),ns:d.namespaces.join("+")});U.ajax({url:g,success:function(a){U.log("loaded: "+g),f(null,a)},error:function(a,b,c){U.log("failed loading: "+g),f("failed loading resource.json error: "+c)},dataType:"json",async:b.getAsync})}}else{var h,i=d.namespaces.length*a.length;U.each(d.namespaces,function(d,f){U.each(a,function(a,d){var g=function(a,b){a&&(h=h||[],h.push(a)),e[d]=e[d]||{},e[d][f]=b,i--,0===i&&c(h,e)};"function"==typeof b.customLoad?b.customLoad(d,f,b,g):O._fetchOne(d,f,b,g)})})}},_fetchOne:function(a,b,c,d){var e=v(c.resGetPath,{lng:a,ns:b});U.ajax({url:e,success:function(a){U.log("loaded: "+e),d(null,a)},error:function(a,b,c){if(b&&200==b||a&&a.status&&200==a.status)U.error("There is a typo in: "+e);else if(b&&404==b||a&&a.status&&404==a.status)U.log("Does not exist: "+e);else{var f=b?b:a&&a.status?a.status:null;U.log(f+" when loading "+e)}d(c,{})},dataType:"json",async:c.getAsync})},postMissing:function(a,b,c,d,e){var f={};f[c]=d;var g=[];if("fallback"===Q.sendMissingTo&&Q.fallbackLng[0]!==!1)for(var h=0;hh;h++)g.push({lng:e[h],url:v(Q.resPostPath,{lng:e[h],ns:b})});for(var j=0,k=g.length;k>j;j++){var l=g[j];U.ajax({url:l.url,type:Q.sendType,data:f,success:function(){U.log("posted missing key '"+c+"' to: "+l.url);for(var a=c.split("."),e=0,f=K[l.lng][b];a[e];)f=f[a[e]]=e===a.length-1?d:f[a[e]]||{},e++},error:function(){U.log("failed posting missing key '"+c+"' to: "+l.url)},dataType:"json",async:Q.postAsync})}},reload:t};var Q={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:["dev"],fallbackNS:[],detectLngQS:"setLng",detectLngFromLocalStorage:!1,ns:"translation",fallbackOnNull:!0,fallbackOnEmpty:!1,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",defaultVariables:!1,reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,indefiniteSuffix:"_indefinite",indefiniteNotFound:["indefinite_not_found",Math.random()].join(""),setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",cookieDomain:void 0,objectTreeKeyHandler:void 0,postProcess:void 0,parseMissingKey:void 0,missingKeyHandler:O.postMissing,shortcutFunction:"sprintf"},R={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},S={create:function(a,b,c,d){var e;if(c){var f=new Date;f.setTime(f.getTime()+60*c*1e3),e="; expires="+f.toGMTString()}else e="";d=d?"domain="+d+";":"",document.cookie=a+"="+b+e+";"+d+"path=/"},read:function(a){for(var b=a+"=",c=document.cookie.split(";"),d=0;d-1){var c=a.split("-");b=Q.lowerCaseLng?c[0].toLowerCase()+"-"+c[1].toLowerCase():c[0].toLowerCase()+"-"+c[1].toUpperCase()}else b=Q.lowerCaseLng?a.toLowerCase():a;return b}var c=this.log,d=[],e=Q.lngWhitelist||!1,f=function(a){!e||e.indexOf(a)>-1?d.push(a):c("rejecting non-whitelisted language: "+a)};if("string"==typeof a&&a.indexOf("-")>-1){var g=a.split("-");"unspecific"!==Q.load&&f(b(a)),"current"!==Q.load&&f(b(g[this.getCountyIndexOfLng(a)]))}else f(b(a));for(var h=0;h1)},2:function(a){return Number(1!=a)},3:function(){return 0},4:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},5:function(a){return Number(0===a?0:1==a?1:2==a?2:a%100>=3&&10>=a%100?3:a%100>=11?4:5)},6:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)},7:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},8:function(a){return Number(1==a?0:2==a?1:8!=a&&11!=a?2:3)},9:function(a){return Number(a>=2)},10:function(a){return Number(1==a?0:2==a?1:7>a?2:11>a?3:4)},11:function(a){return Number(1==a||11==a?0:2==a||12==a?1:a>2&&20>a?2:3)},12:function(a){return Number(a%10!=1||a%100==11)},13:function(a){return Number(0!==a)},14:function(a){return Number(1==a?0:2==a?1:3==a?2:3)},15:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&(10>a%100||a%100>=20)?1:2)},16:function(a){return Number(a%10==1&&a%100!=11?0:0!==a?1:2)},17:function(a){return Number(1==a||a%10==1?0:1)},18:function(a){return Number(1==a?1:2)},19:function(a){return Number(1==a?0:0===a||a%100>1&&11>a%100?1:a%100>10&&20>a%100?2:3)},20:function(a){return Number(1==a?0:0===a||a%100>0&&20>a%100?1:2)},21:function(a){return Number(a%100==1?1:a%100==2?2:a%100==3||a%100==4?3:0)}},X={rules:function(){var a,b={};for(a=V.length;a--;)b[V[a][0]]={name:V[a][1],numbers:V[a][2],plurals:W[V[a][3]]};return b}(),addRule:function(a,b){X.rules[a]=b},setCurrentLng:function(a){if(!X.currentRule||X.currentRule.lng!==a){var b=a.split("-");X.currentRule={lng:a,rule:X.rules[b[0]]}}},needsPlural:function(a,b){var c,d=a.split("-");return c=X.currentRule&&X.currentRule.lng===a?X.currentRule.rule:X.rules[d[U.getCountyIndexOfLng(a)]],c&&c.numbers.length<=1?!1:1!==this.get(a,b)},get:function(a,b){function c(b,c){var d;if(d=X.currentRule&&X.currentRule.lng===a?X.currentRule.rule:X.rules[b]){var e;e=d.plurals(d.noAbs?c:Math.abs(c));var f=d.numbers[e];return 2===d.numbers.length&&1===d.numbers[0]&&(2===f?f=-1:1===f&&(f=1)),f}return 1===c?"1":"-1"}var d=a.split("-");return c(d[U.getCountyIndexOfLng(a)],b)}},Y={},Z=function(a,b){Y[a]=b},$=function(){function a(a){return Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}function b(a,b){for(var c=[];b>0;c[--b]=a);return c.join("")}var c=function(){return c.cache.hasOwnProperty(arguments[0])||(c.cache[arguments[0]]=c.parse(arguments[0])),c.format.call(null,c.cache[arguments[0]],arguments)};return c.format=function(c,d){var e,f,g,h,i,j,k,l=1,m=c.length,n="",o=[];for(f=0;m>f;f++)if(n=a(c[f]),"string"===n)o.push(c[f]);else if("array"===n){if(h=c[f],h[2])for(e=d[l],g=0;g=0?"+"+e:e,j=h[4]?"0"==h[4]?"0":h[4].charAt(1):" ",k=h[6]-String(e).length,i=h[6]?b(j,k):"",o.push(h[5]?e+i:i+e)}return o.join("")},c.cache={},c.parse=function(a){for(var b=a,c=[],d=[],e=0;b;){if(null!==(c=/^[^\x25]+/.exec(b)))d.push(c[0]);else if(null!==(c=/^\x25{2}/.exec(b)))d.push("%");else{if(null===(c=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(b)))throw"[sprintf] huh?";if(c[2]){e|=1;var f=[],g=c[2],h=[];if(null===(h=/^([a-z_][a-z_\d]*)/i.exec(g)))throw"[sprintf] huh?";for(f.push(h[1]);""!==(g=g.substring(h[0].length));)if(null!==(h=/^\.([a-z_][a-z_\d]*)/i.exec(g)))f.push(h[1]);else{if(null===(h=/^\[(\d+)\]/.exec(g)))throw"[sprintf] huh?";f.push(h[1])}c[2]=f}else e|=2;if(3===e)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";d.push(c)}b=b.substring(c[0].length)}return d},c}(),_=function(a,b){return b.unshift(a),$.apply(null,b)};Z("sprintf",function(a,b,c){return c.sprintf?"[object Array]"===Object.prototype.toString.apply(c.sprintf)?_(a,c.sprintf):"object"==typeof c.sprintf?$(a,c.sprintf):a:a}),J.init=g,J.setLng=r,J.preload=h,J.addResourceBundle=i,J.hasResourceBundle=j,J.getResourceBundle=k,J.addResource=m,J.addResources=n,J.removeResourceBundle=l,J.loadNamespace=p,J.loadNamespaces=q,J.setDefaultNamespace=o,J.t=B,J.translate=B,J.exists=A,J.detectLanguage=U.detectLanguage,J.pluralExtensions=X,J.sync=O,J.functions=U,J.lng=s,J.addPostProcessor=Z,J.applyReplacement=U.applyReplacement,J.options=Q}("undefined"==typeof exports?window:exports); \ No newline at end of file diff --git a/libs/i18next/release/i18next.commonjs.withJQuery-1.8.2.js b/libs/i18next/release/i18next.commonjs.withJQuery-1.8.2.js new file mode 100644 index 00000000..fb96e55b --- /dev/null +++ b/libs/i18next/release/i18next.commonjs.withJQuery-1.8.2.js @@ -0,0 +1,2186 @@ +// i18next, v1.8.2 +// Copyright (c)2015 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function(root) { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + // Add string trim for IE8. + if (typeof String.prototype.trim !== 'function') { + String.prototype.trim = function() { + return this.replace(/^\s+|\s+$/g, ''); + } + } + + var $ = root.jQuery || root.Zepto + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = [] + , initialized = false + , sync = {}; + + + + // Export the i18next object for **CommonJS**. + // If we're not in CommonJS, add `i18n` to the + // global object or to jquery. + if (typeof module !== 'undefined' && module.exports) { + module.exports = i18n; + if (!$) { + try { + $ = require('jquery'); + } catch(e) { + // just ignore + } + } + + } else { + root.i18n = root.i18n || i18n; + } + + if ($) { + $.i18n = $.i18n || i18n; + } + sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = f.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + f.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + if ((status && status == 200) || (xhr && xhr.status && xhr.status == 200)) { + // file loaded but invalid json, stop waste time ! + f.error('There is a typo in: ' + url); + } else if ((status && status == 404) || (xhr && xhr.status && xhr.status == 404)) { + f.log('Does not exist: ' + url); + } else { + var theStatus = status ? status : ((xhr && xhr.status) ? xhr.status : null); + f.log(theStatus + ' when loading ' + url); + } + + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback' && o.fallbackLng[0] !== false) { + for (var i = 0; i < o.fallbackLng.length; i++) { + urls.push({lng: o.fallbackLng[i], url: applyReplacement(o.resPostPath, { lng: o.fallbackLng[i], ns: ns })}); + } + } else if (o.sendMissingTo === 'current' || (o.sendMissingTo === 'fallback' && o.fallbackLng[0] === false) ) { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + }, + + reload: reload + }; + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: ['dev'], + fallbackNS: [], + detectLngQS: 'setLng', + detectLngFromLocalStorage: false, + ns: { + namespaces: ['translation'], + defaultNs: 'translation' + }, + fallbackOnNull: true, + fallbackOnEmpty: false, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + defaultVariables: false, + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + indefiniteSuffix: '_indefinite', + indefiniteNotFound: ['indefinite_not_found', Math.random()].join(''), + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + cookieDomain: undefined, + + objectTreeKeyHandler: undefined, + postProcess: undefined, + parseMissingKey: undefined, + missingKeyHandler: sync.postMissing, + + shortcutFunction: 'sprintf' // or: defaultValue + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _deepExtend(target, source) { + for (var prop in source) + if (prop in target) + _deepExtend(target[prop], source[prop]); + else + target[prop] = source[prop]; + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || Object.prototype.toString.apply(object) !== '[object Array]' || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + try { + return JSON.parse(data) + } catch (e) { + f.error('Can not parse JSON. URL: ' + url); + return {}; + } + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + // file: protocol always gives status code 0, so check for data + if (status === 200 || (status === 0 && data.text())) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes,domain) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + domain = (domain)? "domain="+domain+";" : ""; + document.cookie = name+"="+value+expires+";"+domain+"path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes,domain) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + deepExtend: _deepExtend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : (typeof document !== 'undefined' ? _ajax : function() {}), + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + error: function(str) { + if (typeof console !== "undefined") console.error(str); + }, + getCountyIndexOfLng: function(lng) { + var lng_index = 0; + if (lng === 'nb-NO' || lng === 'nn-NO' || lng === 'nb-no' || lng === 'nn-no') lng_index = 1; + return lng_index; + }, + toLanguages: function(lng) { + var log = this.log; + + function applyCase(l) { + var ret = l; + + if (typeof l === 'string' && l.indexOf('-') > -1) { + var parts = l.split('-'); + + ret = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } else { + ret = o.lowerCaseLng ? l.toLowerCase() : l; + } + + return ret; + } + + var languages = []; + var whitelist = o.lngWhitelist || false; + var addLanguage = function(language){ + //reject langs not whitelisted + if(!whitelist || whitelist.indexOf(language) > -1){ + languages.push(language); + }else{ + log('rejecting non-whitelisted language: ' + language); + } + }; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + if (o.load !== 'unspecific') addLanguage(applyCase(lng)); + if (o.load !== 'current') addLanguage(applyCase(parts[this.getCountyIndexOfLng(lng)])); + } else { + addLanguage(applyCase(lng)); + } + + for (var i = 0; i < o.fallbackLng.length; i++) { + if (languages.indexOf(o.fallbackLng[i]) === -1 && o.fallbackLng[i]) languages.push(applyCase(o.fallbackLng[i])); + } + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + }, + regexReplacementEscape: function(strOrFn) { + if (typeof strOrFn === 'string') { + return strOrFn.replace(/\$/g, "$$$$"); + } else { + return strOrFn; + } + }, + localStorage: { + setItem: function(key, value) { + if (window.localStorage) { + try { + window.localStorage.setItem(key, value); + } catch (e) { + f.log('failed to set value for key "' + key + '" to localStorage.'); + } + } + }, + getItem: function(key, value) { + if (window.localStorage) { + try { + return window.localStorage.getItem(key, value); + } catch (e) { + f.log('failed to get value for key "' + key + '" from localStorage.'); + return undefined; + } + } + } + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + delete o.fixLng; /* passed in each time */ + + // override functions: .log(), .detectLanguage(), etc + if (o.functions) { + delete o.functions; + f.extend(f, options.functions); + } + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // fallback languages + if (typeof o.fallbackLng == 'string' || typeof o.fallbackLng == 'boolean') { + o.fallbackLng = [o.fallbackLng]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + if (o.useCookie && f.cookie.read(o.cookieName) !== currentLng){ //cookie is unset or invalid + f.cookie.create(o.cookieName, currentLng, o.cookieExpirationTime, o.cookieDomain); + } + if (o.detectLngFromLocalStorage && typeof document !== 'undefined' && window.localStorage) { + f.localStorage.setItem('i18next_lng', currentLng); + } + + var lngTranslate = translate; + if (options.fixLng) { + lngTranslate = function(key, options) { + options = options || {}; + options.lng = options.lng || lngTranslate.lng; + return translate(key, options); + }; + lngTranslate.lng = currentLng; + } + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + initialized = true; + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + initialized = true; + + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources, deep) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + if (deep) { + f.deepExtend(resStore[lng][ns], resources); + } else { + f.extend(resStore[lng][ns], resources); + } + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function hasResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + var res = resStore[lng][ns] || {}; + + var hasValues = false; + for(var prop in res) { + if (res.hasOwnProperty(prop)) { + hasValues = true; + } + } + + return hasValues; + } + + function getResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + return f.extend({}, resStore[lng][ns]); + } + + function removeResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = {}; + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function addResource(lng, ns, key, value) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + var keys = key.split(o.keyseparator); + var x = 0; + var node = resStore[lng][ns]; + var origRef = node; + + while (keys[x]) { + if (x == keys.length - 1) + node[keys[x]] = value; + else { + if (node[keys[x]] == null) + node[keys[x]] = {}; + + node = node[keys[x]]; + } + x++; + } + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function addResources(lng, ns, resources) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + for (var m in resources) { + if (typeof resources[m] === 'string') addResource(lng, ns, m, resources[m]); + } + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, options, cb) { + if (typeof options === 'function') { + cb = options; + options = {}; + } else if (!options) { + options = {}; + } + + options.lng = lng; + return init(options, cb); + } + + function lng() { + return currentLng; + } + + function reload(cb) { + resStore = {}; + setLng(currentLng, cb); + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else if (attr === 'prepend') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.prepend($.t(key, optionsToUse)); + } else if (attr === 'append') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.append($.t(key, optionsToUse)); + } else if (attr.indexOf("data-") === 0) { + var dataAttr = attr.substr(("data-").length); + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.data(dataAttr) }, options) : options; + var translated = $.t(key, optionsToUse); + //we change into the data cache + ele.data(dataAttr, translated); + //we change into the dom + ele.attr(attr, translated); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key && typeof key !== 'undefined' && key !== false) key = ele.text() || ele.val(); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + var hash = replacementHash.replace && typeof replacementHash.replace === 'object' ? replacementHash.replace : replacementHash; + f.each(hash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), f.regexReplacementEscape(value)); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(f.escape(value))); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(value)); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + if (index_of_end_of_closing <= index_of_opening) { + f.error('there is an missing closing in following translation value', translated); + return ''; + } + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, f.regexReplacementEscape(translated_token)); + } + return translated; + } + + function hasContext(options) { + return (options.context && (typeof options.context == 'string' || typeof options.context == 'number')); + } + + function needsPlural(options, lng) { + return (options.count !== undefined && typeof options.count != 'string'/* && pluralExtensions.needsPlural(lng, options.count)*/); + } + + function needsIndefiniteArticle(options) { + return (options.indefinite_article !== undefined && typeof options.indefinite_article != 'string' && options.indefinite_article); + } + + function exists(key, options) { + options = options || {}; + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + options = options || {}; + + if (!initialized) { + f.log('i18next not finished initialization. you might have called t function before loading resources finished.') + return options.defaultValue || ''; + }; + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _getDefaultValue(key, options) { + return (options.defaultValue !== undefined) ? options.defaultValue : key; + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(potentialKeys, options) { + if (options && typeof options !== 'object') { + if (o.shortcutFunction === 'sprintf') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else if (o.shortcutFunction === 'defaultValue') { + options = { + defaultValue: options + } + } + } else { + options = options || {}; + } + + if (typeof o.defaultVariables === 'object') { + options = f.extend({}, o.defaultVariables, options); + } + + if (potentialKeys === undefined || potentialKeys === null || potentialKeys === '') return ''; + + if (typeof potentialKeys === 'number') { + potentialKeys = String(potentialKeys); + } + + if (typeof potentialKeys === 'string') { + potentialKeys = [potentialKeys]; + } + + var key = potentialKeys[0]; + + if (potentialKeys.length > 1) { + for (var i = 0; i < potentialKeys.length; i++) { + key = potentialKeys[i]; + if (exists(key, options)) { + break; + } + } + } + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng, options.fallbackLng) : languages + , ns = options.ns || o.ns.defaultNs + , parts; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing && typeof o.missingKeyHandler === 'function') { + if (options.lng) { + o.missingKeyHandler(lngs[0], ns, key, notFound, lngs); + } else { + o.missingKeyHandler(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessorsToApply; + if (typeof o.postProcess === 'string' && o.postProcess !== '') { + postProcessorsToApply = [o.postProcess]; + } else if (typeof o.postProcess === 'array' || typeof o.postProcess === 'object') { + postProcessorsToApply = o.postProcess; + } else { + postProcessorsToApply = []; + } + + if (typeof options.postProcess === 'string' && options.postProcess !== '') { + postProcessorsToApply = postProcessorsToApply.concat([options.postProcess]); + } else if (typeof options.postProcess === 'array' || typeof options.postProcess === 'object') { + postProcessorsToApply = postProcessorsToApply.concat(options.postProcess); + } + + if (found !== undefined && postProcessorsToApply.length) { + postProcessorsToApply.forEach(function(postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + }); + } + + // process notFound if function exists + var splitNotFound = notFound; + if (notFound.indexOf(o.nsseparator) > -1) { + parts = notFound.split(o.nsseparator); + splitNotFound = parts[1]; + } + if (splitNotFound === key && o.parseMissingKey) { + notFound = o.parseMissingKey(notFound); + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessorsToApply.length) { + var val = _getDefaultValue(key, options); + postProcessorsToApply.forEach(function(postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](val, key, options); + } + }); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options) { + options = options || {}; + + var optionWithoutCount, translated + , notFound = _getDefaultValue(key, options) + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + // CI mode + if (lngs[0].toLowerCase() === 'cimode') return notFound; + + // passed in lng + if (options.lngs) lngs = options.lngs; + if (options.lng) { + lngs = f.toLanguages(options.lng, options.fallbackLng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options, lngs[0])) { + optionWithoutCount = f.extend({ lngs: [lngs[0]]}, options); + delete optionWithoutCount.count; + optionWithoutCount._origLng = optionWithoutCount._origLng || optionWithoutCount.lng || lngs[0]; + delete optionWithoutCount.lng; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey; + if (!pluralExtensions.needsPlural(lngs[0], options.count)) { + pluralKey = ns + o.nsseparator + key; + } else { + pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(lngs[0], options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + } + + translated = translate(pluralKey, optionWithoutCount); + + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } else if (lngs.length > 1) { + // remove failed lng + var clone = lngs.slice(); + clone.shift(); + options = f.extend(options, { lngs: clone }); + options._origLng = optionWithoutCount._origLng; + delete options.lng; + // retry with fallbacks + translated = translate(ns + o.nsseparator + key, options); + if (translated != o.pluralNotFound) return translated; + } else { + optionWithoutCount.lng = optionWithoutCount._origLng; + delete optionWithoutCount._origLng; + translated = translate(ns + o.nsseparator + key, optionWithoutCount); + + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); + } + } + + if (needsIndefiniteArticle(options)) { + var optionsWithoutIndef = f.extend({}, options); + delete optionsWithoutIndef.indefinite_article; + optionsWithoutIndef.defaultValue = o.indefiniteNotFound; + // If we don't have a count, we want the indefinite, if we do have a count, and needsPlural is false + var indefiniteKey = ns + o.nsseparator + key + (((options.count && !needsPlural(options, lngs[0])) || !options.count) ? o.indefiniteSuffix : ""); + translated = translate(indefiniteKey, optionsWithoutIndef); + if (translated != o.indefiniteNotFound) { + return translated; + } + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + var valueType = Object.prototype.toString.apply(value); + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (valueType === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + if (o.objectTreeKeyHandler && typeof o.objectTreeKeyHandler == 'function') { + value = o.objectTreeKeyHandler(key, value, l, ns, options); + } else { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned an object instead of string.'; + f.log(value); + } + } else if (valueType !== '[object Number]' && valueType !== '[object Function]' && valueType !== '[object RegExp]') { + var copy = (valueType === '[object Array]') ? [] : {}; // apply child translation on a copy + f.each(value, function(m) { + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + }); + value = copy; + } + } + + if (typeof value === 'string' && value.trim() === '' && o.fallbackOnEmpty === true) + value = undefined; + + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length > 0))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found || (found==="" && o.fallbackOnEmpty === false)) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + options.isFallbackLookup = false; + } + + return found; + } + function detectLanguage() { + var detectedLng; + var whitelist = o.lngWhitelist || []; + var userLngChoices = []; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var params = query.split('&'); + for (var i=0; i 0) { + var key = params[i].substring(0,pos); + if (key == o.detectLngQS) { + userLngChoices.push(params[i].substring(pos+1)); + } + } + } + })(); + } + + // get from cookie + if (o.useCookie && typeof document !== 'undefined') { + var c = f.cookie.read(o.cookieName); + if (c) userLngChoices.push(c); + } + + // get from localStorage + if (o.detectLngFromLocalStorage && typeof window !== 'undefined' && window.localStorage) { + userLngChoices.push(f.localStorage.getItem('i18next_lng')); + } + + // get from navigator + if (typeof navigator !== 'undefined') { + if (navigator.languages) { // chrome only; not an array, so can't use .push.apply instead of iterating + for (var i=0;i -1) { + var parts = lng.split('-'); + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } + + if (whitelist.length === 0 || whitelist.indexOf(lng) > -1) { + detectedLng = lng; + break; + } + } + })(); + + //fallback + if (!detectedLng){ + detectedLng = o.fallbackLng[0]; + } + + return detectedLng; + } + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + + /* [code, name, numbers, pluralsType] */ + var _rules = [ + ["ach", "Acholi", [1,2], 1], + ["af", "Afrikaans",[1,2], 2], + ["ak", "Akan", [1,2], 1], + ["am", "Amharic", [1,2], 1], + ["an", "Aragonese",[1,2], 2], + ["ar", "Arabic", [0,1,2,3,11,100],5], + ["arn", "Mapudungun",[1,2], 1], + ["ast", "Asturian", [1,2], 2], + ["ay", "Aymará", [1], 3], + ["az", "Azerbaijani",[1,2],2], + ["be", "Belarusian",[1,2,5],4], + ["bg", "Bulgarian",[1,2], 2], + ["bn", "Bengali", [1,2], 2], + ["bo", "Tibetan", [1], 3], + ["br", "Breton", [1,2], 1], + ["bs", "Bosnian", [1,2,5],4], + ["ca", "Catalan", [1,2], 2], + ["cgg", "Chiga", [1], 3], + ["cs", "Czech", [1,2,5],6], + ["csb", "Kashubian",[1,2,5],7], + ["cy", "Welsh", [1,2,3,8],8], + ["da", "Danish", [1,2], 2], + ["de", "German", [1,2], 2], + ["dev", "Development Fallback", [1,2], 2], + ["dz", "Dzongkha", [1], 3], + ["el", "Greek", [1,2], 2], + ["en", "English", [1,2], 2], + ["eo", "Esperanto",[1,2], 2], + ["es", "Spanish", [1,2], 2], + ["es_ar","Argentinean Spanish", [1,2], 2], + ["et", "Estonian", [1,2], 2], + ["eu", "Basque", [1,2], 2], + ["fa", "Persian", [1], 3], + ["fi", "Finnish", [1,2], 2], + ["fil", "Filipino", [1,2], 1], + ["fo", "Faroese", [1,2], 2], + ["fr", "French", [1,2], 9], + ["fur", "Friulian", [1,2], 2], + ["fy", "Frisian", [1,2], 2], + ["ga", "Irish", [1,2,3,7,11],10], + ["gd", "Scottish Gaelic",[1,2,3,20],11], + ["gl", "Galician", [1,2], 2], + ["gu", "Gujarati", [1,2], 2], + ["gun", "Gun", [1,2], 1], + ["ha", "Hausa", [1,2], 2], + ["he", "Hebrew", [1,2], 2], + ["hi", "Hindi", [1,2], 2], + ["hr", "Croatian", [1,2,5],4], + ["hu", "Hungarian",[1,2], 2], + ["hy", "Armenian", [1,2], 2], + ["ia", "Interlingua",[1,2],2], + ["id", "Indonesian",[1], 3], + ["is", "Icelandic",[1,2], 12], + ["it", "Italian", [1,2], 2], + ["ja", "Japanese", [1], 3], + ["jbo", "Lojban", [1], 3], + ["jv", "Javanese", [0,1], 13], + ["ka", "Georgian", [1], 3], + ["kk", "Kazakh", [1], 3], + ["km", "Khmer", [1], 3], + ["kn", "Kannada", [1,2], 2], + ["ko", "Korean", [1], 3], + ["ku", "Kurdish", [1,2], 2], + ["kw", "Cornish", [1,2,3,4],14], + ["ky", "Kyrgyz", [1], 3], + ["lb", "Letzeburgesch",[1,2],2], + ["ln", "Lingala", [1,2], 1], + ["lo", "Lao", [1], 3], + ["lt", "Lithuanian",[1,2,10],15], + ["lv", "Latvian", [1,2,0],16], + ["mai", "Maithili", [1,2], 2], + ["mfe", "Mauritian Creole",[1,2],1], + ["mg", "Malagasy", [1,2], 1], + ["mi", "Maori", [1,2], 1], + ["mk", "Macedonian",[1,2],17], + ["ml", "Malayalam",[1,2], 2], + ["mn", "Mongolian",[1,2], 2], + ["mnk", "Mandinka", [0,1,2],18], + ["mr", "Marathi", [1,2], 2], + ["ms", "Malay", [1], 3], + ["mt", "Maltese", [1,2,11,20],19], + ["nah", "Nahuatl", [1,2], 2], + ["nap", "Neapolitan",[1,2], 2], + ["nb", "Norwegian Bokmal",[1,2],2], + ["ne", "Nepali", [1,2], 2], + ["nl", "Dutch", [1,2], 2], + ["nn", "Norwegian Nynorsk",[1,2],2], + ["no", "Norwegian",[1,2], 2], + ["nso", "Northern Sotho",[1,2],2], + ["oc", "Occitan", [1,2], 1], + ["or", "Oriya", [2,1], 2], + ["pa", "Punjabi", [1,2], 2], + ["pap", "Papiamento",[1,2], 2], + ["pl", "Polish", [1,2,5],7], + ["pms", "Piemontese",[1,2], 2], + ["ps", "Pashto", [1,2], 2], + ["pt", "Portuguese",[1,2], 2], + ["pt_br","Brazilian Portuguese",[1,2], 2], + ["rm", "Romansh", [1,2], 2], + ["ro", "Romanian", [1,2,20],20], + ["ru", "Russian", [1,2,5],4], + ["sah", "Yakut", [1], 3], + ["sco", "Scots", [1,2], 2], + ["se", "Northern Sami",[1,2], 2], + ["si", "Sinhala", [1,2], 2], + ["sk", "Slovak", [1,2,5],6], + ["sl", "Slovenian",[5,1,2,3],21], + ["so", "Somali", [1,2], 2], + ["son", "Songhay", [1,2], 2], + ["sq", "Albanian", [1,2], 2], + ["sr", "Serbian", [1,2,5],4], + ["su", "Sundanese",[1], 3], + ["sv", "Swedish", [1,2], 2], + ["sw", "Swahili", [1,2], 2], + ["ta", "Tamil", [1,2], 2], + ["te", "Telugu", [1,2], 2], + ["tg", "Tajik", [1,2], 1], + ["th", "Thai", [1], 3], + ["ti", "Tigrinya", [1,2], 1], + ["tk", "Turkmen", [1,2], 2], + ["tr", "Turkish", [1,2], 1], + ["tt", "Tatar", [1], 3], + ["ug", "Uyghur", [1], 3], + ["uk", "Ukrainian",[1,2,5],4], + ["ur", "Urdu", [1,2], 2], + ["uz", "Uzbek", [1,2], 1], + ["vi", "Vietnamese",[1], 3], + ["wa", "Walloon", [1,2], 1], + ["wo", "Wolof", [1], 3], + ["yo", "Yoruba", [1,2], 2], + ["zh", "Chinese", [1], 3] + ]; + + var _rulesPluralsTypes = { + 1: function(n) {return Number(n > 1);}, + 2: function(n) {return Number(n != 1);}, + 3: function(n) {return 0;}, + 4: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 5: function(n) {return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5);}, + 6: function(n) {return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2);}, + 7: function(n) {return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 8: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3);}, + 9: function(n) {return Number(n >= 2);}, + 10: function(n) {return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;}, + 11: function(n) {return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3);}, + 12: function(n) {return Number(n%10!=1 || n%100==11);}, + 13: function(n) {return Number(n !== 0);}, + 14: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3);}, + 15: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 16: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2);}, + 17: function(n) {return Number(n==1 || n%10==1 ? 0 : 1);}, + 18: function(n) {return Number(0 ? 0 : n==1 ? 1 : 2);}, + 19: function(n) {return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3);}, + 20: function(n) {return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2);}, + 21: function(n) {return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }; + + var pluralExtensions = { + + rules: (function () { + var l, rules = {}; + for (l=_rules.length; l-- ;) { + rules[_rules[l][0]] = { + name: _rules[l][1], + numbers: _rules[l][2], + plurals: _rulesPluralsTypes[_rules[l][3]] + } + } + return rules; + }()), + + // you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + needsPlural: function(lng, count) { + var parts = lng.split('-'); + + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[parts[f.getCountyIndexOfLng(lng)]]; + } + + if (ext && ext.numbers.length <= 1) { + return false; + } else { + return this.get(lng, count) !== 1; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i; + if (ext.noAbs) { + i = ext.plurals(c); + } else { + i = ext.plurals(Math.abs(c)); + } + + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[f.getCountyIndexOfLng(lng)], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.hasResourceBundle = hasResourceBundle; + i18n.getResourceBundle = getResourceBundle; + i18n.addResource = addResource; + i18n.addResources = addResources; + i18n.removeResourceBundle = removeResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.applyReplacement = f.applyReplacement; + i18n.options = o; + +})(typeof exports === 'undefined' ? window : exports); \ No newline at end of file diff --git a/libs/i18next/release/i18next.commonjs.withJQuery-1.8.2.min.js b/libs/i18next/release/i18next.commonjs.withJQuery-1.8.2.min.js new file mode 100644 index 00000000..af364373 --- /dev/null +++ b/libs/i18next/release/i18next.commonjs.withJQuery-1.8.2.min.js @@ -0,0 +1,5 @@ +// i18next, v1.8.2 +// Copyright (c)2015 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +!function(a){function b(a,b){if(!b||"function"==typeof b)return a;for(var c in b)a[c]=b[c];return a}function c(a,b){for(var d in b)d in a?c(a[d],b[d]):a[d]=b[d];return a}function d(a,b,c){var d,e=0,f=a.length,g=void 0===f||"[object Array]"!==Object.prototype.toString.apply(a)||"function"==typeof a;if(c)if(g){for(d in a)if(b.apply(a[d],c)===!1)break}else for(;f>e&&b.apply(a[e++],c)!==!1;);else if(g){for(d in a)if(b.call(a[d],d,a[d])===!1)break}else for(;f>e&&b.call(a[e],e,a[e++])!==!1;);return a}function e(a){return"string"==typeof a?a.replace(/[&<>"'\/]/g,function(a){return R[a]}):a}function f(a){var b=function(a){if(window.XMLHttpRequest)return a(null,new XMLHttpRequest);if(window.ActiveXObject)try{return a(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(b){return a(null,new ActiveXObject("Microsoft.XMLHTTP"))}return a(new Error)},c=function(a){if("string"==typeof a)return a;var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")},d=function(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;cd?b+=String.fromCharCode(d):d>127&&2048>d?(b+=String.fromCharCode(d>>6|192),b+=String.fromCharCode(63&d|128)):(b+=String.fromCharCode(d>>12|224),b+=String.fromCharCode(d>>6&63|128),b+=String.fromCharCode(63&d|128))}return b},e=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";a=d(a);var c,e,f,g,h,i,j,k="",l=0;do c=a.charCodeAt(l++),e=a.charCodeAt(l++),f=a.charCodeAt(l++),g=c>>2,h=(3&c)<<4|e>>4,i=(15&e)<<2|f>>6,j=63&f,isNaN(e)?i=j=64:isNaN(f)&&(j=64),k+=b.charAt(g)+b.charAt(h)+b.charAt(i)+b.charAt(j),c=e=f="",g=h=i=j="";while(l1&&(d+=d.indexOf("?")>-1?"&"+k:"?"+k),e.jsonp){var l=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=d,void l.appendChild(m)}}b(function(b,c){if(b)return h(b);c.open(a,d,e.async);for(var f in j)j.hasOwnProperty(f)&&c.setRequestHeader(f,j[f]);c.onreadystatechange=function(){if(4===c.readyState){var a=c.responseText||"";if(!h)return;h(c.status,{text:function(){return a},json:function(){try{return JSON.parse(a)}catch(b){return U.error("Can not parse JSON. URL: "+d),{}}}})}},c.send(i)})},h={authBasic:function(a,b){g.headers.Authorization="Basic "+e(a+":"+b)},connect:function(a,b,c){return g("CONNECT",a,b,c)},del:function(a,b,c){return g("DELETE",a,b,c)},get:function(a,b,c){return g("GET",a,b,c)},head:function(a,b,c){return g("HEAD",a,b,c)},headers:function(a){g.headers=a||{}},isAllowed:function(a,b,c){this.options(a,function(a,d){c(-1!==d.text().indexOf(b))})},options:function(a,b,c){return g("OPTIONS",a,b,c)},patch:function(a,b,c){return g("PATCH",a,b,c)},post:function(a,b,c){return g("POST",a,b,c)},put:function(a,b,c){return g("PUT",a,b,c)},trace:function(a,b,c){return g("TRACE",a,b,c)}},i=a.type?a.type.toLowerCase():"get";h[i](a.url,a,function(b,c){200===b||0===b&&c.text()?a.success(c.json(),b,null):a.error(c.text(),b,null)})}function g(a,b){"function"==typeof a&&(b=a,a={}),a=a||{},U.extend(Q,a),delete Q.fixLng,Q.functions&&(delete Q.functions,U.extend(U,a.functions)),"string"==typeof Q.ns&&(Q.ns={namespaces:[Q.ns],defaultNs:Q.ns}),"string"==typeof Q.fallbackNS&&(Q.fallbackNS=[Q.fallbackNS]),("string"==typeof Q.fallbackLng||"boolean"==typeof Q.fallbackLng)&&(Q.fallbackLng=[Q.fallbackLng]),Q.interpolationPrefixEscaped=U.regexEscape(Q.interpolationPrefix),Q.interpolationSuffixEscaped=U.regexEscape(Q.interpolationSuffix),Q.lng||(Q.lng=U.detectLanguage()),M=U.toLanguages(Q.lng),H=M[0],U.log("currentLng set to: "+H),Q.useCookie&&U.cookie.read(Q.cookieName)!==H&&U.cookie.create(Q.cookieName,H,Q.cookieExpirationTime,Q.cookieDomain),Q.detectLngFromLocalStorage&&"undefined"!=typeof document&&window.localStorage&&U.localStorage.setItem("i18next_lng",H);var c=B;a.fixLng&&(c=function(a,b){return b=b||{},b.lng=b.lng||c.lng,B(a,b)},c.lng=H),X.setCurrentLng(H),I&&Q.setJqueryExt&&u();var d;if(I&&I.Deferred&&(d=I.Deferred()),!Q.resStore){var e=U.toLanguages(Q.lng);"string"==typeof Q.preload&&(Q.preload=[Q.preload]);for(var f=0,g=Q.preload.length;g>f;f++)for(var h=U.toLanguages(Q.preload[f]),i=0,j=h.length;j>i;i++)e.indexOf(h[i])<0&&e.push(h[i]);return J.sync.load(e,Q,function(a,e){K=e,N=!0,b&&b(c),d&&d.resolve(c)}),d?d.promise():void 0}return K=Q.resStore,N=!0,b&&b(c),d&&d.resolve(c),d?d.promise():void 0}function h(a,b){"string"==typeof a&&(a=[a]);for(var c=0,d=a.length;d>c;c++)Q.preload.indexOf(a[c])<0&&Q.preload.push(a[c]);return g(b)}function i(a,b,c,d){"string"!=typeof b?(c=b,b=Q.ns.defaultNs):Q.ns.namespaces.indexOf(b)<0&&Q.ns.namespaces.push(b),K[a]=K[a]||{},K[a][b]=K[a][b]||{},d?U.deepExtend(K[a][b],c):U.extend(K[a][b],c),Q.useLocalStorage&&O._storeLocal(K)}function j(a,b){"string"!=typeof b&&(b=Q.ns.defaultNs),K[a]=K[a]||{};var c=K[a][b]||{},d=!1;for(var e in c)c.hasOwnProperty(e)&&(d=!0);return d}function k(a,b){return"string"!=typeof b&&(b=Q.ns.defaultNs),K[a]=K[a]||{},U.extend({},K[a][b])}function l(a,b){"string"!=typeof b&&(b=Q.ns.defaultNs),K[a]=K[a]||{},K[a][b]={},Q.useLocalStorage&&O._storeLocal(K)}function m(a,b,c,d){"string"!=typeof b?(resource=b,b=Q.ns.defaultNs):Q.ns.namespaces.indexOf(b)<0&&Q.ns.namespaces.push(b),K[a]=K[a]||{},K[a][b]=K[a][b]||{};for(var e=c.split(Q.keyseparator),f=0,g=K[a][b];e[f];)f==e.length-1?g[e[f]]=d:(null==g[e[f]]&&(g[e[f]]={}),g=g[e[f]]),f++;Q.useLocalStorage&&O._storeLocal(K)}function n(a,b,c){"string"!=typeof b?(resource=b,b=Q.ns.defaultNs):Q.ns.namespaces.indexOf(b)<0&&Q.ns.namespaces.push(b);for(var d in c)"string"==typeof c[d]&&m(a,b,d,c[d])}function o(a){Q.ns.defaultNs=a}function p(a,b){q([a],b)}function q(a,b){var c={dynamicLoad:Q.dynamicLoad,resGetPath:Q.resGetPath,getAsync:Q.getAsync,customLoad:Q.customLoad,ns:{namespaces:a,defaultNs:""}},d=U.toLanguages(Q.lng);"string"==typeof Q.preload&&(Q.preload=[Q.preload]);for(var e=0,f=Q.preload.length;f>e;e++)for(var g=U.toLanguages(Q.preload[e]),h=0,i=g.length;i>h;h++)d.indexOf(g[h])<0&&d.push(g[h]);for(var j=[],k=0,l=d.length;l>k;k++){var m=!1,n=K[d[k]];if(n)for(var o=0,p=a.length;p>o;o++)n[a[o]]||(m=!0);else m=!0;m&&j.push(d[k])}j.length?J.sync._fetch(j,c,function(c,d){var e=a.length*j.length;U.each(a,function(a,c){Q.ns.namespaces.indexOf(c)<0&&Q.ns.namespaces.push(c),U.each(j,function(a,f){K[f]=K[f]||{},K[f][c]=d[f][c],e--,0===e&&b&&(Q.useLocalStorage&&J.sync._storeLocal(K),b())})})}):b&&b()}function r(a,b,c){return"function"==typeof b?(c=b,b={}):b||(b={}),b.lng=a,g(b,c)}function s(){return H}function t(a){K={},r(H,a)}function u(){function a(a,b,c){if(0!==b.length){var d="text";if(0===b.indexOf("[")){var e=b.split("]");b=e[1],d=e[0].substr(1,e[0].length-1)}b.indexOf(";")===b.length-1&&(b=b.substr(0,b.length-2));var f;if("html"===d)f=Q.defaultValueFromContent?I.extend({defaultValue:a.html()},c):c,a.html(I.t(b,f));else if("text"===d)f=Q.defaultValueFromContent?I.extend({defaultValue:a.text()},c):c,a.text(I.t(b,f));else if("prepend"===d)f=Q.defaultValueFromContent?I.extend({defaultValue:a.html()},c):c,a.prepend(I.t(b,f));else if("append"===d)f=Q.defaultValueFromContent?I.extend({defaultValue:a.html()},c):c,a.append(I.t(b,f));else if(0===d.indexOf("data-")){var g=d.substr("data-".length);f=Q.defaultValueFromContent?I.extend({defaultValue:a.data(g)},c):c;var h=I.t(b,f);a.data(g,h),a.attr(d,h)}else f=Q.defaultValueFromContent?I.extend({defaultValue:a.attr(d)},c):c,a.attr(d,I.t(b,f))}}function b(b,c){var d=b.attr(Q.selectorAttr);if(d||"undefined"==typeof d||d===!1||(d=b.text()||b.val()),d){var e=b,f=b.data("i18n-target");if(f&&(e=b.find(f)||b),c||Q.useDataAttrOptions!==!0||(c=b.data("i18n-options")),c=c||{},d.indexOf(";")>=0){var g=d.split(";");I.each(g,function(b,d){""!==d&&a(e,d,c)})}else a(e,d,c);Q.useDataAttrOptions===!0&&b.data("i18n-options",c)}}I.t=I.t||B,I.fn.i18n=function(a){return this.each(function(){b(I(this),a);var c=I(this).find("["+Q.selectorAttr+"]");c.each(function(){b(I(this),a)})})}}function v(a,b,c,d){if(!a)return a;if(d=d||b,a.indexOf(d.interpolationPrefix||Q.interpolationPrefix)<0)return a;var e=d.interpolationPrefix?U.regexEscape(d.interpolationPrefix):Q.interpolationPrefixEscaped,f=d.interpolationSuffix?U.regexEscape(d.interpolationSuffix):Q.interpolationSuffixEscaped,g="HTML"+f,h=b.replace&&"object"==typeof b.replace?b.replace:b;return U.each(h,function(b,h){var i=c?c+Q.keyseparator+b:b;"object"==typeof h&&null!==h?a=v(a,h,i,d):d.escapeInterpolation||Q.escapeInterpolation?(a=a.replace(new RegExp([e,i,g].join(""),"g"),U.regexReplacementEscape(h)),a=a.replace(new RegExp([e,i,f].join(""),"g"),U.regexReplacementEscape(U.escape(h)))):a=a.replace(new RegExp([e,i,f].join(""),"g"),U.regexReplacementEscape(h))}),a}function w(a,b){var c=",",d="{",e="}",f=U.extend({},b);for(delete f.postProcess;-1!=a.indexOf(Q.reusePrefix)&&(L++,!(L>Q.maxRecursion));){var g=a.lastIndexOf(Q.reusePrefix),h=a.indexOf(Q.reuseSuffix,g)+Q.reuseSuffix.length,i=a.substring(g,h),j=i.replace(Q.reusePrefix,"").replace(Q.reuseSuffix,"");if(g>=h)return U.error("there is an missing closing in following translation value",a),"";if(-1!=j.indexOf(c)){var k=j.indexOf(c);if(-1!=j.indexOf(d,k)&&-1!=j.indexOf(e,k)){var l=j.indexOf(d,k),m=j.indexOf(e,l)+e.length;try{f=U.extend(f,JSON.parse(j.substring(l,m))),j=j.substring(0,k)}catch(n){}}}var o=E(j,f);a=a.replace(i,U.regexReplacementEscape(o))}return a}function x(a){return a.context&&("string"==typeof a.context||"number"==typeof a.context)}function y(a){return void 0!==a.count&&"string"!=typeof a.count}function z(a){return void 0!==a.indefinite_article&&"string"!=typeof a.indefinite_article&&a.indefinite_article}function A(a,b){b=b||{};var c=C(a,b),d=F(a,b);return void 0!==d||d===c}function B(a,b){return b=b||{},N?(L=0,E.apply(null,arguments)):(U.log("i18next not finished initialization. you might have called t function before loading resources finished."),b.defaultValue||"")}function C(a,b){return void 0!==b.defaultValue?b.defaultValue:a}function D(){for(var a=[],b=1;b1)for(var d=0;d-1&&(e=c.split(Q.nsseparator),i=e[0],c=e[1]),void 0===g&&Q.sendMissing&&"function"==typeof Q.missingKeyHandler&&(b.lng?Q.missingKeyHandler(h[0],i,c,f,h):Q.missingKeyHandler(Q.lng,i,c,f,h));var j;j="string"==typeof Q.postProcess&&""!==Q.postProcess?[Q.postProcess]:"array"==typeof Q.postProcess||"object"==typeof Q.postProcess?Q.postProcess:[],"string"==typeof b.postProcess&&""!==b.postProcess?j=j.concat([b.postProcess]):("array"==typeof b.postProcess||"object"==typeof b.postProcess)&&(j=j.concat(b.postProcess)),void 0!==g&&j.length&&j.forEach(function(a){Y[a]&&(g=Y[a](g,c,b))});var k=f;if(f.indexOf(Q.nsseparator)>-1&&(e=f.split(Q.nsseparator),k=e[1]),k===c&&Q.parseMissingKey&&(f=Q.parseMissingKey(f)),void 0===g&&(f=v(f,b),f=w(f,b),j.length)){var l=C(c,b);j.forEach(function(a){Y[a]&&(g=Y[a](l,c,b))})}return void 0!==g?g:f}function F(a,b){b=b||{};var c,d,e=C(a,b),f=M;if(!K)return e;if("cimode"===f[0].toLowerCase())return e;if(b.lngs&&(f=b.lngs),b.lng&&(f=U.toLanguages(b.lng,b.fallbackLng),!K[f[0]])){var g=Q.getAsync;Q.getAsync=!1,J.sync.load(f,Q,function(a,b){U.extend(K,b),Q.getAsync=g})}var h=b.ns||Q.ns.defaultNs;if(a.indexOf(Q.nsseparator)>-1){var i=a.split(Q.nsseparator);h=i[0],a=i[1]}if(x(b)){c=U.extend({},b),delete c.context,c.defaultValue=Q.contextNotFound;var j=h+Q.nsseparator+a+"_"+b.context;if(d=B(j,c),d!=Q.contextNotFound)return v(d,{context:b.context})}if(y(b,f[0])){c=U.extend({lngs:[f[0]]},b),delete c.count,c._origLng=c._origLng||c.lng||f[0],delete c.lng,c.defaultValue=Q.pluralNotFound;var k;if(X.needsPlural(f[0],b.count)){k=h+Q.nsseparator+a+Q.pluralSuffix;var l=X.get(f[0],b.count);l>=0?k=k+"_"+l:1===l&&(k=h+Q.nsseparator+a)}else k=h+Q.nsseparator+a;if(d=B(k,c),d!=Q.pluralNotFound)return v(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix});if(!(f.length>1))return c.lng=c._origLng,delete c._origLng,d=B(h+Q.nsseparator+a,c),v(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix});var m=f.slice();if(m.shift(),b=U.extend(b,{lngs:m}),b._origLng=c._origLng,delete b.lng,d=B(h+Q.nsseparator+a,b),d!=Q.pluralNotFound)return d}if(z(b)){var n=U.extend({},b);delete n.indefinite_article,n.defaultValue=Q.indefiniteNotFound;var o=h+Q.nsseparator+a+(b.count&&!y(b,f[0])||!b.count?Q.indefiniteSuffix:"");if(d=B(o,n),d!=Q.indefiniteNotFound)return d}for(var p,q=a.split(Q.keyseparator),r=0,s=f.length;s>r&&void 0===p;r++){for(var t=f[r],u=0,A=K[t]&&K[t][h];q[u];)A=A&&A[q[u]],u++;if(void 0!==A){var D=Object.prototype.toString.apply(A);if("string"==typeof A)A=v(A,b),A=w(A,b);else if("[object Array]"!==D||Q.returnObjectTrees||b.returnObjectTrees){if(null===A&&Q.fallbackOnNull===!0)A=void 0;else if(null!==A)if(Q.returnObjectTrees||b.returnObjectTrees){if("[object Number]"!==D&&"[object Function]"!==D&&"[object RegExp]"!==D){var G="[object Array]"===D?[]:{};U.each(A,function(c){G[c]=E(h+Q.nsseparator+a+Q.keyseparator+c,b)}),A=G}}else Q.objectTreeKeyHandler&&"function"==typeof Q.objectTreeKeyHandler?A=Q.objectTreeKeyHandler(a,A,t,h,b):(A="key '"+h+":"+a+" ("+t+")' returned an object instead of string.",U.log(A))}else A=A.join("\n"),A=v(A,b),A=w(A,b);"string"==typeof A&&""===A.trim()&&Q.fallbackOnEmpty===!0&&(A=void 0),p=A}}if(void 0===p&&!b.isFallbackLookup&&(Q.fallbackToDefaultNS===!0||Q.fallbackNS&&Q.fallbackNS.length>0)){if(b.isFallbackLookup=!0,Q.fallbackNS.length){for(var H=0,I=Q.fallbackNS.length;I>H;H++)if(p=F(Q.fallbackNS[H]+Q.nsseparator+a,b),p||""===p&&Q.fallbackOnEmpty===!1){var L=p.indexOf(Q.nsseparator)>-1?p.split(Q.nsseparator)[1]:p,N=e.indexOf(Q.nsseparator)>-1?e.split(Q.nsseparator)[1]:e;if(L!==N)break}}else p=F(a,b);b.isFallbackLookup=!1}return p}function G(){var a,b=Q.lngWhitelist||[],c=[];if("undefined"!=typeof window&&!function(){for(var a=window.location.search.substring(1),b=a.split("&"),d=0;d0){var f=b[d].substring(0,e);f==Q.detectLngQS&&c.push(b[d].substring(e+1))}}}(),Q.useCookie&&"undefined"!=typeof document){var d=U.cookie.read(Q.cookieName);d&&c.push(d)}if(Q.detectLngFromLocalStorage&&"undefined"!=typeof window&&window.localStorage&&c.push(U.localStorage.getItem("i18next_lng")),"undefined"!=typeof navigator){if(navigator.languages)for(var e=0;e-1){var f=e.split("-");e=Q.lowerCaseLng?f[0].toLowerCase()+"-"+f[1].toLowerCase():f[0].toLowerCase()+"-"+f[1].toUpperCase()}if(0===b.length||b.indexOf(e)>-1){a=e;break}}}(),a||(a=Q.fallbackLng[0]),a}Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>0&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=c;arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d))));for(var e=d>=0?Math.min(d,c-1):c-Math.abs(d);e>=0;e--)if(e in b&&b[e]===a)return e;return-1}),"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")});var H,I=a.jQuery||a.Zepto,J={},K={},L=0,M=[],N=!1,O={};if("undefined"!=typeof module&&module.exports){if(module.exports=J,!I)try{I=require("jquery")}catch(P){}}else a.i18n=a.i18n||J;I&&(I.i18n=I.i18n||J),O={load:function(a,b,c){b.useLocalStorage?O._loadLocal(a,b,function(d,e){for(var f=[],g=0,h=a.length;h>g;g++)e[a[g]]||f.push(a[g]);f.length>0?O._fetch(f,b,function(a,b){U.extend(e,b),O._storeLocal(b),c(null,e)}):c(null,e)}):O._fetch(a,b,function(a,b){c(null,b)})},_loadLocal:function(a,b,c){var d={},e=(new Date).getTime();if(window.localStorage){var f=a.length;U.each(a,function(a,g){var h=U.localStorage.getItem("res_"+g);h&&(h=JSON.parse(h),h.i18nStamp&&h.i18nStamp+b.localStorageExpirationTime>e&&(d[g]=h)),f--,0===f&&c(null,d)})}},_storeLocal:function(a){if(window.localStorage)for(var b in a)a[b].i18nStamp=(new Date).getTime(),U.localStorage.setItem("res_"+b,JSON.stringify(a[b]))},_fetch:function(a,b,c){var d=b.ns,e={};if(b.dynamicLoad){var f=function(a,b){c(null,b)};if("function"==typeof b.customLoad)b.customLoad(a,d.namespaces,b,f);else{var g=v(b.resGetPath,{lng:a.join("+"),ns:d.namespaces.join("+")});U.ajax({url:g,success:function(a){U.log("loaded: "+g),f(null,a)},error:function(a,b,c){U.log("failed loading: "+g),f("failed loading resource.json error: "+c)},dataType:"json",async:b.getAsync})}}else{var h,i=d.namespaces.length*a.length;U.each(d.namespaces,function(d,f){U.each(a,function(a,d){var g=function(a,b){a&&(h=h||[],h.push(a)),e[d]=e[d]||{},e[d][f]=b,i--,0===i&&c(h,e)};"function"==typeof b.customLoad?b.customLoad(d,f,b,g):O._fetchOne(d,f,b,g)})})}},_fetchOne:function(a,b,c,d){var e=v(c.resGetPath,{lng:a,ns:b});U.ajax({url:e,success:function(a){U.log("loaded: "+e),d(null,a)},error:function(a,b,c){if(b&&200==b||a&&a.status&&200==a.status)U.error("There is a typo in: "+e);else if(b&&404==b||a&&a.status&&404==a.status)U.log("Does not exist: "+e);else{var f=b?b:a&&a.status?a.status:null;U.log(f+" when loading "+e)}d(c,{})},dataType:"json",async:c.getAsync})},postMissing:function(a,b,c,d,e){var f={};f[c]=d;var g=[];if("fallback"===Q.sendMissingTo&&Q.fallbackLng[0]!==!1)for(var h=0;hh;h++)g.push({lng:e[h],url:v(Q.resPostPath,{lng:e[h],ns:b})});for(var j=0,k=g.length;k>j;j++){var l=g[j];U.ajax({url:l.url,type:Q.sendType,data:f,success:function(){U.log("posted missing key '"+c+"' to: "+l.url);for(var a=c.split("."),e=0,f=K[l.lng][b];a[e];)f=f[a[e]]=e===a.length-1?d:f[a[e]]||{},e++},error:function(){U.log("failed posting missing key '"+c+"' to: "+l.url)},dataType:"json",async:Q.postAsync})}},reload:t};var Q={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:["dev"],fallbackNS:[],detectLngQS:"setLng",detectLngFromLocalStorage:!1,ns:{namespaces:["translation"],defaultNs:"translation"},fallbackOnNull:!0,fallbackOnEmpty:!1,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",defaultVariables:!1,reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,indefiniteSuffix:"_indefinite",indefiniteNotFound:["indefinite_not_found",Math.random()].join(""),setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",cookieDomain:void 0,objectTreeKeyHandler:void 0,postProcess:void 0,parseMissingKey:void 0,missingKeyHandler:O.postMissing,shortcutFunction:"sprintf"},R={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},S={create:function(a,b,c,d){var e;if(c){var f=new Date;f.setTime(f.getTime()+60*c*1e3),e="; expires="+f.toGMTString()}else e="";d=d?"domain="+d+";":"",document.cookie=a+"="+b+e+";"+d+"path=/"},read:function(a){for(var b=a+"=",c=document.cookie.split(";"),d=0;d-1){var c=a.split("-");b=Q.lowerCaseLng?c[0].toLowerCase()+"-"+c[1].toLowerCase():c[0].toLowerCase()+"-"+c[1].toUpperCase()}else b=Q.lowerCaseLng?a.toLowerCase():a;return b}var c=this.log,d=[],e=Q.lngWhitelist||!1,f=function(a){!e||e.indexOf(a)>-1?d.push(a):c("rejecting non-whitelisted language: "+a)};if("string"==typeof a&&a.indexOf("-")>-1){var g=a.split("-");"unspecific"!==Q.load&&f(b(a)),"current"!==Q.load&&f(b(g[this.getCountyIndexOfLng(a)]))}else f(b(a));for(var h=0;h1)},2:function(a){return Number(1!=a)},3:function(){return 0},4:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},5:function(a){return Number(0===a?0:1==a?1:2==a?2:a%100>=3&&10>=a%100?3:a%100>=11?4:5)},6:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)},7:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},8:function(a){return Number(1==a?0:2==a?1:8!=a&&11!=a?2:3)},9:function(a){return Number(a>=2)},10:function(a){return Number(1==a?0:2==a?1:7>a?2:11>a?3:4)},11:function(a){return Number(1==a||11==a?0:2==a||12==a?1:a>2&&20>a?2:3)},12:function(a){return Number(a%10!=1||a%100==11)},13:function(a){return Number(0!==a)},14:function(a){return Number(1==a?0:2==a?1:3==a?2:3)},15:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&(10>a%100||a%100>=20)?1:2)},16:function(a){return Number(a%10==1&&a%100!=11?0:0!==a?1:2)},17:function(a){return Number(1==a||a%10==1?0:1)},18:function(a){return Number(1==a?1:2)},19:function(a){return Number(1==a?0:0===a||a%100>1&&11>a%100?1:a%100>10&&20>a%100?2:3)},20:function(a){return Number(1==a?0:0===a||a%100>0&&20>a%100?1:2)},21:function(a){return Number(a%100==1?1:a%100==2?2:a%100==3||a%100==4?3:0)}},X={rules:function(){var a,b={};for(a=V.length;a--;)b[V[a][0]]={name:V[a][1],numbers:V[a][2],plurals:W[V[a][3]]};return b}(),addRule:function(a,b){X.rules[a]=b},setCurrentLng:function(a){if(!X.currentRule||X.currentRule.lng!==a){var b=a.split("-");X.currentRule={lng:a,rule:X.rules[b[0]]}}},needsPlural:function(a,b){var c,d=a.split("-");return c=X.currentRule&&X.currentRule.lng===a?X.currentRule.rule:X.rules[d[U.getCountyIndexOfLng(a)]],c&&c.numbers.length<=1?!1:1!==this.get(a,b)},get:function(a,b){function c(b,c){var d;if(d=X.currentRule&&X.currentRule.lng===a?X.currentRule.rule:X.rules[b]){var e;e=d.plurals(d.noAbs?c:Math.abs(c));var f=d.numbers[e];return 2===d.numbers.length&&1===d.numbers[0]&&(2===f?f=-1:1===f&&(f=1)),f}return 1===c?"1":"-1"}var d=a.split("-");return c(d[U.getCountyIndexOfLng(a)],b)}},Y={},Z=function(a,b){Y[a]=b},$=function(){function a(a){return Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}function b(a,b){for(var c=[];b>0;c[--b]=a);return c.join("")}var c=function(){return c.cache.hasOwnProperty(arguments[0])||(c.cache[arguments[0]]=c.parse(arguments[0])),c.format.call(null,c.cache[arguments[0]],arguments)};return c.format=function(c,d){var e,f,g,h,i,j,k,l=1,m=c.length,n="",o=[];for(f=0;m>f;f++)if(n=a(c[f]),"string"===n)o.push(c[f]);else if("array"===n){if(h=c[f],h[2])for(e=d[l],g=0;g=0?"+"+e:e,j=h[4]?"0"==h[4]?"0":h[4].charAt(1):" ",k=h[6]-String(e).length,i=h[6]?b(j,k):"",o.push(h[5]?e+i:i+e)}return o.join("")},c.cache={},c.parse=function(a){for(var b=a,c=[],d=[],e=0;b;){if(null!==(c=/^[^\x25]+/.exec(b)))d.push(c[0]);else if(null!==(c=/^\x25{2}/.exec(b)))d.push("%");else{if(null===(c=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(b)))throw"[sprintf] huh?";if(c[2]){e|=1;var f=[],g=c[2],h=[];if(null===(h=/^([a-z_][a-z_\d]*)/i.exec(g)))throw"[sprintf] huh?";for(f.push(h[1]);""!==(g=g.substring(h[0].length));)if(null!==(h=/^\.([a-z_][a-z_\d]*)/i.exec(g)))f.push(h[1]);else{if(null===(h=/^\[(\d+)\]/.exec(g)))throw"[sprintf] huh?";f.push(h[1])}c[2]=f}else e|=2;if(3===e)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";d.push(c)}b=b.substring(c[0].length)}return d},c}(),_=function(a,b){return b.unshift(a),$.apply(null,b)};Z("sprintf",function(a,b,c){return c.sprintf?"[object Array]"===Object.prototype.toString.apply(c.sprintf)?_(a,c.sprintf):"object"==typeof c.sprintf?$(a,c.sprintf):a:a}),J.init=g,J.setLng=r,J.preload=h,J.addResourceBundle=i,J.hasResourceBundle=j,J.getResourceBundle=k,J.addResource=m,J.addResources=n,J.removeResourceBundle=l,J.loadNamespace=p,J.loadNamespaces=q,J.setDefaultNamespace=o,J.t=B,J.translate=B,J.exists=A,J.detectLanguage=U.detectLanguage,J.pluralExtensions=X,J.sync=O,J.functions=U,J.lng=s,J.addPostProcessor=Z,J.applyReplacement=U.applyReplacement,J.options=Q}("undefined"==typeof exports?window:exports); \ No newline at end of file diff --git a/libs/i18next/release/i18next.commonjs.withJQuery-latest.js b/libs/i18next/release/i18next.commonjs.withJQuery-latest.js new file mode 100644 index 00000000..fb96e55b --- /dev/null +++ b/libs/i18next/release/i18next.commonjs.withJQuery-latest.js @@ -0,0 +1,2186 @@ +// i18next, v1.8.2 +// Copyright (c)2015 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +(function(root) { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + // Add string trim for IE8. + if (typeof String.prototype.trim !== 'function') { + String.prototype.trim = function() { + return this.replace(/^\s+|\s+$/g, ''); + } + } + + var $ = root.jQuery || root.Zepto + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = [] + , initialized = false + , sync = {}; + + + + // Export the i18next object for **CommonJS**. + // If we're not in CommonJS, add `i18n` to the + // global object or to jquery. + if (typeof module !== 'undefined' && module.exports) { + module.exports = i18n; + if (!$) { + try { + $ = require('jquery'); + } catch(e) { + // just ignore + } + } + + } else { + root.i18n = root.i18n || i18n; + } + + if ($) { + $.i18n = $.i18n || i18n; + } + sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = f.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + f.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + if ((status && status == 200) || (xhr && xhr.status && xhr.status == 200)) { + // file loaded but invalid json, stop waste time ! + f.error('There is a typo in: ' + url); + } else if ((status && status == 404) || (xhr && xhr.status && xhr.status == 404)) { + f.log('Does not exist: ' + url); + } else { + var theStatus = status ? status : ((xhr && xhr.status) ? xhr.status : null); + f.log(theStatus + ' when loading ' + url); + } + + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback' && o.fallbackLng[0] !== false) { + for (var i = 0; i < o.fallbackLng.length; i++) { + urls.push({lng: o.fallbackLng[i], url: applyReplacement(o.resPostPath, { lng: o.fallbackLng[i], ns: ns })}); + } + } else if (o.sendMissingTo === 'current' || (o.sendMissingTo === 'fallback' && o.fallbackLng[0] === false) ) { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + }, + + reload: reload + }; + // defaults + var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: ['dev'], + fallbackNS: [], + detectLngQS: 'setLng', + detectLngFromLocalStorage: false, + ns: { + namespaces: ['translation'], + defaultNs: 'translation' + }, + fallbackOnNull: true, + fallbackOnEmpty: false, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + defaultVariables: false, + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + indefiniteSuffix: '_indefinite', + indefiniteNotFound: ['indefinite_not_found', Math.random()].join(''), + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + cookieDomain: undefined, + + objectTreeKeyHandler: undefined, + postProcess: undefined, + parseMissingKey: undefined, + missingKeyHandler: sync.postMissing, + + shortcutFunction: 'sprintf' // or: defaultValue + }; + function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; + } + + function _deepExtend(target, source) { + for (var prop in source) + if (prop in target) + _deepExtend(target[prop], source[prop]); + else + target[prop] = source[prop]; + return target; + } + + function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || Object.prototype.toString.apply(object) !== '[object Array]' || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; + } + + var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' + }; + + function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } + } + + function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + try { + return JSON.parse(data) + } catch (e) { + f.error('Can not parse JSON. URL: ' + url); + return {}; + } + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + // file: protocol always gives status code 0, so check for data + if (status === 200 || (status === 0 && data.text())) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); + } + + var _cookie = { + create: function(name,value,minutes,domain) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + domain = (domain)? "domain="+domain+";" : ""; + document.cookie = name+"="+value+expires+";"+domain+"path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } + }; + + var cookie_noop = { + create: function(name,value,minutes,domain) {}, + read: function(name) { return null; }, + remove: function(name) {} + }; + + + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + extend: $ ? $.extend : _extend, + deepExtend: _deepExtend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : (typeof document !== 'undefined' ? _ajax : function() {}), + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + error: function(str) { + if (typeof console !== "undefined") console.error(str); + }, + getCountyIndexOfLng: function(lng) { + var lng_index = 0; + if (lng === 'nb-NO' || lng === 'nn-NO' || lng === 'nb-no' || lng === 'nn-no') lng_index = 1; + return lng_index; + }, + toLanguages: function(lng) { + var log = this.log; + + function applyCase(l) { + var ret = l; + + if (typeof l === 'string' && l.indexOf('-') > -1) { + var parts = l.split('-'); + + ret = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } else { + ret = o.lowerCaseLng ? l.toLowerCase() : l; + } + + return ret; + } + + var languages = []; + var whitelist = o.lngWhitelist || false; + var addLanguage = function(language){ + //reject langs not whitelisted + if(!whitelist || whitelist.indexOf(language) > -1){ + languages.push(language); + }else{ + log('rejecting non-whitelisted language: ' + language); + } + }; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + if (o.load !== 'unspecific') addLanguage(applyCase(lng)); + if (o.load !== 'current') addLanguage(applyCase(parts[this.getCountyIndexOfLng(lng)])); + } else { + addLanguage(applyCase(lng)); + } + + for (var i = 0; i < o.fallbackLng.length; i++) { + if (languages.indexOf(o.fallbackLng[i]) === -1 && o.fallbackLng[i]) languages.push(applyCase(o.fallbackLng[i])); + } + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + }, + regexReplacementEscape: function(strOrFn) { + if (typeof strOrFn === 'string') { + return strOrFn.replace(/\$/g, "$$$$"); + } else { + return strOrFn; + } + }, + localStorage: { + setItem: function(key, value) { + if (window.localStorage) { + try { + window.localStorage.setItem(key, value); + } catch (e) { + f.log('failed to set value for key "' + key + '" to localStorage.'); + } + } + }, + getItem: function(key, value) { + if (window.localStorage) { + try { + return window.localStorage.getItem(key, value); + } catch (e) { + f.log('failed to get value for key "' + key + '" from localStorage.'); + return undefined; + } + } + } + } + }; + function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + delete o.fixLng; /* passed in each time */ + + // override functions: .log(), .detectLanguage(), etc + if (o.functions) { + delete o.functions; + f.extend(f, options.functions); + } + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // fallback languages + if (typeof o.fallbackLng == 'string' || typeof o.fallbackLng == 'boolean') { + o.fallbackLng = [o.fallbackLng]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + if (o.useCookie && f.cookie.read(o.cookieName) !== currentLng){ //cookie is unset or invalid + f.cookie.create(o.cookieName, currentLng, o.cookieExpirationTime, o.cookieDomain); + } + if (o.detectLngFromLocalStorage && typeof document !== 'undefined' && window.localStorage) { + f.localStorage.setItem('i18next_lng', currentLng); + } + + var lngTranslate = translate; + if (options.fixLng) { + lngTranslate = function(key, options) { + options = options || {}; + options.lng = options.lng || lngTranslate.lng; + return translate(key, options); + }; + lngTranslate.lng = currentLng; + } + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + initialized = true; + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + initialized = true; + + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + }); + + if (deferred) return deferred.promise(); + } + function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); + } + + function addResourceBundle(lng, ns, resources, deep) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + if (deep) { + f.deepExtend(resStore[lng][ns], resources); + } else { + f.extend(resStore[lng][ns], resources); + } + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function hasResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + var res = resStore[lng][ns] || {}; + + var hasValues = false; + for(var prop in res) { + if (res.hasOwnProperty(prop)) { + hasValues = true; + } + } + + return hasValues; + } + + function getResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + return f.extend({}, resStore[lng][ns]); + } + + function removeResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = {}; + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function addResource(lng, ns, key, value) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + var keys = key.split(o.keyseparator); + var x = 0; + var node = resStore[lng][ns]; + var origRef = node; + + while (keys[x]) { + if (x == keys.length - 1) + node[keys[x]] = value; + else { + if (node[keys[x]] == null) + node[keys[x]] = {}; + + node = node[keys[x]]; + } + x++; + } + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } + } + + function addResources(lng, ns, resources) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + for (var m in resources) { + if (typeof resources[m] === 'string') addResource(lng, ns, m, resources[m]); + } + } + + function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; + } + + function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); + } + + function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } + } + + function setLng(lng, options, cb) { + if (typeof options === 'function') { + cb = options; + options = {}; + } else if (!options) { + options = {}; + } + + options.lng = lng; + return init(options, cb); + } + + function lng() { + return currentLng; + } + + function reload(cb) { + resStore = {}; + setLng(currentLng, cb); + } + function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else if (attr === 'prepend') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.prepend($.t(key, optionsToUse)); + } else if (attr === 'append') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.append($.t(key, optionsToUse)); + } else if (attr.indexOf("data-") === 0) { + var dataAttr = attr.substr(("data-").length); + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.data(dataAttr) }, options) : options; + var translated = $.t(key, optionsToUse); + //we change into the data cache + ele.data(dataAttr, translated); + //we change into the dom + ele.attr(attr, translated); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key && typeof key !== 'undefined' && key !== false) key = ele.text() || ele.val(); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; + } + function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + var hash = replacementHash.replace && typeof replacementHash.replace === 'object' ? replacementHash.replace : replacementHash; + f.each(hash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), f.regexReplacementEscape(value)); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(f.escape(value))); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(value)); + } + // str = options.escapeInterpolation; + } + }); + return str; + } + + // append it to functions + f.applyReplacement = applyReplacement; + + function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + if (index_of_end_of_closing <= index_of_opening) { + f.error('there is an missing closing in following translation value', translated); + return ''; + } + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, f.regexReplacementEscape(translated_token)); + } + return translated; + } + + function hasContext(options) { + return (options.context && (typeof options.context == 'string' || typeof options.context == 'number')); + } + + function needsPlural(options, lng) { + return (options.count !== undefined && typeof options.count != 'string'/* && pluralExtensions.needsPlural(lng, options.count)*/); + } + + function needsIndefiniteArticle(options) { + return (options.indefinite_article !== undefined && typeof options.indefinite_article != 'string' && options.indefinite_article); + } + + function exists(key, options) { + options = options || {}; + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options); + + return found !== undefined || found === notFound; + } + + function translate(key, options) { + options = options || {}; + + if (!initialized) { + f.log('i18next not finished initialization. you might have called t function before loading resources finished.') + return options.defaultValue || ''; + }; + replacementCounter = 0; + return _translate.apply(null, arguments); + } + + function _getDefaultValue(key, options) { + return (options.defaultValue !== undefined) ? options.defaultValue : key; + } + + function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + } + + function _translate(potentialKeys, options) { + if (options && typeof options !== 'object') { + if (o.shortcutFunction === 'sprintf') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else if (o.shortcutFunction === 'defaultValue') { + options = { + defaultValue: options + } + } + } else { + options = options || {}; + } + + if (typeof o.defaultVariables === 'object') { + options = f.extend({}, o.defaultVariables, options); + } + + if (potentialKeys === undefined || potentialKeys === null || potentialKeys === '') return ''; + + if (typeof potentialKeys === 'number') { + potentialKeys = String(potentialKeys); + } + + if (typeof potentialKeys === 'string') { + potentialKeys = [potentialKeys]; + } + + var key = potentialKeys[0]; + + if (potentialKeys.length > 1) { + for (var i = 0; i < potentialKeys.length; i++) { + key = potentialKeys[i]; + if (exists(key, options)) { + break; + } + } + } + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng, options.fallbackLng) : languages + , ns = options.ns || o.ns.defaultNs + , parts; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing && typeof o.missingKeyHandler === 'function') { + if (options.lng) { + o.missingKeyHandler(lngs[0], ns, key, notFound, lngs); + } else { + o.missingKeyHandler(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessorsToApply; + if (typeof o.postProcess === 'string' && o.postProcess !== '') { + postProcessorsToApply = [o.postProcess]; + } else if (typeof o.postProcess === 'array' || typeof o.postProcess === 'object') { + postProcessorsToApply = o.postProcess; + } else { + postProcessorsToApply = []; + } + + if (typeof options.postProcess === 'string' && options.postProcess !== '') { + postProcessorsToApply = postProcessorsToApply.concat([options.postProcess]); + } else if (typeof options.postProcess === 'array' || typeof options.postProcess === 'object') { + postProcessorsToApply = postProcessorsToApply.concat(options.postProcess); + } + + if (found !== undefined && postProcessorsToApply.length) { + postProcessorsToApply.forEach(function(postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + }); + } + + // process notFound if function exists + var splitNotFound = notFound; + if (notFound.indexOf(o.nsseparator) > -1) { + parts = notFound.split(o.nsseparator); + splitNotFound = parts[1]; + } + if (splitNotFound === key && o.parseMissingKey) { + notFound = o.parseMissingKey(notFound); + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessorsToApply.length) { + var val = _getDefaultValue(key, options); + postProcessorsToApply.forEach(function(postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](val, key, options); + } + }); + } + } + + return (found !== undefined) ? found : notFound; + } + + function _find(key, options) { + options = options || {}; + + var optionWithoutCount, translated + , notFound = _getDefaultValue(key, options) + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + // CI mode + if (lngs[0].toLowerCase() === 'cimode') return notFound; + + // passed in lng + if (options.lngs) lngs = options.lngs; + if (options.lng) { + lngs = f.toLanguages(options.lng, options.fallbackLng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options, lngs[0])) { + optionWithoutCount = f.extend({ lngs: [lngs[0]]}, options); + delete optionWithoutCount.count; + optionWithoutCount._origLng = optionWithoutCount._origLng || optionWithoutCount.lng || lngs[0]; + delete optionWithoutCount.lng; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey; + if (!pluralExtensions.needsPlural(lngs[0], options.count)) { + pluralKey = ns + o.nsseparator + key; + } else { + pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(lngs[0], options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + } + + translated = translate(pluralKey, optionWithoutCount); + + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } else if (lngs.length > 1) { + // remove failed lng + var clone = lngs.slice(); + clone.shift(); + options = f.extend(options, { lngs: clone }); + options._origLng = optionWithoutCount._origLng; + delete options.lng; + // retry with fallbacks + translated = translate(ns + o.nsseparator + key, options); + if (translated != o.pluralNotFound) return translated; + } else { + optionWithoutCount.lng = optionWithoutCount._origLng; + delete optionWithoutCount._origLng; + translated = translate(ns + o.nsseparator + key, optionWithoutCount); + + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); + } + } + + if (needsIndefiniteArticle(options)) { + var optionsWithoutIndef = f.extend({}, options); + delete optionsWithoutIndef.indefinite_article; + optionsWithoutIndef.defaultValue = o.indefiniteNotFound; + // If we don't have a count, we want the indefinite, if we do have a count, and needsPlural is false + var indefiniteKey = ns + o.nsseparator + key + (((options.count && !needsPlural(options, lngs[0])) || !options.count) ? o.indefiniteSuffix : ""); + translated = translate(indefiniteKey, optionsWithoutIndef); + if (translated != o.indefiniteNotFound) { + return translated; + } + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + var valueType = Object.prototype.toString.apply(value); + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (valueType === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + if (o.objectTreeKeyHandler && typeof o.objectTreeKeyHandler == 'function') { + value = o.objectTreeKeyHandler(key, value, l, ns, options); + } else { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned an object instead of string.'; + f.log(value); + } + } else if (valueType !== '[object Number]' && valueType !== '[object Function]' && valueType !== '[object RegExp]') { + var copy = (valueType === '[object Array]') ? [] : {}; // apply child translation on a copy + f.each(value, function(m) { + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + }); + value = copy; + } + } + + if (typeof value === 'string' && value.trim() === '' && o.fallbackOnEmpty === true) + value = undefined; + + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length > 0))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found || (found==="" && o.fallbackOnEmpty === false)) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + options.isFallbackLookup = false; + } + + return found; + } + function detectLanguage() { + var detectedLng; + var whitelist = o.lngWhitelist || []; + var userLngChoices = []; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var params = query.split('&'); + for (var i=0; i 0) { + var key = params[i].substring(0,pos); + if (key == o.detectLngQS) { + userLngChoices.push(params[i].substring(pos+1)); + } + } + } + })(); + } + + // get from cookie + if (o.useCookie && typeof document !== 'undefined') { + var c = f.cookie.read(o.cookieName); + if (c) userLngChoices.push(c); + } + + // get from localStorage + if (o.detectLngFromLocalStorage && typeof window !== 'undefined' && window.localStorage) { + userLngChoices.push(f.localStorage.getItem('i18next_lng')); + } + + // get from navigator + if (typeof navigator !== 'undefined') { + if (navigator.languages) { // chrome only; not an array, so can't use .push.apply instead of iterating + for (var i=0;i -1) { + var parts = lng.split('-'); + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } + + if (whitelist.length === 0 || whitelist.indexOf(lng) > -1) { + detectedLng = lng; + break; + } + } + })(); + + //fallback + if (!detectedLng){ + detectedLng = o.fallbackLng[0]; + } + + return detectedLng; + } + // definition http://translate.sourceforge.net/wiki/l10n/pluralforms + + /* [code, name, numbers, pluralsType] */ + var _rules = [ + ["ach", "Acholi", [1,2], 1], + ["af", "Afrikaans",[1,2], 2], + ["ak", "Akan", [1,2], 1], + ["am", "Amharic", [1,2], 1], + ["an", "Aragonese",[1,2], 2], + ["ar", "Arabic", [0,1,2,3,11,100],5], + ["arn", "Mapudungun",[1,2], 1], + ["ast", "Asturian", [1,2], 2], + ["ay", "Aymará", [1], 3], + ["az", "Azerbaijani",[1,2],2], + ["be", "Belarusian",[1,2,5],4], + ["bg", "Bulgarian",[1,2], 2], + ["bn", "Bengali", [1,2], 2], + ["bo", "Tibetan", [1], 3], + ["br", "Breton", [1,2], 1], + ["bs", "Bosnian", [1,2,5],4], + ["ca", "Catalan", [1,2], 2], + ["cgg", "Chiga", [1], 3], + ["cs", "Czech", [1,2,5],6], + ["csb", "Kashubian",[1,2,5],7], + ["cy", "Welsh", [1,2,3,8],8], + ["da", "Danish", [1,2], 2], + ["de", "German", [1,2], 2], + ["dev", "Development Fallback", [1,2], 2], + ["dz", "Dzongkha", [1], 3], + ["el", "Greek", [1,2], 2], + ["en", "English", [1,2], 2], + ["eo", "Esperanto",[1,2], 2], + ["es", "Spanish", [1,2], 2], + ["es_ar","Argentinean Spanish", [1,2], 2], + ["et", "Estonian", [1,2], 2], + ["eu", "Basque", [1,2], 2], + ["fa", "Persian", [1], 3], + ["fi", "Finnish", [1,2], 2], + ["fil", "Filipino", [1,2], 1], + ["fo", "Faroese", [1,2], 2], + ["fr", "French", [1,2], 9], + ["fur", "Friulian", [1,2], 2], + ["fy", "Frisian", [1,2], 2], + ["ga", "Irish", [1,2,3,7,11],10], + ["gd", "Scottish Gaelic",[1,2,3,20],11], + ["gl", "Galician", [1,2], 2], + ["gu", "Gujarati", [1,2], 2], + ["gun", "Gun", [1,2], 1], + ["ha", "Hausa", [1,2], 2], + ["he", "Hebrew", [1,2], 2], + ["hi", "Hindi", [1,2], 2], + ["hr", "Croatian", [1,2,5],4], + ["hu", "Hungarian",[1,2], 2], + ["hy", "Armenian", [1,2], 2], + ["ia", "Interlingua",[1,2],2], + ["id", "Indonesian",[1], 3], + ["is", "Icelandic",[1,2], 12], + ["it", "Italian", [1,2], 2], + ["ja", "Japanese", [1], 3], + ["jbo", "Lojban", [1], 3], + ["jv", "Javanese", [0,1], 13], + ["ka", "Georgian", [1], 3], + ["kk", "Kazakh", [1], 3], + ["km", "Khmer", [1], 3], + ["kn", "Kannada", [1,2], 2], + ["ko", "Korean", [1], 3], + ["ku", "Kurdish", [1,2], 2], + ["kw", "Cornish", [1,2,3,4],14], + ["ky", "Kyrgyz", [1], 3], + ["lb", "Letzeburgesch",[1,2],2], + ["ln", "Lingala", [1,2], 1], + ["lo", "Lao", [1], 3], + ["lt", "Lithuanian",[1,2,10],15], + ["lv", "Latvian", [1,2,0],16], + ["mai", "Maithili", [1,2], 2], + ["mfe", "Mauritian Creole",[1,2],1], + ["mg", "Malagasy", [1,2], 1], + ["mi", "Maori", [1,2], 1], + ["mk", "Macedonian",[1,2],17], + ["ml", "Malayalam",[1,2], 2], + ["mn", "Mongolian",[1,2], 2], + ["mnk", "Mandinka", [0,1,2],18], + ["mr", "Marathi", [1,2], 2], + ["ms", "Malay", [1], 3], + ["mt", "Maltese", [1,2,11,20],19], + ["nah", "Nahuatl", [1,2], 2], + ["nap", "Neapolitan",[1,2], 2], + ["nb", "Norwegian Bokmal",[1,2],2], + ["ne", "Nepali", [1,2], 2], + ["nl", "Dutch", [1,2], 2], + ["nn", "Norwegian Nynorsk",[1,2],2], + ["no", "Norwegian",[1,2], 2], + ["nso", "Northern Sotho",[1,2],2], + ["oc", "Occitan", [1,2], 1], + ["or", "Oriya", [2,1], 2], + ["pa", "Punjabi", [1,2], 2], + ["pap", "Papiamento",[1,2], 2], + ["pl", "Polish", [1,2,5],7], + ["pms", "Piemontese",[1,2], 2], + ["ps", "Pashto", [1,2], 2], + ["pt", "Portuguese",[1,2], 2], + ["pt_br","Brazilian Portuguese",[1,2], 2], + ["rm", "Romansh", [1,2], 2], + ["ro", "Romanian", [1,2,20],20], + ["ru", "Russian", [1,2,5],4], + ["sah", "Yakut", [1], 3], + ["sco", "Scots", [1,2], 2], + ["se", "Northern Sami",[1,2], 2], + ["si", "Sinhala", [1,2], 2], + ["sk", "Slovak", [1,2,5],6], + ["sl", "Slovenian",[5,1,2,3],21], + ["so", "Somali", [1,2], 2], + ["son", "Songhay", [1,2], 2], + ["sq", "Albanian", [1,2], 2], + ["sr", "Serbian", [1,2,5],4], + ["su", "Sundanese",[1], 3], + ["sv", "Swedish", [1,2], 2], + ["sw", "Swahili", [1,2], 2], + ["ta", "Tamil", [1,2], 2], + ["te", "Telugu", [1,2], 2], + ["tg", "Tajik", [1,2], 1], + ["th", "Thai", [1], 3], + ["ti", "Tigrinya", [1,2], 1], + ["tk", "Turkmen", [1,2], 2], + ["tr", "Turkish", [1,2], 1], + ["tt", "Tatar", [1], 3], + ["ug", "Uyghur", [1], 3], + ["uk", "Ukrainian",[1,2,5],4], + ["ur", "Urdu", [1,2], 2], + ["uz", "Uzbek", [1,2], 1], + ["vi", "Vietnamese",[1], 3], + ["wa", "Walloon", [1,2], 1], + ["wo", "Wolof", [1], 3], + ["yo", "Yoruba", [1,2], 2], + ["zh", "Chinese", [1], 3] + ]; + + var _rulesPluralsTypes = { + 1: function(n) {return Number(n > 1);}, + 2: function(n) {return Number(n != 1);}, + 3: function(n) {return 0;}, + 4: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 5: function(n) {return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5);}, + 6: function(n) {return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2);}, + 7: function(n) {return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 8: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3);}, + 9: function(n) {return Number(n >= 2);}, + 10: function(n) {return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;}, + 11: function(n) {return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3);}, + 12: function(n) {return Number(n%10!=1 || n%100==11);}, + 13: function(n) {return Number(n !== 0);}, + 14: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3);}, + 15: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 16: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2);}, + 17: function(n) {return Number(n==1 || n%10==1 ? 0 : 1);}, + 18: function(n) {return Number(0 ? 0 : n==1 ? 1 : 2);}, + 19: function(n) {return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3);}, + 20: function(n) {return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2);}, + 21: function(n) {return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } + }; + + var pluralExtensions = { + + rules: (function () { + var l, rules = {}; + for (l=_rules.length; l-- ;) { + rules[_rules[l][0]] = { + name: _rules[l][1], + numbers: _rules[l][2], + plurals: _rulesPluralsTypes[_rules[l][3]] + } + } + return rules; + }()), + + // you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + needsPlural: function(lng, count) { + var parts = lng.split('-'); + + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[parts[f.getCountyIndexOfLng(lng)]]; + } + + if (ext && ext.numbers.length <= 1) { + return false; + } else { + return this.get(lng, count) !== 1; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i; + if (ext.noAbs) { + i = ext.plurals(c); + } else { + i = ext.plurals(Math.abs(c)); + } + + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[f.getCountyIndexOfLng(lng)], count); + } + + }; + var postProcessors = {}; + var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; + }; + // sprintf support + var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; + })(); + + var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); + }; + + addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; + }); + // public api interface + i18n.init = init; + i18n.setLng = setLng; + i18n.preload = preload; + i18n.addResourceBundle = addResourceBundle; + i18n.hasResourceBundle = hasResourceBundle; + i18n.getResourceBundle = getResourceBundle; + i18n.addResource = addResource; + i18n.addResources = addResources; + i18n.removeResourceBundle = removeResourceBundle; + i18n.loadNamespace = loadNamespace; + i18n.loadNamespaces = loadNamespaces; + i18n.setDefaultNamespace = setDefaultNamespace; + i18n.t = translate; + i18n.translate = translate; + i18n.exists = exists; + i18n.detectLanguage = f.detectLanguage; + i18n.pluralExtensions = pluralExtensions; + i18n.sync = sync; + i18n.functions = f; + i18n.lng = lng; + i18n.addPostProcessor = addPostProcessor; + i18n.applyReplacement = f.applyReplacement; + i18n.options = o; + +})(typeof exports === 'undefined' ? window : exports); \ No newline at end of file diff --git a/libs/i18next/release/i18next.commonjs.withJQuery-latest.min.js b/libs/i18next/release/i18next.commonjs.withJQuery-latest.min.js new file mode 100644 index 00000000..af364373 --- /dev/null +++ b/libs/i18next/release/i18next.commonjs.withJQuery-latest.min.js @@ -0,0 +1,5 @@ +// i18next, v1.8.2 +// Copyright (c)2015 Jan Mühlemann (jamuhl). +// Distributed under MIT license +// http://i18next.com +!function(a){function b(a,b){if(!b||"function"==typeof b)return a;for(var c in b)a[c]=b[c];return a}function c(a,b){for(var d in b)d in a?c(a[d],b[d]):a[d]=b[d];return a}function d(a,b,c){var d,e=0,f=a.length,g=void 0===f||"[object Array]"!==Object.prototype.toString.apply(a)||"function"==typeof a;if(c)if(g){for(d in a)if(b.apply(a[d],c)===!1)break}else for(;f>e&&b.apply(a[e++],c)!==!1;);else if(g){for(d in a)if(b.call(a[d],d,a[d])===!1)break}else for(;f>e&&b.call(a[e],e,a[e++])!==!1;);return a}function e(a){return"string"==typeof a?a.replace(/[&<>"'\/]/g,function(a){return R[a]}):a}function f(a){var b=function(a){if(window.XMLHttpRequest)return a(null,new XMLHttpRequest);if(window.ActiveXObject)try{return a(null,new ActiveXObject("Msxml2.XMLHTTP"))}catch(b){return a(null,new ActiveXObject("Microsoft.XMLHTTP"))}return a(new Error)},c=function(a){if("string"==typeof a)return a;var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")},d=function(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;cd?b+=String.fromCharCode(d):d>127&&2048>d?(b+=String.fromCharCode(d>>6|192),b+=String.fromCharCode(63&d|128)):(b+=String.fromCharCode(d>>12|224),b+=String.fromCharCode(d>>6&63|128),b+=String.fromCharCode(63&d|128))}return b},e=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";a=d(a);var c,e,f,g,h,i,j,k="",l=0;do c=a.charCodeAt(l++),e=a.charCodeAt(l++),f=a.charCodeAt(l++),g=c>>2,h=(3&c)<<4|e>>4,i=(15&e)<<2|f>>6,j=63&f,isNaN(e)?i=j=64:isNaN(f)&&(j=64),k+=b.charAt(g)+b.charAt(h)+b.charAt(i)+b.charAt(j),c=e=f="",g=h=i=j="";while(l1&&(d+=d.indexOf("?")>-1?"&"+k:"?"+k),e.jsonp){var l=document.getElementsByTagName("head")[0],m=document.createElement("script");return m.type="text/javascript",m.src=d,void l.appendChild(m)}}b(function(b,c){if(b)return h(b);c.open(a,d,e.async);for(var f in j)j.hasOwnProperty(f)&&c.setRequestHeader(f,j[f]);c.onreadystatechange=function(){if(4===c.readyState){var a=c.responseText||"";if(!h)return;h(c.status,{text:function(){return a},json:function(){try{return JSON.parse(a)}catch(b){return U.error("Can not parse JSON. URL: "+d),{}}}})}},c.send(i)})},h={authBasic:function(a,b){g.headers.Authorization="Basic "+e(a+":"+b)},connect:function(a,b,c){return g("CONNECT",a,b,c)},del:function(a,b,c){return g("DELETE",a,b,c)},get:function(a,b,c){return g("GET",a,b,c)},head:function(a,b,c){return g("HEAD",a,b,c)},headers:function(a){g.headers=a||{}},isAllowed:function(a,b,c){this.options(a,function(a,d){c(-1!==d.text().indexOf(b))})},options:function(a,b,c){return g("OPTIONS",a,b,c)},patch:function(a,b,c){return g("PATCH",a,b,c)},post:function(a,b,c){return g("POST",a,b,c)},put:function(a,b,c){return g("PUT",a,b,c)},trace:function(a,b,c){return g("TRACE",a,b,c)}},i=a.type?a.type.toLowerCase():"get";h[i](a.url,a,function(b,c){200===b||0===b&&c.text()?a.success(c.json(),b,null):a.error(c.text(),b,null)})}function g(a,b){"function"==typeof a&&(b=a,a={}),a=a||{},U.extend(Q,a),delete Q.fixLng,Q.functions&&(delete Q.functions,U.extend(U,a.functions)),"string"==typeof Q.ns&&(Q.ns={namespaces:[Q.ns],defaultNs:Q.ns}),"string"==typeof Q.fallbackNS&&(Q.fallbackNS=[Q.fallbackNS]),("string"==typeof Q.fallbackLng||"boolean"==typeof Q.fallbackLng)&&(Q.fallbackLng=[Q.fallbackLng]),Q.interpolationPrefixEscaped=U.regexEscape(Q.interpolationPrefix),Q.interpolationSuffixEscaped=U.regexEscape(Q.interpolationSuffix),Q.lng||(Q.lng=U.detectLanguage()),M=U.toLanguages(Q.lng),H=M[0],U.log("currentLng set to: "+H),Q.useCookie&&U.cookie.read(Q.cookieName)!==H&&U.cookie.create(Q.cookieName,H,Q.cookieExpirationTime,Q.cookieDomain),Q.detectLngFromLocalStorage&&"undefined"!=typeof document&&window.localStorage&&U.localStorage.setItem("i18next_lng",H);var c=B;a.fixLng&&(c=function(a,b){return b=b||{},b.lng=b.lng||c.lng,B(a,b)},c.lng=H),X.setCurrentLng(H),I&&Q.setJqueryExt&&u();var d;if(I&&I.Deferred&&(d=I.Deferred()),!Q.resStore){var e=U.toLanguages(Q.lng);"string"==typeof Q.preload&&(Q.preload=[Q.preload]);for(var f=0,g=Q.preload.length;g>f;f++)for(var h=U.toLanguages(Q.preload[f]),i=0,j=h.length;j>i;i++)e.indexOf(h[i])<0&&e.push(h[i]);return J.sync.load(e,Q,function(a,e){K=e,N=!0,b&&b(c),d&&d.resolve(c)}),d?d.promise():void 0}return K=Q.resStore,N=!0,b&&b(c),d&&d.resolve(c),d?d.promise():void 0}function h(a,b){"string"==typeof a&&(a=[a]);for(var c=0,d=a.length;d>c;c++)Q.preload.indexOf(a[c])<0&&Q.preload.push(a[c]);return g(b)}function i(a,b,c,d){"string"!=typeof b?(c=b,b=Q.ns.defaultNs):Q.ns.namespaces.indexOf(b)<0&&Q.ns.namespaces.push(b),K[a]=K[a]||{},K[a][b]=K[a][b]||{},d?U.deepExtend(K[a][b],c):U.extend(K[a][b],c),Q.useLocalStorage&&O._storeLocal(K)}function j(a,b){"string"!=typeof b&&(b=Q.ns.defaultNs),K[a]=K[a]||{};var c=K[a][b]||{},d=!1;for(var e in c)c.hasOwnProperty(e)&&(d=!0);return d}function k(a,b){return"string"!=typeof b&&(b=Q.ns.defaultNs),K[a]=K[a]||{},U.extend({},K[a][b])}function l(a,b){"string"!=typeof b&&(b=Q.ns.defaultNs),K[a]=K[a]||{},K[a][b]={},Q.useLocalStorage&&O._storeLocal(K)}function m(a,b,c,d){"string"!=typeof b?(resource=b,b=Q.ns.defaultNs):Q.ns.namespaces.indexOf(b)<0&&Q.ns.namespaces.push(b),K[a]=K[a]||{},K[a][b]=K[a][b]||{};for(var e=c.split(Q.keyseparator),f=0,g=K[a][b];e[f];)f==e.length-1?g[e[f]]=d:(null==g[e[f]]&&(g[e[f]]={}),g=g[e[f]]),f++;Q.useLocalStorage&&O._storeLocal(K)}function n(a,b,c){"string"!=typeof b?(resource=b,b=Q.ns.defaultNs):Q.ns.namespaces.indexOf(b)<0&&Q.ns.namespaces.push(b);for(var d in c)"string"==typeof c[d]&&m(a,b,d,c[d])}function o(a){Q.ns.defaultNs=a}function p(a,b){q([a],b)}function q(a,b){var c={dynamicLoad:Q.dynamicLoad,resGetPath:Q.resGetPath,getAsync:Q.getAsync,customLoad:Q.customLoad,ns:{namespaces:a,defaultNs:""}},d=U.toLanguages(Q.lng);"string"==typeof Q.preload&&(Q.preload=[Q.preload]);for(var e=0,f=Q.preload.length;f>e;e++)for(var g=U.toLanguages(Q.preload[e]),h=0,i=g.length;i>h;h++)d.indexOf(g[h])<0&&d.push(g[h]);for(var j=[],k=0,l=d.length;l>k;k++){var m=!1,n=K[d[k]];if(n)for(var o=0,p=a.length;p>o;o++)n[a[o]]||(m=!0);else m=!0;m&&j.push(d[k])}j.length?J.sync._fetch(j,c,function(c,d){var e=a.length*j.length;U.each(a,function(a,c){Q.ns.namespaces.indexOf(c)<0&&Q.ns.namespaces.push(c),U.each(j,function(a,f){K[f]=K[f]||{},K[f][c]=d[f][c],e--,0===e&&b&&(Q.useLocalStorage&&J.sync._storeLocal(K),b())})})}):b&&b()}function r(a,b,c){return"function"==typeof b?(c=b,b={}):b||(b={}),b.lng=a,g(b,c)}function s(){return H}function t(a){K={},r(H,a)}function u(){function a(a,b,c){if(0!==b.length){var d="text";if(0===b.indexOf("[")){var e=b.split("]");b=e[1],d=e[0].substr(1,e[0].length-1)}b.indexOf(";")===b.length-1&&(b=b.substr(0,b.length-2));var f;if("html"===d)f=Q.defaultValueFromContent?I.extend({defaultValue:a.html()},c):c,a.html(I.t(b,f));else if("text"===d)f=Q.defaultValueFromContent?I.extend({defaultValue:a.text()},c):c,a.text(I.t(b,f));else if("prepend"===d)f=Q.defaultValueFromContent?I.extend({defaultValue:a.html()},c):c,a.prepend(I.t(b,f));else if("append"===d)f=Q.defaultValueFromContent?I.extend({defaultValue:a.html()},c):c,a.append(I.t(b,f));else if(0===d.indexOf("data-")){var g=d.substr("data-".length);f=Q.defaultValueFromContent?I.extend({defaultValue:a.data(g)},c):c;var h=I.t(b,f);a.data(g,h),a.attr(d,h)}else f=Q.defaultValueFromContent?I.extend({defaultValue:a.attr(d)},c):c,a.attr(d,I.t(b,f))}}function b(b,c){var d=b.attr(Q.selectorAttr);if(d||"undefined"==typeof d||d===!1||(d=b.text()||b.val()),d){var e=b,f=b.data("i18n-target");if(f&&(e=b.find(f)||b),c||Q.useDataAttrOptions!==!0||(c=b.data("i18n-options")),c=c||{},d.indexOf(";")>=0){var g=d.split(";");I.each(g,function(b,d){""!==d&&a(e,d,c)})}else a(e,d,c);Q.useDataAttrOptions===!0&&b.data("i18n-options",c)}}I.t=I.t||B,I.fn.i18n=function(a){return this.each(function(){b(I(this),a);var c=I(this).find("["+Q.selectorAttr+"]");c.each(function(){b(I(this),a)})})}}function v(a,b,c,d){if(!a)return a;if(d=d||b,a.indexOf(d.interpolationPrefix||Q.interpolationPrefix)<0)return a;var e=d.interpolationPrefix?U.regexEscape(d.interpolationPrefix):Q.interpolationPrefixEscaped,f=d.interpolationSuffix?U.regexEscape(d.interpolationSuffix):Q.interpolationSuffixEscaped,g="HTML"+f,h=b.replace&&"object"==typeof b.replace?b.replace:b;return U.each(h,function(b,h){var i=c?c+Q.keyseparator+b:b;"object"==typeof h&&null!==h?a=v(a,h,i,d):d.escapeInterpolation||Q.escapeInterpolation?(a=a.replace(new RegExp([e,i,g].join(""),"g"),U.regexReplacementEscape(h)),a=a.replace(new RegExp([e,i,f].join(""),"g"),U.regexReplacementEscape(U.escape(h)))):a=a.replace(new RegExp([e,i,f].join(""),"g"),U.regexReplacementEscape(h))}),a}function w(a,b){var c=",",d="{",e="}",f=U.extend({},b);for(delete f.postProcess;-1!=a.indexOf(Q.reusePrefix)&&(L++,!(L>Q.maxRecursion));){var g=a.lastIndexOf(Q.reusePrefix),h=a.indexOf(Q.reuseSuffix,g)+Q.reuseSuffix.length,i=a.substring(g,h),j=i.replace(Q.reusePrefix,"").replace(Q.reuseSuffix,"");if(g>=h)return U.error("there is an missing closing in following translation value",a),"";if(-1!=j.indexOf(c)){var k=j.indexOf(c);if(-1!=j.indexOf(d,k)&&-1!=j.indexOf(e,k)){var l=j.indexOf(d,k),m=j.indexOf(e,l)+e.length;try{f=U.extend(f,JSON.parse(j.substring(l,m))),j=j.substring(0,k)}catch(n){}}}var o=E(j,f);a=a.replace(i,U.regexReplacementEscape(o))}return a}function x(a){return a.context&&("string"==typeof a.context||"number"==typeof a.context)}function y(a){return void 0!==a.count&&"string"!=typeof a.count}function z(a){return void 0!==a.indefinite_article&&"string"!=typeof a.indefinite_article&&a.indefinite_article}function A(a,b){b=b||{};var c=C(a,b),d=F(a,b);return void 0!==d||d===c}function B(a,b){return b=b||{},N?(L=0,E.apply(null,arguments)):(U.log("i18next not finished initialization. you might have called t function before loading resources finished."),b.defaultValue||"")}function C(a,b){return void 0!==b.defaultValue?b.defaultValue:a}function D(){for(var a=[],b=1;b1)for(var d=0;d-1&&(e=c.split(Q.nsseparator),i=e[0],c=e[1]),void 0===g&&Q.sendMissing&&"function"==typeof Q.missingKeyHandler&&(b.lng?Q.missingKeyHandler(h[0],i,c,f,h):Q.missingKeyHandler(Q.lng,i,c,f,h));var j;j="string"==typeof Q.postProcess&&""!==Q.postProcess?[Q.postProcess]:"array"==typeof Q.postProcess||"object"==typeof Q.postProcess?Q.postProcess:[],"string"==typeof b.postProcess&&""!==b.postProcess?j=j.concat([b.postProcess]):("array"==typeof b.postProcess||"object"==typeof b.postProcess)&&(j=j.concat(b.postProcess)),void 0!==g&&j.length&&j.forEach(function(a){Y[a]&&(g=Y[a](g,c,b))});var k=f;if(f.indexOf(Q.nsseparator)>-1&&(e=f.split(Q.nsseparator),k=e[1]),k===c&&Q.parseMissingKey&&(f=Q.parseMissingKey(f)),void 0===g&&(f=v(f,b),f=w(f,b),j.length)){var l=C(c,b);j.forEach(function(a){Y[a]&&(g=Y[a](l,c,b))})}return void 0!==g?g:f}function F(a,b){b=b||{};var c,d,e=C(a,b),f=M;if(!K)return e;if("cimode"===f[0].toLowerCase())return e;if(b.lngs&&(f=b.lngs),b.lng&&(f=U.toLanguages(b.lng,b.fallbackLng),!K[f[0]])){var g=Q.getAsync;Q.getAsync=!1,J.sync.load(f,Q,function(a,b){U.extend(K,b),Q.getAsync=g})}var h=b.ns||Q.ns.defaultNs;if(a.indexOf(Q.nsseparator)>-1){var i=a.split(Q.nsseparator);h=i[0],a=i[1]}if(x(b)){c=U.extend({},b),delete c.context,c.defaultValue=Q.contextNotFound;var j=h+Q.nsseparator+a+"_"+b.context;if(d=B(j,c),d!=Q.contextNotFound)return v(d,{context:b.context})}if(y(b,f[0])){c=U.extend({lngs:[f[0]]},b),delete c.count,c._origLng=c._origLng||c.lng||f[0],delete c.lng,c.defaultValue=Q.pluralNotFound;var k;if(X.needsPlural(f[0],b.count)){k=h+Q.nsseparator+a+Q.pluralSuffix;var l=X.get(f[0],b.count);l>=0?k=k+"_"+l:1===l&&(k=h+Q.nsseparator+a)}else k=h+Q.nsseparator+a;if(d=B(k,c),d!=Q.pluralNotFound)return v(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix});if(!(f.length>1))return c.lng=c._origLng,delete c._origLng,d=B(h+Q.nsseparator+a,c),v(d,{count:b.count,interpolationPrefix:b.interpolationPrefix,interpolationSuffix:b.interpolationSuffix});var m=f.slice();if(m.shift(),b=U.extend(b,{lngs:m}),b._origLng=c._origLng,delete b.lng,d=B(h+Q.nsseparator+a,b),d!=Q.pluralNotFound)return d}if(z(b)){var n=U.extend({},b);delete n.indefinite_article,n.defaultValue=Q.indefiniteNotFound;var o=h+Q.nsseparator+a+(b.count&&!y(b,f[0])||!b.count?Q.indefiniteSuffix:"");if(d=B(o,n),d!=Q.indefiniteNotFound)return d}for(var p,q=a.split(Q.keyseparator),r=0,s=f.length;s>r&&void 0===p;r++){for(var t=f[r],u=0,A=K[t]&&K[t][h];q[u];)A=A&&A[q[u]],u++;if(void 0!==A){var D=Object.prototype.toString.apply(A);if("string"==typeof A)A=v(A,b),A=w(A,b);else if("[object Array]"!==D||Q.returnObjectTrees||b.returnObjectTrees){if(null===A&&Q.fallbackOnNull===!0)A=void 0;else if(null!==A)if(Q.returnObjectTrees||b.returnObjectTrees){if("[object Number]"!==D&&"[object Function]"!==D&&"[object RegExp]"!==D){var G="[object Array]"===D?[]:{};U.each(A,function(c){G[c]=E(h+Q.nsseparator+a+Q.keyseparator+c,b)}),A=G}}else Q.objectTreeKeyHandler&&"function"==typeof Q.objectTreeKeyHandler?A=Q.objectTreeKeyHandler(a,A,t,h,b):(A="key '"+h+":"+a+" ("+t+")' returned an object instead of string.",U.log(A))}else A=A.join("\n"),A=v(A,b),A=w(A,b);"string"==typeof A&&""===A.trim()&&Q.fallbackOnEmpty===!0&&(A=void 0),p=A}}if(void 0===p&&!b.isFallbackLookup&&(Q.fallbackToDefaultNS===!0||Q.fallbackNS&&Q.fallbackNS.length>0)){if(b.isFallbackLookup=!0,Q.fallbackNS.length){for(var H=0,I=Q.fallbackNS.length;I>H;H++)if(p=F(Q.fallbackNS[H]+Q.nsseparator+a,b),p||""===p&&Q.fallbackOnEmpty===!1){var L=p.indexOf(Q.nsseparator)>-1?p.split(Q.nsseparator)[1]:p,N=e.indexOf(Q.nsseparator)>-1?e.split(Q.nsseparator)[1]:e;if(L!==N)break}}else p=F(a,b);b.isFallbackLookup=!1}return p}function G(){var a,b=Q.lngWhitelist||[],c=[];if("undefined"!=typeof window&&!function(){for(var a=window.location.search.substring(1),b=a.split("&"),d=0;d0){var f=b[d].substring(0,e);f==Q.detectLngQS&&c.push(b[d].substring(e+1))}}}(),Q.useCookie&&"undefined"!=typeof document){var d=U.cookie.read(Q.cookieName);d&&c.push(d)}if(Q.detectLngFromLocalStorage&&"undefined"!=typeof window&&window.localStorage&&c.push(U.localStorage.getItem("i18next_lng")),"undefined"!=typeof navigator){if(navigator.languages)for(var e=0;e-1){var f=e.split("-");e=Q.lowerCaseLng?f[0].toLowerCase()+"-"+f[1].toLowerCase():f[0].toLowerCase()+"-"+f[1].toUpperCase()}if(0===b.length||b.indexOf(e)>-1){a=e;break}}}(),a||(a=Q.fallbackLng[0]),a}Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>0&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(a){"use strict";if(null==this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=c;arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!=d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d))));for(var e=d>=0?Math.min(d,c-1):c-Math.abs(d);e>=0;e--)if(e in b&&b[e]===a)return e;return-1}),"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")});var H,I=a.jQuery||a.Zepto,J={},K={},L=0,M=[],N=!1,O={};if("undefined"!=typeof module&&module.exports){if(module.exports=J,!I)try{I=require("jquery")}catch(P){}}else a.i18n=a.i18n||J;I&&(I.i18n=I.i18n||J),O={load:function(a,b,c){b.useLocalStorage?O._loadLocal(a,b,function(d,e){for(var f=[],g=0,h=a.length;h>g;g++)e[a[g]]||f.push(a[g]);f.length>0?O._fetch(f,b,function(a,b){U.extend(e,b),O._storeLocal(b),c(null,e)}):c(null,e)}):O._fetch(a,b,function(a,b){c(null,b)})},_loadLocal:function(a,b,c){var d={},e=(new Date).getTime();if(window.localStorage){var f=a.length;U.each(a,function(a,g){var h=U.localStorage.getItem("res_"+g);h&&(h=JSON.parse(h),h.i18nStamp&&h.i18nStamp+b.localStorageExpirationTime>e&&(d[g]=h)),f--,0===f&&c(null,d)})}},_storeLocal:function(a){if(window.localStorage)for(var b in a)a[b].i18nStamp=(new Date).getTime(),U.localStorage.setItem("res_"+b,JSON.stringify(a[b]))},_fetch:function(a,b,c){var d=b.ns,e={};if(b.dynamicLoad){var f=function(a,b){c(null,b)};if("function"==typeof b.customLoad)b.customLoad(a,d.namespaces,b,f);else{var g=v(b.resGetPath,{lng:a.join("+"),ns:d.namespaces.join("+")});U.ajax({url:g,success:function(a){U.log("loaded: "+g),f(null,a)},error:function(a,b,c){U.log("failed loading: "+g),f("failed loading resource.json error: "+c)},dataType:"json",async:b.getAsync})}}else{var h,i=d.namespaces.length*a.length;U.each(d.namespaces,function(d,f){U.each(a,function(a,d){var g=function(a,b){a&&(h=h||[],h.push(a)),e[d]=e[d]||{},e[d][f]=b,i--,0===i&&c(h,e)};"function"==typeof b.customLoad?b.customLoad(d,f,b,g):O._fetchOne(d,f,b,g)})})}},_fetchOne:function(a,b,c,d){var e=v(c.resGetPath,{lng:a,ns:b});U.ajax({url:e,success:function(a){U.log("loaded: "+e),d(null,a)},error:function(a,b,c){if(b&&200==b||a&&a.status&&200==a.status)U.error("There is a typo in: "+e);else if(b&&404==b||a&&a.status&&404==a.status)U.log("Does not exist: "+e);else{var f=b?b:a&&a.status?a.status:null;U.log(f+" when loading "+e)}d(c,{})},dataType:"json",async:c.getAsync})},postMissing:function(a,b,c,d,e){var f={};f[c]=d;var g=[];if("fallback"===Q.sendMissingTo&&Q.fallbackLng[0]!==!1)for(var h=0;hh;h++)g.push({lng:e[h],url:v(Q.resPostPath,{lng:e[h],ns:b})});for(var j=0,k=g.length;k>j;j++){var l=g[j];U.ajax({url:l.url,type:Q.sendType,data:f,success:function(){U.log("posted missing key '"+c+"' to: "+l.url);for(var a=c.split("."),e=0,f=K[l.lng][b];a[e];)f=f[a[e]]=e===a.length-1?d:f[a[e]]||{},e++},error:function(){U.log("failed posting missing key '"+c+"' to: "+l.url)},dataType:"json",async:Q.postAsync})}},reload:t};var Q={lng:void 0,load:"all",preload:[],lowerCaseLng:!1,returnObjectTrees:!1,fallbackLng:["dev"],fallbackNS:[],detectLngQS:"setLng",detectLngFromLocalStorage:!1,ns:{namespaces:["translation"],defaultNs:"translation"},fallbackOnNull:!0,fallbackOnEmpty:!1,fallbackToDefaultNS:!1,nsseparator:":",keyseparator:".",selectorAttr:"data-i18n",debug:!1,resGetPath:"locales/__lng__/__ns__.json",resPostPath:"locales/add/__lng__/__ns__",getAsync:!0,postAsync:!0,resStore:void 0,useLocalStorage:!1,localStorageExpirationTime:6048e5,dynamicLoad:!1,sendMissing:!1,sendMissingTo:"fallback",sendType:"POST",interpolationPrefix:"__",interpolationSuffix:"__",defaultVariables:!1,reusePrefix:"$t(",reuseSuffix:")",pluralSuffix:"_plural",pluralNotFound:["plural_not_found",Math.random()].join(""),contextNotFound:["context_not_found",Math.random()].join(""),escapeInterpolation:!1,indefiniteSuffix:"_indefinite",indefiniteNotFound:["indefinite_not_found",Math.random()].join(""),setJqueryExt:!0,defaultValueFromContent:!0,useDataAttrOptions:!1,cookieExpirationTime:void 0,useCookie:!0,cookieName:"i18next",cookieDomain:void 0,objectTreeKeyHandler:void 0,postProcess:void 0,parseMissingKey:void 0,missingKeyHandler:O.postMissing,shortcutFunction:"sprintf"},R={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},S={create:function(a,b,c,d){var e;if(c){var f=new Date;f.setTime(f.getTime()+60*c*1e3),e="; expires="+f.toGMTString()}else e="";d=d?"domain="+d+";":"",document.cookie=a+"="+b+e+";"+d+"path=/"},read:function(a){for(var b=a+"=",c=document.cookie.split(";"),d=0;d-1){var c=a.split("-");b=Q.lowerCaseLng?c[0].toLowerCase()+"-"+c[1].toLowerCase():c[0].toLowerCase()+"-"+c[1].toUpperCase()}else b=Q.lowerCaseLng?a.toLowerCase():a;return b}var c=this.log,d=[],e=Q.lngWhitelist||!1,f=function(a){!e||e.indexOf(a)>-1?d.push(a):c("rejecting non-whitelisted language: "+a)};if("string"==typeof a&&a.indexOf("-")>-1){var g=a.split("-");"unspecific"!==Q.load&&f(b(a)),"current"!==Q.load&&f(b(g[this.getCountyIndexOfLng(a)]))}else f(b(a));for(var h=0;h1)},2:function(a){return Number(1!=a)},3:function(){return 0},4:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},5:function(a){return Number(0===a?0:1==a?1:2==a?2:a%100>=3&&10>=a%100?3:a%100>=11?4:5)},6:function(a){return Number(1==a?0:a>=2&&4>=a?1:2)},7:function(a){return Number(1==a?0:a%10>=2&&4>=a%10&&(10>a%100||a%100>=20)?1:2)},8:function(a){return Number(1==a?0:2==a?1:8!=a&&11!=a?2:3)},9:function(a){return Number(a>=2)},10:function(a){return Number(1==a?0:2==a?1:7>a?2:11>a?3:4)},11:function(a){return Number(1==a||11==a?0:2==a||12==a?1:a>2&&20>a?2:3)},12:function(a){return Number(a%10!=1||a%100==11)},13:function(a){return Number(0!==a)},14:function(a){return Number(1==a?0:2==a?1:3==a?2:3)},15:function(a){return Number(a%10==1&&a%100!=11?0:a%10>=2&&(10>a%100||a%100>=20)?1:2)},16:function(a){return Number(a%10==1&&a%100!=11?0:0!==a?1:2)},17:function(a){return Number(1==a||a%10==1?0:1)},18:function(a){return Number(1==a?1:2)},19:function(a){return Number(1==a?0:0===a||a%100>1&&11>a%100?1:a%100>10&&20>a%100?2:3)},20:function(a){return Number(1==a?0:0===a||a%100>0&&20>a%100?1:2)},21:function(a){return Number(a%100==1?1:a%100==2?2:a%100==3||a%100==4?3:0)}},X={rules:function(){var a,b={};for(a=V.length;a--;)b[V[a][0]]={name:V[a][1],numbers:V[a][2],plurals:W[V[a][3]]};return b}(),addRule:function(a,b){X.rules[a]=b},setCurrentLng:function(a){if(!X.currentRule||X.currentRule.lng!==a){var b=a.split("-");X.currentRule={lng:a,rule:X.rules[b[0]]}}},needsPlural:function(a,b){var c,d=a.split("-");return c=X.currentRule&&X.currentRule.lng===a?X.currentRule.rule:X.rules[d[U.getCountyIndexOfLng(a)]],c&&c.numbers.length<=1?!1:1!==this.get(a,b)},get:function(a,b){function c(b,c){var d;if(d=X.currentRule&&X.currentRule.lng===a?X.currentRule.rule:X.rules[b]){var e;e=d.plurals(d.noAbs?c:Math.abs(c));var f=d.numbers[e];return 2===d.numbers.length&&1===d.numbers[0]&&(2===f?f=-1:1===f&&(f=1)),f}return 1===c?"1":"-1"}var d=a.split("-");return c(d[U.getCountyIndexOfLng(a)],b)}},Y={},Z=function(a,b){Y[a]=b},$=function(){function a(a){return Object.prototype.toString.call(a).slice(8,-1).toLowerCase()}function b(a,b){for(var c=[];b>0;c[--b]=a);return c.join("")}var c=function(){return c.cache.hasOwnProperty(arguments[0])||(c.cache[arguments[0]]=c.parse(arguments[0])),c.format.call(null,c.cache[arguments[0]],arguments)};return c.format=function(c,d){var e,f,g,h,i,j,k,l=1,m=c.length,n="",o=[];for(f=0;m>f;f++)if(n=a(c[f]),"string"===n)o.push(c[f]);else if("array"===n){if(h=c[f],h[2])for(e=d[l],g=0;g=0?"+"+e:e,j=h[4]?"0"==h[4]?"0":h[4].charAt(1):" ",k=h[6]-String(e).length,i=h[6]?b(j,k):"",o.push(h[5]?e+i:i+e)}return o.join("")},c.cache={},c.parse=function(a){for(var b=a,c=[],d=[],e=0;b;){if(null!==(c=/^[^\x25]+/.exec(b)))d.push(c[0]);else if(null!==(c=/^\x25{2}/.exec(b)))d.push("%");else{if(null===(c=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(b)))throw"[sprintf] huh?";if(c[2]){e|=1;var f=[],g=c[2],h=[];if(null===(h=/^([a-z_][a-z_\d]*)/i.exec(g)))throw"[sprintf] huh?";for(f.push(h[1]);""!==(g=g.substring(h[0].length));)if(null!==(h=/^\.([a-z_][a-z_\d]*)/i.exec(g)))f.push(h[1]);else{if(null===(h=/^\[(\d+)\]/.exec(g)))throw"[sprintf] huh?";f.push(h[1])}c[2]=f}else e|=2;if(3===e)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";d.push(c)}b=b.substring(c[0].length)}return d},c}(),_=function(a,b){return b.unshift(a),$.apply(null,b)};Z("sprintf",function(a,b,c){return c.sprintf?"[object Array]"===Object.prototype.toString.apply(c.sprintf)?_(a,c.sprintf):"object"==typeof c.sprintf?$(a,c.sprintf):a:a}),J.init=g,J.setLng=r,J.preload=h,J.addResourceBundle=i,J.hasResourceBundle=j,J.getResourceBundle=k,J.addResource=m,J.addResources=n,J.removeResourceBundle=l,J.loadNamespace=p,J.loadNamespaces=q,J.setDefaultNamespace=o,J.t=B,J.translate=B,J.exists=A,J.detectLanguage=U.detectLanguage,J.pluralExtensions=X,J.sync=O,J.functions=U,J.lng=s,J.addPostProcessor=Z,J.applyReplacement=U.applyReplacement,J.options=Q}("undefined"==typeof exports?window:exports); \ No newline at end of file diff --git a/libs/i18next/sample/static/index.html b/libs/i18next/sample/static/index.html new file mode 100644 index 00000000..e4265009 --- /dev/null +++ b/libs/i18next/sample/static/index.html @@ -0,0 +1,82 @@ + + + + + Basic Sample Usage + + + + + + + + +

you can switch lng via ?setLng='lngTag'

+ en-US + |   + de-DE + +

translated via $.t('app.name')

+ - + + +
with value insert $.t('app.insert', {youAre: 'great'})
+ + +
with plural $.t('app.insert', {youAre: 'great'})
+ - + +
nesting
+ + +
with translation context $.t('friend_context', {context: 'male || female'})
+ - + + +

loaded via attribute 'data-i18n' and $('.nav').i18n();

+ +
basic text
+ + + + +
extended usage of 'data-i18n' - apply to other attributes
+
+ + +
+ + + + + + diff --git a/libs/i18next/sample/static/locales/de/ns.special.json b/libs/i18next/sample/static/locales/de/ns.special.json new file mode 100644 index 00000000..b4fcdeb0 --- /dev/null +++ b/libs/i18next/sample/static/locales/de/ns.special.json @@ -0,0 +1,11 @@ +{ + "app": { + "name": "i18n", + "insert": "du bist __youAre__", + "child": "__count__ Kind", + "child_plural": "__count__ Kinder", + "friend_context": "Ein Freund", + "friend_context_male": "Ein Freund", + "friend_context_female": "Eine Freundin" + } +} diff --git a/libs/i18next/sample/static/locales/dev/ns.common.json b/libs/i18next/sample/static/locales/dev/ns.common.json new file mode 100644 index 00000000..2cbd4111 --- /dev/null +++ b/libs/i18next/sample/static/locales/dev/ns.common.json @@ -0,0 +1,12 @@ +{ + "app": { + "company": { + "name": "my company" + } + }, + "attr": { + "placeholder": "translated placeholder", + "title": "translated title" + }, + "add": "add" +} \ No newline at end of file diff --git a/libs/i18next/sample/static/locales/dev/ns.special.json b/libs/i18next/sample/static/locales/dev/ns.special.json new file mode 100644 index 00000000..f2eda864 --- /dev/null +++ b/libs/i18next/sample/static/locales/dev/ns.special.json @@ -0,0 +1,10 @@ +{ + "nav": { + "home": "home", + "1": "link 1", + "2": "link 2" + }, + "btn": { + "hoverMe": "hover me!" + } +} \ No newline at end of file diff --git a/libs/i18next/sample/static/locales/en-US/ns.special.json b/libs/i18next/sample/static/locales/en-US/ns.special.json new file mode 100644 index 00000000..fd9988c2 --- /dev/null +++ b/libs/i18next/sample/static/locales/en-US/ns.special.json @@ -0,0 +1,11 @@ +{ + "app": { + "name": "i18n", + "insert": "you are __youAre__", + "child": "__count__ child", + "child_plural": "__count__ children", + "friend_context": "A friend", + "friend_context_male": "A boyfriend", + "friend_context_female": "A girlfriend" + } +} \ No newline at end of file diff --git a/libs/i18next/sample/static/locales/en/ns.special.json b/libs/i18next/sample/static/locales/en/ns.special.json new file mode 100644 index 00000000..113e69f6 --- /dev/null +++ b/libs/i18next/sample/static/locales/en/ns.special.json @@ -0,0 +1,7 @@ +{ + "app": { + "area": "Area 51", + "district": "District 9 is more fun than $t(app.area)" + } +} + diff --git a/libs/i18next/sample/static/readme.txt b/libs/i18next/sample/static/readme.txt new file mode 100644 index 00000000..6fcbe792 --- /dev/null +++ b/libs/i18next/sample/static/readme.txt @@ -0,0 +1,3 @@ +best open index.html in firefox! + +for other browsers you will have to deploy the sample on a server. \ No newline at end of file diff --git a/libs/i18next/spec/functions.spec.js b/libs/i18next/spec/functions.spec.js new file mode 100644 index 00000000..eaed4da7 --- /dev/null +++ b/libs/i18next/spec/functions.spec.js @@ -0,0 +1,15 @@ +describe('basic functionality', function() { + + //= functions/functions.CI.spec.js + + //= functions/functions.setlng.spec.js + + //= functions/functions.preload.spec.js + + //= functions/functions.postprocessor.spec.js + + //= functions/functions.postmissing.spec.js + + //= functions/functions.objectTreeKeyHandler.spec.js + +}); \ No newline at end of file diff --git a/libs/i18next/spec/functions/functions.CI.spec.js b/libs/i18next/spec/functions/functions.CI.spec.js new file mode 100644 index 00000000..475e1444 --- /dev/null +++ b/libs/i18next/spec/functions/functions.CI.spec.js @@ -0,0 +1,22 @@ +describe('CI mode', function() { + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { + resStore: { + 'en-US': { translation: { 'simpleTest': 'ok_from_en-US' } }, + 'de-DE': { translation: { 'simpleTest': 'ok_from_de-DE' } } + } + }), function(t) { done(); } ); + }); + + it('it should provide resources for set language', function(done) { + expect(i18n.t('simpleTest')).to.be('ok_from_en-US'); + + i18n.setLng('CIMode', function(t) { + expect(t('simpleTest')).to.be('simpleTest'); + done(); + }); + + }); + +}); \ No newline at end of file diff --git a/libs/i18next/spec/functions/functions.objectTreeKeyHandler.spec.js b/libs/i18next/spec/functions/functions.objectTreeKeyHandler.spec.js new file mode 100644 index 00000000..87d4769a --- /dev/null +++ b/libs/i18next/spec/functions/functions.objectTreeKeyHandler.spec.js @@ -0,0 +1,19 @@ +describe('using objectTreeKeyHandler', function() { + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { + objectTreeKeyHandler: function(key, value, lng, ns, opts) { + return i18n.t(key + '.a'); + }, + resStore: { + 'en-US': { translation: { 'simpleTest': { a: 'a value', b: 'b value' } } } + }, + returnObjectTrees: false + }), function(t) { done(); } ); + }); + + it('it should apply objectTreeKeyHandler', function() { + expect(i18n.t('simpleTest')).to.be('a value'); + }); + +}); \ No newline at end of file diff --git a/libs/i18next/spec/functions/functions.postmissing.spec.js b/libs/i18next/spec/functions/functions.postmissing.spec.js new file mode 100644 index 00000000..b58ded8e --- /dev/null +++ b/libs/i18next/spec/functions/functions.postmissing.spec.js @@ -0,0 +1,161 @@ +describe('post missing resources', function() { + + describe('to fallback', function() { + var server, stub, spy; + + beforeEach(function(done) { + server = sinon.fakeServer.create(); + stub = sinon.stub(i18n.functions, "ajax"); + spy = sinon.spy(i18n.options, 'missingKeyHandler'); + + + server.respondWith([200, { "Content-Type": "text/html", "Content-Length": 2 }, "OK"]); + + i18n.init(i18n.functions.extend(opts, { + sendMissing: true, + resStore: { + 'en-US': { translation: { } }, + 'en': { translation: { } }, + 'dev': { translation: { } } + } + }), function(t) { done(); } ); + }); + + afterEach(function() { + server.restore(); + stub.restore(); + spy.restore(); + }); + + it('it should post missing resource to server', function() { + i18n.t('missing'); + server.respond(); + expect(stub.calledOnce).to.be(true); + }); + + it('it should post missing resource to server when language is passed in', function() { + i18n.t('missing_en', { lng: 'en' }); + server.respond(); + expect(stub.calledOnce).to.be(true); + }); + + it('it should call with right arguments', function() { + i18n.t('missing'); + expect(spy.args[0][0]).to.be('en-US'); + expect(spy.args[0][1]).to.be('translation'); + expect(spy.args[0][2]).to.be('missing'); + expect(spy.args[0][3]).to.be('missing'); + }); + + describe('with fallbackLng set to false', function() { + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { + lng: 'de', + sendMissing: true, + fallbackLng: false, + sendMissingTo: 'fallback', + resStore: { + 'en-US': { translation: { } }, + 'en': { translation: { } }, + 'dev': { translation: { } } + } + }), function(t) { done(); } ); + }); + + it('it should post missing resource to server', function() { + i18n.t('missing'); + server.respond(); + expect(stub.calledOnce).to.be(true); + }); + + it('it should call post missing with right arguments', function() { + i18n.t('missing'); + expect(spy.args[0][0]).to.be('de'); + expect(spy.args[0][1]).to.be('translation'); + expect(spy.args[0][2]).to.be('missing'); + expect(spy.args[0][3]).to.be('missing'); + }); + + it('it should call ajax with right arguments', function() { + i18n.t('missing'); + expect(stub.args[0][0].url).to.be('locales/add/de/translation'); + }); + + }); + + }); + + describe('to current', function() { + var server, stub; + + beforeEach(function(done) { + server = sinon.fakeServer.create(); + stub = sinon.stub(i18n.functions, "ajax"); + + server.respondWith([200, { "Content-Type": "text/html", "Content-Length": 2 }, "OK"]); + + i18n.init(i18n.functions.extend(opts, { + sendMissing: true, + sendMissingTo: 'current', + //fallbackLng: false, + resStore: { + 'en-US': { translation: { } }, + 'en': { translation: { } }, + 'dev': { translation: { } } + } + }), function(t) { done(); } ); + }); + + afterEach(function() { + server.restore(); + stub.restore(); + }); + + it('it should post missing resource for all lng to server', function() { + i18n.t('missing'); + server.respond(); + expect(stub.calledOnce).to.be(true); + }); + + it('it should call ajax with right arguments', function() { + i18n.t('missing2'); + expect(stub.args[0][0].url).to.be('locales/add/en-US/translation'); + }); + + }); + + describe('to all', function() { + var server, stub; + + beforeEach(function(done) { + server = sinon.fakeServer.create(); + stub = sinon.stub(i18n.functions, "ajax"); + + server.respondWith([200, { "Content-Type": "text/html", "Content-Length": 2 }, "OK"]); + + i18n.init(i18n.functions.extend(opts, { + sendMissing: true, + sendMissingTo: 'all', + resStore: { + 'en-US': { translation: { } }, + 'en': { translation: { } }, + 'dev': { translation: { } } + } + }), function(t) { done(); } ); + }); + + afterEach(function() { + server.restore(); + stub.restore(); + }); + + it('it should post missing resource for all lng to server', function() { + i18n.t('missing'); + server.respond(); + expect(stub.calledThrice).to.be(true); + }); + + }); + +}); \ No newline at end of file diff --git a/libs/i18next/spec/functions/functions.postprocessor.spec.js b/libs/i18next/spec/functions/functions.postprocessor.spec.js new file mode 100644 index 00000000..bd3226bf --- /dev/null +++ b/libs/i18next/spec/functions/functions.postprocessor.spec.js @@ -0,0 +1,59 @@ +describe('postprocessing tranlation', function() { + + describe('having a postprocessor', function() { + + before(function(){ + i18n.addPostProcessor('myProcessor', function(val, key, opts) { + return 'ok_from_postprocessor'; + }); + i18n.addPostProcessor('myProcessor2', function(val, key, opts) { + return val + ' ok' ; + }); + }); + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { + resStore: { + 'en-US': { translation: { 'simpleTest': 'ok_from_en-US' } }, + 'de-DE': { translation: { 'simpleTest': 'ok_from_de-DE' } } + } + }), function(t) { done(); } ); + }); + + it('it should postprocess the translation by passing in postProcess name to t function', function() { + expect(i18n.t('simpleTest', {postProcess: 'myProcessor'})).to.be('ok_from_postprocessor'); + }); + + it('it should postprocess on default value', function() { + expect(i18n.t('notFound1', {defaultValue: 'defaultValue', postProcess: 'myProcessor2'})).to.be('defaultValue ok'); + }); + + it('it should postprocess on missing value', function() { + expect(i18n.t('notFound2', {postProcess: 'myProcessor2'})).to.be('notFound2 ok'); + }); + + it('it should postprocess with multiple post processors', function() { + expect(i18n.t('simpleTest', {postProcess: ['myProcessor', 'myProcessor2']})).to.be('ok_from_postprocessor ok'); + }); + + describe('or setting it as default on init', function() { + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { + resStore: { + 'en-US': { translation: { 'simpleTest': 'ok_from_en-US' } }, + 'de-DE': { translation: { 'simpleTest': 'ok_from_de-DE' } } + }, + postProcess: 'myProcessor' + }), function(t) { done(); } ); + }); + + it('it should postprocess the translation by default', function() { + expect(i18n.t('simpleTest')).to.be('ok_from_postprocessor'); + }); + + }); + + }); + +}); \ No newline at end of file diff --git a/libs/i18next/spec/functions/functions.preload.spec.js b/libs/i18next/spec/functions/functions.preload.spec.js new file mode 100644 index 00000000..373b1c0a --- /dev/null +++ b/libs/i18next/spec/functions/functions.preload.spec.js @@ -0,0 +1,24 @@ +describe('preloading multiple languages', function() { + + var spy; + + beforeEach(function(done) { + spy = sinon.spy(i18n.sync, '_fetchOne'); + i18n.init(opts, function(t) { done(); }); + }); + + afterEach(function() { + spy.restore(); + }); + + it('it should preload resources for languages', function(done) { + spy.reset(); + if (i18n.sync.resStore) i18n.sync.resStore = {}; // to reset for test on server! + i18n.preload('de-DE', function(t) { + expect(spy.callCount).to.be(5); // en-US, en, de-DE, de, dev + done(); + }); + + }); + +}); \ No newline at end of file diff --git a/libs/i18next/spec/functions/functions.setlng.spec.js b/libs/i18next/spec/functions/functions.setlng.spec.js new file mode 100644 index 00000000..46281ac1 --- /dev/null +++ b/libs/i18next/spec/functions/functions.setlng.spec.js @@ -0,0 +1,38 @@ +describe('setting language', function() { + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { + resStore: { + 'en-US': { translation: { 'simpleTest': 'ok_from_en-US' } }, + 'de-DE': { translation: { 'simpleTest': 'ok_from_de-DE' } } + } + }), function(t) { done(); } ); + }); + + it('it should provide resources for set language', function(done) { + expect(i18n.t('simpleTest')).to.be('ok_from_en-US'); + + i18n.setLng('de-DE', function(t) { + expect(t('simpleTest')).to.be('ok_from_de-DE'); + done(); + }); + + }); + + it('should be possible to call setLng multiple times to get specialized callbacks', function(done) { + i18n.setLng('de-DE', { fixLng: true }, function(deDE) { + expect(deDE.lng).to.be('de-DE'); + + i18n.setLng('en-US', { fixLng: true }, function(enUS) { + expect(deDE.lng).to.be('de-DE'); + expect(enUS.lng).to.be('en-US'); + + expect(deDE('simpleTest')).to.be('ok_from_de-DE'); + expect(enUS('simpleTest')).to.be('ok_from_en-US'); + + done(); + }); + }); + }) + +}); \ No newline at end of file diff --git a/libs/i18next/spec/init.spec.js b/libs/i18next/spec/init.spec.js new file mode 100644 index 00000000..756cf5e7 --- /dev/null +++ b/libs/i18next/spec/init.spec.js @@ -0,0 +1,31 @@ +describe('Initialisation', function() { + + //= init/init.load.spec.js + + describe('advanced initialisation options', function() { + + //= init/init.fallbackLng.spec.js + + //= init/init.addResourceOrResourceBundle.spec.js + + //= init/init.getResourceBundle.spec.js + + //= init/init.removeResourceBundle.spec.js + + //= init/init.loadBehaviour.spec.js + + //= init/init.preload.spec.js + + //= init/init.syncFlag.spec.js + + //= init/init.namespace.spec.js + + //= init/init.localstorage.spec.js + + //= init/init.varia.spec.js + + //= init/init.whitelist.spec.js + + }); + +}); diff --git a/libs/i18next/spec/init/init.addResourceOrResourceBundle.spec.js b/libs/i18next/spec/init/init.addResourceOrResourceBundle.spec.js new file mode 100644 index 00000000..438ebaa8 --- /dev/null +++ b/libs/i18next/spec/init/init.addResourceOrResourceBundle.spec.js @@ -0,0 +1,118 @@ +describe('adding resources after init', function() { + + var resStore = { + dev: { translation: { 'simple_dev': 'ok_from_dev' } }, + en: { translation: { 'simple_en': 'ok_from_en' } }//, + //'en-US': { translation: { 'simple_en-US': 'ok_from_en-US' } } + }; + + describe('resources', function() { + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { resStore: resStore }), + function(t) { + i18n.addResource('en-US', 'translation', 'some.deep.thing', 'ok_from_en-US'); + done(); + }); + }); + + it('it should provide passed in resources for translation', function() { + expect(i18n.t('some.deep.thing')).to.be('ok_from_en-US'); + }); + + describe('multiple resources', function() { + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { resStore: resStore }), + function(t) { + i18n.addResources('en-US', 'translation', { + 'some.other.deep.thing': 'ok_from_en-US_1', + 'some.other.deep.deeper.thing': 'ok_from_en-US_2' + }); + done(); + }); + }); + + it('it should add the new namespace to the namespace array', function() { + expect(i18n.t('some.other.deep.thing')).to.be('ok_from_en-US_1'); + expect(i18n.t('some.other.deep.deeper.thing')).to.be('ok_from_en-US_2'); + }); + + }); + + }); + + describe('bundles', function() { + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { resStore: resStore }), + function(t) { + i18n.addResourceBundle('en-US', 'translation', { 'simple_en-US': 'ok_from_en-US' }); + done(); + }); + }); + + it('it should provide passed in resources for translation', function() { + expect(i18n.t('simple_en-US')).to.be('ok_from_en-US'); + expect(i18n.t('simple_en')).to.be('ok_from_en'); + expect(i18n.t('simple_dev')).to.be('ok_from_dev'); + }); + + describe('with a additional namespace', function() { + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { resStore: resStore }), + function(t) { + i18n.addResourceBundle('en-US', 'newNamespace', { 'simple_en-US': 'ok_from_en-US' }); + done(); + }); + }); + + it('it should add the new namespace to the namespace array', function() { + expect(i18n.options.ns.namespaces).to.contain('newNamespace'); + }); + + }); + + describe('with using deep switch', function() { + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { resStore: resStore }), + function(t) { + i18n.addResourceBundle('en-US', 'translation', { 'deep': { 'simple_en-US_1': 'ok_from_en-US_1' }}); + i18n.addResourceBundle('en-US', 'translation', { 'deep': { 'simple_en-US_2': 'ok_from_en-US_2' }}, true); + done(); + }); + }); + + it('it should add the new namespace to the namespace array', function() { + expect(i18n.t('deep.simple_en-US_1')).to.be('ok_from_en-US_1'); + expect(i18n.t('deep.simple_en-US_2')).to.be('ok_from_en-US_2'); + }); + + }); + + describe('check if exists', function() { + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { resStore: resStore }), + function(t) { + i18n.addResourceBundle('en-US', 'translation', { 'deep': { 'simple_en-US_1': 'ok_from_en-US_1' }}); + i18n.addResourceBundle('en-US', 'translation', { 'deep': { 'simple_en-US_2': 'ok_from_en-US_2' }}, true); + done(); + }); + }); + + it('it should return true for existing bundle', function() { + expect(i18n.hasResourceBundle('en-US', 'translation')).to.be.ok(); + }); + + it('it should return false for non-existing bundle', function() { + expect(i18n.hasResourceBundle('de-CH', 'translation')).to.not.be.ok(); + }); + + }); + + }); + +}); \ No newline at end of file diff --git a/libs/i18next/spec/init/init.fallbackLng.spec.js b/libs/i18next/spec/init/init.fallbackLng.spec.js new file mode 100644 index 00000000..12963f30 --- /dev/null +++ b/libs/i18next/spec/init/init.fallbackLng.spec.js @@ -0,0 +1,46 @@ +describe('setting fallbackLng', function() { + + var resStore = { + dev1: { translation: { 'simple_dev1': 'ok_from_dev1' } }, + en: { translation: { 'simple_en': 'ok_from_en' } }, + 'en-US': { translation: { 'simple_en-US': 'ok_from_en-US' } } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { resStore: resStore, fallbackLng: 'dev1' }), + function(t) { done(); }); + }); + + it('it should provide passed in resources for translation', function() { + expect(i18n.t('simple_en-US')).to.be('ok_from_en-US'); + expect(i18n.t('simple_en')).to.be('ok_from_en'); + expect(i18n.t('simple_dev1')).to.be('ok_from_dev1'); + }); + +}); + +describe('multiple fallbackLng', function() { + + var resStore = { + dev1: { translation: { 'simple_dev1': 'ok_from_dev1', 'simple_dev': 'ok_from_dev1' } }, + dev2: { translation: { 'simple_dev2': 'ok_from_dev2', 'simple_dev': 'ok_from_dev2' } }, + en: { translation: { 'simple_en': 'ok_from_en' } }, + 'en-US': { translation: { 'simple_en-US': 'ok_from_en-US' } } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { resStore: resStore, fallbackLng: ['dev1', 'dev2'] }), + function(t) { done(); }); + }); + + it('it should provide passed in resources for translation', function() { + expect(i18n.t('simple_en-US')).to.be('ok_from_en-US'); + expect(i18n.t('simple_en')).to.be('ok_from_en'); + // in one + expect(i18n.t('simple_dev1')).to.be('ok_from_dev1'); + expect(i18n.t('simple_dev2')).to.be('ok_from_dev2'); + // in both + expect(i18n.t('simple_dev')).to.be('ok_from_dev1'); + }); + +}); \ No newline at end of file diff --git a/libs/i18next/spec/init/init.getResourceBundle.spec.js b/libs/i18next/spec/init/init.getResourceBundle.spec.js new file mode 100644 index 00000000..0e86fb44 --- /dev/null +++ b/libs/i18next/spec/init/init.getResourceBundle.spec.js @@ -0,0 +1,41 @@ +describe('getting resources after init', function() { + + var resStore = { + dev: { translation: { 'test': 'ok_from_dev' } }, + en: { translation: { 'test': 'ok_from_en' } }, + 'en-US': { translation: { 'test': 'ok_from_en-US' } } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { resStore: resStore }), function() { + done(); + }); + }); + + it('it should return resources for existing bundle', function() { + var devTranslation = i18n.getResourceBundle('dev', 'translation'); + var enTranslation = i18n.getResourceBundle('en', 'translation'); + var enUSTranslation = i18n.getResourceBundle('en-US', 'translation'); + expect(devTranslation.test).to.be('ok_from_dev'); + expect(enTranslation.test).to.be('ok_from_en'); + expect(enUSTranslation.test).to.be('ok_from_en-US'); + }); + + it('it should return empty object for non-existing bundle', function() { + var nonExisting = i18n.getResourceBundle('en-GB', 'translation'); + expect(Object.keys(nonExisting).length).to.be(0); + }); + + it('it should use default namespace when namespace argument is left out', function() { + var enTranslation = i18n.getResourceBundle('en'); + expect(enTranslation.test).to.be('ok_from_en'); + }); + + it('it should return a clone of the resources', function() { + var enTranslation = i18n.getResourceBundle('en'); + enTranslation.test = 'ok_from_en_changed'; + expect(enTranslation.test).to.be('ok_from_en_changed'); + expect(resStore.en.translation.test).to.be('ok_from_en'); + }); + +}); diff --git a/libs/i18next/spec/init/init.load.spec.js b/libs/i18next/spec/init/init.load.spec.js new file mode 100644 index 00000000..b9f95ba6 --- /dev/null +++ b/libs/i18next/spec/init/init.load.spec.js @@ -0,0 +1,67 @@ +describe('with passed in resource set', function() { + + var resStore = { + dev: { translation: { 'simple_dev': 'ok_from_dev' } }, + en: { translation: { 'simple_en': 'ok_from_en' } }, + 'en-US': { translation: { 'simple_en-US': 'ok_from_en-US' } } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { resStore: resStore }), + function(t) { done(); }); + }); + + it('it should provide passed in resources for translation', function() { + expect(i18n.t('simple_en-US')).to.be('ok_from_en-US'); + expect(i18n.t('simple_en')).to.be('ok_from_en'); + expect(i18n.t('simple_dev')).to.be('ok_from_dev'); + }); + +}); + +describe('loading from server', function() { + + describe('with static route', function() { + + beforeEach(function(done) { + i18n.init(opts, function(t) { done(); }); + }); + + it('it should provide loaded resources for translation', function() { + expect(i18n.t('simple_en-US')).to.be('ok_from_en-US'); + expect(i18n.t('simple_en')).to.be('ok_from_en'); + expect(i18n.t('simple_dev')).to.be('ok_from_dev'); + }); + + }); + + describe('with dynamic route', function() { + + beforeEach(function(done) { + + var res = { + dev: { translation: { 'simple_dev': 'ok_from_dev' } }, + en: { translation: { 'simple_en': 'ok_from_en' } }, + 'en-US': { translation: { 'simple_en-US': 'ok_from_en-US' } } + }; + + var server = sinon.fakeServer.create(); + server.autoRespond = true; + + server.respondWith([200, { "Content-Type": "application/json" }, JSON.stringify(res)]); + + i18n.init(i18n.functions.extend(opts, { + resGetPath: 'locales/resources.json?lng=__lng__&ns=__ns__', + dynamicLoad: true }), + function(t) { server.restore(); done(); }); + }); + + it('it should provide loaded resources for translation', function() { + expect(i18n.t('simple_en-US')).to.be('ok_from_en-US'); + expect(i18n.t('simple_en')).to.be('ok_from_en'); + expect(i18n.t('simple_dev')).to.be('ok_from_dev'); + }); + + }); + +}); \ No newline at end of file diff --git a/libs/i18next/spec/init/init.loadBehaviour.spec.js b/libs/i18next/spec/init/init.loadBehaviour.spec.js new file mode 100644 index 00000000..c79852a9 --- /dev/null +++ b/libs/i18next/spec/init/init.loadBehaviour.spec.js @@ -0,0 +1,88 @@ +describe('setting load', function() { + + describe('to current', function() { + + var spy; + + beforeEach(function(done) { + spy = sinon.spy(i18n.sync, '_fetchOne'); + i18n.init(i18n.functions.extend(opts, { + load: 'current' }), + function(t) { done(); }); + }); + + afterEach(function() { + spy.restore(); + }); + + it('it should load only current and fallback language', function() { + expect(spy.callCount).to.be(2); // en-US, en + }); + + it('it should provide loaded resources for translation', function() { + expect(i18n.t('simple_en-US')).to.be('ok_from_en-US'); + expect(i18n.t('simple_en')).not.to.be('ok_from_en'); + expect(i18n.t('simple_dev')).to.be('ok_from_dev'); + }); + + }); + + describe('to unspecific', function() { + + var spy; + + beforeEach(function(done) { + spy = sinon.spy(i18n.sync, '_fetchOne'); + i18n.init(i18n.functions.extend(opts, { + load: 'unspecific' }), + function(t) { done(); }); + }); + + afterEach(function() { + spy.restore(); + }); + + it('it should load only unspecific and fallback language', function() { + expect(spy.callCount).to.be(2); // en-US, en + }); + + it('it should provide loaded resources for translation', function() { + expect(i18n.t('simple_en-US')).not.to.be('ok_from_en-US'); + expect(i18n.t('simple_en')).to.be('ok_from_en'); + expect(i18n.t('simple_dev')).to.be('ok_from_dev'); + }); + + it('it should return unspecific language', function() { + expect(i18n.lng()).to.be('en'); + }); + + }); + +}); + +describe('with fallback language set to false', function() { + + var spy; + + beforeEach(function(done) { + spy = sinon.spy(i18n.sync, '_fetchOne'); + i18n.init(i18n.functions.extend(opts, { + fallbackLng: false }), + function(t) { done(); }); + }); + + afterEach(function() { + spy.restore(); + }); + + it('it should load only specific and unspecific languages', function() { + expect(spy.callCount).to.be(2); // en-US, en + }); + + it('it should provide loaded resources for translation', function() { + expect(i18n.t('simple_en-US')).to.be('ok_from_en-US'); + expect(i18n.t('simple_en')).to.be('ok_from_en'); + expect(i18n.t('simple_dev')).not.to.be('ok_from_dev'); + }); + +}); \ No newline at end of file diff --git a/libs/i18next/spec/init/init.localstorage.spec.js b/libs/i18next/spec/init/init.localstorage.spec.js new file mode 100644 index 00000000..6cd25a1b --- /dev/null +++ b/libs/i18next/spec/init/init.localstorage.spec.js @@ -0,0 +1,59 @@ +describe('using localStorage', function() { + + var spy; + + before(function() { + window.localStorage.removeItem('res_en-US'); + window.localStorage.removeItem('res_en'); + window.localStorage.removeItem('res_dev'); + }); + + beforeEach(function(done) { + spy = sinon.spy(i18n.sync, '_fetchOne'); + i18n.init(i18n.functions.extend(opts, { + useLocalStorage: true + }), function(t) { done(); }); + }); + + afterEach(function() { + spy.restore(); + }); + + it('it should load language', function() { + expect(spy.callCount).to.be(3); // en-US, en, de-DE, de, fr, dev + }); + + describe('on later init', function() { + + beforeEach(function(done) { + spy.reset(); + i18n.init(function(t) { done(); }); + }); + + it('it should not reload language', function() { + expect(spy.callCount).to.be(0); // de-DE, de, fr, dev + }); + + describe('on later init - after caching duration', function() { + + beforeEach(function(done) { + spy.reset(); + + // exipred + var local = window.localStorage.getItem('res_en-US'); + local = JSON.parse(local); + local.i18nStamp = 0; + window.localStorage.setItem('res_en-US', JSON.stringify(local)); + + i18n.init(function(t) { done(); }); + }); + + it('it should reload language', function() { + expect(spy.callCount).to.be(1); // de-DE, de, fr, dev + }); + + }); + + }); + +}); \ No newline at end of file diff --git a/libs/i18next/spec/init/init.namespace.spec.js b/libs/i18next/spec/init/init.namespace.spec.js new file mode 100644 index 00000000..f50ff417 --- /dev/null +++ b/libs/i18next/spec/init/init.namespace.spec.js @@ -0,0 +1,266 @@ +describe('with namespace', function() { + + describe('with one namespace set', function() { + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { ns: 'ns.special'} ), + function(t) { done(); }); + }); + + it('it should provide loaded resources for translation', function() { + expect(i18n.t('simple_en-US')).to.be('ok_from_special_en-US'); + expect(i18n.t('simple_en')).to.be('ok_from_special_en'); + expect(i18n.t('simple_dev')).to.be('ok_from_special_dev'); + }); + + }); + + describe('with more than one namespace set', function() { + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { ns: { namespaces: ['ns.common', 'ns.special'], defaultNs: 'ns.special'} } ), + function(t) { done(); }); + }); + + it('it should provide loaded resources for translation', function() { + // default ns + expect(i18n.t('simple_en-US')).to.be('ok_from_special_en-US'); + expect(i18n.t('simple_en')).to.be('ok_from_special_en'); + expect(i18n.t('simple_dev')).to.be('ok_from_special_dev'); + + // ns prefix + expect(i18n.t('ns.common:simple_en-US')).to.be('ok_from_common_en-US'); + expect(i18n.t('ns.common:simple_en')).to.be('ok_from_common_en'); + expect(i18n.t('ns.common:simple_dev')).to.be('ok_from_common_dev'); + + // ns in options + expect(i18n.t('simple_en-US', { ns: 'ns.common' })).to.be('ok_from_common_en-US'); + expect(i18n.t('simple_en', { ns: 'ns.common' })).to.be('ok_from_common_en'); + expect(i18n.t('simple_dev', { ns: 'ns.common' })).to.be('ok_from_common_dev'); + }); + + describe('and fallbacking to default namespace', function() { + var resStore = { + dev: { 'ns.special': { 'simple_dev': 'ok_from_dev' } }, + en: { 'ns.special': { 'simple_en': 'ok_from_en' } }, + 'en-US': { 'ns.special': { 'simple_en-US': 'ok_from_en-US' } } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { + fallbackToDefaultNS: true, + resStore: resStore, + ns: { namespaces: ['ns.common', 'ns.special'], defaultNs: 'ns.special'} } ), + function(t) { done(); }); + }); + + it('it should fallback to default ns', function() { + // default ns fallback lookup + expect(i18n.t('ns.common:simple_en-US')).to.be('ok_from_en-US'); + expect(i18n.t('ns.common:simple_en')).to.be('ok_from_en'); + expect(i18n.t('ns.common:simple_dev')).to.be('ok_from_dev'); + }); + + }); + + describe('and fallbacking to set namespace', function() { + var resStore = { + dev: { + 'ns.special': { 'simple_dev': 'ok_from_dev' }, + 'ns.fallback': { 'simple_fallback': 'ok_from_fallback' } + }, + en: { 'ns.special': { 'simple_en': 'ok_from_en' } }, + 'en-US': { 'ns.special': { 'simple_en-US': 'ok_from_en-US' } } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { + fallbackNS: 'ns.fallback', + resStore: resStore, + ns: { namespaces: ['ns.common', 'ns.special', 'ns.fallback'], defaultNs: 'ns.special'} } ), + function(t) { done(); }); + }); + + it('it should fallback to set fallback namespace', function() { + expect(i18n.t('ns.common:simple_fallback')).to.be('ok_from_fallback'); + }); + + }); + + describe('and fallbacking to multiple set namespace', function() { + var resStore = { + dev: { + 'ns.common': {}, + 'ns.special': { 'simple_dev': 'ok_from_dev' }, + 'ns.fallback1': { + 'simple_fallback': 'ok_from_fallback1', + 'simple_fallback1': 'ok_from_fallback1' + } + }, + en: { + 'ns.special': { 'simple_en': 'ok_from_en' }, + 'ns.fallback2': { + 'simple_fallback': 'ok_from_fallback2', + 'simple_fallback2': 'ok_from_fallback2' + } + }, + 'en-US': { 'ns.special': { 'simple_en-US': 'ok_from_en-US' } } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { + fallbackNS: ['ns.fallback1', 'ns.fallback2'], + resStore: resStore, + ns: { namespaces: ['ns.common', 'ns.special', 'ns.fallback'], defaultNs: 'ns.special'} } ), + function(t) { done(); }); + }); + + it('it should fallback to set fallback namespace', function() { + expect(i18n.t('ns.common:simple_fallback')).to.be('ok_from_fallback1'); /* first wins */ + expect(i18n.t('ns.common:simple_fallback1')).to.be('ok_from_fallback1'); + expect(i18n.t('ns.common:simple_fallback2')).to.be('ok_from_fallback2'); + }); + + describe('and post missing', function() { + + var spy; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { + fallbackNS: ['ns.fallback1', 'ns.fallback2'], + resStore: resStore, + sendMissing: true, /* must be changed to saveMissing */ + ns: { namespaces: ['ns.common', 'ns.special', 'ns.fallback'], defaultNs: 'ns.special'} } ), + function(t) { + spy = sinon.spy(i18n.options, 'missingKeyHandler'); + t('ns.common:notExisting'); + done(); + }); + }); + + afterEach(function() { + spy.restore(); + }); + + it('it should post only to origin namespace', function() { + expect(spy.callCount).to.be(1); + expect(spy.args[0][0]).to.be('en-US'); + expect(spy.args[0][1]).to.be('ns.common'); + expect(spy.args[0][2]).to.be('notExisting'); + expect(spy.args[0][3]).to.be('ns.common:notExisting'); + }); + + }); + + }); + + }); + + describe('with reloading additional namespace', function() { + + describe('without using localStorage', function() { + beforeEach(function(done) { + i18n.init(opts, + function(t) { + i18n.setDefaultNamespace('ns.special'); + i18n.loadNamespaces(['ns.common', 'ns.special'], done); + }); + }); + + it('it should provide loaded resources for translation', function() { + // default ns + expect(i18n.t('simple_en-US')).to.be('ok_from_special_en-US'); + expect(i18n.t('simple_en')).to.be('ok_from_special_en'); + expect(i18n.t('simple_dev')).to.be('ok_from_special_dev'); + + // ns prefix + expect(i18n.t('ns.common:simple_en-US')).to.be('ok_from_common_en-US'); + expect(i18n.t('ns.common:simple_en')).to.be('ok_from_common_en'); + expect(i18n.t('ns.common:simple_dev')).to.be('ok_from_common_dev'); + + // ns in options + expect(i18n.t('simple_en-US', { ns: 'ns.common' })).to.be('ok_from_common_en-US'); + expect(i18n.t('simple_en', { ns: 'ns.common' })).to.be('ok_from_common_en'); + expect(i18n.t('simple_dev', { ns: 'ns.common' })).to.be('ok_from_common_dev'); + }); + + it('it should add the new namespaces to the namespace array', function() { + expect(i18n.options.ns.namespaces).to.contain('ns.common'); + expect(i18n.options.ns.namespaces).to.contain('ns.special'); + }); + + describe('and fallbackToDefaultNS turned on', function() { + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { + ns: 'ns.common', + fallbackToDefaultNS: true + }), + function(t) { + i18n.loadNamespaces(['ns.special'], done); + }); + }); + + it('it should fallback to default namespace', function() { + expect(i18n.t('ns.special:test.fallback_en')).to.be('ok_from_common_en-fallback'); + expect(i18n.t('ns.special:test.fallback_dev')).to.be('ok_from_common_dev-fallback'); + }); + + }); + + }); + + describe('with using localStorage', function() { + + var spy; + + before(function() { + if (typeof window !== 'undefined') { // safe use on server + window.localStorage.removeItem('res_en-US'); + window.localStorage.removeItem('res_en'); + window.localStorage.removeItem('res_dev'); + } + }); + + beforeEach(function(done) { + spy = sinon.spy(i18n.sync, '_fetchOne'); + i18n.init(i18n.functions.extend(opts, { + useLocalStorage: true + }), function(t) { + i18n.setDefaultNamespace('ns.special'); + i18n.loadNamespaces(['ns.common', 'ns.special'], done); + }); + }); + + afterEach(function() { + spy.restore(); + }); + + it('it should load language', function() { + expect(spy.callCount).to.be(9); // en-US, en, de-DE, de, fr, dev * 3 namespaces (translate, common, special) + }); + + describe('on later reload of namespaces', function() { + + beforeEach(function(done) { + spy.reset(); + i18n.init(i18n.functions.extend(opts, { + useLocalStorage: true, + ns: 'translation' + }), function(t) { + i18n.setDefaultNamespace('ns.special'); + i18n.loadNamespaces(['ns.common', 'ns.special'], done); + }); + }); + + it('it should not reload language', function() { + expect(spy.callCount).to.be(0); + }); + + }); + + }); + + }); + +}); diff --git a/libs/i18next/spec/init/init.preload.spec.js b/libs/i18next/spec/init/init.preload.spec.js new file mode 100644 index 00000000..7c5653b8 --- /dev/null +++ b/libs/i18next/spec/init/init.preload.spec.js @@ -0,0 +1,35 @@ +describe('preloading multiple languages', function() { + + var spy; + + beforeEach(function(done) { + spy = sinon.spy(i18n.sync, '_fetchOne'); + i18n.init(i18n.functions.extend(opts, { + preload: ['fr', 'de-DE'] }), + function(t) { done(); }); + }); + + afterEach(function() { + spy.restore(); + }); + + it('it should load additional languages', function() { + expect(spy.callCount).to.be(6); // en-US, en, de-DE, de, fr, dev + }); + + describe('changing the language', function() { + + beforeEach(function(done) { + spy.reset(); + if (i18n.sync.resStore) i18n.sync.resStore = {}; // to reset for test on server! + i18n.setLng('de-DE', + function(t) { done(); }); + }); + + it('it should reload the preloaded languages', function() { + expect(spy.callCount).to.be(4); // de-DE, de, fr, dev + }); + + }); + +}); \ No newline at end of file diff --git a/libs/i18next/spec/init/init.removeResourceBundle.spec.js b/libs/i18next/spec/init/init.removeResourceBundle.spec.js new file mode 100644 index 00000000..0ee8776f --- /dev/null +++ b/libs/i18next/spec/init/init.removeResourceBundle.spec.js @@ -0,0 +1,21 @@ +describe('removing resources after init', function() { + + var resStore = { + dev: { translation: { 'test': 'ok_from_dev' } }, + en: { translation: { 'test': 'ok_from_en' } }, + 'en-US': { translation: { 'test': 'ok_from_en-US' } } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { resStore: resStore }), + function(t) { + i18n.removeResourceBundle('en-US', 'translation'); + done(); + }); + }); + + it('it should remove resources', function() { + expect(i18n.t('test')).to.be('ok_from_en'); + }); + +}); \ No newline at end of file diff --git a/libs/i18next/spec/init/init.syncFlag.spec.js b/libs/i18next/spec/init/init.syncFlag.spec.js new file mode 100644 index 00000000..d204919c --- /dev/null +++ b/libs/i18next/spec/init/init.syncFlag.spec.js @@ -0,0 +1,13 @@ +describe('with synchronous flag', function() { + + beforeEach(function() { + i18n.init(i18n.functions.extend(opts, { getAsync: false }) ); + }); + + it('it should provide loaded resources for translation', function() { + expect(i18n.t('simple_en-US')).to.be('ok_from_en-US'); + expect(i18n.t('simple_en')).to.be('ok_from_en'); + expect(i18n.t('simple_dev')).to.be('ok_from_dev'); + }); + +}); \ No newline at end of file diff --git a/libs/i18next/spec/init/init.varia.spec.js b/libs/i18next/spec/init/init.varia.spec.js new file mode 100644 index 00000000..2f30b3ab --- /dev/null +++ b/libs/i18next/spec/init/init.varia.spec.js @@ -0,0 +1,62 @@ +describe('using function provided in callback\'s argument', function() { + + var cbT; + + beforeEach(function(done) { + i18n.init(opts, function(t) { cbT = t; done(); }); + }); + + it('it should provide loaded resources for translation', function() { + expect(cbT('simple_en-US')).to.be('ok_from_en-US'); + expect(cbT('simple_en')).to.be('ok_from_en'); + expect(cbT('simple_dev')).to.be('ok_from_dev'); + }); + +}); + +describe('with lowercase flag', function() { + + describe('default behaviour will uppercase specifc country part.', function() { + + beforeEach(function() { + i18n.init(i18n.functions.extend(opts, { + lng: 'en-us', + resStore: { + 'en-US': { translation: { 'simple_en-US': 'ok_from_en-US' } } + } + }, function(t) { done(); }) ); + }); + + it('it should translate the uppercased lng value', function() { + expect(i18n.t('simple_en-US')).to.be('ok_from_en-US'); + }); + + it('it should get uppercased set language', function() { + expect(i18n.lng()).to.be('en-US'); + }); + + }); + + describe('overridden behaviour will accept lowercased country part.', function() { + + beforeEach(function() { + i18n.init(i18n.functions.extend(opts, { + lng: 'en-us', + lowerCaseLng: true, + resStore: { + 'en-us': { translation: { 'simple_en-us': 'ok_from_en-us' } } + } + }, function(t) { done(); }) ); + }); + + it('it should translate the lowercase lng value', function() { + expect(i18n.t('simple_en-us')).to.be('ok_from_en-us'); + }); + + it('it should get lowercased set language', function() { + expect(i18n.lng()).to.be('en-us'); + }); + + }); + +}); \ No newline at end of file diff --git a/libs/i18next/spec/init/init.whitelist.spec.js b/libs/i18next/spec/init/init.whitelist.spec.js new file mode 100644 index 00000000..1d3db088 --- /dev/null +++ b/libs/i18next/spec/init/init.whitelist.spec.js @@ -0,0 +1,22 @@ +describe('with language whitelist', function() { + + var resStore = { + 'zh-CN': { translation: { 'string_one': 'good_zh-CN' } }, + en: { translation: { 'string_one': 'good_en' } }, + zh: { translation: { 'string_one': 'BAD_zh' } }, + 'en-US': { translation: { 'string_one': 'BAD_en-ZH' } } + }; + + it('should degrade UNwhitelisted 2-part lang code (en-US) to WHITELISTED 1-part (en)', function() { + i18n.init(i18n.functions.extend(opts, { resStore: resStore, lngWhitelist: ['en', 'zh-CN'], lng: 'en-US' })); + expect(i18n.lng()).to.be('en'); + expect(i18n.t('string_one')).to.be('good_en'); + }); + + it('should NOT degrade WHITELISTED 2-part lang code (zh-CN) to UNwhitelisted 1-part (en)', function() { + i18n.init(i18n.functions.extend(opts, { resStore: resStore, lngWhitelist: ['en', 'zh-CN'], lng: 'zh-CN' })); + expect(i18n.lng()).to.be('zh-CN'); + expect(i18n.t('string_one')).to.be('good_zh-CN'); + }); + +}); diff --git a/libs/i18next/spec/jquery.spec.js b/libs/i18next/spec/jquery.spec.js new file mode 100644 index 00000000..df3ed464 --- /dev/null +++ b/libs/i18next/spec/jquery.spec.js @@ -0,0 +1,9 @@ +describe('jQuery integration / specials', function() { + + //= jquery/jquery.deferred.spec.js + + //= jquery/jquery.varia.spec.js + + //= jquery/jquery.i18nFunction.spec.js + +}); diff --git a/libs/i18next/spec/jquery/jquery.deferred.spec.js b/libs/i18next/spec/jquery/jquery.deferred.spec.js new file mode 100644 index 00000000..1c30d1a1 --- /dev/null +++ b/libs/i18next/spec/jquery/jquery.deferred.spec.js @@ -0,0 +1,37 @@ +describe('initialise - use deferrer instead of callback', function() { + + describe('with passed in resource set', function() { + + var resStore = { + dev: { translation: { 'simple_dev': 'ok_from_dev' } }, + en: { translation: { 'simple_en': 'ok_from_en' } }, + 'en-US': { translation: { 'simple_en-US': 'ok_from_en-US' } } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { resStore: resStore })).done(function(t) { done(); }); + }); + + it('it should provide passed in resources for translation', function() { + expect($.t('simple_en-US')).to.be('ok_from_en-US'); + expect($.t('simple_en')).to.be('ok_from_en'); + expect($.t('simple_dev')).to.be('ok_from_dev'); + }); + + }); + + describe('loading from server', function() { + + beforeEach(function(done) { + i18n.init(opts).done(function() { done(); }); + }); + + it('it should provide loaded resources for translation', function() { + expect($.t('simple_en-US')).to.be('ok_from_en-US'); + expect($.t('simple_en')).to.be('ok_from_en'); + expect($.t('simple_dev')).to.be('ok_from_dev'); + }); + + }); + +}); \ No newline at end of file diff --git a/libs/i18next/spec/jquery/jquery.i18nFunction.spec.js b/libs/i18next/spec/jquery/jquery.i18nFunction.spec.js new file mode 100644 index 00000000..19d5c6d4 --- /dev/null +++ b/libs/i18next/spec/jquery/jquery.i18nFunction.spec.js @@ -0,0 +1,300 @@ +describe('using bindings $([selector].i18n())', function() { + + describe('basic - setting text', function() { + + var resStore = { + dev: { translation: { } }, + en: { translation: { } }, + 'en-US': { translation: { 'simpleTest': 'ok_from_en-US' } } + }; + + beforeEach(function(done) { + setFixtures('
'); + + i18n.init(i18n.functions.extend(opts, { resStore: resStore }), + function(t) { done(); }); + }); + + it('it should set text of elements inside selector having data-i18n attribute', function() { + $('#container').i18n(); + expect($('#testBtn').text()).to.be('ok_from_en-US'); + }); + + it('it should set text of element itself if having data-i18n attribute', function() { + $('#testBtn').i18n(); + expect($('#testBtn').text()).to.be('ok_from_en-US'); + }); + + }); + + describe('extended - setting other attributes', function() { + + var resStore = { + dev: { translation: { } }, + en: { translation: { } }, + 'en-US': { translation: { 'simpleTest': 'ok_from_en-US' } } + }; + + beforeEach(function(done) { + setFixtures('
'); + + i18n.init(i18n.functions.extend(opts, { resStore: resStore }), + function(t) { done(); }); + }); + + it('it should set text of elements inside selector having data-i18n attribute', function() { + $('#container').i18n(); + expect($('#testBtn').text()).to.be('ok_from_en-US'); + }); + + it('it should set attributes of elements inside selector having data-i18n attribute', function() { + $('#container').i18n(); + expect($('#testBtn').attr('title')).to.be('ok_from_en-US'); + }); + + }); + + describe('extended - empty key -> double ;;', function() { + + var resStore = { + dev: { translation: { } }, + en: { translation: { } }, + 'en-US': { translation: { 'simpleTest': 'ok_from_en-US' } } + }; + + beforeEach(function(done) { + setFixtures('
'); + + i18n.init(i18n.functions.extend(opts, { resStore: resStore }), + function(t) { done(); }); + }); + + it('it should set text of elements inside selector having data-i18n attribute', function() { + $('#container').i18n(); + expect($('#testBtn').text()).to.be('ok_from_en-US'); + }); + + it('it should set attributes of elements inside selector having data-i18n attribute', function() { + $('#container').i18n(); + expect($('#testBtn').attr('title')).to.be('ok_from_en-US'); + }); + + }); + + describe('extended - pass in options', function() { + + var resStore = { + dev: { translation: { } }, + en: { translation: { } }, + 'en-US': { translation: { 'simpleTest': '__replace__ ok_from_en-US' } } + }; + + beforeEach(function(done) { + setFixtures('
'); + + i18n.init(i18n.functions.extend(opts, { resStore: resStore }), + function(t) { done(); }); + }); + + it('it should set text with passed in options', function() { + $('#container').i18n({ replace: 'replaced' }); + expect($('#testBtn').text()).to.be('replaced ok_from_en-US'); + }); + + }); + + describe('extended - render inner html', function() { + + var resStore = { + dev: { translation: { } }, + en: { translation: { } }, + 'en-US': { translation: { 'simpleTest': '
test
' } } + }; + + beforeEach(function(done) { + setFixtures('
'); + + i18n.init(i18n.functions.extend(opts, { resStore: resStore }), + function(t) { done(); }); + }); + + it('it should set inner html', function() { + $('#container').i18n(); + expect($('#inner').html()).to.be('test'); + }); + + }); + + describe('extended - set data attribute', function() { + + var resStore = { + dev: { translation: { } }, + en: { translation: { } }, + 'en-US': { translation: { 'simpleTest': 'someData' } } + }; + + beforeEach(function(done) { + setFixtures('
'); + + i18n.init(i18n.functions.extend(opts, { resStore: resStore }), + function(t) { done(); }); + }); + + it('it should set data', function() { + $('#container').i18n(); + expect($('#container').data('test')).to.be('someData'); + expect($('#container').attr('data-test')).to.be('someData'); + }); + + }); + + describe('extended - append html', function() { + + var resStore = { + dev: { translation: { } }, + en: { translation: { } }, + 'en-US': { translation: { 'simpleTest': '
test
' } } + }; + + beforeEach(function(done) { + setFixtures('
'); + + i18n.init(i18n.functions.extend(opts, { resStore: resStore }), + function(t) { done(); }); + }); + + it('it should append html', function() { + $('#container').i18n(); + expect($('#container').html()).to.be('
test
'); + }); + + }); + + describe('extended - prepend html', function() { + + var resStore = { + dev: { translation: { } }, + en: { translation: { } }, + 'en-US': { translation: { 'simpleTest': '
test
' } } + }; + + beforeEach(function(done) { + setFixtures('
'); + + i18n.init(i18n.functions.extend(opts, { resStore: resStore }), + function(t) { done(); }); + }); + + it('it should append html', function() { + $('#container').i18n(); + expect($('#container').html()).to.be('
test
'); + }); + + }); + + describe('extended - with target set to inner element', function() { + + var resStore = { + dev: { translation: { } }, + en: { translation: { } }, + 'en-US': { translation: { 'simpleTest': 'test' } } + }; + + beforeEach(function(done) { + setFixtures('
'); + + i18n.init(i18n.functions.extend(opts, { resStore: resStore }), + function(t) { done(); }); + }); + + it('it should set inner html', function() { + $('#container').i18n(); + expect($('#inner').html()).to.be('test'); + }); + + }); + + + describe('extended - write/read options from data attribute', function() { + + var resStore = { + dev: { translation: { } }, + en: { translation: { } }, + 'en-US': { translation: { 'simpleTest': '__replace__ ok_from_en-US' } } + }; + + beforeEach(function(done) { + setFixtures('
'); + + i18n.init(i18n.functions.extend(opts, { + resStore: resStore, + useDataAttrOptions: true + }), + function(t) { + $('#container').i18n({ replace: 'replaced' }); + $('#testBtn').text(''); + done(); + }); + }); + + it('it should set text with attributes options', function() { + $('#container').i18n(); // without option + expect($('#testBtn').text()).to.be('replaced ok_from_en-US'); + }); + + }); + + describe('extended - read options from data attribute', function() { + + var resStore = { + dev: { translation: { } }, + en: { translation: { } }, + 'en-US': { translation: { 'simpleTest': '__replace__ ok_from_en-US' } } + }; + + beforeEach(function(done) { + setFixtures('
'); + + i18n.init(i18n.functions.extend(opts, { + resStore: resStore, + useDataAttrOptions: true + }), + function(t) { + done(); + }); + }); + + it('it should set text with attributes options', function() { + $('#container').i18n(); // without option + expect($('#testBtn').text()).to.be('replaced ok_from_en-US'); + }); + + }); + + describe('extended - read key from inner content', function() { + + var resStore = { + dev: { translation: { } }, + en: { translation: { } }, + 'en-US': { translation: { 'simpleTest2': 'ok_from_en-US' } } + }; + + beforeEach(function(done) { + setFixtures('
'); + + i18n.init(i18n.functions.extend(opts, { + resStore: resStore + }), + function(t) { + done(); + }); + }); + + it('it should read key from inner content', function() { + $('#container').i18n(); // without option + expect($('#testBtn').text()).to.be('ok_from_en-US'); + }); + + }); + +}); \ No newline at end of file diff --git a/libs/i18next/spec/jquery/jquery.varia.spec.js b/libs/i18next/spec/jquery/jquery.varia.spec.js new file mode 100644 index 00000000..8a9ab37f --- /dev/null +++ b/libs/i18next/spec/jquery/jquery.varia.spec.js @@ -0,0 +1,13 @@ +describe('use translation function shortcut $.t', function() { + + beforeEach(function(done) { + i18n.init(opts, function(t) { done(); }); + }); + + it('it should provide translation via $.t', function() { + expect($.t('simple_en-US')).to.be('ok_from_en-US'); + expect($.t('simple_en')).to.be('ok_from_en'); + expect($.t('simple_dev')).to.be('ok_from_dev'); + }); + +}); \ No newline at end of file diff --git a/libs/i18next/spec/server.functions.spec.js b/libs/i18next/spec/server.functions.spec.js new file mode 100644 index 00000000..0aed6209 --- /dev/null +++ b/libs/i18next/spec/server.functions.spec.js @@ -0,0 +1,61 @@ +////////////////////// +// HINT +// +// you need to replace '_fetchOne' with 'fetchOne' to use this on server +// + +var i18n = require('../index') + , expect = require('expect.js') + , sinon = require('sinon'); + +describe('i18next.functions', function() { + + var opts; + + beforeEach(function(done) { + opts = { + lng: 'en-US', + fallbackLng: 'dev', + fallbackNS: [], + fallbackToDefaultNS: false, + fallbackOnNull: true, + fallbackOnEmpty: false, + load: 'all', + preload: [], + supportedLngs: [], + lowerCaseLng: false, + ns: 'translation', + resGetPath: 'test/locales/__lng__/__ns__.json', + resSetPath: 'test/locales/__lng__/new.__ns__.json', + saveMissing: false, + resStore: false, + returnObjectTrees: false, + interpolationPrefix: '__', + interpolationSuffix: '__', + postProcess: '', + parseMissingKey: '', + debug: false, + objectTreeKeyHandler: null, + lngWhitelist: null + }; + + i18n.init(opts, function(t) { + i18n.sync.resStore = {}; + done(); + }); + }); + + //= functions/functions.CI.spec.js + + //= functions/functions.setlng.spec.js + + //= functions/functions.preload.spec.js + + //= functions/functions.postprocessor.spec.js + + // functions/functions.postmissing.spec.js + + //= functions/functions.objectTreeKeyHandler.spec.js + + +}); \ No newline at end of file diff --git a/libs/i18next/spec/server.init.spec.js b/libs/i18next/spec/server.init.spec.js new file mode 100644 index 00000000..115e50ef --- /dev/null +++ b/libs/i18next/spec/server.init.spec.js @@ -0,0 +1,75 @@ +////////////////////// +// HINT +// +// you need to replace '_fetchOne' with 'fetchOne' to use this on server +// fix line 351 'sendMissing' -> 'saveMissing' +// + + +var i18n = require('../index') + , expect = require('expect.js') + , sinon = require('sinon'); + +describe('i18next.init', function() { + + var opts; + + beforeEach(function(done) { + opts = { + lng: 'en-US', + fallbackLng: 'dev', + fallbackNS: [], + fallbackToDefaultNS: false, + fallbackOnNull: true, + fallbackOnEmpty: false, + load: 'all', + preload: [], + supportedLngs: [], + lowerCaseLng: false, + ns: 'translation', + resGetPath: 'test/locales/__lng__/__ns__.json', + resSetPath: 'test/locales/__lng__/new.__ns__.json', + saveMissing: false, + sendMissingTo: 'fallback', + resStore: false, + returnObjectTrees: false, + interpolationPrefix: '__', + interpolationSuffix: '__', + postProcess: '', + parseMissingKey: '', + debug: false, + objectTreeKeyHandler: null, + lngWhitelist: null + }; + + i18n.init(opts, function(t) { + i18n.sync.resStore = {}; + done(); + }); + }); + + // init/init.load.spec.js + + describe('advanced initialisation options', function() { + + //= init/init.fallbackLng.spec.js + + //= init/init.addResourceOrResourceBundle.spec.js + + //= init/init.removeResourceBundle.spec.js + + //= init/init.loadBehaviour.spec.js + + //= init/init.preload.spec.js + + // init/init.syncFlag.spec.js + + //= init/init.namespace.spec.js + + // init/init.localstorage.spec.js + + //= init/init.varia.spec.js + + }); + +}); \ No newline at end of file diff --git a/libs/i18next/spec/server.translate.spec.js b/libs/i18next/spec/server.translate.spec.js new file mode 100644 index 00000000..3b4c2d68 --- /dev/null +++ b/libs/i18next/spec/server.translate.spec.js @@ -0,0 +1,67 @@ +var i18n = require('../index') + , expect = require('expect.js') + , sinon = require('sinon'); + +describe('i18next.translate', function() { + + var opts; + + beforeEach(function() { + opts = { + lng: 'en-US', + fallbackLng: 'dev', + fallbackNS: [], + fallbackToDefaultNS: false, + fallbackOnNull: true, + fallbackOnEmpty: false, + load: 'all', + preload: [], + supportedLngs: [], + lowerCaseLng: false, + ns: 'translation', + resGetPath: 'test/locales/__lng__/__ns__.json', + resSetPath: 'test/locales/__lng__/new.__ns__.json', + saveMissing: false, + resStore: false, + returnObjectTrees: false, + interpolationPrefix: '__', + interpolationSuffix: '__', + postProcess: '', + parseMissingKey: '', + debug: false, + objectTreeKeyHandler: null, + lngWhitelist: null + }; + }); + + //= translate/translate.nonStringKeys.spec.js + + //= translate/translate.missingKey.spec.js + + //= translate/translate.nullValue.spec.js + + //= translate/translate.emptyValue.spec.js + + //= translate/translate.arrayKey.spec.js + + //= translate/translate.arrayValue.spec.js + + //= translate/translate.objectValue.spec.js + + //= translate/translate.nesting.spec.js + + describe('interpolation - replacing values inside a string', function() { + + //= translate/translate.interpolation.spec.js + + //= translate/translate.sprintf.spec.js + + }); + + //= translate/translate.plurals.spec.js + + //= translate/translate.context.spec.js + + //= translate/translate.setlng.spec.js + +}); \ No newline at end of file diff --git a/libs/i18next/spec/spec.js b/libs/i18next/spec/spec.js new file mode 100644 index 00000000..e3b0ff6f --- /dev/null +++ b/libs/i18next/spec/spec.js @@ -0,0 +1,44 @@ +describe('i18next', function() { + + var i18n = $.i18n + , opts; + + beforeEach(function() { + opts = { + lng: 'en-US', + load: 'all', + fallbackLng: 'dev', + fallbackNS: [], + fallbackOnNull: true, + fallbackOnEmpty: false, + preload: [], + lowerCaseLng: false, + ns: 'translation', + fallbackToDefaultNS: false, + resGetPath: 'locales/__lng__/__ns__.json', + dynamicLoad: false, + useLocalStorage: false, + sendMissing: false, + resStore: false, + getAsync: true, + returnObjectTrees: false, + debug: false, + selectorAttr: 'data-i18n', + postProcess: '', + parseMissingKey: '', + interpolationPrefix: '__', + interpolationSuffix: '__', + defaultVariables: false, + shortcutFunction: 'sprintf', + objectTreeKeyHandler: null, + lngWhitelist: null + }; + }); + + + //= init.spec.js + //= functions.spec.js + //= translate.spec.js + //= jquery.spec.js + +}); diff --git a/libs/i18next/spec/translate.spec.js b/libs/i18next/spec/translate.spec.js new file mode 100644 index 00000000..b61e2aaf --- /dev/null +++ b/libs/i18next/spec/translate.spec.js @@ -0,0 +1,41 @@ +describe('translation functionality', function() { + + //= translate/translate.nonStringKeys.spec.js + + //= translate/translate.missingKey.spec.js + + //= translate/translate.exists.spec.js + + //= translate/translate.nullValue.spec.js + + //= translate/translate.emptyValue.spec.js + + //= translate/translate.arrayKey.spec.js + + //= translate/translate.arrayValue.spec.js + + //= translate/translate.objectValue.spec.js + + //= translate/translate.nesting.spec.js + + describe('interpolation - replacing values inside a string', function() { + + //= translate/translate.interpolation.spec.js + + //= translate/translate.sprintf.spec.js + + //= translate/translate.defaultVariables.spec.js + + }); + + //= translate/translate.plurals.spec.js + + //= translate/translate.indefinite.spec.js + + //= translate/translate.context.spec.js + + //= translate/translate.setlng.spec.js + + //= translate/translate.defaultValue.spec.js + +}); diff --git a/libs/i18next/spec/translate/translate.arrayKey.spec.js b/libs/i18next/spec/translate/translate.arrayKey.spec.js new file mode 100644 index 00000000..80182b3e --- /dev/null +++ b/libs/i18next/spec/translate/translate.arrayKey.spec.js @@ -0,0 +1,30 @@ +describe('resource key as array', function() { + var resStore = { + dev: { translation: { existing1: 'hello _name_', existing2: 'howdy __name__' } }, + en: { translation: { } }, + 'en-US': { translation: { } } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { resStore: resStore }), + function(t) { done(); }); + }); + + describe('when none of the keys exist', function() { + it('return the same value as translating the last non-existent key', function() { + expect(i18n.t(['nonexistent1', 'nonexistent2'], {name: "Joe"})).to.equal(i18n.t('nonexistent2', {name: "Joe"})); + }); + }); + + describe('when one of the keys exist', function() { + it('return the same value as translating the one existing key', function() { + expect(i18n.t(['nonexistent1', 'existing2'], {name: "Joe"})).to.equal(i18n.t('existing2', {name: "Joe"})); + }); + }); + + describe('when two or more of the keys exist', function() { + it('return the same value as translating the first existing key', function() { + expect(i18n.t(['nonexistent1', 'existing2', 'existing1'], {name: "Joe"})).to.equal(i18n.t('existing2', {name: "Joe"})); + }); + }); +}); diff --git a/libs/i18next/spec/translate/translate.arrayValue.spec.js b/libs/i18next/spec/translate/translate.arrayValue.spec.js new file mode 100644 index 00000000..5e265e1d --- /dev/null +++ b/libs/i18next/spec/translate/translate.arrayValue.spec.js @@ -0,0 +1,16 @@ +describe('resource string as array', function() { + var resStore = { + dev: { translation: { testarray: ["title", "text"] } }, + en: { translation: { } }, + 'en-US': { translation: { } } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { resStore: resStore }), + function(t) { done(); }); + }); + + it('it should translate nested value', function() { + expect(i18n.t('testarray')).to.be('title\ntext'); + }); +}); \ No newline at end of file diff --git a/libs/i18next/spec/translate/translate.context.spec.js b/libs/i18next/spec/translate/translate.context.spec.js new file mode 100644 index 00000000..bd45e83d --- /dev/null +++ b/libs/i18next/spec/translate/translate.context.spec.js @@ -0,0 +1,77 @@ +describe('context usage', function() { + + describe('basic usage', function() { + var resStore = { + dev: { 'ns.2': { + friend_context: 'A friend from ns2', + friend_context_male: 'A boyfriend from ns2', + friend_context_female: 'A girlfriend from ns2' + } + }, + en: { 'ns.1': { + friend_context: 'A friend', + friend_context_male: 'A boyfriend', + friend_context_female: 'A girlfriend' + } + }, + 'en-US': { translation: { } } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { + resStore: resStore, + ns: { namespaces: ['ns.1', 'ns.2'], defaultNs: 'ns.1'} + }), + function(t) { done(); }); + }); + + it('it should provide correct context form', function() { + expect(i18n.t('friend_context')).to.be('A friend'); + expect(i18n.t('friend_context', {context: ''})).to.be('A friend'); + expect(i18n.t('friend_context', {context: 'male'})).to.be('A boyfriend'); + expect(i18n.t('friend_context', {context: 'female'})).to.be('A girlfriend'); + }); + + it('it should provide correct context form for second namespace', function() { + expect(i18n.t('ns.2:friend_context')).to.be('A friend from ns2'); + expect(i18n.t('ns.2:friend_context', {context: ''})).to.be('A friend from ns2'); + expect(i18n.t('ns.2:friend_context', {context: 'male'})).to.be('A boyfriend from ns2'); + expect(i18n.t('ns.2:friend_context', {context: 'female'})).to.be('A girlfriend from ns2'); + }); + }); + + describe('extended usage - in combination with plurals', function() { + var resStore = { + dev: { translation: { } }, + en: { translation: { + friend_context: '__count__ friend', + friend_context_male: '__count__ boyfriend', + friend_context_female: '__count__ girlfriend', + friend_context_plural: '__count__ friends', + friend_context_male_plural: '__count__ boyfriends', + friend_context_female_plural: '__count__ girlfriends' + } + }, + 'en-US': { translation: { } } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { resStore: resStore }), + function(t) { done(); }); + }); + + it('it should provide correct context with plural forms', function() { + expect(i18n.t('friend_context', { count: 1 })).to.be('1 friend'); + expect(i18n.t('friend_context', {context: '', count: 1 })).to.be('1 friend'); + expect(i18n.t('friend_context', {context: 'male', count: 1 })).to.be('1 boyfriend'); + expect(i18n.t('friend_context', {context: 'female', count: 1 })).to.be('1 girlfriend'); + + expect(i18n.t('friend_context', { count: 10 })).to.be('10 friends'); + expect(i18n.t('friend_context', {context: '', count: 10 })).to.be('10 friends'); + expect(i18n.t('friend_context', {context: 'male', count: 10 })).to.be('10 boyfriends'); + expect(i18n.t('friend_context', {context: 'female', count: 10 })).to.be('10 girlfriends'); + }); + + }); + +}); \ No newline at end of file diff --git a/libs/i18next/spec/translate/translate.defaultValue.spec.js b/libs/i18next/spec/translate/translate.defaultValue.spec.js new file mode 100644 index 00000000..23a68e89 --- /dev/null +++ b/libs/i18next/spec/translate/translate.defaultValue.spec.js @@ -0,0 +1,23 @@ +describe('using sprintf', function() { + + var resStore = { + dev: { translation: { } }, + en: { translation: { } }, + 'en-US': { + translation: { + test: 'hi' + } + } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { resStore: resStore, shortcutFunction: 'defaultValue' }), + function(t) { done(); }); + }); + + + it('it should recognize the defaultValue syntax set as shortcutFunction', function() { + expect(i18n.t('notFound', 'second param defaultValue')).to.be('second param defaultValue'); + }); + +}); \ No newline at end of file diff --git a/libs/i18next/spec/translate/translate.defaultVariables.spec.js b/libs/i18next/spec/translate/translate.defaultVariables.spec.js new file mode 100644 index 00000000..0f249699 --- /dev/null +++ b/libs/i18next/spec/translate/translate.defaultVariables.spec.js @@ -0,0 +1,22 @@ +describe('with default variables', function() { + + var defaultVariables = { + name: 'John' + }; + + beforeEach(function(done) { + i18n.init( + i18n.functions.extend(opts, { defaultVariables: defaultVariables }), + function(t) { done(); } + ); + }); + + it('it should use default variable', function() { + expect(i18n.t('Hello __name__')).to.be('Hello John'); + }); + + it('it should replace default variable', function() { + expect(i18n.t('Hello __name__', {name: 'Ben'})).to.be('Hello Ben'); + }); + +}); diff --git a/libs/i18next/spec/translate/translate.emptyValue.spec.js b/libs/i18next/spec/translate/translate.emptyValue.spec.js new file mode 100644 index 00000000..ee9a6f4a --- /dev/null +++ b/libs/i18next/spec/translate/translate.emptyValue.spec.js @@ -0,0 +1,101 @@ +describe('key with empty string value as valid option', function() { + var resStore = { + dev: { translation: { empty: '' } }, + en: { translation: { } }, + 'en-US': { translation: { } } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { resStore: resStore }), + function(t) { done(); }); + }); + + it('it should translate correctly', function() { + expect(i18n.t('empty')).to.be(''); + }); + + describe('missing on unspecific', function() { + var resStore = { + dev: { translation: { empty: 'text' } }, + en: { translation: { } }, + 'en-US': { translation: { empty: '' } } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { resStore: resStore, lng: 'en' }), + function(t) { done(); }); + }); + + it('it should translate correctly', function() { + expect(i18n.t('empty')).to.be('text'); + }); + }); + + describe('on specific language', function() { + var resStore = { + dev: { translation: { empty: 'text' } }, + en: { translation: { } }, + 'en-US': { translation: { empty: '' } } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { resStore: resStore }), + function(t) { done(); }); + }); + + it('it should translate correctly', function() { + expect(i18n.t('empty')).to.be(''); + }); + }); +}); + +describe('key with empty string set to fallback if empty', function() { + var resStore = { + dev: { translation: { empty: '' } }, + en: { translation: { } }, + 'en-US': { translation: { } } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { resStore: resStore, fallbackOnEmpty: true }), + function(t) { done(); }); + }); + + it('it should translate correctly', function() { + expect(i18n.t('empty')).to.be('empty'); + }); + + describe('missing on unspecific', function() { + var resStore = { + dev: { translation: { empty: 'text' } }, + en: { translation: { } }, + 'en-US': { translation: { empty: '' } } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { resStore: resStore, lng: 'en', fallbackOnEmpty: true }), + function(t) { done(); }); + }); + + it('it should translate correctly', function() { + expect(i18n.t('empty')).to.be('text'); + }); + }); + + describe('on specific language', function() { + var resStore = { + dev: { translation: { empty: 'text' } }, + en: { translation: { } }, + 'en-US': { translation: { empty: '' } } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { resStore: resStore, fallbackOnEmpty: true }), + function(t) { done(); }); + }); + + it('it should translate correctly', function() { + expect(i18n.t('empty')).to.be('text'); + }); + }); +}); \ No newline at end of file diff --git a/libs/i18next/spec/translate/translate.exists.spec.js b/libs/i18next/spec/translate/translate.exists.spec.js new file mode 100644 index 00000000..a0c03bc6 --- /dev/null +++ b/libs/i18next/spec/translate/translate.exists.spec.js @@ -0,0 +1,41 @@ +describe('Check for existence of keys', function() { + var resStore = { + dev: { translation: { iExist: '' } }, + en: { translation: { } }, + 'en-US': { translation: { } } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { resStore: resStore }), + function(t) { done(); }); + }); + + it('it should exist', function() { + expect(i18n.exists('iExist')).to.be(true); + }); + + it('it should not exist', function() { + expect(i18n.exists('iDontExist')).to.be(false); + }); + + describe('missing on unspecific', function() { + var resStore = { + dev: { translation: { iExist: 'text' } }, + en: { translation: { } }, + 'en-US': { translation: { empty: '' } } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { resStore: resStore, lng: 'en' }), + function(t) { done(); }); + }); + + it('it should exist', function() { + expect(i18n.exists('iExist')).to.be(true); + }); + + it('it should not exist', function() { + expect(i18n.exists('iDontExist')).to.be(false); + }); + }); +}); diff --git a/libs/i18next/spec/translate/translate.indefinite.spec.js b/libs/i18next/spec/translate/translate.indefinite.spec.js new file mode 100644 index 00000000..ef2b4462 --- /dev/null +++ b/libs/i18next/spec/translate/translate.indefinite.spec.js @@ -0,0 +1,85 @@ +describe('indefinite article usage', function() { + describe('basic usage - singular, plural and indefinite', function() { + var resStore = { + dev: { + 'ns.2': { + thing: '__count__ thing from ns.2', + thing_plural: '__count__ things from ns.2', + thing_indefinite: 'A thing from ns.2', + thing_plural_indefinite: 'Some things from ns.2' + }, + 'ns.3': { + thing: '__count__ things', + thing_indefinite: 'A thing', + thing_plural_indefinite: 'Some things' + } + }, + en: { }, + 'en-US': { + 'ns.1': { + thing: '__count__ thing', + thing_plural: '__count__ things', + thing_indefinite: 'A thing' + } + } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { + resStore: resStore, + ns: { namespaces: ['ns.1', 'ns.2', 'ns.3'], defaultNs: 'ns.1'} + }), function(t) { done(); }); + }); + + it('it should provide the indefinite article when requested for singular forms', function() { + expect(i18n.t('thing')).to.be('__count__ thing'); + expect(i18n.t('thing', {indefinite_article: true})).to.be('A thing'); + expect(i18n.t('thing', {count:1})).to.be('1 thing'); + expect(i18n.t('thing', {count:5})).to.be('5 things'); + expect(i18n.t('thing', {count:1, indefinite_article: true})).to.be('A thing'); + expect(i18n.t('thing', {count:5, indefinite_article: true})).to.be('5 things'); + }); + + it('it should provide the indefinite article when requested for singular forms for second namespace', function() { + expect(i18n.t('ns.2:thing', {count:1})).to.be('1 thing from ns.2'); + expect(i18n.t('ns.2:thing', {count:5})).to.be('5 things from ns.2'); + expect(i18n.t('ns.2:thing', {count:1, indefinite_article: true})).to.be('A thing from ns.2'); + expect(i18n.t('ns.2:thing', {count:5, indefinite_article: true})).to.be('Some things from ns.2'); + }); + + it('it should provide the right indefinite translations from the third namespace', function() { + expect(i18n.t('ns.3:thing', {count:5})).to.be('5 things'); + expect(i18n.t('ns.3:thing', {count:1, indefinite_article: true})).to.be('A thing'); + expect(i18n.t('ns.3:thing', {count:5, indefinite_article: true})).to.be('Some things') + }); + }); + + describe('extended usage - indefinite articles in languages with different plural forms', function() { + var resStore = { + dev: { + translation: { + } + }, + zh: { + translation: { + key: "__count__ thing", + key_indefinite: "a thing" + } + } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { + lng: 'zh', + resStore: resStore + }), function(t) { done(); }); + }); + + it('it should provide the correct indefinite articles', function() { + expect(i18n.t('key', {count: 1})).to.be('1 thing'); + expect(i18n.t('key', {count: 5})).to.be('5 thing'); + expect(i18n.t('key', {count: 1, indefinite_article: true})).to.be('a thing'); + expect(i18n.t('key', {count: 5, indefinite_article: true})).to.be('a thing'); + }); + }); +}); diff --git a/libs/i18next/spec/translate/translate.interpolation.spec.js b/libs/i18next/spec/translate/translate.interpolation.spec.js new file mode 100644 index 00000000..141c7914 --- /dev/null +++ b/libs/i18next/spec/translate/translate.interpolation.spec.js @@ -0,0 +1,199 @@ +describe('default i18next way', function() { + + var resStore = { + dev: { translation: { } }, + en: { translation: { } }, + 'en-US': { + translation: { + interpolationTest1: 'added __toAdd__', + interpolationTest2: 'added __toAdd__ __toAdd__ twice', + interpolationTest3: 'added __child.one__ __child.two__', + interpolationTest4: 'added __child.grandChild.three__' + } + } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { resStore: resStore }), + function(t) { done(); }); + }); + + it('it should replace passed in key/values', function() { + expect(i18n.t('interpolationTest1', {toAdd: 'something'})).to.be('added something'); + expect(i18n.t('interpolationTest2', {toAdd: 'something'})).to.be('added something something twice'); + expect(i18n.t('interpolationTest3', { child: { one: '1', two: '2'}})).to.be('added 1 2'); + expect(i18n.t('interpolationTest4', { child: { grandChild: { three: '3'}}})).to.be('added 3'); + }); + + it('it should replace passed in key/values in replace member', function() { + expect(i18n.t('interpolationTest1', { replace: {toAdd: 'something'} })).to.be('added something'); + expect(i18n.t('interpolationTest2', { replace: {toAdd: 'something'} })).to.be('added something something twice'); + expect(i18n.t('interpolationTest3', { replace: { child: { one: '1', two: '2'}} })).to.be('added 1 2'); + expect(i18n.t('interpolationTest4', { replace: { child: { grandChild: { three: '3'}}} })).to.be('added 3'); + }); + + it("it should not escape HTML", function() { + expect(i18n.t('interpolationTest1', {toAdd: ''})).to.be('added '); + }); + + it('it should replace passed in key/values on defaultValue', function() { + expect(i18n.t('interpolationTest5', {defaultValue: 'added __toAdd__', toAdd: 'something'})).to.be('added something'); + }); + + it("it should escape dollar signs in replacement values", function() { + expect(i18n.t('interpolationTest1', {toAdd: '$&'})).to.be('added $&'); + }); + +}); + +describe('default i18next way - different prefix/suffix', function() { + + var resStore = { + dev: { translation: { } }, + en: { translation: { } }, + 'en-US': { + translation: { + interpolationTest1: 'added *toAdd*', + interpolationTest2: 'added *toAdd* *toAdd* twice', + interpolationTest3: 'added *child.one* *child.two*', + interpolationTest4: 'added *child.grandChild.three*' + } + } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { + resStore: resStore, + interpolationPrefix: '*', + interpolationSuffix: '*' + }), function(t) { done(); }); + }); + + it('it should replace passed in key/values', function() { + expect(i18n.t('interpolationTest1', {toAdd: 'something'})).to.be('added something'); + expect(i18n.t('interpolationTest2', {toAdd: 'something'})).to.be('added something something twice'); + expect(i18n.t('interpolationTest3', { child: { one: '1', two: '2'}})).to.be('added 1 2'); + expect(i18n.t('interpolationTest4', { child: { grandChild: { three: '3'}}})).to.be('added 3'); + }); + + it('it should replace passed in key/values on defaultValue', function() { + expect(i18n.t('interpolationTest5', {defaultValue: 'added *toAdd*', toAdd: 'something'})).to.be('added something'); + }); + +}); + +describe('default i18next way - different prefix/suffix via options', function() { + + var resStore = { + dev: { translation: { } }, + en: { translation: { } }, + 'en-US': { + translation: { + interpolationTest1: 'added *toAdd*', + interpolationTest2: 'added *toAdd* *toAdd* twice', + interpolationTest3: 'added *child.one* *child.two*', + interpolationTest4: 'added *child.grandChild.three*', + interpolationTest5: 'added *count*', + interpolationTest5_plural: 'added *count*' + } + } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { + resStore: resStore + }), function(t) { done(); }); + }); + + it('it should replace passed in key/values', function() { + expect(i18n.t('interpolationTest1', {toAdd: 'something', interpolationPrefix: '*', interpolationSuffix: '*'})).to.be('added something'); + expect(i18n.t('interpolationTest2', {toAdd: 'something', interpolationPrefix: '*', interpolationSuffix: '*'})).to.be('added something something twice'); + expect(i18n.t('interpolationTest3', { child: { one: '1', two: '2'}, interpolationPrefix: '*', interpolationSuffix: '*'})).to.be('added 1 2'); + expect(i18n.t('interpolationTest4', { child: { grandChild: { three: '3'}}, interpolationPrefix: '*', interpolationSuffix: '*'})).to.be('added 3'); + expect(i18n.t('interpolationTest5', { count: 3, interpolationPrefix: '*', interpolationSuffix: '*'})).to.be('added 3'); + }); + + it('it should replace passed in key/values on defaultValue', function() { + expect(i18n.t('interpolationTest6', {defaultValue: 'added *toAdd*', toAdd: 'something', interpolationPrefix: '*', interpolationSuffix: '*'})).to.be('added something'); + }); + +}); + +describe('default i18next way - with escaping interpolated arguments per default', function () { + var resStore = { + dev: { translation: { } }, + en: { translation: { } }, + 'en-US': { + translation: { + interpolationTest1: 'added __toAdd__', + interpolationTest5: 'added __toAddHTML__', + interpolationTest6: 'added __child.oneHTML__', + interpolationTest7: 'added __toAddHTML__ __toAdd__' + } + } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { + resStore: resStore, + escapeInterpolation: true + }), function(t) { done(); }); + }); + + it("it should escape HTML", function() { + expect(i18n.t('interpolationTest1', {toAdd: ''})).to.be('added <html>'); + }); + + it("it should not escape when HTML is suffixed", function() { + expect(i18n.t('interpolationTest5', {toAdd: ''})).to.be('added '); + expect(i18n.t('interpolationTest6', { child: { one: '<1>'}})).to.be('added <1>'); + }); + + it("it should support both escaping and not escaping HTML", function() { + expect(i18n.t('interpolationTest7', {toAdd: '', escapeInterpolation: true})).to.be('added <html>'); + }); + + it("it should escape dollar signs in replacement values", function() { + expect(i18n.t('interpolationTest1', {toAdd: '$&'})).to.be('added $&'); + }); + +}); + +describe('default i18next way - with escaping interpolated arguments per default via options', function () { + var resStore = { + dev: { translation: { } }, + en: { translation: { } }, + 'en-US': { + translation: { + interpolationTest1: 'added __toAdd__', + interpolationTest5: 'added __toAddHTML__', + interpolationTest6: 'added __child.oneHTML__', + interpolationTest7: 'added __toAddHTML__ __toAdd__' + } + } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { + resStore: resStore + }), function(t) { done(); }); + }); + + it("it should escape HTML", function() { + expect(i18n.t('interpolationTest1', {toAdd: '', escapeInterpolation: true})).to.be('added <html>'); + }); + + it("it should not escape when HTML is suffixed", function() { + expect(i18n.t('interpolationTest5', {toAdd: '', escapeInterpolation: true})).to.be('added '); + expect(i18n.t('interpolationTest6', { child: { one: '<1>', escapeInterpolation: true}})).to.be('added <1>'); + }); + + it("it should support both escaping and not escaping HTML", function() { + expect(i18n.t('interpolationTest7', {toAdd: '', escapeInterpolation: true})).to.be('added <html>'); + }); + + it("it should escape dollar signs in replacement values", function() { + expect(i18n.t('interpolationTest1', {toAdd: '$&'})).to.be('added $&'); + }); + +}); \ No newline at end of file diff --git a/libs/i18next/spec/translate/translate.missingKey.spec.js b/libs/i18next/spec/translate/translate.missingKey.spec.js new file mode 100644 index 00000000..54e0b7e1 --- /dev/null +++ b/libs/i18next/spec/translate/translate.missingKey.spec.js @@ -0,0 +1,63 @@ +describe('resource is missing', function() { + var resStore = { + dev: { translation: { } }, + en: { translation: { } }, + 'en-US': { translation: { } } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { resStore: resStore }), + function(t) { done(); }); + }); + + it('it should return key', function() { + expect(i18n.t('missing')).to.be('missing'); + }); + + it('it should return default value if set', function() { + expect(i18n.t('missing', { defaultValue: 'defaultOfMissing'})).to.be('defaultOfMissing'); + }); + + describe('with namespaces', function() { + + it('it should return key', function() { + expect(i18n.t('translate:missing')).to.be('translate:missing'); + }); + + it('it should return default value if set', function() { + expect(i18n.t('translate:missing', { defaultValue: 'defaultOfMissing'})).to.be('defaultOfMissing'); + }); + + describe('and function parseMissingKey set', function() { + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { + parseMissingKey: function(key) { + var ret = key; + + if (ret.indexOf(':')) { + ret = ret.substring(ret.lastIndexOf(':')+1, ret.length); + } + + if (ret.indexOf('.')) { + ret = ret.substring(ret.lastIndexOf('.')+1, ret.length); + } + + return ret; + } + }), function(t) { done(); }); + }); + + it('it should parse key', function() { + expect(i18n.t('translate:missing')).to.be('missing'); + expect(i18n.t('translate:somenesting.missing')).to.be('missing'); + }); + + it('it should return default value if set', function() { + expect(i18n.t('translate:missing', { defaultValue: 'defaultOfMissing'})).to.be('defaultOfMissing'); + }); + + }); + + }); + +}); \ No newline at end of file diff --git a/libs/i18next/spec/translate/translate.nesting.spec.js b/libs/i18next/spec/translate/translate.nesting.spec.js new file mode 100644 index 00000000..861b3537 --- /dev/null +++ b/libs/i18next/spec/translate/translate.nesting.spec.js @@ -0,0 +1,62 @@ +describe('resource nesting', function() { + var resStore = { + dev: { translation: { nesting1: '1 $t(nesting2)' } }, + en: { translation: { nesting2: '2 $t(nesting3)' } }, + 'en-US': { translation: { nesting3: '3' } } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { resStore: resStore }), + function(t) { done(); }); + }); + + it('it should translate nested value', function() { + expect(i18n.t('nesting1')).to.be('1 2 3'); + }); + + it('it should apply nested value on defaultValue', function() { + expect(i18n.t('nesting_default', {defaultValue: '0 $t(nesting1)'})).to.be('0 1 2 3'); + }); + + describe('resource nesting syntax error', function() { + var resStore = { + dev: { translation: { nesting1: '1 $t(nesting2' } }, + en: { translation: { nesting2: '2 $t(nesting3)' } }, + 'en-US': { translation: { nesting3: '3' } } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { resStore: resStore }), + function(t) { done(); }); + }); + + it('it should translate nested value', function() { + expect(i18n.t('nesting1')).to.be(''); + }); + + }); + + describe('with setting new options', function() { + var resStore = { + dev: { translation: { + nesting1: '$t(nesting2, {"count": __girls__}) and __count__ boy', + nesting1_plural: '$t(nesting2, {"count": __girls__}) and __count__ boys' + } }, + en: { translation: { + nesting2: '__count__ girl', + nesting2_plural: '__count__ girls' + } } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { resStore: resStore }), + function(t) { done(); }); + }); + + it('it should translate nested value and set new options', function() { + expect(i18n.t('nesting1', {count: 2, girls: 3})).to.be('3 girls and 2 boys'); + expect(i18n.t('nesting1', {count: 1, girls: 3})).to.be('3 girls and 1 boy'); + }); + }); + +}); \ No newline at end of file diff --git a/libs/i18next/spec/translate/translate.nonStringKeys.spec.js b/libs/i18next/spec/translate/translate.nonStringKeys.spec.js new file mode 100644 index 00000000..63945a2d --- /dev/null +++ b/libs/i18next/spec/translate/translate.nonStringKeys.spec.js @@ -0,0 +1,32 @@ +describe('keys with non supported values', function() { + + var resStore = { + dev: { translation: { } }, + en: { translation: { } }, + 'en-US': { + translation: { + test: 'hi' + } + } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { resStore: resStore }), + function(t) { done(); }); + }); + + + it('it should not break on null key', function() { + expect(i18n.t(null)).to.be(''); + }); + + it('it should not break on undefined key', function() { + expect(i18n.t(undefined)).to.be(''); + }); + + it('it should stringify first on number key', function() { + expect(i18n.t(1)).to.be(i18n.t('1')); + expect(i18n.t(1.1)).to.be(i18n.t('1.1')); + }); + +}); \ No newline at end of file diff --git a/libs/i18next/spec/translate/translate.nullValue.spec.js b/libs/i18next/spec/translate/translate.nullValue.spec.js new file mode 100644 index 00000000..89472b8b --- /dev/null +++ b/libs/i18next/spec/translate/translate.nullValue.spec.js @@ -0,0 +1,38 @@ +describe('resource string is null', function() { + var resStore = { + dev: { translation: { key1: null, key2: { key3: null } } }, + en: { translation: { } }, + 'en-US': { translation: { } } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { resStore: resStore, returnObjectTrees: true, fallbackOnNull: false }), + function(t) { done(); }); + }); + + it('it should translate value', function() { + expect(i18n.t('key1')).to.be(null); + expect(i18n.t('key2')).to.eql({ key3: null }); + }); + + describe('with option fallbackOnNull = true', function() { + var resStore = { + dev: { translation: { key1: 'fallbackKey1', key2: { key3: 'fallbackKey3' } } }, + en: { translation: { } }, + 'en-US': { translation: { key1: null, key2: { key3: null } } } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { resStore: resStore, fallbackOnNull: true}), + function(t) { done(); }); + }); + + it('it should translate to fallback value', function() { + expect(i18n.t('key1')).to.be('fallbackKey1'); + expect(i18n.t('key2.key3')).to.eql('fallbackKey3'); + }); + + }); + + +}); \ No newline at end of file diff --git a/libs/i18next/spec/translate/translate.objectValue.spec.js b/libs/i18next/spec/translate/translate.objectValue.spec.js new file mode 100644 index 00000000..fb8ba8f6 --- /dev/null +++ b/libs/i18next/spec/translate/translate.objectValue.spec.js @@ -0,0 +1,108 @@ +describe('accessing tree values', function() { + + var resStore = { + dev: { translation: { } }, + en: { translation: { } }, + 'en-US': { + translation: { + test: { 'simple_en-US': 'ok_from_en-US' } + } + } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { + resStore: resStore } + ), function(t) { done(); }); + }); + + it('it should return nested string as usual', function() { + expect(i18n.t('test.simple_en-US')).to.be('ok_from_en-US'); + }); + + it('it should not fail silently on accessing an objectTree', function() { + expect(i18n.t('test')).to.be('key \'translation:test (en-US)\' returned an object instead of string.'); + }); + + describe('optional return an objectTree for UI components,...', function() { + + describe('with init flag', function() { + + var resStore = { + dev: { translation: { + test_dev: { res_dev: 'added __replace__' } + } + }, + en: { translation: { } }, + 'en-US': { + translation: { + test_en_US: { res_en_US: 'added __replace__' } + } + } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { + returnObjectTrees: true, + resStore: resStore } + ), function(t) { done(); }); + }); + + it('it should return objectTree applying options', function() { + expect(i18n.t('test_en_US', { replace: 'two' })).to.eql({ 'res_en_US': 'added two' }); + expect(i18n.t('test_en_US', { replace: 'three' })).to.eql({ 'res_en_US': 'added three' }); + expect(i18n.t('test_en_US', { replace: 'four' })).to.eql({ 'res_en_US': 'added four' }); + + // from fallback + expect(i18n.t('test_dev', { replace: 'two' })).to.eql({ 'res_dev': 'added two' }); + }); + + }); + + describe('with flag in options', function() { + + var resStore = { + dev: { translation: { } }, + en: { translation: { } }, + 'en-US': { + translation: { + test: { res: 'added __replace__', + id: 0, + regex: /test/, + func: function () {}, + template: '4', + title: 'About...', + text: 'Site description', + media: ['test'] + } + } + } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { + returnObjectTrees: false, + resStore: resStore }), + function(t) { done(); } ); + }); + + it('it should return objectTree', function() { + expect(i18n.t('test', { returnObjectTrees: true, replace: 'two' })).to.eql({ + res: 'added two', + id: 0, + regex: resStore['en-US'].translation.test.regex, + func: resStore['en-US'].translation.test.func, + template: '4', + title: 'About...', + text: 'Site description', + media: ['test'] + }); + //expect(i18n.t('test', { returnObjectTrees: true, replace: 'three' })).to.eql({ 'res': 'added three' }); + //expect(i18n.t('test', { returnObjectTrees: true, replace: 'four' })).to.eql({ 'res': 'added four' }); + }); + + }); + + }); + +}); \ No newline at end of file diff --git a/libs/i18next/spec/translate/translate.plurals.spec.js b/libs/i18next/spec/translate/translate.plurals.spec.js new file mode 100644 index 00000000..817ebace --- /dev/null +++ b/libs/i18next/spec/translate/translate.plurals.spec.js @@ -0,0 +1,296 @@ +describe('plural usage', function() { + + describe('basic usage - singular and plural form', function() { + var resStore = { + dev: { 'ns.2': { + pluralTest: 'singular from ns.2', + pluralTest_plural: 'plural from ns.2', + pluralTestWithCount: '__count__ item from ns.2', + pluralTestWithCount_plural: '__count__ items from ns.2' + }}, + en: { }, + 'en-US': { + 'ns.1': { + pluralTest: 'singular', + pluralTest_plural: 'plural', + pluralTestWithCount: '__count__ item', + pluralTestWithCount_plural: '__count__ items' + } + } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { + resStore: resStore, + ns: { namespaces: ['ns.1', 'ns.2'], defaultNs: 'ns.1'} + }), + function(t) { done(); }); + }); + + it('it should provide correct plural or singular form', function() { + expect(i18n.t('pluralTest', {count: 0})).to.be('plural'); + expect(i18n.t('pluralTest', {count: 1})).to.be('singular'); + expect(i18n.t('pluralTest', {count: 2})).to.be('plural'); + expect(i18n.t('pluralTest', {count: 7})).to.be('plural'); + + expect(i18n.t('pluralTestWithCount', {count: 0})).to.be('0 items'); + expect(i18n.t('pluralTestWithCount', {count: 1})).to.be('1 item'); + expect(i18n.t('pluralTestWithCount', {count: 7})).to.be('7 items'); + }); + + it('it should provide correct plural or singular form for second namespace', function() { + expect(i18n.t('ns.2:pluralTest', {count: 0})).to.be('plural from ns.2'); + expect(i18n.t('ns.2:pluralTest', {count: 1})).to.be('singular from ns.2'); + expect(i18n.t('ns.2:pluralTest', {count: 2})).to.be('plural from ns.2'); + expect(i18n.t('ns.2:pluralTest', {count: 7})).to.be('plural from ns.2'); + + expect(i18n.t('ns.2:pluralTestWithCount', {count: 1})).to.be('1 item from ns.2'); + expect(i18n.t('ns.2:pluralTestWithCount', {count: 7})).to.be('7 items from ns.2'); + }); + + }); + + describe('fallback on count with non-plurals', function() { + var resStore = { + dev: { 'ns.2': { + pluralTestWithCount: '__count__ item from ns.2' + }}, + en: { }, + 'en-US': { + 'ns.1': { + pluralTestWithCount: '__count__ item' + } + } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { + resStore: resStore, + ns: { namespaces: ['ns.1', 'ns.2'], defaultNs: 'ns.1'} + }), + function(t) { done(); }); + }); + + it('it should provide correct singular form', function() { + expect(i18n.t('pluralTestWithCount', {count: 0})).to.be('0 item'); + expect(i18n.t('pluralTestWithCount', {count: 1})).to.be('1 item'); + expect(i18n.t('pluralTestWithCount', {count: 7})).to.be('7 item'); + }); + + it('it should provide correct singular form for second namespace', function() { + expect(i18n.t('ns.2:pluralTestWithCount', {count: 1})).to.be('1 item from ns.2'); + expect(i18n.t('ns.2:pluralTestWithCount', {count: 7})).to.be('7 item from ns.2'); + }); + + }); + + describe('Plurals with passing lng to translation function', function() { + + var resStore = { + 'nl': { + 'translation': { + pluralTestWithCount: '__count__ item', + pluralTestWithCount_plural: '__count__ items' + } + } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { + supportedLngs: ['nl'], + resStore: resStore + }), + function(t) { done(); }); + }); + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { + resStore: resStore + }), + function(t) { done(); }); + }); + it('should return the correct string for key', function() { + var resStore = { + nl: { + test: '__count__ items' + } + }; + + expect(i18n.t('pluralTestWithCount', {count: 12, lng: 'nl'})).to.equal('12 items'); + expect(i18n.t('pluralTestWithCount', {count: 0, lng: 'nl'})).to.equal('0 items'); + }); + }); + + describe('basic usage - singular and plural form on fallbacks', function() { + var resStore = { + 'fr': { + 'translation': {} + }, + 'en': { + 'translation': { + pluralTest: 'singular', + pluralTest_plural: 'plural', + pluralTestWithCount: '__count__ item', + pluralTestWithCount_plural: '__count__ items' + } + } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { + resStore: resStore, + lng: 'fr', + fallbackLng: 'en' + }), + function(t) { done(); }); + }); + + it('it should provide correct plural or singular form', function() { + expect(i18n.t('pluralTest', {count: 0})).to.be('plural'); + expect(i18n.t('pluralTest', {count: 1})).to.be('singular'); + expect(i18n.t('pluralTest', {count: 2})).to.be('plural'); + expect(i18n.t('pluralTest', {count: 7})).to.be('plural'); + + expect(i18n.t('pluralTestWithCount', {count: 0})).to.be('0 items'); + expect(i18n.t('pluralTestWithCount', {count: 1})).to.be('1 item'); + expect(i18n.t('pluralTestWithCount', {count: 7})).to.be('7 items'); + }); + + }); + + + describe('basic usage 2 - singular and plural form in french', function() { + var resStore = { + dev: { 'ns.2': { + pluralTest: 'singular from ns.2', + pluralTest_plural: 'plural from ns.2', + pluralTestWithCount: '__count__ item from ns.2', + pluralTestWithCount_plural: '__count__ items from ns.2' + }}, + en: { }, + 'fr': { + 'ns.1': { + pluralTest: 'singular', + pluralTest_plural: 'plural', + pluralTestWithCount: '__count__ item', + pluralTestWithCount_plural: '__count__ items' + } + } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { + lng: 'fr', + resStore: resStore, + ns: { namespaces: ['ns.1', 'ns.2'], defaultNs: 'ns.1'} + }), + function(t) { done(); }); + }); + + it('it should provide correct plural or singular form', function() { + expect(i18n.t('pluralTest', {count: 0})).to.be('singular'); + expect(i18n.t('pluralTest', {count: 1})).to.be('singular'); + expect(i18n.t('pluralTest', {count: 2})).to.be('plural'); + expect(i18n.t('pluralTest', {count: 7})).to.be('plural'); + + expect(i18n.t('pluralTestWithCount', {count: 0})).to.be('0 item'); + expect(i18n.t('pluralTestWithCount', {count: 1})).to.be('1 item'); + expect(i18n.t('pluralTestWithCount', {count: 7})).to.be('7 items'); + }); + }); + + describe('extended usage - multiple plural forms - ar', function() { + var resStore = { + dev: { translation: { } }, + ar: { translation: { + key: 'singular', + key_plural_0: 'zero', + key_plural_2: 'two', + key_plural_3: 'few', + key_plural_11: 'many', + key_plural_100: 'plural' + } + }, + 'ar-??': { translation: { } } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { lng: 'ar', resStore: resStore }), + function(t) { done(); }); + }); + + it('it should provide correct plural forms', function() { + expect(i18n.t('key', {count: 0})).to.be('zero'); + expect(i18n.t('key', {count: 1})).to.be('singular'); + expect(i18n.t('key', {count: 2})).to.be('two'); + expect(i18n.t('key', {count: 3})).to.be('few'); + expect(i18n.t('key', {count: 4})).to.be('few'); + expect(i18n.t('key', {count: 104})).to.be('few'); + expect(i18n.t('key', {count: 11})).to.be('many'); + expect(i18n.t('key', {count: 99})).to.be('many'); + expect(i18n.t('key', {count: 199})).to.be('many'); + expect(i18n.t('key', {count: 100})).to.be('plural'); + }); + }); + + describe('extended usage - multiple plural forms - ru', function() { + var resStore = { + dev: { translation: { } }, + ru: { translation: { + key: '1,21,31', + key_plural_2: '2,3,4', + key_plural_5: '0,5,6' + } + }, + 'ru-??': { translation: { } } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { lng: 'ru', resStore: resStore }), + function(t) { done(); }); + }); + + it('it should provide correct plural forms', function() { + expect(i18n.t('key', {count: 0})).to.be('0,5,6'); + expect(i18n.t('key', {count: 1})).to.be('1,21,31'); + expect(i18n.t('key', {count: 2})).to.be('2,3,4'); + expect(i18n.t('key', {count: 3})).to.be('2,3,4'); + expect(i18n.t('key', {count: 4})).to.be('2,3,4'); + expect(i18n.t('key', {count: 104})).to.be('2,3,4'); + expect(i18n.t('key', {count: 11})).to.be('0,5,6'); + expect(i18n.t('key', {count: 24})).to.be('2,3,4'); + expect(i18n.t('key', {count: 25})).to.be('0,5,6'); + expect(i18n.t('key', {count: 99})).to.be('0,5,6'); + expect(i18n.t('key', {count: 199})).to.be('0,5,6'); + expect(i18n.t('key', {count: 100})).to.be('0,5,6'); + }); + }); + + describe('extended usage - ask for a key in a language with a different plural form', function() { + var resStore = { + en: { translation: { + key:'singular_en', + key_plural:'plural_en' + } + }, + zh: { translation: { + key: 'singular_zh' + } + } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { lng: 'zh', resStore: resStore }), + function(t) { done(); }); + }); + + it('it should provide translation for passed in language with 1 item', function() { + expect(i18n.t('key', { lng: 'en', count:1 })).to.be('singular_en'); + }); + + it('it should provide translation for passed in language with 2 items', function() { + expect(i18n.t('key', { lng: 'en', count:2 })).to.be('plural_en'); + }); + }); + +}); \ No newline at end of file diff --git a/libs/i18next/spec/translate/translate.setlng.spec.js b/libs/i18next/spec/translate/translate.setlng.spec.js new file mode 100644 index 00000000..37b1089c --- /dev/null +++ b/libs/i18next/spec/translate/translate.setlng.spec.js @@ -0,0 +1,22 @@ +describe('with passed in languages different from set one', function() { + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { + preload: ['de-DE'] }), + function(t) { done(); }); + }); + + it('it should provide translation for passed in language', function() { + expect(i18n.t('simple_de', { lng: 'de-DE' })).to.be('ok_from_de'); + }); + + describe('with language not preloaded', function() { + + it('it should provide translation for passed in language after loading file sync', function() { + var expectedValue = i18n.clientVersion ? 'simple_fr' : 'ok_from_fr'; + expect(i18n.t('simple_fr', { lng: 'fr' })).to.be(expectedValue); + }); + + }); + +}); \ No newline at end of file diff --git a/libs/i18next/spec/translate/translate.sprintf.spec.js b/libs/i18next/spec/translate/translate.sprintf.spec.js new file mode 100644 index 00000000..844e8464 --- /dev/null +++ b/libs/i18next/spec/translate/translate.sprintf.spec.js @@ -0,0 +1,30 @@ +describe('using sprintf', function() { + + var resStore = { + dev: { translation: { } }, + en: { translation: { } }, + 'en-US': { + translation: { + interpolationTest1: 'The first 4 letters of the english alphabet are: %s, %s, %s and %s', + interpolationTest2: 'Hello %(users[0].name)s, %(users[1].name)s and %(users[2].name)s', + interpolationTest3: 'The last letter of the english alphabet is %s' + } + } + }; + + beforeEach(function(done) { + i18n.init(i18n.functions.extend(opts, { resStore: resStore }), + function(t) { done(); }); + }); + + it('it should replace passed in key/values', function() { + expect(i18n.t('interpolationTest1', {postProcess: 'sprintf', sprintf: ['a', 'b', 'c', 'd']})).to.be('The first 4 letters of the english alphabet are: a, b, c and d'); + expect(i18n.t('interpolationTest2', {postProcess: 'sprintf', sprintf: { users: [{name: 'Dolly'}, {name: 'Molly'}, {name: 'Polly'}] } })).to.be('Hello Dolly, Molly and Polly'); + }); + + it('it should recognize the sprintf syntax and automatically add the sprintf processor', function() { + expect(i18n.t('interpolationTest1', 'a', 'b', 'c', 'd')).to.be('The first 4 letters of the english alphabet are: a, b, c and d'); + expect(i18n.t('interpolationTest3', 'z')).to.be('The last letter of the english alphabet is z'); + }); + +}); \ No newline at end of file diff --git a/libs/i18next/src/amd.jquery.js b/libs/i18next/src/amd.jquery.js new file mode 100644 index 00000000..2250a5a8 --- /dev/null +++ b/libs/i18next/src/amd.jquery.js @@ -0,0 +1,43 @@ +(function (root, factory) { + if (typeof exports === 'object') { + + var jquery = require('jquery'); + + module.exports = factory(jquery); + + } else if (typeof define === 'function' && define.amd) { + + define(['jquery'], factory); + + } +}(this, function ($) { + + //= i18next.shim.js + + var i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = [] + , initialized = false + , sync = {}; + + //= i18next.sync.js + //= i18next.defaults.js + //= i18next.helpers.js + //= i18next.init.js + //= i18next.functions.js + //= i18next.jquery.js + //= i18next.translate.js + //= i18next.detectLanguage.js + //= i18next.plurals.js + //= i18next.postProcessor.js + //= i18next.postProcessor.sprintf.js + //= i18next.api.js + + $.i18n = i18n; + $.t = i18n.t; + + return i18n; + +})); \ No newline at end of file diff --git a/libs/i18next/src/amd.js b/libs/i18next/src/amd.js new file mode 100644 index 00000000..d1827e18 --- /dev/null +++ b/libs/i18next/src/amd.js @@ -0,0 +1,39 @@ +(function (root, factory) { + if (typeof exports === 'object') { + + module.exports = factory(); + + } else if (typeof define === 'function' && define.amd) { + + define([], factory); + + } +}(this, function () { + + //= i18next.shim.js + + var $ = undefined + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = [] + , initialized = false + , sync = {}; + + //= i18next.sync.js + //= i18next.defaults.js + //= i18next.helpers.js + //= i18next.init.js + //= i18next.functions.js + //= i18next.jquery.js + //= i18next.translate.js + //= i18next.detectLanguage.js + //= i18next.plurals.js + //= i18next.postProcessor.js + //= i18next.postProcessor.sprintf.js + //= i18next.api.js + + return i18n; + +})); \ No newline at end of file diff --git a/libs/i18next/src/commonjs.jquery.js b/libs/i18next/src/commonjs.jquery.js new file mode 100644 index 00000000..ddcab15e --- /dev/null +++ b/libs/i18next/src/commonjs.jquery.js @@ -0,0 +1,30 @@ +(function(root) { + + //= i18next.shim.js + + var $ = root.jQuery || root.Zepto + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = [] + , initialized = false + , sync = {}; + + + + //= i18next.exports.jquery.js + //= i18next.sync.js + //= i18next.defaults.js + //= i18next.helpers.js + //= i18next.init.js + //= i18next.functions.js + //= i18next.jquery.js + //= i18next.translate.js + //= i18next.detectLanguage.js + //= i18next.plurals.js + //= i18next.postProcessor.js + //= i18next.postProcessor.sprintf.js + //= i18next.api.js + +})(typeof exports === 'undefined' ? window : exports); \ No newline at end of file diff --git a/libs/i18next/src/i18next.api.js b/libs/i18next/src/i18next.api.js new file mode 100644 index 00000000..497d14f3 --- /dev/null +++ b/libs/i18next/src/i18next.api.js @@ -0,0 +1,24 @@ +// public api interface +i18n.init = init; +i18n.setLng = setLng; +i18n.preload = preload; +i18n.addResourceBundle = addResourceBundle; +i18n.hasResourceBundle = hasResourceBundle; +i18n.getResourceBundle = getResourceBundle; +i18n.addResource = addResource; +i18n.addResources = addResources; +i18n.removeResourceBundle = removeResourceBundle; +i18n.loadNamespace = loadNamespace; +i18n.loadNamespaces = loadNamespaces; +i18n.setDefaultNamespace = setDefaultNamespace; +i18n.t = translate; +i18n.translate = translate; +i18n.exists = exists; +i18n.detectLanguage = f.detectLanguage; +i18n.pluralExtensions = pluralExtensions; +i18n.sync = sync; +i18n.functions = f; +i18n.lng = lng; +i18n.addPostProcessor = addPostProcessor; +i18n.applyReplacement = f.applyReplacement; +i18n.options = o; diff --git a/libs/i18next/src/i18next.defaults.js b/libs/i18next/src/i18next.defaults.js new file mode 100644 index 00000000..b8ce93b7 --- /dev/null +++ b/libs/i18next/src/i18next.defaults.js @@ -0,0 +1,65 @@ +// defaults +var o = { + lng: undefined, + load: 'all', + preload: [], + lowerCaseLng: false, + returnObjectTrees: false, + fallbackLng: ['dev'], + fallbackNS: [], + detectLngQS: 'setLng', + detectLngFromLocalStorage: false, + ns: { + namespaces: ['translation'], + defaultNs: 'translation' + }, + fallbackOnNull: true, + fallbackOnEmpty: false, + fallbackToDefaultNS: false, + nsseparator: ':', + keyseparator: '.', + selectorAttr: 'data-i18n', + debug: false, + + resGetPath: 'locales/__lng__/__ns__.json', + resPostPath: 'locales/add/__lng__/__ns__', + + getAsync: true, + postAsync: true, + + resStore: undefined, + useLocalStorage: false, + localStorageExpirationTime: 7*24*60*60*1000, + + dynamicLoad: false, + sendMissing: false, + sendMissingTo: 'fallback', // current | all + sendType: 'POST', + + interpolationPrefix: '__', + interpolationSuffix: '__', + defaultVariables: false, + reusePrefix: '$t(', + reuseSuffix: ')', + pluralSuffix: '_plural', + pluralNotFound: ['plural_not_found', Math.random()].join(''), + contextNotFound: ['context_not_found', Math.random()].join(''), + escapeInterpolation: false, + indefiniteSuffix: '_indefinite', + indefiniteNotFound: ['indefinite_not_found', Math.random()].join(''), + + setJqueryExt: true, + defaultValueFromContent: true, + useDataAttrOptions: false, + cookieExpirationTime: undefined, + useCookie: true, + cookieName: 'i18next', + cookieDomain: undefined, + + objectTreeKeyHandler: undefined, + postProcess: undefined, + parseMissingKey: undefined, + missingKeyHandler: sync.postMissing, + + shortcutFunction: 'sprintf' // or: defaultValue +}; diff --git a/libs/i18next/src/i18next.detectLanguage.js b/libs/i18next/src/i18next.detectLanguage.js new file mode 100644 index 00000000..b08b1b76 --- /dev/null +++ b/libs/i18next/src/i18next.detectLanguage.js @@ -0,0 +1,74 @@ +function detectLanguage() { + var detectedLng; + var whitelist = o.lngWhitelist || []; + var userLngChoices = []; + + // get from qs + var qsParm = []; + if (typeof window !== 'undefined') { + (function() { + var query = window.location.search.substring(1); + var params = query.split('&'); + for (var i=0; i 0) { + var key = params[i].substring(0,pos); + if (key == o.detectLngQS) { + userLngChoices.push(params[i].substring(pos+1)); + } + } + } + })(); + } + + // get from cookie + if (o.useCookie && typeof document !== 'undefined') { + var c = f.cookie.read(o.cookieName); + if (c) userLngChoices.push(c); + } + + // get from localStorage + if (o.detectLngFromLocalStorage && typeof window !== 'undefined' && window.localStorage) { + userLngChoices.push(f.localStorage.getItem('i18next_lng')); + } + + // get from navigator + if (typeof navigator !== 'undefined') { + if (navigator.languages) { // chrome only; not an array, so can't use .push.apply instead of iterating + for (var i=0;i -1) { + var parts = lng.split('-'); + lng = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } + + if (whitelist.length === 0 || whitelist.indexOf(lng) > -1) { + detectedLng = lng; + break; + } + } + })(); + + //fallback + if (!detectedLng){ + detectedLng = o.fallbackLng[0]; + } + + return detectedLng; +} diff --git a/libs/i18next/src/i18next.exports.jquery.js b/libs/i18next/src/i18next.exports.jquery.js new file mode 100644 index 00000000..190bb204 --- /dev/null +++ b/libs/i18next/src/i18next.exports.jquery.js @@ -0,0 +1,20 @@ +// Export the i18next object for **CommonJS**. +// If we're not in CommonJS, add `i18n` to the +// global object or to jquery. +if (typeof module !== 'undefined' && module.exports) { + module.exports = i18n; + if (!$) { + try { + $ = require('jquery'); + } catch(e) { + // just ignore + } + } + +} else { + root.i18n = root.i18n || i18n; +} + +if ($) { + $.i18n = $.i18n || i18n; +} diff --git a/libs/i18next/src/i18next.exports.js b/libs/i18next/src/i18next.exports.js new file mode 100644 index 00000000..66c2594a --- /dev/null +++ b/libs/i18next/src/i18next.exports.js @@ -0,0 +1,12 @@ +// Export the i18next object for **CommonJS**. +// If we're not in CommonJS, add `i18n` to the +// global object or to jquery. +if (typeof module !== 'undefined' && module.exports) { + module.exports = i18n; +} else { + if ($) { + $.i18n = $.i18n || i18n; + } + + root.i18n = root.i18n || i18n; +} \ No newline at end of file diff --git a/libs/i18next/src/i18next.functions.js b/libs/i18next/src/i18next.functions.js new file mode 100644 index 00000000..4cfdaa05 --- /dev/null +++ b/libs/i18next/src/i18next.functions.js @@ -0,0 +1,209 @@ +function preload(lngs, cb) { + if (typeof lngs === 'string') lngs = [lngs]; + for (var i = 0, l = lngs.length; i < l; i++) { + if (o.preload.indexOf(lngs[i]) < 0) { + o.preload.push(lngs[i]); + } + } + return init(cb); +} + +function addResourceBundle(lng, ns, resources, deep) { + if (typeof ns !== 'string') { + resources = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + if (deep) { + f.deepExtend(resStore[lng][ns], resources); + } else { + f.extend(resStore[lng][ns], resources); + } + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } +} + +function hasResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + var res = resStore[lng][ns] || {}; + + var hasValues = false; + for(var prop in res) { + if (res.hasOwnProperty(prop)) { + hasValues = true; + } + } + + return hasValues; +} + +function getResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + return f.extend({}, resStore[lng][ns]); +} + +function removeResourceBundle(lng, ns) { + if (typeof ns !== 'string') { + ns = o.ns.defaultNs; + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = {}; + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } +} + +function addResource(lng, ns, key, value) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + resStore[lng] = resStore[lng] || {}; + resStore[lng][ns] = resStore[lng][ns] || {}; + + var keys = key.split(o.keyseparator); + var x = 0; + var node = resStore[lng][ns]; + var origRef = node; + + while (keys[x]) { + if (x == keys.length - 1) + node[keys[x]] = value; + else { + if (node[keys[x]] == null) + node[keys[x]] = {}; + + node = node[keys[x]]; + } + x++; + } + if (o.useLocalStorage) { + sync._storeLocal(resStore); + } +} + +function addResources(lng, ns, resources) { + if (typeof ns !== 'string') { + resource = ns; + ns = o.ns.defaultNs; + } else if (o.ns.namespaces.indexOf(ns) < 0) { + o.ns.namespaces.push(ns); + } + + for (var m in resources) { + if (typeof resources[m] === 'string') addResource(lng, ns, m, resources[m]); + } +} + +function setDefaultNamespace(ns) { + o.ns.defaultNs = ns; +} + +function loadNamespace(namespace, cb) { + loadNamespaces([namespace], cb); +} + +function loadNamespaces(namespaces, cb) { + var opts = { + dynamicLoad: o.dynamicLoad, + resGetPath: o.resGetPath, + getAsync: o.getAsync, + customLoad: o.customLoad, + ns: { namespaces: namespaces, defaultNs: ''} /* new namespaces to load */ + }; + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // check if we have to load + var lngNeedLoad = []; + for (var a = 0, lenA = lngsToLoad.length; a < lenA; a++) { + var needLoad = false; + var resSet = resStore[lngsToLoad[a]]; + if (resSet) { + for (var b = 0, lenB = namespaces.length; b < lenB; b++) { + if (!resSet[namespaces[b]]) needLoad = true; + } + } else { + needLoad = true; + } + + if (needLoad) lngNeedLoad.push(lngsToLoad[a]); + } + + if (lngNeedLoad.length) { + i18n.sync._fetch(lngNeedLoad, opts, function(err, store) { + var todo = namespaces.length * lngNeedLoad.length; + + // load each file individual + f.each(namespaces, function(nsIndex, nsValue) { + + // append namespace to namespace array + if (o.ns.namespaces.indexOf(nsValue) < 0) { + o.ns.namespaces.push(nsValue); + } + + f.each(lngNeedLoad, function(lngIndex, lngValue) { + resStore[lngValue] = resStore[lngValue] || {}; + resStore[lngValue][nsValue] = store[lngValue][nsValue]; + + todo--; // wait for all done befor callback + if (todo === 0 && cb) { + if (o.useLocalStorage) i18n.sync._storeLocal(resStore); + cb(); + } + }); + }); + }); + } else { + if (cb) cb(); + } +} + +function setLng(lng, options, cb) { + if (typeof options === 'function') { + cb = options; + options = {}; + } else if (!options) { + options = {}; + } + + options.lng = lng; + return init(options, cb); +} + +function lng() { + return currentLng; +} + +function reload(cb) { + resStore = {}; + setLng(currentLng, cb); +} diff --git a/libs/i18next/src/i18next.helpers.js b/libs/i18next/src/i18next.helpers.js new file mode 100644 index 00000000..bb06c4b2 --- /dev/null +++ b/libs/i18next/src/i18next.helpers.js @@ -0,0 +1,505 @@ +function _extend(target, source) { + if (!source || typeof source === 'function') { + return target; + } + + for (var attr in source) { target[attr] = source[attr]; } + return target; +} + +function _deepExtend(target, source) { + for (var prop in source) + if (prop in target) + _deepExtend(target[prop], source[prop]); + else + target[prop] = source[prop]; + return target; +} + +function _each(object, callback, args) { + var name, i = 0, + length = object.length, + isObj = length === undefined || Object.prototype.toString.apply(object) !== '[object Array]' || typeof object === "function"; + + if (args) { + if (isObj) { + for (name in object) { + if (callback.apply(object[name], args) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.apply(object[i++], args) === false) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if (isObj) { + for (name in object) { + if (callback.call(object[name], name, object[name]) === false) { + break; + } + } + } else { + for ( ; i < length; ) { + if (callback.call(object[i], i, object[i++]) === false) { + break; + } + } + } + } + + return object; +} + +var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' +}; + +function _escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + }else{ + return data; + } +} + +function _ajax(options) { + + // v0.5.0 of https://github.com/goloroden/http.js + var getXhr = function (callback) { + // Use the native XHR object if the browser supports it. + if (window.XMLHttpRequest) { + return callback(null, new XMLHttpRequest()); + } else if (window.ActiveXObject) { + // In Internet Explorer check for ActiveX versions of the XHR object. + try { + return callback(null, new ActiveXObject("Msxml2.XMLHTTP")); + } catch (e) { + return callback(null, new ActiveXObject("Microsoft.XMLHTTP")); + } + } + + // If no XHR support was found, throw an error. + return callback(new Error()); + }; + + var encodeUsingUrlEncoding = function (data) { + if(typeof data === 'string') { + return data; + } + + var result = []; + for(var dataItem in data) { + if(data.hasOwnProperty(dataItem)) { + result.push(encodeURIComponent(dataItem) + '=' + encodeURIComponent(data[dataItem])); + } + } + + return result.join('&'); + }; + + var utf8 = function (text) { + text = text.replace(/\r\n/g, '\n'); + var result = ''; + + for(var i = 0; i < text.length; i++) { + var c = text.charCodeAt(i); + + if(c < 128) { + result += String.fromCharCode(c); + } else if((c > 127) && (c < 2048)) { + result += String.fromCharCode((c >> 6) | 192); + result += String.fromCharCode((c & 63) | 128); + } else { + result += String.fromCharCode((c >> 12) | 224); + result += String.fromCharCode(((c >> 6) & 63) | 128); + result += String.fromCharCode((c & 63) | 128); + } + } + + return result; + }; + + var base64 = function (text) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + text = utf8(text); + var result = '', + chr1, chr2, chr3, + enc1, enc2, enc3, enc4, + i = 0; + + do { + chr1 = text.charCodeAt(i++); + chr2 = text.charCodeAt(i++); + chr3 = text.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if(isNaN(chr2)) { + enc3 = enc4 = 64; + } else if(isNaN(chr3)) { + enc4 = 64; + } + + result += + keyStr.charAt(enc1) + + keyStr.charAt(enc2) + + keyStr.charAt(enc3) + + keyStr.charAt(enc4); + chr1 = chr2 = chr3 = ''; + enc1 = enc2 = enc3 = enc4 = ''; + } while(i < text.length); + + return result; + }; + + var mergeHeaders = function () { + // Use the first header object as base. + var result = arguments[0]; + + // Iterate through the remaining header objects and add them. + for(var i = 1; i < arguments.length; i++) { + var currentHeaders = arguments[i]; + for(var header in currentHeaders) { + if(currentHeaders.hasOwnProperty(header)) { + result[header] = currentHeaders[header]; + } + } + } + + // Return the merged headers. + return result; + }; + + var ajax = function (method, url, options, callback) { + // Adjust parameters. + if(typeof options === 'function') { + callback = options; + options = {}; + } + + // Set default parameter values. + options.cache = options.cache || false; + options.data = options.data || {}; + options.headers = options.headers || {}; + options.jsonp = options.jsonp || false; + options.async = options.async === undefined ? true : options.async; + + // Merge the various header objects. + var headers = mergeHeaders({ + 'accept': '*/*', + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' + }, ajax.headers, options.headers); + + // Encode the data according to the content-type. + var payload; + if (headers['content-type'] === 'application/json') { + payload = JSON.stringify(options.data); + } else { + payload = encodeUsingUrlEncoding(options.data); + } + + // Specially prepare GET requests: Setup the query string, handle caching and make a JSONP call + // if neccessary. + if(method === 'GET') { + // Setup the query string. + var queryString = []; + if(payload) { + queryString.push(payload); + payload = null; + } + + // Handle caching. + if(!options.cache) { + queryString.push('_=' + (new Date()).getTime()); + } + + // If neccessary prepare the query string for a JSONP call. + if(options.jsonp) { + queryString.push('callback=' + options.jsonp); + queryString.push('jsonp=' + options.jsonp); + } + + // Merge the query string and attach it to the url. + queryString = queryString.join('&'); + if (queryString.length > 1) { + if (url.indexOf('?') > -1) { + url += '&' + queryString; + } else { + url += '?' + queryString; + } + } + + // Make a JSONP call if neccessary. + if(options.jsonp) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + head.appendChild(script); + return; + } + } + + // Since we got here, it is no JSONP request, so make a normal XHR request. + getXhr(function (err, xhr) { + if(err) return callback(err); + + // Open the request. + xhr.open(method, url, options.async); + + // Set the request headers. + for(var header in headers) { + if(headers.hasOwnProperty(header)) { + xhr.setRequestHeader(header, headers[header]); + } + } + + // Handle the request events. + xhr.onreadystatechange = function () { + if(xhr.readyState === 4) { + var data = xhr.responseText || ''; + + // If no callback is given, return. + if(!callback) { + return; + } + + // Return an object that provides access to the data as text and JSON. + callback(xhr.status, { + text: function () { + return data; + }, + + json: function () { + try { + return JSON.parse(data) + } catch (e) { + f.error('Can not parse JSON. URL: ' + url); + return {}; + } + } + }); + } + }; + + // Actually send the XHR request. + xhr.send(payload); + }); + }; + + // Define the external interface. + var http = { + authBasic: function (username, password) { + ajax.headers['Authorization'] = 'Basic ' + base64(username + ':' + password); + }, + + connect: function (url, options, callback) { + return ajax('CONNECT', url, options, callback); + }, + + del: function (url, options, callback) { + return ajax('DELETE', url, options, callback); + }, + + get: function (url, options, callback) { + return ajax('GET', url, options, callback); + }, + + head: function (url, options, callback) { + return ajax('HEAD', url, options, callback); + }, + + headers: function (headers) { + ajax.headers = headers || {}; + }, + + isAllowed: function (url, verb, callback) { + this.options(url, function (status, data) { + callback(data.text().indexOf(verb) !== -1); + }); + }, + + options: function (url, options, callback) { + return ajax('OPTIONS', url, options, callback); + }, + + patch: function (url, options, callback) { + return ajax('PATCH', url, options, callback); + }, + + post: function (url, options, callback) { + return ajax('POST', url, options, callback); + }, + + put: function (url, options, callback) { + return ajax('PUT', url, options, callback); + }, + + trace: function (url, options, callback) { + return ajax('TRACE', url, options, callback); + } + }; + + + var methode = options.type ? options.type.toLowerCase() : 'get'; + + http[methode](options.url, options, function (status, data) { + // file: protocol always gives status code 0, so check for data + if (status === 200 || (status === 0 && data.text())) { + options.success(data.json(), status, null); + } else { + options.error(data.text(), status, null); + } + }); +} + +var _cookie = { + create: function(name,value,minutes,domain) { + var expires; + if (minutes) { + var date = new Date(); + date.setTime(date.getTime()+(minutes*60*1000)); + expires = "; expires="+date.toGMTString(); + } + else expires = ""; + domain = (domain)? "domain="+domain+";" : ""; + document.cookie = name+"="+value+expires+";"+domain+"path=/"; + }, + + read: function(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length,c.length); + } + return null; + }, + + remove: function(name) { + this.create(name,"",-1); + } +}; + +var cookie_noop = { + create: function(name,value,minutes,domain) {}, + read: function(name) { return null; }, + remove: function(name) {} +}; + + + +// move dependent functions to a container so that +// they can be overriden easier in no jquery environment (node.js) +var f = { + extend: $ ? $.extend : _extend, + deepExtend: _deepExtend, + each: $ ? $.each : _each, + ajax: $ ? $.ajax : (typeof document !== 'undefined' ? _ajax : function() {}), + cookie: typeof document !== 'undefined' ? _cookie : cookie_noop, + detectLanguage: detectLanguage, + escape: _escape, + log: function(str) { + if (o.debug && typeof console !== "undefined") console.log(str); + }, + error: function(str) { + if (typeof console !== "undefined") console.error(str); + }, + getCountyIndexOfLng: function(lng) { + var lng_index = 0; + if (lng === 'nb-NO' || lng === 'nn-NO' || lng === 'nb-no' || lng === 'nn-no') lng_index = 1; + return lng_index; + }, + toLanguages: function(lng) { + var log = this.log; + + function applyCase(l) { + var ret = l; + + if (typeof l === 'string' && l.indexOf('-') > -1) { + var parts = l.split('-'); + + ret = o.lowerCaseLng ? + parts[0].toLowerCase() + '-' + parts[1].toLowerCase() : + parts[0].toLowerCase() + '-' + parts[1].toUpperCase(); + } else { + ret = o.lowerCaseLng ? l.toLowerCase() : l; + } + + return ret; + } + + var languages = []; + var whitelist = o.lngWhitelist || false; + var addLanguage = function(language){ + //reject langs not whitelisted + if(!whitelist || whitelist.indexOf(language) > -1){ + languages.push(language); + }else{ + log('rejecting non-whitelisted language: ' + language); + } + }; + if (typeof lng === 'string' && lng.indexOf('-') > -1) { + var parts = lng.split('-'); + + if (o.load !== 'unspecific') addLanguage(applyCase(lng)); + if (o.load !== 'current') addLanguage(applyCase(parts[this.getCountyIndexOfLng(lng)])); + } else { + addLanguage(applyCase(lng)); + } + + for (var i = 0; i < o.fallbackLng.length; i++) { + if (languages.indexOf(o.fallbackLng[i]) === -1 && o.fallbackLng[i]) languages.push(applyCase(o.fallbackLng[i])); + } + return languages; + }, + regexEscape: function(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + }, + regexReplacementEscape: function(strOrFn) { + if (typeof strOrFn === 'string') { + return strOrFn.replace(/\$/g, "$$$$"); + } else { + return strOrFn; + } + }, + localStorage: { + setItem: function(key, value) { + if (window.localStorage) { + try { + window.localStorage.setItem(key, value); + } catch (e) { + f.log('failed to set value for key "' + key + '" to localStorage.'); + } + } + }, + getItem: function(key, value) { + if (window.localStorage) { + try { + return window.localStorage.getItem(key, value); + } catch (e) { + f.log('failed to get value for key "' + key + '" from localStorage.'); + return undefined; + } + } + } + } +}; diff --git a/libs/i18next/src/i18next.init.js b/libs/i18next/src/i18next.init.js new file mode 100644 index 00000000..3968fa21 --- /dev/null +++ b/libs/i18next/src/i18next.init.js @@ -0,0 +1,104 @@ +function init(options, cb) { + + if (typeof options === 'function') { + cb = options; + options = {}; + } + options = options || {}; + + // override defaults with passed in options + f.extend(o, options); + delete o.fixLng; /* passed in each time */ + + // override functions: .log(), .detectLanguage(), etc + if (o.functions) { + delete o.functions; + f.extend(f, options.functions); + } + + // create namespace object if namespace is passed in as string + if (typeof o.ns == 'string') { + o.ns = { namespaces: [o.ns], defaultNs: o.ns}; + } + + // fallback namespaces + if (typeof o.fallbackNS == 'string') { + o.fallbackNS = [o.fallbackNS]; + } + + // fallback languages + if (typeof o.fallbackLng == 'string' || typeof o.fallbackLng == 'boolean') { + o.fallbackLng = [o.fallbackLng]; + } + + // escape prefix/suffix + o.interpolationPrefixEscaped = f.regexEscape(o.interpolationPrefix); + o.interpolationSuffixEscaped = f.regexEscape(o.interpolationSuffix); + + if (!o.lng) o.lng = f.detectLanguage(); + + languages = f.toLanguages(o.lng); + currentLng = languages[0]; + f.log('currentLng set to: ' + currentLng); + + if (o.useCookie && f.cookie.read(o.cookieName) !== currentLng){ //cookie is unset or invalid + f.cookie.create(o.cookieName, currentLng, o.cookieExpirationTime, o.cookieDomain); + } + if (o.detectLngFromLocalStorage && typeof document !== 'undefined' && window.localStorage) { + f.localStorage.setItem('i18next_lng', currentLng); + } + + var lngTranslate = translate; + if (options.fixLng) { + lngTranslate = function(key, options) { + options = options || {}; + options.lng = options.lng || lngTranslate.lng; + return translate(key, options); + }; + lngTranslate.lng = currentLng; + } + + pluralExtensions.setCurrentLng(currentLng); + + // add JQuery extensions + if ($ && o.setJqueryExt) addJqueryFunct(); + + // jQuery deferred + var deferred; + if ($ && $.Deferred) { + deferred = $.Deferred(); + } + + // return immidiatly if res are passed in + if (o.resStore) { + resStore = o.resStore; + initialized = true; + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + if (deferred) return deferred.promise(); + return; + } + + // languages to load + var lngsToLoad = f.toLanguages(o.lng); + if (typeof o.preload === 'string') o.preload = [o.preload]; + for (var i = 0, l = o.preload.length; i < l; i++) { + var pres = f.toLanguages(o.preload[i]); + for (var y = 0, len = pres.length; y < len; y++) { + if (lngsToLoad.indexOf(pres[y]) < 0) { + lngsToLoad.push(pres[y]); + } + } + } + + // else load them + i18n.sync.load(lngsToLoad, o, function(err, store) { + resStore = store; + initialized = true; + + if (cb) cb(lngTranslate); + if (deferred) deferred.resolve(lngTranslate); + }); + + if (deferred) return deferred.promise(); +} diff --git a/libs/i18next/src/i18next.jquery.js b/libs/i18next/src/i18next.jquery.js new file mode 100644 index 00000000..26bf668e --- /dev/null +++ b/libs/i18next/src/i18next.jquery.js @@ -0,0 +1,90 @@ +function addJqueryFunct() { + // $.t shortcut + $.t = $.t || translate; + + function parse(ele, key, options) { + if (key.length === 0) return; + + var attr = 'text'; + + if (key.indexOf('[') === 0) { + var parts = key.split(']'); + key = parts[1]; + attr = parts[0].substr(1, parts[0].length-1); + } + + if (key.indexOf(';') === key.length-1) { + key = key.substr(0, key.length-2); + } + + var optionsToUse; + if (attr === 'html') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.html($.t(key, optionsToUse)); + } else if (attr === 'text') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.text() }, options) : options; + ele.text($.t(key, optionsToUse)); + } else if (attr === 'prepend') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.prepend($.t(key, optionsToUse)); + } else if (attr === 'append') { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.html() }, options) : options; + ele.append($.t(key, optionsToUse)); + } else if (attr.indexOf("data-") === 0) { + var dataAttr = attr.substr(("data-").length); + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.data(dataAttr) }, options) : options; + var translated = $.t(key, optionsToUse); + //we change into the data cache + ele.data(dataAttr, translated); + //we change into the dom + ele.attr(attr, translated); + } else { + optionsToUse = o.defaultValueFromContent ? $.extend({ defaultValue: ele.attr(attr) }, options) : options; + ele.attr(attr, $.t(key, optionsToUse)); + } + } + + function localize(ele, options) { + var key = ele.attr(o.selectorAttr); + if (!key && typeof key !== 'undefined' && key !== false) key = ele.text() || ele.val(); + if (!key) return; + + var target = ele + , targetSelector = ele.data("i18n-target"); + if (targetSelector) { + target = ele.find(targetSelector) || ele; + } + + if (!options && o.useDataAttrOptions === true) { + options = ele.data("i18n-options"); + } + options = options || {}; + + if (key.indexOf(';') >= 0) { + var keys = key.split(';'); + + $.each(keys, function(m, k) { + if (k !== '') parse(target, k, options); + }); + + } else { + parse(target, key, options); + } + + if (o.useDataAttrOptions === true) ele.data("i18n-options", options); + } + + // fn + $.fn.i18n = function (options) { + return this.each(function() { + // localize element itself + localize($(this), options); + + // localize childs + var elements = $(this).find('[' + o.selectorAttr + ']'); + elements.each(function() { + localize($(this), options); + }); + }); + }; +} diff --git a/libs/i18next/src/i18next.js b/libs/i18next/src/i18next.js new file mode 100644 index 00000000..3706f69d --- /dev/null +++ b/libs/i18next/src/i18next.js @@ -0,0 +1,30 @@ +(function(root) { + + //= i18next.shim.js + + var $ = root.jQuery || root.Zepto + , i18n = {} + , resStore = {} + , currentLng + , replacementCounter = 0 + , languages = [] + , initialized = false + , sync = {}; + + + + //= i18next.exports.js + //= i18next.sync.js + //= i18next.defaults.js + //= i18next.helpers.js + //= i18next.init.js + //= i18next.functions.js + //= i18next.jquery.js + //= i18next.translate.js + //= i18next.detectLanguage.js + //= i18next.plurals.js + //= i18next.postProcessor.js + //= i18next.postProcessor.sprintf.js + //= i18next.api.js + +})(typeof exports === 'undefined' ? window : exports); \ No newline at end of file diff --git a/libs/i18next/src/i18next.plurals.js b/libs/i18next/src/i18next.plurals.js new file mode 100644 index 00000000..00dcfed4 --- /dev/null +++ b/libs/i18next/src/i18next.plurals.js @@ -0,0 +1,244 @@ +// definition http://translate.sourceforge.net/wiki/l10n/pluralforms + +/* [code, name, numbers, pluralsType] */ +var _rules = [ + ["ach", "Acholi", [1,2], 1], + ["af", "Afrikaans",[1,2], 2], + ["ak", "Akan", [1,2], 1], + ["am", "Amharic", [1,2], 1], + ["an", "Aragonese",[1,2], 2], + ["ar", "Arabic", [0,1,2,3,11,100],5], + ["arn", "Mapudungun",[1,2], 1], + ["ast", "Asturian", [1,2], 2], + ["ay", "Aymará", [1], 3], + ["az", "Azerbaijani",[1,2],2], + ["be", "Belarusian",[1,2,5],4], + ["bg", "Bulgarian",[1,2], 2], + ["bn", "Bengali", [1,2], 2], + ["bo", "Tibetan", [1], 3], + ["br", "Breton", [1,2], 1], + ["bs", "Bosnian", [1,2,5],4], + ["ca", "Catalan", [1,2], 2], + ["cgg", "Chiga", [1], 3], + ["cs", "Czech", [1,2,5],6], + ["csb", "Kashubian",[1,2,5],7], + ["cy", "Welsh", [1,2,3,8],8], + ["da", "Danish", [1,2], 2], + ["de", "German", [1,2], 2], + ["dev", "Development Fallback", [1,2], 2], + ["dz", "Dzongkha", [1], 3], + ["el", "Greek", [1,2], 2], + ["en", "English", [1,2], 2], + ["eo", "Esperanto",[1,2], 2], + ["es", "Spanish", [1,2], 2], + ["es_ar","Argentinean Spanish", [1,2], 2], + ["et", "Estonian", [1,2], 2], + ["eu", "Basque", [1,2], 2], + ["fa", "Persian", [1], 3], + ["fi", "Finnish", [1,2], 2], + ["fil", "Filipino", [1,2], 1], + ["fo", "Faroese", [1,2], 2], + ["fr", "French", [1,2], 9], + ["fur", "Friulian", [1,2], 2], + ["fy", "Frisian", [1,2], 2], + ["ga", "Irish", [1,2,3,7,11],10], + ["gd", "Scottish Gaelic",[1,2,3,20],11], + ["gl", "Galician", [1,2], 2], + ["gu", "Gujarati", [1,2], 2], + ["gun", "Gun", [1,2], 1], + ["ha", "Hausa", [1,2], 2], + ["he", "Hebrew", [1,2], 2], + ["hi", "Hindi", [1,2], 2], + ["hr", "Croatian", [1,2,5],4], + ["hu", "Hungarian",[1,2], 2], + ["hy", "Armenian", [1,2], 2], + ["ia", "Interlingua",[1,2],2], + ["id", "Indonesian",[1], 3], + ["is", "Icelandic",[1,2], 12], + ["it", "Italian", [1,2], 2], + ["ja", "Japanese", [1], 3], + ["jbo", "Lojban", [1], 3], + ["jv", "Javanese", [0,1], 13], + ["ka", "Georgian", [1], 3], + ["kk", "Kazakh", [1], 3], + ["km", "Khmer", [1], 3], + ["kn", "Kannada", [1,2], 2], + ["ko", "Korean", [1], 3], + ["ku", "Kurdish", [1,2], 2], + ["kw", "Cornish", [1,2,3,4],14], + ["ky", "Kyrgyz", [1], 3], + ["lb", "Letzeburgesch",[1,2],2], + ["ln", "Lingala", [1,2], 1], + ["lo", "Lao", [1], 3], + ["lt", "Lithuanian",[1,2,10],15], + ["lv", "Latvian", [1,2,0],16], + ["mai", "Maithili", [1,2], 2], + ["mfe", "Mauritian Creole",[1,2],1], + ["mg", "Malagasy", [1,2], 1], + ["mi", "Maori", [1,2], 1], + ["mk", "Macedonian",[1,2],17], + ["ml", "Malayalam",[1,2], 2], + ["mn", "Mongolian",[1,2], 2], + ["mnk", "Mandinka", [0,1,2],18], + ["mr", "Marathi", [1,2], 2], + ["ms", "Malay", [1], 3], + ["mt", "Maltese", [1,2,11,20],19], + ["nah", "Nahuatl", [1,2], 2], + ["nap", "Neapolitan",[1,2], 2], + ["nb", "Norwegian Bokmal",[1,2],2], + ["ne", "Nepali", [1,2], 2], + ["nl", "Dutch", [1,2], 2], + ["nn", "Norwegian Nynorsk",[1,2],2], + ["no", "Norwegian",[1,2], 2], + ["nso", "Northern Sotho",[1,2],2], + ["oc", "Occitan", [1,2], 1], + ["or", "Oriya", [2,1], 2], + ["pa", "Punjabi", [1,2], 2], + ["pap", "Papiamento",[1,2], 2], + ["pl", "Polish", [1,2,5],7], + ["pms", "Piemontese",[1,2], 2], + ["ps", "Pashto", [1,2], 2], + ["pt", "Portuguese",[1,2], 2], + ["pt_br","Brazilian Portuguese",[1,2], 2], + ["rm", "Romansh", [1,2], 2], + ["ro", "Romanian", [1,2,20],20], + ["ru", "Russian", [1,2,5],4], + ["sah", "Yakut", [1], 3], + ["sco", "Scots", [1,2], 2], + ["se", "Northern Sami",[1,2], 2], + ["si", "Sinhala", [1,2], 2], + ["sk", "Slovak", [1,2,5],6], + ["sl", "Slovenian",[5,1,2,3],21], + ["so", "Somali", [1,2], 2], + ["son", "Songhay", [1,2], 2], + ["sq", "Albanian", [1,2], 2], + ["sr", "Serbian", [1,2,5],4], + ["su", "Sundanese",[1], 3], + ["sv", "Swedish", [1,2], 2], + ["sw", "Swahili", [1,2], 2], + ["ta", "Tamil", [1,2], 2], + ["te", "Telugu", [1,2], 2], + ["tg", "Tajik", [1,2], 1], + ["th", "Thai", [1], 3], + ["ti", "Tigrinya", [1,2], 1], + ["tk", "Turkmen", [1,2], 2], + ["tr", "Turkish", [1,2], 1], + ["tt", "Tatar", [1], 3], + ["ug", "Uyghur", [1], 3], + ["uk", "Ukrainian",[1,2,5],4], + ["ur", "Urdu", [1,2], 2], + ["uz", "Uzbek", [1,2], 1], + ["vi", "Vietnamese",[1], 3], + ["wa", "Walloon", [1,2], 1], + ["wo", "Wolof", [1], 3], + ["yo", "Yoruba", [1,2], 2], + ["zh", "Chinese", [1], 3] +]; + +var _rulesPluralsTypes = { + 1: function(n) {return Number(n > 1);}, + 2: function(n) {return Number(n != 1);}, + 3: function(n) {return 0;}, + 4: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 5: function(n) {return Number(n===0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5);}, + 6: function(n) {return Number((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2);}, + 7: function(n) {return Number(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 8: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3);}, + 9: function(n) {return Number(n >= 2);}, + 10: function(n) {return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;}, + 11: function(n) {return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3);}, + 12: function(n) {return Number(n%10!=1 || n%100==11);}, + 13: function(n) {return Number(n !== 0);}, + 14: function(n) {return Number((n==1) ? 0 : (n==2) ? 1 : (n == 3) ? 2 : 3);}, + 15: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2);}, + 16: function(n) {return Number(n%10==1 && n%100!=11 ? 0 : n !== 0 ? 1 : 2);}, + 17: function(n) {return Number(n==1 || n%10==1 ? 0 : 1);}, + 18: function(n) {return Number(0 ? 0 : n==1 ? 1 : 2);}, + 19: function(n) {return Number(n==1 ? 0 : n===0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3);}, + 20: function(n) {return Number(n==1 ? 0 : (n===0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2);}, + 21: function(n) {return Number(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0); } +}; + +var pluralExtensions = { + + rules: (function () { + var l, rules = {}; + for (l=_rules.length; l-- ;) { + rules[_rules[l][0]] = { + name: _rules[l][1], + numbers: _rules[l][2], + plurals: _rulesPluralsTypes[_rules[l][3]] + } + } + return rules; + }()), + + // you can add your own pluralExtensions + addRule: function(lng, obj) { + pluralExtensions.rules[lng] = obj; + }, + + setCurrentLng: function(lng) { + if (!pluralExtensions.currentRule || pluralExtensions.currentRule.lng !== lng) { + var parts = lng.split('-'); + + pluralExtensions.currentRule = { + lng: lng, + rule: pluralExtensions.rules[parts[0]] + }; + } + }, + + needsPlural: function(lng, count) { + var parts = lng.split('-'); + + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[parts[f.getCountyIndexOfLng(lng)]]; + } + + if (ext && ext.numbers.length <= 1) { + return false; + } else { + return this.get(lng, count) !== 1; + } + }, + + get: function(lng, count) { + var parts = lng.split('-'); + + function getResult(l, c) { + var ext; + if (pluralExtensions.currentRule && pluralExtensions.currentRule.lng === lng) { + ext = pluralExtensions.currentRule.rule; + } else { + ext = pluralExtensions.rules[l]; + } + if (ext) { + var i; + if (ext.noAbs) { + i = ext.plurals(c); + } else { + i = ext.plurals(Math.abs(c)); + } + + var number = ext.numbers[i]; + if (ext.numbers.length === 2 && ext.numbers[0] === 1) { + if (number === 2) { + number = -1; // regular plural + } else if (number === 1) { + number = 1; // singular + } + }//console.log(count + '-' + number); + return number; + } else { + return c === 1 ? '1' : '-1'; + } + } + + return getResult(parts[f.getCountyIndexOfLng(lng)], count); + } + +}; \ No newline at end of file diff --git a/libs/i18next/src/i18next.postProcessor.js b/libs/i18next/src/i18next.postProcessor.js new file mode 100644 index 00000000..7eef7e9c --- /dev/null +++ b/libs/i18next/src/i18next.postProcessor.js @@ -0,0 +1,4 @@ +var postProcessors = {}; +var addPostProcessor = function(name, fc) { + postProcessors[name] = fc; +}; \ No newline at end of file diff --git a/libs/i18next/src/i18next.postProcessor.sprintf.js b/libs/i18next/src/i18next.postProcessor.sprintf.js new file mode 100644 index 00000000..2d5bf3f2 --- /dev/null +++ b/libs/i18next/src/i18next.postProcessor.sprintf.js @@ -0,0 +1,136 @@ +// sprintf support +var sprintf = (function() { + function get_type(variable) { + return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); + } + function str_repeat(input, multiplier) { + for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} + return output.join(''); + } + + var str_format = function() { + if (!str_format.cache.hasOwnProperty(arguments[0])) { + str_format.cache[arguments[0]] = str_format.parse(arguments[0]); + } + return str_format.format.call(null, str_format.cache[arguments[0]], arguments); + }; + + str_format.format = function(parse_tree, argv) { + var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; + for (i = 0; i < tree_length; i++) { + node_type = get_type(parse_tree[i]); + if (node_type === 'string') { + output.push(parse_tree[i]); + } + else if (node_type === 'array') { + match = parse_tree[i]; // convenience purposes only + if (match[2]) { // keyword argument + arg = argv[cursor]; + for (k = 0; k < match[2].length; k++) { + if (!arg.hasOwnProperty(match[2][k])) { + throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); + } + arg = arg[match[2][k]]; + } + } + else if (match[1]) { // positional argument (explicit) + arg = argv[match[1]]; + } + else { // positional argument (implicit) + arg = argv[cursor++]; + } + + if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { + throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); + } + switch (match[8]) { + case 'b': arg = arg.toString(2); break; + case 'c': arg = String.fromCharCode(arg); break; + case 'd': arg = parseInt(arg, 10); break; + case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; + case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; + case 'o': arg = arg.toString(8); break; + case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; + case 'u': arg = Math.abs(arg); break; + case 'x': arg = arg.toString(16); break; + case 'X': arg = arg.toString(16).toUpperCase(); break; + } + arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); + pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; + pad_length = match[6] - String(arg).length; + pad = match[6] ? str_repeat(pad_character, pad_length) : ''; + output.push(match[5] ? arg + pad : pad + arg); + } + } + return output.join(''); + }; + + str_format.cache = {}; + + str_format.parse = function(fmt) { + var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; + while (_fmt) { + if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { + parse_tree.push(match[0]); + } + else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { + parse_tree.push('%'); + } + else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { + if (match[2]) { + arg_names |= 1; + var field_list = [], replacement_field = match[2], field_match = []; + if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { + if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { + field_list.push(field_match[1]); + } + else { + throw('[sprintf] huh?'); + } + } + } + else { + throw('[sprintf] huh?'); + } + match[2] = field_list; + } + else { + arg_names |= 2; + } + if (arg_names === 3) { + throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); + } + parse_tree.push(match); + } + else { + throw('[sprintf] huh?'); + } + _fmt = _fmt.substring(match[0].length); + } + return parse_tree; + }; + + return str_format; +})(); + +var vsprintf = function(fmt, argv) { + argv.unshift(fmt); + return sprintf.apply(null, argv); +}; + +addPostProcessor("sprintf", function(val, key, opts) { + if (!opts.sprintf) return val; + + if (Object.prototype.toString.apply(opts.sprintf) === '[object Array]') { + return vsprintf(val, opts.sprintf); + } else if (typeof opts.sprintf === 'object') { + return sprintf(val, opts.sprintf); + } + + return val; +}); \ No newline at end of file diff --git a/libs/i18next/src/i18next.shim.js b/libs/i18next/src/i18next.shim.js new file mode 100644 index 00000000..31a3aefc --- /dev/null +++ b/libs/i18next/src/i18next.shim.js @@ -0,0 +1,71 @@ +// add indexOf to non ECMA-262 standard compliant browsers +if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } +} + +// add lastIndexOf to non ECMA-262 standard compliant browsers +if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n != 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; +} + +// Add string trim for IE8. +if (typeof String.prototype.trim !== 'function') { + String.prototype.trim = function() { + return this.replace(/^\s+|\s+$/g, ''); + } +} diff --git a/libs/i18next/src/i18next.sync.js b/libs/i18next/src/i18next.sync.js new file mode 100644 index 00000000..d82e585a --- /dev/null +++ b/libs/i18next/src/i18next.sync.js @@ -0,0 +1,203 @@ +sync = { + + load: function(lngs, options, cb) { + if (options.useLocalStorage) { + sync._loadLocal(lngs, options, function(err, store) { + var missingLngs = []; + for (var i = 0, len = lngs.length; i < len; i++) { + if (!store[lngs[i]]) missingLngs.push(lngs[i]); + } + + if (missingLngs.length > 0) { + sync._fetch(missingLngs, options, function(err, fetched) { + f.extend(store, fetched); + sync._storeLocal(fetched); + + cb(null, store); + }); + } else { + cb(null, store); + } + }); + } else { + sync._fetch(lngs, options, function(err, store){ + cb(null, store); + }); + } + }, + + _loadLocal: function(lngs, options, cb) { + var store = {} + , nowMS = new Date().getTime(); + + if(window.localStorage) { + + var todo = lngs.length; + + f.each(lngs, function(key, lng) { + var local = f.localStorage.getItem('res_' + lng); + + if (local) { + local = JSON.parse(local); + + if (local.i18nStamp && local.i18nStamp + options.localStorageExpirationTime > nowMS) { + store[lng] = local; + } + } + + todo--; // wait for all done befor callback + if (todo === 0) cb(null, store); + }); + } + }, + + _storeLocal: function(store) { + if(window.localStorage) { + for (var m in store) { + store[m].i18nStamp = new Date().getTime(); + f.localStorage.setItem('res_' + m, JSON.stringify(store[m])); + } + } + return; + }, + + _fetch: function(lngs, options, cb) { + var ns = options.ns + , store = {}; + + if (!options.dynamicLoad) { + var todo = ns.namespaces.length * lngs.length + , errors; + + // load each file individual + f.each(ns.namespaces, function(nsIndex, nsValue) { + f.each(lngs, function(lngIndex, lngValue) { + + // Call this once our translation has returned. + var loadComplete = function(err, data) { + if (err) { + errors = errors || []; + errors.push(err); + } + store[lngValue] = store[lngValue] || {}; + store[lngValue][nsValue] = data; + + todo--; // wait for all done befor callback + if (todo === 0) cb(errors, store); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngValue, nsValue, options, loadComplete); + } else { + //~ // Use our inbuilt sync. + sync._fetchOne(lngValue, nsValue, options, loadComplete); + } + }); + }); + } else { + // Call this once our translation has returned. + var loadComplete = function(err, data) { + cb(null, data); + }; + + if(typeof options.customLoad == 'function'){ + // Use the specified custom callback. + options.customLoad(lngs, ns.namespaces, options, loadComplete); + } else { + var url = applyReplacement(options.resGetPath, { lng: lngs.join('+'), ns: ns.namespaces.join('+') }); + // load all needed stuff once + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + loadComplete(null, data); + }, + error : function(xhr, status, error) { + f.log('failed loading: ' + url); + loadComplete('failed loading resource.json error: ' + error); + }, + dataType: "json", + async : options.getAsync + }); + } + } + }, + + _fetchOne: function(lng, ns, options, done) { + var url = applyReplacement(options.resGetPath, { lng: lng, ns: ns }); + f.ajax({ + url: url, + success: function(data, status, xhr) { + f.log('loaded: ' + url); + done(null, data); + }, + error : function(xhr, status, error) { + if ((status && status == 200) || (xhr && xhr.status && xhr.status == 200)) { + // file loaded but invalid json, stop waste time ! + f.error('There is a typo in: ' + url); + } else if ((status && status == 404) || (xhr && xhr.status && xhr.status == 404)) { + f.log('Does not exist: ' + url); + } else { + var theStatus = status ? status : ((xhr && xhr.status) ? xhr.status : null); + f.log(theStatus + ' when loading ' + url); + } + + done(error, {}); + }, + dataType: "json", + async : options.getAsync + }); + }, + + postMissing: function(lng, ns, key, defaultValue, lngs) { + var payload = {}; + payload[key] = defaultValue; + + var urls = []; + + if (o.sendMissingTo === 'fallback' && o.fallbackLng[0] !== false) { + for (var i = 0; i < o.fallbackLng.length; i++) { + urls.push({lng: o.fallbackLng[i], url: applyReplacement(o.resPostPath, { lng: o.fallbackLng[i], ns: ns })}); + } + } else if (o.sendMissingTo === 'current' || (o.sendMissingTo === 'fallback' && o.fallbackLng[0] === false) ) { + urls.push({lng: lng, url: applyReplacement(o.resPostPath, { lng: lng, ns: ns })}); + } else if (o.sendMissingTo === 'all') { + for (var i = 0, l = lngs.length; i < l; i++) { + urls.push({lng: lngs[i], url: applyReplacement(o.resPostPath, { lng: lngs[i], ns: ns })}); + } + } + + for (var y = 0, len = urls.length; y < len; y++) { + var item = urls[y]; + f.ajax({ + url: item.url, + type: o.sendType, + data: payload, + success: function(data, status, xhr) { + f.log('posted missing key \'' + key + '\' to: ' + item.url); + + // add key to resStore + var keys = key.split('.'); + var x = 0; + var value = resStore[item.lng][ns]; + while (keys[x]) { + if (x === keys.length - 1) { + value = value[keys[x]] = defaultValue; + } else { + value = value[keys[x]] = value[keys[x]] || {}; + } + x++; + } + }, + error : function(xhr, status, error) { + f.log('failed posting missing key \'' + key + '\' to: ' + item.url); + }, + dataType: "json", + async : o.postAsync + }); + } + }, + + reload: reload +}; diff --git a/libs/i18next/src/i18next.translate.js b/libs/i18next/src/i18next.translate.js new file mode 100644 index 00000000..7b007722 --- /dev/null +++ b/libs/i18next/src/i18next.translate.js @@ -0,0 +1,417 @@ +function applyReplacement(str, replacementHash, nestedKey, options) { + if (!str) return str; + + options = options || replacementHash; // first call uses replacement hash combined with options + if (str.indexOf(options.interpolationPrefix || o.interpolationPrefix) < 0) return str; + + var prefix = options.interpolationPrefix ? f.regexEscape(options.interpolationPrefix) : o.interpolationPrefixEscaped + , suffix = options.interpolationSuffix ? f.regexEscape(options.interpolationSuffix) : o.interpolationSuffixEscaped + , unEscapingSuffix = 'HTML'+suffix; + + var hash = replacementHash.replace && typeof replacementHash.replace === 'object' ? replacementHash.replace : replacementHash; + f.each(hash, function(key, value) { + var nextKey = nestedKey ? nestedKey + o.keyseparator + key : key; + if (typeof value === 'object' && value !== null) { + str = applyReplacement(str, value, nextKey, options); + } else { + if (options.escapeInterpolation || o.escapeInterpolation) { + str = str.replace(new RegExp([prefix, nextKey, unEscapingSuffix].join(''), 'g'), f.regexReplacementEscape(value)); + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(f.escape(value))); + } else { + str = str.replace(new RegExp([prefix, nextKey, suffix].join(''), 'g'), f.regexReplacementEscape(value)); + } + // str = options.escapeInterpolation; + } + }); + return str; +} + +// append it to functions +f.applyReplacement = applyReplacement; + +function applyReuse(translated, options) { + var comma = ','; + var options_open = '{'; + var options_close = '}'; + + var opts = f.extend({}, options); + delete opts.postProcess; + + while (translated.indexOf(o.reusePrefix) != -1) { + replacementCounter++; + if (replacementCounter > o.maxRecursion) { break; } // safety net for too much recursion + var index_of_opening = translated.lastIndexOf(o.reusePrefix); + var index_of_end_of_closing = translated.indexOf(o.reuseSuffix, index_of_opening) + o.reuseSuffix.length; + var token = translated.substring(index_of_opening, index_of_end_of_closing); + var token_without_symbols = token.replace(o.reusePrefix, '').replace(o.reuseSuffix, ''); + + if (index_of_end_of_closing <= index_of_opening) { + f.error('there is an missing closing in following translation value', translated); + return ''; + } + + if (token_without_symbols.indexOf(comma) != -1) { + var index_of_token_end_of_closing = token_without_symbols.indexOf(comma); + if (token_without_symbols.indexOf(options_open, index_of_token_end_of_closing) != -1 && token_without_symbols.indexOf(options_close, index_of_token_end_of_closing) != -1) { + var index_of_opts_opening = token_without_symbols.indexOf(options_open, index_of_token_end_of_closing); + var index_of_opts_end_of_closing = token_without_symbols.indexOf(options_close, index_of_opts_opening) + options_close.length; + try { + opts = f.extend(opts, JSON.parse(token_without_symbols.substring(index_of_opts_opening, index_of_opts_end_of_closing))); + token_without_symbols = token_without_symbols.substring(0, index_of_token_end_of_closing); + } catch (e) { + } + } + } + + var translated_token = _translate(token_without_symbols, opts); + translated = translated.replace(token, f.regexReplacementEscape(translated_token)); + } + return translated; +} + +function hasContext(options) { + return (options.context && (typeof options.context == 'string' || typeof options.context == 'number')); +} + +function needsPlural(options, lng) { + return (options.count !== undefined && typeof options.count != 'string'/* && pluralExtensions.needsPlural(lng, options.count)*/); +} + +function needsIndefiniteArticle(options) { + return (options.indefinite_article !== undefined && typeof options.indefinite_article != 'string' && options.indefinite_article); +} + +function exists(key, options) { + options = options || {}; + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options); + + return found !== undefined || found === notFound; +} + +function translate(key, options) { + options = options || {}; + + if (!initialized) { + f.log('i18next not finished initialization. you might have called t function before loading resources finished.') + return options.defaultValue || ''; + }; + replacementCounter = 0; + return _translate.apply(null, arguments); +} + +function _getDefaultValue(key, options) { + return (options.defaultValue !== undefined) ? options.defaultValue : key; +} + +function _injectSprintfProcessor() { + + var values = []; + + // mh: build array from second argument onwards + for (var i = 1; i < arguments.length; i++) { + values.push(arguments[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; +} + +function _translate(potentialKeys, options) { + if (options && typeof options !== 'object') { + if (o.shortcutFunction === 'sprintf') { + // mh: gettext like sprintf syntax found, automatically create sprintf processor + options = _injectSprintfProcessor.apply(null, arguments); + } else if (o.shortcutFunction === 'defaultValue') { + options = { + defaultValue: options + } + } + } else { + options = options || {}; + } + + if (typeof o.defaultVariables === 'object') { + options = f.extend({}, o.defaultVariables, options); + } + + if (potentialKeys === undefined || potentialKeys === null || potentialKeys === '') return ''; + + if (typeof potentialKeys === 'number') { + potentialKeys = String(potentialKeys); + } + + if (typeof potentialKeys === 'string') { + potentialKeys = [potentialKeys]; + } + + var key = potentialKeys[0]; + + if (potentialKeys.length > 1) { + for (var i = 0; i < potentialKeys.length; i++) { + key = potentialKeys[i]; + if (exists(key, options)) { + break; + } + } + } + + var notFound = _getDefaultValue(key, options) + , found = _find(key, options) + , lngs = options.lng ? f.toLanguages(options.lng, options.fallbackLng) : languages + , ns = options.ns || o.ns.defaultNs + , parts; + + // split ns and key + if (key.indexOf(o.nsseparator) > -1) { + parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (found === undefined && o.sendMissing && typeof o.missingKeyHandler === 'function') { + if (options.lng) { + o.missingKeyHandler(lngs[0], ns, key, notFound, lngs); + } else { + o.missingKeyHandler(o.lng, ns, key, notFound, lngs); + } + } + + var postProcessorsToApply; + if (typeof o.postProcess === 'string' && o.postProcess !== '') { + postProcessorsToApply = [o.postProcess]; + } else if (typeof o.postProcess === 'array' || typeof o.postProcess === 'object') { + postProcessorsToApply = o.postProcess; + } else { + postProcessorsToApply = []; + } + + if (typeof options.postProcess === 'string' && options.postProcess !== '') { + postProcessorsToApply = postProcessorsToApply.concat([options.postProcess]); + } else if (typeof options.postProcess === 'array' || typeof options.postProcess === 'object') { + postProcessorsToApply = postProcessorsToApply.concat(options.postProcess); + } + + if (found !== undefined && postProcessorsToApply.length) { + postProcessorsToApply.forEach(function(postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](found, key, options); + } + }); + } + + // process notFound if function exists + var splitNotFound = notFound; + if (notFound.indexOf(o.nsseparator) > -1) { + parts = notFound.split(o.nsseparator); + splitNotFound = parts[1]; + } + if (splitNotFound === key && o.parseMissingKey) { + notFound = o.parseMissingKey(notFound); + } + + if (found === undefined) { + notFound = applyReplacement(notFound, options); + notFound = applyReuse(notFound, options); + + if (postProcessorsToApply.length) { + var val = _getDefaultValue(key, options); + postProcessorsToApply.forEach(function(postProcessor) { + if (postProcessors[postProcessor]) { + found = postProcessors[postProcessor](val, key, options); + } + }); + } + } + + return (found !== undefined) ? found : notFound; +} + +function _find(key, options) { + options = options || {}; + + var optionWithoutCount, translated + , notFound = _getDefaultValue(key, options) + , lngs = languages; + + if (!resStore) { return notFound; } // no resStore to translate from + + // CI mode + if (lngs[0].toLowerCase() === 'cimode') return notFound; + + // passed in lng + if (options.lngs) lngs = options.lngs; + if (options.lng) { + lngs = f.toLanguages(options.lng, options.fallbackLng); + + if (!resStore[lngs[0]]) { + var oldAsync = o.getAsync; + o.getAsync = false; + + i18n.sync.load(lngs, o, function(err, store) { + f.extend(resStore, store); + o.getAsync = oldAsync; + }); + } + } + + var ns = options.ns || o.ns.defaultNs; + if (key.indexOf(o.nsseparator) > -1) { + var parts = key.split(o.nsseparator); + ns = parts[0]; + key = parts[1]; + } + + if (hasContext(options)) { + optionWithoutCount = f.extend({}, options); + delete optionWithoutCount.context; + optionWithoutCount.defaultValue = o.contextNotFound; + + var contextKey = ns + o.nsseparator + key + '_' + options.context; + + translated = translate(contextKey, optionWithoutCount); + if (translated != o.contextNotFound) { + return applyReplacement(translated, { context: options.context }); // apply replacement for context only + } // else continue translation with original/nonContext key + } + + if (needsPlural(options, lngs[0])) { + optionWithoutCount = f.extend({ lngs: [lngs[0]]}, options); + delete optionWithoutCount.count; + optionWithoutCount._origLng = optionWithoutCount._origLng || optionWithoutCount.lng || lngs[0]; + delete optionWithoutCount.lng; + optionWithoutCount.defaultValue = o.pluralNotFound; + + var pluralKey; + if (!pluralExtensions.needsPlural(lngs[0], options.count)) { + pluralKey = ns + o.nsseparator + key; + } else { + pluralKey = ns + o.nsseparator + key + o.pluralSuffix; + var pluralExtension = pluralExtensions.get(lngs[0], options.count); + if (pluralExtension >= 0) { + pluralKey = pluralKey + '_' + pluralExtension; + } else if (pluralExtension === 1) { + pluralKey = ns + o.nsseparator + key; // singular + } + } + + translated = translate(pluralKey, optionWithoutCount); + + if (translated != o.pluralNotFound) { + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); // apply replacement for count only + } else if (lngs.length > 1) { + // remove failed lng + var clone = lngs.slice(); + clone.shift(); + options = f.extend(options, { lngs: clone }); + options._origLng = optionWithoutCount._origLng; + delete options.lng; + // retry with fallbacks + translated = translate(ns + o.nsseparator + key, options); + if (translated != o.pluralNotFound) return translated; + } else { + optionWithoutCount.lng = optionWithoutCount._origLng; + delete optionWithoutCount._origLng; + translated = translate(ns + o.nsseparator + key, optionWithoutCount); + + return applyReplacement(translated, { + count: options.count, + interpolationPrefix: options.interpolationPrefix, + interpolationSuffix: options.interpolationSuffix + }); + } + } + + if (needsIndefiniteArticle(options)) { + var optionsWithoutIndef = f.extend({}, options); + delete optionsWithoutIndef.indefinite_article; + optionsWithoutIndef.defaultValue = o.indefiniteNotFound; + // If we don't have a count, we want the indefinite, if we do have a count, and needsPlural is false + var indefiniteKey = ns + o.nsseparator + key + (((options.count && !needsPlural(options, lngs[0])) || !options.count) ? o.indefiniteSuffix : ""); + translated = translate(indefiniteKey, optionsWithoutIndef); + if (translated != o.indefiniteNotFound) { + return translated; + } + } + + var found; + var keys = key.split(o.keyseparator); + for (var i = 0, len = lngs.length; i < len; i++ ) { + if (found !== undefined) break; + + var l = lngs[i]; + + var x = 0; + var value = resStore[l] && resStore[l][ns]; + while (keys[x]) { + value = value && value[keys[x]]; + x++; + } + if (value !== undefined) { + var valueType = Object.prototype.toString.apply(value); + if (typeof value === 'string') { + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (valueType === '[object Array]' && !o.returnObjectTrees && !options.returnObjectTrees) { + value = value.join('\n'); + value = applyReplacement(value, options); + value = applyReuse(value, options); + } else if (value === null && o.fallbackOnNull === true) { + value = undefined; + } else if (value !== null) { + if (!o.returnObjectTrees && !options.returnObjectTrees) { + if (o.objectTreeKeyHandler && typeof o.objectTreeKeyHandler == 'function') { + value = o.objectTreeKeyHandler(key, value, l, ns, options); + } else { + value = 'key \'' + ns + ':' + key + ' (' + l + ')\' ' + + 'returned an object instead of string.'; + f.log(value); + } + } else if (valueType !== '[object Number]' && valueType !== '[object Function]' && valueType !== '[object RegExp]') { + var copy = (valueType === '[object Array]') ? [] : {}; // apply child translation on a copy + f.each(value, function(m) { + copy[m] = _translate(ns + o.nsseparator + key + o.keyseparator + m, options); + }); + value = copy; + } + } + + if (typeof value === 'string' && value.trim() === '' && o.fallbackOnEmpty === true) + value = undefined; + + found = value; + } + } + + if (found === undefined && !options.isFallbackLookup && (o.fallbackToDefaultNS === true || (o.fallbackNS && o.fallbackNS.length > 0))) { + // set flag for fallback lookup - avoid recursion + options.isFallbackLookup = true; + + if (o.fallbackNS.length) { + + for (var y = 0, lenY = o.fallbackNS.length; y < lenY; y++) { + found = _find(o.fallbackNS[y] + o.nsseparator + key, options); + + if (found || (found==="" && o.fallbackOnEmpty === false)) { + /* compare value without namespace */ + var foundValue = found.indexOf(o.nsseparator) > -1 ? found.split(o.nsseparator)[1] : found + , notFoundValue = notFound.indexOf(o.nsseparator) > -1 ? notFound.split(o.nsseparator)[1] : notFound; + + if (foundValue !== notFoundValue) break; + } + } + } else { + found = _find(key, options); // fallback to default NS + } + options.isFallbackLookup = false; + } + + return found; +} diff --git a/libs/i18next/test/index.html b/libs/i18next/test/index.html new file mode 100644 index 00000000..670565f4 --- /dev/null +++ b/libs/i18next/test/index.html @@ -0,0 +1,29 @@ + + + + Mocha Tests + + + + + + + + + + + + + + + + + + +
+ + \ No newline at end of file diff --git a/libs/i18next/test/libs/expect-dom.js b/libs/i18next/test/libs/expect-dom.js new file mode 100644 index 00000000..27cb601c --- /dev/null +++ b/libs/i18next/test/libs/expect-dom.js @@ -0,0 +1,173 @@ + +(function() { + var assertions = { + cssclass: function(className) { + this.assert(this.obj.hasClass(className), + "Expected element to have class " + className, + "Expected element to not have class " + className); + }, + + attr: function(attrName, expectedValue) { + if (expectedValue) + this.assert(this.obj.attr(attrName) == expectedValue, + "Expected element to have attribute '" + attrName + "' with value '" + expectedValue + "'", + "Expected element to have attribute '" + attrName + "' with value other than '" + expectedValue + "'" + ); + else + this.assert(this.obj.attr(attrName), + "Expected element to have attribute " + attrName, + "Expected element to not have attribute " + attrName + ); + }, + + id: function(id) { + this.assert(this.obj.attr("id") === id, + "Expected element to have id '" + id + "'", + "Expected element to not have id '" + id + "'" + ); + }, + + html: function(html) { + this.assert(this.obj.html() === normalizeHtmlTagCase(html), + "Expected element to have html '" + html + "' but had '" + this.obj.html() + "'", + "Expected element to not have html '" + this.obj.html() + "'" + ); + }, + + text: function(text) { + if (text && $.isFunction(text.test)) { + this.assert(text.test(this.obj.text()), + "Expected element text '" + this.obj.text() + "' to match regex '" + text.source + "'", + "Expected element text '" + this.obj.text() + "' to not match regex '" + text.source + "'" + ); + } else { + this.assert(this.obj.text() == text, + "Expected element to have text '" + text + "' but had '" + this.obj.text() + "'", + "Expected element to not have text '" + this.obj.text() + "'" + ); + } + }, + + value: function(value) { + this.assert(this.obj.val() == value, + "Expected element to have value '" + value + "' but had '" + this.obj.val() + "'", + "Expected element to not have value '" + this.obj.val() + "'" + ); + }, + + + data: function(key, expectedValue) { + if (expectedValue) + this.assert(this.obj.data(key) == expectedValue, + "Expected element to have data '" + key + "' with value '" + expectedValue + "'", + "Expected element to have data '" + key + "' with value other than '" + expectedValue + "'" + ); + else + this.assert(this.obj.data(key) !== undefined, + "Expected element to have data " + key, + "Expected element to not have data " + key + ); + }, + + visible: function() { + this.assert(this.obj.is(":visible"), + "Expected element to be visible", + "Expected element to not be visible" + ); + }, + + hidden: function() { + this.assert(this.obj.is(":hidden"), + "Expected element to be hidden", + "Expected element to not be hidden" + ); + }, + + selected: function() { + this.assert(this.obj.is(":selected"), + "Expected element to be selected", + "Expected element to not be selected" + ); + }, + + checked: function() { + this.assert(this.obj.is(":checked"), + "Expected element to be checked", + "Expected element to not be checked" + ); + }, + + empty: function() { + this.assert(this.obj.is(":empty"), + "Expected element to be empty", + "Expected element to not be empty" + ); + }, + + exist: function() { + this.assert(this.obj.size() > 0, + "Expected element to exist", + "Expected element to not exist" + ); + }, + + matchSelector: function(selector) { + this.assert(this.obj.is(selector), + "Expected element to match selector '" + selector + "'", + "Expected element to not match selector '" + selector + "'" + ); + }, + + containChild: function(selector) { + this.assert(this.obj.find(selector).size() > 0, + "Expected element to contain child '" + selector + "'", + "Expected element to not contain child '" + selector + "'" + ); + }, + + disabled: function() { + this.assert(this.obj.is(":disabled"), + "Expected element to be disabled", + "Expected element to not be disabled" + ); + }, + + handle: function(eventName) { + var events = this.obj.data("events"); + this.assert(events && events[eventName] && events[eventName].length > 0, + "Expected element to handle event '" + eventName + "'", + "Expected element to not handle event '" + eventName + "'" + ); + }, + + handleWith: function(eventName, eventHandler) { + var stack = this.obj.data("events")[eventName]; + if (!stack) this.assert(false, "No events bound for '" + eventName + "'"); + var i; + for (i = 0; i < stack.length; i++) { + if (stack[i].handler == eventHandler) { + return; + } + } + + this.assert(false, "No matching handler found for '" + eventName + "'"); + } + + }; + + normalizeHtmlTagCase = function(html) { + return $('
').append(html).html(); + }; + + if (typeof(expect) !== "undefined") { + var assertionProtype; + if (typeof(expect.Assertion) !== "undefined") + assertionPrototype = expect.Assertion.prototype; + + for (var assertion in assertions) { + if (!assertionPrototype[assertion.name]) + assertionPrototype[assertion] = assertions[assertion]; + } + } +})(); + diff --git a/libs/i18next/test/libs/expect.js b/libs/i18next/test/libs/expect.js new file mode 100644 index 00000000..c266eba8 --- /dev/null +++ b/libs/i18next/test/libs/expect.js @@ -0,0 +1,1202 @@ + +(function (global, module) { + + if ('undefined' == typeof module) { + var module = { exports: {} } + , exports = module.exports + } + + /** + * Exports. + */ + + module.exports = expect; + expect.Assertion = Assertion; + + /** + * Exports version. + */ + + expect.version = '0.1.2'; + + /** + * Possible assertion flags. + */ + + var flags = { + not: ['to', 'be', 'have', 'include', 'only'] + , to: ['be', 'have', 'include', 'only', 'not'] + , only: ['have'] + , have: ['own'] + , be: ['an'] + }; + + function expect (obj) { + return new Assertion(obj); + } + + /** + * Constructor + * + * @api private + */ + + function Assertion (obj, flag, parent) { + this.obj = obj; + this.flags = {}; + + if (undefined != parent) { + this.flags[flag] = true; + + for (var i in parent.flags) { + if (parent.flags.hasOwnProperty(i)) { + this.flags[i] = true; + } + } + } + + var $flags = flag ? flags[flag] : keys(flags) + , self = this + + if ($flags) { + for (var i = 0, l = $flags.length; i < l; i++) { + // avoid recursion + if (this.flags[$flags[i]]) continue; + + var name = $flags[i] + , assertion = new Assertion(this.obj, name, this) + + if ('function' == typeof Assertion.prototype[name]) { + // clone the function, make sure we dont touch the prot reference + var old = this[name]; + this[name] = function () { + return old.apply(self, arguments); + } + + for (var fn in Assertion.prototype) { + if (Assertion.prototype.hasOwnProperty(fn) && fn != name) { + this[name][fn] = bind(assertion[fn], assertion); + } + } + } else { + this[name] = assertion; + } + } + } + }; + + /** + * Performs an assertion + * + * @api private + */ + + Assertion.prototype.assert = function (truth, msg, error) { + var msg = this.flags.not ? error : msg + , ok = this.flags.not ? !truth : truth; + + if (!ok) { + throw new Error(msg); + } + + this.and = new Assertion(this.obj); + }; + + /** + * Check if the value is truthy + * + * @api public + */ + + Assertion.prototype.ok = function () { + this.assert( + !!this.obj + , 'expected ' + i(this.obj) + ' to be truthy' + , 'expected ' + i(this.obj) + ' to be falsy'); + }; + + /** + * Assert that the function throws. + * + * @param {Function|RegExp} callback, or regexp to match error string against + * @api public + */ + + Assertion.prototype.throwError = + Assertion.prototype.throwException = function (fn) { + expect(this.obj).to.be.a('function'); + + var thrown = false + , not = this.flags.not + + try { + this.obj(); + } catch (e) { + if ('function' == typeof fn) { + fn(e); + } else if ('object' == typeof fn) { + var subject = 'string' == typeof e ? e : e.message; + if (not) { + expect(subject).to.not.match(fn); + } else { + expect(subject).to.match(fn); + } + } + thrown = true; + } + + if ('object' == typeof fn && not) { + // in the presence of a matcher, ensure the `not` only applies to + // the matching. + this.flags.not = false; + } + + var name = this.obj.name || 'fn'; + this.assert( + thrown + , 'expected ' + name + ' to throw an exception' + , 'expected ' + name + ' not to throw an exception'); + }; + + /** + * Checks if the array is empty. + * + * @api public + */ + + Assertion.prototype.empty = function () { + var expectation; + + if ('object' == typeof this.obj && null !== this.obj && !isArray(this.obj)) { + if ('number' == typeof this.obj.length) { + expectation = !this.obj.length; + } else { + expectation = !keys(this.obj).length; + } + } else { + if ('string' != typeof this.obj) { + expect(this.obj).to.be.an('object'); + } + + expect(this.obj).to.have.property('length'); + expectation = !this.obj.length; + } + + this.assert( + expectation + , 'expected ' + i(this.obj) + ' to be empty' + , 'expected ' + i(this.obj) + ' to not be empty'); + return this; + }; + + /** + * Checks if the obj exactly equals another. + * + * @api public + */ + + Assertion.prototype.be = + Assertion.prototype.equal = function (obj) { + this.assert( + obj === this.obj + , 'expected ' + i(this.obj) + ' to equal ' + i(obj) + , 'expected ' + i(this.obj) + ' to not equal ' + i(obj)); + return this; + }; + + /** + * Checks if the obj sortof equals another. + * + * @api public + */ + + Assertion.prototype.eql = function (obj) { + this.assert( + expect.eql(obj, this.obj) + , 'expected ' + i(this.obj) + ' to sort of equal ' + i(obj) + , 'expected ' + i(this.obj) + ' to sort of not equal ' + i(obj)); + return this; + }; + + /** + * Assert within start to finish (inclusive). + * + * @param {Number} start + * @param {Number} finish + * @api public + */ + + Assertion.prototype.within = function (start, finish) { + var range = start + '..' + finish; + this.assert( + this.obj >= start && this.obj <= finish + , 'expected ' + i(this.obj) + ' to be within ' + range + , 'expected ' + i(this.obj) + ' to not be within ' + range); + return this; + }; + + /** + * Assert typeof / instance of + * + * @api public + */ + + Assertion.prototype.a = + Assertion.prototype.an = function (type) { + if ('string' == typeof type) { + // proper english in error msg + var n = /^[aeiou]/.test(type) ? 'n' : ''; + + // typeof with support for 'array' + this.assert( + 'array' == type ? isArray(this.obj) : + 'object' == type + ? 'object' == typeof this.obj && null !== this.obj + : type == typeof this.obj + , 'expected ' + i(this.obj) + ' to be a' + n + ' ' + type + , 'expected ' + i(this.obj) + ' not to be a' + n + ' ' + type); + } else { + // instanceof + var name = type.name || 'supplied constructor'; + this.assert( + this.obj instanceof type + , 'expected ' + i(this.obj) + ' to be an instance of ' + name + , 'expected ' + i(this.obj) + ' not to be an instance of ' + name); + } + + return this; + }; + + /** + * Assert numeric value above _n_. + * + * @param {Number} n + * @api public + */ + + Assertion.prototype.greaterThan = + Assertion.prototype.above = function (n) { + this.assert( + this.obj > n + , 'expected ' + i(this.obj) + ' to be above ' + n + , 'expected ' + i(this.obj) + ' to be below ' + n); + return this; + }; + + /** + * Assert numeric value below _n_. + * + * @param {Number} n + * @api public + */ + + Assertion.prototype.lessThan = + Assertion.prototype.below = function (n) { + this.assert( + this.obj < n + , 'expected ' + i(this.obj) + ' to be below ' + n + , 'expected ' + i(this.obj) + ' to be above ' + n); + return this; + }; + + /** + * Assert string value matches _regexp_. + * + * @param {RegExp} regexp + * @api public + */ + + Assertion.prototype.match = function (regexp) { + this.assert( + regexp.exec(this.obj) + , 'expected ' + i(this.obj) + ' to match ' + regexp + , 'expected ' + i(this.obj) + ' not to match ' + regexp); + return this; + }; + + /** + * Assert property "length" exists and has value of _n_. + * + * @param {Number} n + * @api public + */ + + Assertion.prototype.length = function (n) { + expect(this.obj).to.have.property('length'); + var len = this.obj.length; + this.assert( + n == len + , 'expected ' + i(this.obj) + ' to have a length of ' + n + ' but got ' + len + , 'expected ' + i(this.obj) + ' to not have a length of ' + len); + return this; + }; + + /** + * Assert property _name_ exists, with optional _val_. + * + * @param {String} name + * @param {Mixed} val + * @api public + */ + + Assertion.prototype.property = function (name, val) { + if (this.flags.own) { + this.assert( + Object.prototype.hasOwnProperty.call(this.obj, name) + , 'expected ' + i(this.obj) + ' to have own property ' + i(name) + , 'expected ' + i(this.obj) + ' to not have own property ' + i(name)); + return this; + } + + if (this.flags.not && undefined !== val) { + if (undefined === this.obj[name]) { + throw new Error(i(this.obj) + ' has no property ' + i(name)); + } + } else { + var hasProp; + try { + hasProp = name in this.obj + } catch (e) { + hasProp = undefined !== this.obj[name] + } + + this.assert( + hasProp + , 'expected ' + i(this.obj) + ' to have a property ' + i(name) + , 'expected ' + i(this.obj) + ' to not have a property ' + i(name)); + } + + if (undefined !== val) { + this.assert( + val === this.obj[name] + , 'expected ' + i(this.obj) + ' to have a property ' + i(name) + + ' of ' + i(val) + ', but got ' + i(this.obj[name]) + , 'expected ' + i(this.obj) + ' to not have a property ' + i(name) + + ' of ' + i(val)); + } + + this.obj = this.obj[name]; + return this; + }; + + /** + * Assert that the array contains _obj_ or string contains _obj_. + * + * @param {Mixed} obj|string + * @api public + */ + + Assertion.prototype.string = + Assertion.prototype.contain = function (obj) { + if ('string' == typeof this.obj) { + this.assert( + ~this.obj.indexOf(obj) + , 'expected ' + i(this.obj) + ' to contain ' + i(obj) + , 'expected ' + i(this.obj) + ' to not contain ' + i(obj)); + } else { + this.assert( + ~indexOf(this.obj, obj) + , 'expected ' + i(this.obj) + ' to contain ' + i(obj) + , 'expected ' + i(this.obj) + ' to not contain ' + i(obj)); + } + return this; + }; + + /** + * Assert exact keys or inclusion of keys by using + * the `.own` modifier. + * + * @param {Array|String ...} keys + * @api public + */ + + Assertion.prototype.key = + Assertion.prototype.keys = function ($keys) { + var str + , ok = true; + + $keys = isArray($keys) + ? $keys + : Array.prototype.slice.call(arguments); + + if (!$keys.length) throw new Error('keys required'); + + var actual = keys(this.obj) + , len = $keys.length; + + // Inclusion + ok = every($keys, function (key) { + return ~indexOf(actual, key); + }); + + // Strict + if (!this.flags.not && this.flags.only) { + ok = ok && $keys.length == actual.length; + } + + // Key string + if (len > 1) { + $keys = map($keys, function (key) { + return i(key); + }); + var last = $keys.pop(); + str = $keys.join(', ') + ', and ' + last; + } else { + str = i($keys[0]); + } + + // Form + str = (len > 1 ? 'keys ' : 'key ') + str; + + // Have / include + str = (!this.flags.only ? 'include ' : 'only have ') + str; + + // Assertion + this.assert( + ok + , 'expected ' + i(this.obj) + ' to ' + str + , 'expected ' + i(this.obj) + ' to not ' + str); + + return this; + }; + + /** + * Function bind implementation. + */ + + function bind (fn, scope) { + return function () { + return fn.apply(scope, arguments); + } + } + + /** + * Array every compatibility + * + * @see bit.ly/5Fq1N2 + * @api public + */ + + function every (arr, fn, thisObj) { + var scope = thisObj || global; + for (var i = 0, j = arr.length; i < j; ++i) { + if (!fn.call(scope, arr[i], i, arr)) { + return false; + } + } + return true; + }; + + /** + * Array indexOf compatibility. + * + * @see bit.ly/a5Dxa2 + * @api public + */ + + function indexOf (arr, o, i) { + if (Array.prototype.indexOf) { + return Array.prototype.indexOf.call(arr, o, i); + } + + if (arr.length === undefined) { + return -1; + } + + for (var j = arr.length, i = i < 0 ? i + j < 0 ? 0 : i + j : i || 0 + ; i < j && arr[i] !== o; i++); + + return j <= i ? -1 : i; + }; + + /** + * Inspects an object. + * + * @see taken from node.js `util` module (copyright Joyent, MIT license) + * @api private + */ + + function i (obj, showHidden, depth) { + var seen = []; + + function stylize (str) { + return str; + }; + + function format (value, recurseTimes) { + // Provide a hook for user-specified inspect functions. + // Check that value is an object with an inspect function on it + if (value && typeof value.inspect === 'function' && + // Filter out the util module, it's inspect function is special + value !== exports && + // Also filter out any prototype objects using the circular check. + !(value.constructor && value.constructor.prototype === value)) { + return value.inspect(recurseTimes); + } + + // Primitive types cannot have properties + switch (typeof value) { + case 'undefined': + return stylize('undefined', 'undefined'); + + case 'string': + var simple = '\'' + json.stringify(value).replace(/^"|"$/g, '') + .replace(/'/g, "\\'") + .replace(/\\"/g, '"') + '\''; + return stylize(simple, 'string'); + + case 'number': + return stylize('' + value, 'number'); + + case 'boolean': + return stylize('' + value, 'boolean'); + } + // For some reason typeof null is "object", so special case here. + if (value === null) { + return stylize('null', 'null'); + } + + // Look up the keys of the object. + var visible_keys = keys(value); + var $keys = showHidden ? Object.getOwnPropertyNames(value) : visible_keys; + + // Functions without properties can be shortcutted. + if (typeof value === 'function' && $keys.length === 0) { + if (isRegExp(value)) { + return stylize('' + value, 'regexp'); + } else { + var name = value.name ? ': ' + value.name : ''; + return stylize('[Function' + name + ']', 'special'); + } + } + + // Dates without properties can be shortcutted + if (isDate(value) && $keys.length === 0) { + return stylize(value.toUTCString(), 'date'); + } + + var base, type, braces; + // Determine the object type + if (isArray(value)) { + type = 'Array'; + braces = ['[', ']']; + } else { + type = 'Object'; + braces = ['{', '}']; + } + + // Make functions say that they are functions + if (typeof value === 'function') { + var n = value.name ? ': ' + value.name : ''; + base = (isRegExp(value)) ? ' ' + value : ' [Function' + n + ']'; + } else { + base = ''; + } + + // Make dates with properties first say the date + if (isDate(value)) { + base = ' ' + value.toUTCString(); + } + + if ($keys.length === 0) { + return braces[0] + base + braces[1]; + } + + if (recurseTimes < 0) { + if (isRegExp(value)) { + return stylize('' + value, 'regexp'); + } else { + return stylize('[Object]', 'special'); + } + } + + seen.push(value); + + var output = map($keys, function (key) { + var name, str; + if (value.__lookupGetter__) { + if (value.__lookupGetter__(key)) { + if (value.__lookupSetter__(key)) { + str = stylize('[Getter/Setter]', 'special'); + } else { + str = stylize('[Getter]', 'special'); + } + } else { + if (value.__lookupSetter__(key)) { + str = stylize('[Setter]', 'special'); + } + } + } + if (indexOf(visible_keys, key) < 0) { + name = '[' + key + ']'; + } + if (!str) { + if (indexOf(seen, value[key]) < 0) { + if (recurseTimes === null) { + str = format(value[key]); + } else { + str = format(value[key], recurseTimes - 1); + } + if (str.indexOf('\n') > -1) { + if (isArray(value)) { + str = map(str.split('\n'), function (line) { + return ' ' + line; + }).join('\n').substr(2); + } else { + str = '\n' + map(str.split('\n'), function (line) { + return ' ' + line; + }).join('\n'); + } + } + } else { + str = stylize('[Circular]', 'special'); + } + } + if (typeof name === 'undefined') { + if (type === 'Array' && key.match(/^\d+$/)) { + return str; + } + name = json.stringify('' + key); + if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) { + name = name.substr(1, name.length - 2); + name = stylize(name, 'name'); + } else { + name = name.replace(/'/g, "\\'") + .replace(/\\"/g, '"') + .replace(/(^"|"$)/g, "'"); + name = stylize(name, 'string'); + } + } + + return name + ': ' + str; + }); + + seen.pop(); + + var numLinesEst = 0; + var length = reduce(output, function (prev, cur) { + numLinesEst++; + if (indexOf(cur, '\n') >= 0) numLinesEst++; + return prev + cur.length + 1; + }, 0); + + if (length > 50) { + output = braces[0] + + (base === '' ? '' : base + '\n ') + + ' ' + + output.join(',\n ') + + ' ' + + braces[1]; + + } else { + output = braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1]; + } + + return output; + } + return format(obj, (typeof depth === 'undefined' ? 2 : depth)); + }; + + function isArray (ar) { + return Object.prototype.toString.call(ar) == '[object Array]'; + }; + + function isRegExp(re) { + var s = '' + re; + return re instanceof RegExp || // easy case + // duck-type for context-switching evalcx case + typeof(re) === 'function' && + re.constructor.name === 'RegExp' && + re.compile && + re.test && + re.exec && + s.match(/^\/.*\/[gim]{0,3}$/); + }; + + function isDate(d) { + if (d instanceof Date) return true; + return false; + }; + + function keys (obj) { + if (Object.keys) { + return Object.keys(obj); + } + + var keys = []; + + for (var i in obj) { + if (Object.prototype.hasOwnProperty.call(obj, i)) { + keys.push(i); + } + } + + return keys; + } + + function map (arr, mapper, that) { + if (Array.prototype.map) { + return Array.prototype.map.call(arr, mapper, that); + } + + var other= new Array(arr.length); + + for (var i= 0, n = arr.length; i= 2) { + var rv = arguments[1]; + } else { + do { + if (i in this) { + rv = this[i++]; + break; + } + + // if array contains no values, no initial value to return + if (++i >= len) + throw new TypeError(); + } while (true); + } + + for (; i < len; i++) { + if (i in this) + rv = fun.call(null, rv, this[i], i, this); + } + + return rv; + }; + + /** + * Asserts deep equality + * + * @see taken from node.js `assert` module (copyright Joyent, MIT license) + * @api private + */ + + expect.eql = function eql (actual, expected) { + // 7.1. All identical values are equivalent, as determined by ===. + if (actual === expected) { + return true; + } else if ('undefined' != typeof Buffer + && Buffer.isBuffer(actual) && Buffer.isBuffer(expected)) { + if (actual.length != expected.length) return false; + + for (var i = 0; i < actual.length; i++) { + if (actual[i] !== expected[i]) return false; + } + + return true; + + // 7.2. If the expected value is a Date object, the actual value is + // equivalent if it is also a Date object that refers to the same time. + } else if (actual instanceof Date && expected instanceof Date) { + return actual.getTime() === expected.getTime(); + + // 7.3. Other pairs that do not both pass typeof value == "object", + // equivalence is determined by ==. + } else if (typeof actual != 'object' && typeof expected != 'object') { + return actual == expected; + + // 7.4. For all other Object pairs, including Array objects, equivalence is + // determined by having the same number of owned properties (as verified + // with Object.prototype.hasOwnProperty.call), the same set of keys + // (although not necessarily the same order), equivalent values for every + // corresponding key, and an identical "prototype" property. Note: this + // accounts for both named and indexed properties on Arrays. + } else { + return objEquiv(actual, expected); + } + } + + function isUndefinedOrNull (value) { + return value === null || value === undefined; + } + + function isArguments (object) { + return Object.prototype.toString.call(object) == '[object Arguments]'; + } + + function objEquiv (a, b) { + if (isUndefinedOrNull(a) || isUndefinedOrNull(b)) + return false; + // an identical "prototype" property. + if (a.prototype !== b.prototype) return false; + //~~~I've managed to break Object.keys through screwy arguments passing. + // Converting to array solves the problem. + if (isArguments(a)) { + if (!isArguments(b)) { + return false; + } + a = pSlice.call(a); + b = pSlice.call(b); + return expect.eql(a, b); + } + try{ + var ka = keys(a), + kb = keys(b), + key, i; + } catch (e) {//happens when one is a string literal and the other isn't + return false; + } + // having the same number of owned properties (keys incorporates hasOwnProperty) + if (ka.length != kb.length) + return false; + //the same set of keys (although not necessarily the same order), + ka.sort(); + kb.sort(); + //~~~cheap key test + for (i = ka.length - 1; i >= 0; i--) { + if (ka[i] != kb[i]) + return false; + } + //equivalent values for every corresponding key, and + //~~~possibly expensive deep test + for (i = ka.length - 1; i >= 0; i--) { + key = ka[i]; + if (!expect.eql(a[key], b[key])) + return false; + } + return true; + } + + var json = (function () { + "use strict"; + + if ('object' == typeof JSON && JSON.parse && JSON.stringify) { + return { + parse: nativeJSON.parse + , stringify: nativeJSON.stringify + } + } + + var JSON = {}; + + function f(n) { + // Format integers to have at least two digits. + return n < 10 ? '0' + n : n; + } + + function date(d, key) { + return isFinite(d.valueOf()) ? + d.getUTCFullYear() + '-' + + f(d.getUTCMonth() + 1) + '-' + + f(d.getUTCDate()) + 'T' + + f(d.getUTCHours()) + ':' + + f(d.getUTCMinutes()) + ':' + + f(d.getUTCSeconds()) + 'Z' : null; + }; + + var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, + escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, + gap, + indent, + meta = { // table of character substitutions + '\b': '\\b', + '\t': '\\t', + '\n': '\\n', + '\f': '\\f', + '\r': '\\r', + '"' : '\\"', + '\\': '\\\\' + }, + rep; + + + function quote(string) { + + // If the string contains no control characters, no quote characters, and no + // backslash characters, then we can safely slap some quotes around it. + // Otherwise we must also replace the offending characters with safe escape + // sequences. + + escapable.lastIndex = 0; + return escapable.test(string) ? '"' + string.replace(escapable, function (a) { + var c = meta[a]; + return typeof c === 'string' ? c : + '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4); + }) + '"' : '"' + string + '"'; + } + + + function str(key, holder) { + + // Produce a string from holder[key]. + + var i, // The loop counter. + k, // The member key. + v, // The member value. + length, + mind = gap, + partial, + value = holder[key]; + + // If the value has a toJSON method, call it to obtain a replacement value. + + if (value instanceof Date) { + value = date(key); + } + + // If we were called with a replacer function, then call the replacer to + // obtain a replacement value. + + if (typeof rep === 'function') { + value = rep.call(holder, key, value); + } + + // What happens next depends on the value's type. + + switch (typeof value) { + case 'string': + return quote(value); + + case 'number': + + // JSON numbers must be finite. Encode non-finite numbers as null. + + return isFinite(value) ? String(value) : 'null'; + + case 'boolean': + case 'null': + + // If the value is a boolean or null, convert it to a string. Note: + // typeof null does not produce 'null'. The case is included here in + // the remote chance that this gets fixed someday. + + return String(value); + + // If the type is 'object', we might be dealing with an object or an array or + // null. + + case 'object': + + // Due to a specification blunder in ECMAScript, typeof null is 'object', + // so watch out for that case. + + if (!value) { + return 'null'; + } + + // Make an array to hold the partial results of stringifying this object value. + + gap += indent; + partial = []; + + // Is the value an array? + + if (Object.prototype.toString.apply(value) === '[object Array]') { + + // The value is an array. Stringify every element. Use null as a placeholder + // for non-JSON values. + + length = value.length; + for (i = 0; i < length; i += 1) { + partial[i] = str(i, value) || 'null'; + } + + // Join all of the elements together, separated with commas, and wrap them in + // brackets. + + v = partial.length === 0 ? '[]' : gap ? + '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' : + '[' + partial.join(',') + ']'; + gap = mind; + return v; + } + + // If the replacer is an array, use it to select the members to be stringified. + + if (rep && typeof rep === 'object') { + length = rep.length; + for (i = 0; i < length; i += 1) { + if (typeof rep[i] === 'string') { + k = rep[i]; + v = str(k, value); + if (v) { + partial.push(quote(k) + (gap ? ': ' : ':') + v); + } + } + } + } else { + + // Otherwise, iterate through all of the keys in the object. + + for (k in value) { + if (Object.prototype.hasOwnProperty.call(value, k)) { + v = str(k, value); + if (v) { + partial.push(quote(k) + (gap ? ': ' : ':') + v); + } + } + } + } + + // Join all of the member texts together, separated with commas, + // and wrap them in braces. + + v = partial.length === 0 ? '{}' : gap ? + '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' : + '{' + partial.join(',') + '}'; + gap = mind; + return v; + } + } + + // If the JSON object does not yet have a stringify method, give it one. + + JSON.stringify = function (value, replacer, space) { + + // The stringify method takes a value and an optional replacer, and an optional + // space parameter, and returns a JSON text. The replacer can be a function + // that can replace values, or an array of strings that will select the keys. + // A default replacer method can be provided. Use of the space parameter can + // produce text that is more easily readable. + + var i; + gap = ''; + indent = ''; + + // If the space parameter is a number, make an indent string containing that + // many spaces. + + if (typeof space === 'number') { + for (i = 0; i < space; i += 1) { + indent += ' '; + } + + // If the space parameter is a string, it will be used as the indent string. + + } else if (typeof space === 'string') { + indent = space; + } + + // If there is a replacer, it must be a function or an array. + // Otherwise, throw an error. + + rep = replacer; + if (replacer && typeof replacer !== 'function' && + (typeof replacer !== 'object' || + typeof replacer.length !== 'number')) { + throw new Error('JSON.stringify'); + } + + // Make a fake root object containing our value under the key of ''. + // Return the result of stringifying the value. + + return str('', {'': value}); + }; + + // If the JSON object does not yet have a parse method, give it one. + + JSON.parse = function (text, reviver) { + // The parse method takes a text and an optional reviver function, and returns + // a JavaScript value if the text is a valid JSON text. + + var j; + + function walk(holder, key) { + + // The walk method is used to recursively walk the resulting structure so + // that modifications can be made. + + var k, v, value = holder[key]; + if (value && typeof value === 'object') { + for (k in value) { + if (Object.prototype.hasOwnProperty.call(value, k)) { + v = walk(value, k); + if (v !== undefined) { + value[k] = v; + } else { + delete value[k]; + } + } + } + } + return reviver.call(holder, key, value); + } + + + // Parsing happens in four stages. In the first stage, we replace certain + // Unicode characters with escape sequences. JavaScript handles many characters + // incorrectly, either silently deleting them, or treating them as line endings. + + text = String(text); + cx.lastIndex = 0; + if (cx.test(text)) { + text = text.replace(cx, function (a) { + return '\\u' + + ('0000' + a.charCodeAt(0).toString(16)).slice(-4); + }); + } + + // In the second stage, we run the text against regular expressions that look + // for non-JSON patterns. We are especially concerned with '()' and 'new' + // because they can cause invocation, and '=' because it can cause mutation. + // But just to be safe, we want to reject all unexpected forms. + + // We split the second stage into 4 regexp operations in order to work around + // crippling inefficiencies in IE's and Safari's regexp engines. First we + // replace the JSON backslash pairs with '@' (a non-JSON character). Second, we + // replace all simple value tokens with ']' characters. Third, we delete all + // open brackets that follow a colon or comma or that begin the text. Finally, + // we look to see that the remaining characters are only whitespace or ']' or + // ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval. + + if (/^[\],:{}\s]*$/ + .test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@') + .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']') + .replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) { + + // In the third stage we use the eval function to compile the text into a + // JavaScript structure. The '{' operator is subject to a syntactic ambiguity + // in JavaScript: it can begin a block or an object literal. We wrap the text + // in parens to eliminate the ambiguity. + + j = eval('(' + text + ')'); + + // In the optional fourth stage, we recursively walk the new structure, passing + // each name/value pair to a reviver function for possible transformation. + + return typeof reviver === 'function' ? + walk({'': j}, '') : j; + } + + // If the text is not JSON parseable, then a SyntaxError is thrown. + + throw new SyntaxError('JSON.parse'); + }; + + return JSON; + })(); + + if ('undefined' != typeof window) { + window.expect = module.exports; + } + +})( + this + , 'undefined' != typeof module ? module : {} + , 'undefined' != typeof exports ? exports : {} +); diff --git a/libs/i18next/test/libs/jquery-1.9.1.min.js b/libs/i18next/test/libs/jquery-1.9.1.min.js new file mode 100644 index 00000000..006e9531 --- /dev/null +++ b/libs/i18next/test/libs/jquery-1.9.1.min.js @@ -0,0 +1,5 @@ +/*! jQuery v1.9.1 | (c) 2005, 2012 jQuery Foundation, Inc. | jquery.org/license +//@ sourceMappingURL=jquery.min.map +*/(function(e,t){var n,r,i=typeof t,o=e.document,a=e.location,s=e.jQuery,u=e.$,l={},c=[],p="1.9.1",f=c.concat,d=c.push,h=c.slice,g=c.indexOf,m=l.toString,y=l.hasOwnProperty,v=p.trim,b=function(e,t){return new b.fn.init(e,t,r)},x=/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source,w=/\S+/g,T=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,N=/^(?:(<[\w\W]+>)[^>]*|#([\w-]*))$/,C=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,k=/^[\],:{}\s]*$/,E=/(?:^|:|,)(?:\s*\[)+/g,S=/\\(?:["\\\/bfnrt]|u[\da-fA-F]{4})/g,A=/"[^"\\\r\n]*"|true|false|null|-?(?:\d+\.|)\d+(?:[eE][+-]?\d+|)/g,j=/^-ms-/,D=/-([\da-z])/gi,L=function(e,t){return t.toUpperCase()},H=function(e){(o.addEventListener||"load"===e.type||"complete"===o.readyState)&&(q(),b.ready())},q=function(){o.addEventListener?(o.removeEventListener("DOMContentLoaded",H,!1),e.removeEventListener("load",H,!1)):(o.detachEvent("onreadystatechange",H),e.detachEvent("onload",H))};b.fn=b.prototype={jquery:p,constructor:b,init:function(e,n,r){var i,a;if(!e)return this;if("string"==typeof e){if(i="<"===e.charAt(0)&&">"===e.charAt(e.length-1)&&e.length>=3?[null,e,null]:N.exec(e),!i||!i[1]&&n)return!n||n.jquery?(n||r).find(e):this.constructor(n).find(e);if(i[1]){if(n=n instanceof b?n[0]:n,b.merge(this,b.parseHTML(i[1],n&&n.nodeType?n.ownerDocument||n:o,!0)),C.test(i[1])&&b.isPlainObject(n))for(i in n)b.isFunction(this[i])?this[i](n[i]):this.attr(i,n[i]);return this}if(a=o.getElementById(i[2]),a&&a.parentNode){if(a.id!==i[2])return r.find(e);this.length=1,this[0]=a}return this.context=o,this.selector=e,this}return e.nodeType?(this.context=this[0]=e,this.length=1,this):b.isFunction(e)?r.ready(e):(e.selector!==t&&(this.selector=e.selector,this.context=e.context),b.makeArray(e,this))},selector:"",length:0,size:function(){return this.length},toArray:function(){return h.call(this)},get:function(e){return null==e?this.toArray():0>e?this[this.length+e]:this[e]},pushStack:function(e){var t=b.merge(this.constructor(),e);return t.prevObject=this,t.context=this.context,t},each:function(e,t){return b.each(this,e,t)},ready:function(e){return b.ready.promise().done(e),this},slice:function(){return this.pushStack(h.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},eq:function(e){var t=this.length,n=+e+(0>e?t:0);return this.pushStack(n>=0&&t>n?[this[n]]:[])},map:function(e){return this.pushStack(b.map(this,function(t,n){return e.call(t,n,t)}))},end:function(){return this.prevObject||this.constructor(null)},push:d,sort:[].sort,splice:[].splice},b.fn.init.prototype=b.fn,b.extend=b.fn.extend=function(){var e,n,r,i,o,a,s=arguments[0]||{},u=1,l=arguments.length,c=!1;for("boolean"==typeof s&&(c=s,s=arguments[1]||{},u=2),"object"==typeof s||b.isFunction(s)||(s={}),l===u&&(s=this,--u);l>u;u++)if(null!=(o=arguments[u]))for(i in o)e=s[i],r=o[i],s!==r&&(c&&r&&(b.isPlainObject(r)||(n=b.isArray(r)))?(n?(n=!1,a=e&&b.isArray(e)?e:[]):a=e&&b.isPlainObject(e)?e:{},s[i]=b.extend(c,a,r)):r!==t&&(s[i]=r));return s},b.extend({noConflict:function(t){return e.$===b&&(e.$=u),t&&e.jQuery===b&&(e.jQuery=s),b},isReady:!1,readyWait:1,holdReady:function(e){e?b.readyWait++:b.ready(!0)},ready:function(e){if(e===!0?!--b.readyWait:!b.isReady){if(!o.body)return setTimeout(b.ready);b.isReady=!0,e!==!0&&--b.readyWait>0||(n.resolveWith(o,[b]),b.fn.trigger&&b(o).trigger("ready").off("ready"))}},isFunction:function(e){return"function"===b.type(e)},isArray:Array.isArray||function(e){return"array"===b.type(e)},isWindow:function(e){return null!=e&&e==e.window},isNumeric:function(e){return!isNaN(parseFloat(e))&&isFinite(e)},type:function(e){return null==e?e+"":"object"==typeof e||"function"==typeof e?l[m.call(e)]||"object":typeof e},isPlainObject:function(e){if(!e||"object"!==b.type(e)||e.nodeType||b.isWindow(e))return!1;try{if(e.constructor&&!y.call(e,"constructor")&&!y.call(e.constructor.prototype,"isPrototypeOf"))return!1}catch(n){return!1}var r;for(r in e);return r===t||y.call(e,r)},isEmptyObject:function(e){var t;for(t in e)return!1;return!0},error:function(e){throw Error(e)},parseHTML:function(e,t,n){if(!e||"string"!=typeof e)return null;"boolean"==typeof t&&(n=t,t=!1),t=t||o;var r=C.exec(e),i=!n&&[];return r?[t.createElement(r[1])]:(r=b.buildFragment([e],t,i),i&&b(i).remove(),b.merge([],r.childNodes))},parseJSON:function(n){return e.JSON&&e.JSON.parse?e.JSON.parse(n):null===n?n:"string"==typeof n&&(n=b.trim(n),n&&k.test(n.replace(S,"@").replace(A,"]").replace(E,"")))?Function("return "+n)():(b.error("Invalid JSON: "+n),t)},parseXML:function(n){var r,i;if(!n||"string"!=typeof n)return null;try{e.DOMParser?(i=new DOMParser,r=i.parseFromString(n,"text/xml")):(r=new ActiveXObject("Microsoft.XMLDOM"),r.async="false",r.loadXML(n))}catch(o){r=t}return r&&r.documentElement&&!r.getElementsByTagName("parsererror").length||b.error("Invalid XML: "+n),r},noop:function(){},globalEval:function(t){t&&b.trim(t)&&(e.execScript||function(t){e.eval.call(e,t)})(t)},camelCase:function(e){return e.replace(j,"ms-").replace(D,L)},nodeName:function(e,t){return e.nodeName&&e.nodeName.toLowerCase()===t.toLowerCase()},each:function(e,t,n){var r,i=0,o=e.length,a=M(e);if(n){if(a){for(;o>i;i++)if(r=t.apply(e[i],n),r===!1)break}else for(i in e)if(r=t.apply(e[i],n),r===!1)break}else if(a){for(;o>i;i++)if(r=t.call(e[i],i,e[i]),r===!1)break}else for(i in e)if(r=t.call(e[i],i,e[i]),r===!1)break;return e},trim:v&&!v.call("\ufeff\u00a0")?function(e){return null==e?"":v.call(e)}:function(e){return null==e?"":(e+"").replace(T,"")},makeArray:function(e,t){var n=t||[];return null!=e&&(M(Object(e))?b.merge(n,"string"==typeof e?[e]:e):d.call(n,e)),n},inArray:function(e,t,n){var r;if(t){if(g)return g.call(t,e,n);for(r=t.length,n=n?0>n?Math.max(0,r+n):n:0;r>n;n++)if(n in t&&t[n]===e)return n}return-1},merge:function(e,n){var r=n.length,i=e.length,o=0;if("number"==typeof r)for(;r>o;o++)e[i++]=n[o];else while(n[o]!==t)e[i++]=n[o++];return e.length=i,e},grep:function(e,t,n){var r,i=[],o=0,a=e.length;for(n=!!n;a>o;o++)r=!!t(e[o],o),n!==r&&i.push(e[o]);return i},map:function(e,t,n){var r,i=0,o=e.length,a=M(e),s=[];if(a)for(;o>i;i++)r=t(e[i],i,n),null!=r&&(s[s.length]=r);else for(i in e)r=t(e[i],i,n),null!=r&&(s[s.length]=r);return f.apply([],s)},guid:1,proxy:function(e,n){var r,i,o;return"string"==typeof n&&(o=e[n],n=e,e=o),b.isFunction(e)?(r=h.call(arguments,2),i=function(){return e.apply(n||this,r.concat(h.call(arguments)))},i.guid=e.guid=e.guid||b.guid++,i):t},access:function(e,n,r,i,o,a,s){var u=0,l=e.length,c=null==r;if("object"===b.type(r)){o=!0;for(u in r)b.access(e,n,u,r[u],!0,a,s)}else if(i!==t&&(o=!0,b.isFunction(i)||(s=!0),c&&(s?(n.call(e,i),n=null):(c=n,n=function(e,t,n){return c.call(b(e),n)})),n))for(;l>u;u++)n(e[u],r,s?i:i.call(e[u],u,n(e[u],r)));return o?e:c?n.call(e):l?n(e[0],r):a},now:function(){return(new Date).getTime()}}),b.ready.promise=function(t){if(!n)if(n=b.Deferred(),"complete"===o.readyState)setTimeout(b.ready);else if(o.addEventListener)o.addEventListener("DOMContentLoaded",H,!1),e.addEventListener("load",H,!1);else{o.attachEvent("onreadystatechange",H),e.attachEvent("onload",H);var r=!1;try{r=null==e.frameElement&&o.documentElement}catch(i){}r&&r.doScroll&&function a(){if(!b.isReady){try{r.doScroll("left")}catch(e){return setTimeout(a,50)}q(),b.ready()}}()}return n.promise(t)},b.each("Boolean Number String Function Array Date RegExp Object Error".split(" "),function(e,t){l["[object "+t+"]"]=t.toLowerCase()});function M(e){var t=e.length,n=b.type(e);return b.isWindow(e)?!1:1===e.nodeType&&t?!0:"array"===n||"function"!==n&&(0===t||"number"==typeof t&&t>0&&t-1 in e)}r=b(o);var _={};function F(e){var t=_[e]={};return b.each(e.match(w)||[],function(e,n){t[n]=!0}),t}b.Callbacks=function(e){e="string"==typeof e?_[e]||F(e):b.extend({},e);var n,r,i,o,a,s,u=[],l=!e.once&&[],c=function(t){for(r=e.memory&&t,i=!0,a=s||0,s=0,o=u.length,n=!0;u&&o>a;a++)if(u[a].apply(t[0],t[1])===!1&&e.stopOnFalse){r=!1;break}n=!1,u&&(l?l.length&&c(l.shift()):r?u=[]:p.disable())},p={add:function(){if(u){var t=u.length;(function i(t){b.each(t,function(t,n){var r=b.type(n);"function"===r?e.unique&&p.has(n)||u.push(n):n&&n.length&&"string"!==r&&i(n)})})(arguments),n?o=u.length:r&&(s=t,c(r))}return this},remove:function(){return u&&b.each(arguments,function(e,t){var r;while((r=b.inArray(t,u,r))>-1)u.splice(r,1),n&&(o>=r&&o--,a>=r&&a--)}),this},has:function(e){return e?b.inArray(e,u)>-1:!(!u||!u.length)},empty:function(){return u=[],this},disable:function(){return u=l=r=t,this},disabled:function(){return!u},lock:function(){return l=t,r||p.disable(),this},locked:function(){return!l},fireWith:function(e,t){return t=t||[],t=[e,t.slice?t.slice():t],!u||i&&!l||(n?l.push(t):c(t)),this},fire:function(){return p.fireWith(this,arguments),this},fired:function(){return!!i}};return p},b.extend({Deferred:function(e){var t=[["resolve","done",b.Callbacks("once memory"),"resolved"],["reject","fail",b.Callbacks("once memory"),"rejected"],["notify","progress",b.Callbacks("memory")]],n="pending",r={state:function(){return n},always:function(){return i.done(arguments).fail(arguments),this},then:function(){var e=arguments;return b.Deferred(function(n){b.each(t,function(t,o){var a=o[0],s=b.isFunction(e[t])&&e[t];i[o[1]](function(){var e=s&&s.apply(this,arguments);e&&b.isFunction(e.promise)?e.promise().done(n.resolve).fail(n.reject).progress(n.notify):n[a+"With"](this===r?n.promise():this,s?[e]:arguments)})}),e=null}).promise()},promise:function(e){return null!=e?b.extend(e,r):r}},i={};return r.pipe=r.then,b.each(t,function(e,o){var a=o[2],s=o[3];r[o[1]]=a.add,s&&a.add(function(){n=s},t[1^e][2].disable,t[2][2].lock),i[o[0]]=function(){return i[o[0]+"With"](this===i?r:this,arguments),this},i[o[0]+"With"]=a.fireWith}),r.promise(i),e&&e.call(i,i),i},when:function(e){var t=0,n=h.call(arguments),r=n.length,i=1!==r||e&&b.isFunction(e.promise)?r:0,o=1===i?e:b.Deferred(),a=function(e,t,n){return function(r){t[e]=this,n[e]=arguments.length>1?h.call(arguments):r,n===s?o.notifyWith(t,n):--i||o.resolveWith(t,n)}},s,u,l;if(r>1)for(s=Array(r),u=Array(r),l=Array(r);r>t;t++)n[t]&&b.isFunction(n[t].promise)?n[t].promise().done(a(t,l,n)).fail(o.reject).progress(a(t,u,s)):--i;return i||o.resolveWith(l,n),o.promise()}}),b.support=function(){var t,n,r,a,s,u,l,c,p,f,d=o.createElement("div");if(d.setAttribute("className","t"),d.innerHTML="
a",n=d.getElementsByTagName("*"),r=d.getElementsByTagName("a")[0],!n||!r||!n.length)return{};s=o.createElement("select"),l=s.appendChild(o.createElement("option")),a=d.getElementsByTagName("input")[0],r.style.cssText="top:1px;float:left;opacity:.5",t={getSetAttribute:"t"!==d.className,leadingWhitespace:3===d.firstChild.nodeType,tbody:!d.getElementsByTagName("tbody").length,htmlSerialize:!!d.getElementsByTagName("link").length,style:/top/.test(r.getAttribute("style")),hrefNormalized:"/a"===r.getAttribute("href"),opacity:/^0.5/.test(r.style.opacity),cssFloat:!!r.style.cssFloat,checkOn:!!a.value,optSelected:l.selected,enctype:!!o.createElement("form").enctype,html5Clone:"<:nav>"!==o.createElement("nav").cloneNode(!0).outerHTML,boxModel:"CSS1Compat"===o.compatMode,deleteExpando:!0,noCloneEvent:!0,inlineBlockNeedsLayout:!1,shrinkWrapBlocks:!1,reliableMarginRight:!0,boxSizingReliable:!0,pixelPosition:!1},a.checked=!0,t.noCloneChecked=a.cloneNode(!0).checked,s.disabled=!0,t.optDisabled=!l.disabled;try{delete d.test}catch(h){t.deleteExpando=!1}a=o.createElement("input"),a.setAttribute("value",""),t.input=""===a.getAttribute("value"),a.value="t",a.setAttribute("type","radio"),t.radioValue="t"===a.value,a.setAttribute("checked","t"),a.setAttribute("name","t"),u=o.createDocumentFragment(),u.appendChild(a),t.appendChecked=a.checked,t.checkClone=u.cloneNode(!0).cloneNode(!0).lastChild.checked,d.attachEvent&&(d.attachEvent("onclick",function(){t.noCloneEvent=!1}),d.cloneNode(!0).click());for(f in{submit:!0,change:!0,focusin:!0})d.setAttribute(c="on"+f,"t"),t[f+"Bubbles"]=c in e||d.attributes[c].expando===!1;return d.style.backgroundClip="content-box",d.cloneNode(!0).style.backgroundClip="",t.clearCloneStyle="content-box"===d.style.backgroundClip,b(function(){var n,r,a,s="padding:0;margin:0;border:0;display:block;box-sizing:content-box;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;",u=o.getElementsByTagName("body")[0];u&&(n=o.createElement("div"),n.style.cssText="border:0;width:0;height:0;position:absolute;top:0;left:-9999px;margin-top:1px",u.appendChild(n).appendChild(d),d.innerHTML="
t
",a=d.getElementsByTagName("td"),a[0].style.cssText="padding:0;margin:0;border:0;display:none",p=0===a[0].offsetHeight,a[0].style.display="",a[1].style.display="none",t.reliableHiddenOffsets=p&&0===a[0].offsetHeight,d.innerHTML="",d.style.cssText="box-sizing:border-box;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;padding:1px;border:1px;display:block;width:4px;margin-top:1%;position:absolute;top:1%;",t.boxSizing=4===d.offsetWidth,t.doesNotIncludeMarginInBodyOffset=1!==u.offsetTop,e.getComputedStyle&&(t.pixelPosition="1%"!==(e.getComputedStyle(d,null)||{}).top,t.boxSizingReliable="4px"===(e.getComputedStyle(d,null)||{width:"4px"}).width,r=d.appendChild(o.createElement("div")),r.style.cssText=d.style.cssText=s,r.style.marginRight=r.style.width="0",d.style.width="1px",t.reliableMarginRight=!parseFloat((e.getComputedStyle(r,null)||{}).marginRight)),typeof d.style.zoom!==i&&(d.innerHTML="",d.style.cssText=s+"width:1px;padding:1px;display:inline;zoom:1",t.inlineBlockNeedsLayout=3===d.offsetWidth,d.style.display="block",d.innerHTML="
",d.firstChild.style.width="5px",t.shrinkWrapBlocks=3!==d.offsetWidth,t.inlineBlockNeedsLayout&&(u.style.zoom=1)),u.removeChild(n),n=d=a=r=null)}),n=s=u=l=r=a=null,t}();var O=/(?:\{[\s\S]*\}|\[[\s\S]*\])$/,B=/([A-Z])/g;function P(e,n,r,i){if(b.acceptData(e)){var o,a,s=b.expando,u="string"==typeof n,l=e.nodeType,p=l?b.cache:e,f=l?e[s]:e[s]&&s;if(f&&p[f]&&(i||p[f].data)||!u||r!==t)return f||(l?e[s]=f=c.pop()||b.guid++:f=s),p[f]||(p[f]={},l||(p[f].toJSON=b.noop)),("object"==typeof n||"function"==typeof n)&&(i?p[f]=b.extend(p[f],n):p[f].data=b.extend(p[f].data,n)),o=p[f],i||(o.data||(o.data={}),o=o.data),r!==t&&(o[b.camelCase(n)]=r),u?(a=o[n],null==a&&(a=o[b.camelCase(n)])):a=o,a}}function R(e,t,n){if(b.acceptData(e)){var r,i,o,a=e.nodeType,s=a?b.cache:e,u=a?e[b.expando]:b.expando;if(s[u]){if(t&&(o=n?s[u]:s[u].data)){b.isArray(t)?t=t.concat(b.map(t,b.camelCase)):t in o?t=[t]:(t=b.camelCase(t),t=t in o?[t]:t.split(" "));for(r=0,i=t.length;i>r;r++)delete o[t[r]];if(!(n?$:b.isEmptyObject)(o))return}(n||(delete s[u].data,$(s[u])))&&(a?b.cleanData([e],!0):b.support.deleteExpando||s!=s.window?delete s[u]:s[u]=null)}}}b.extend({cache:{},expando:"jQuery"+(p+Math.random()).replace(/\D/g,""),noData:{embed:!0,object:"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",applet:!0},hasData:function(e){return e=e.nodeType?b.cache[e[b.expando]]:e[b.expando],!!e&&!$(e)},data:function(e,t,n){return P(e,t,n)},removeData:function(e,t){return R(e,t)},_data:function(e,t,n){return P(e,t,n,!0)},_removeData:function(e,t){return R(e,t,!0)},acceptData:function(e){if(e.nodeType&&1!==e.nodeType&&9!==e.nodeType)return!1;var t=e.nodeName&&b.noData[e.nodeName.toLowerCase()];return!t||t!==!0&&e.getAttribute("classid")===t}}),b.fn.extend({data:function(e,n){var r,i,o=this[0],a=0,s=null;if(e===t){if(this.length&&(s=b.data(o),1===o.nodeType&&!b._data(o,"parsedAttrs"))){for(r=o.attributes;r.length>a;a++)i=r[a].name,i.indexOf("data-")||(i=b.camelCase(i.slice(5)),W(o,i,s[i]));b._data(o,"parsedAttrs",!0)}return s}return"object"==typeof e?this.each(function(){b.data(this,e)}):b.access(this,function(n){return n===t?o?W(o,e,b.data(o,e)):null:(this.each(function(){b.data(this,e,n)}),t)},null,n,arguments.length>1,null,!0)},removeData:function(e){return this.each(function(){b.removeData(this,e)})}});function W(e,n,r){if(r===t&&1===e.nodeType){var i="data-"+n.replace(B,"-$1").toLowerCase();if(r=e.getAttribute(i),"string"==typeof r){try{r="true"===r?!0:"false"===r?!1:"null"===r?null:+r+""===r?+r:O.test(r)?b.parseJSON(r):r}catch(o){}b.data(e,n,r)}else r=t}return r}function $(e){var t;for(t in e)if(("data"!==t||!b.isEmptyObject(e[t]))&&"toJSON"!==t)return!1;return!0}b.extend({queue:function(e,n,r){var i;return e?(n=(n||"fx")+"queue",i=b._data(e,n),r&&(!i||b.isArray(r)?i=b._data(e,n,b.makeArray(r)):i.push(r)),i||[]):t},dequeue:function(e,t){t=t||"fx";var n=b.queue(e,t),r=n.length,i=n.shift(),o=b._queueHooks(e,t),a=function(){b.dequeue(e,t)};"inprogress"===i&&(i=n.shift(),r--),o.cur=i,i&&("fx"===t&&n.unshift("inprogress"),delete o.stop,i.call(e,a,o)),!r&&o&&o.empty.fire()},_queueHooks:function(e,t){var n=t+"queueHooks";return b._data(e,n)||b._data(e,n,{empty:b.Callbacks("once memory").add(function(){b._removeData(e,t+"queue"),b._removeData(e,n)})})}}),b.fn.extend({queue:function(e,n){var r=2;return"string"!=typeof e&&(n=e,e="fx",r--),r>arguments.length?b.queue(this[0],e):n===t?this:this.each(function(){var t=b.queue(this,e,n);b._queueHooks(this,e),"fx"===e&&"inprogress"!==t[0]&&b.dequeue(this,e)})},dequeue:function(e){return this.each(function(){b.dequeue(this,e)})},delay:function(e,t){return e=b.fx?b.fx.speeds[e]||e:e,t=t||"fx",this.queue(t,function(t,n){var r=setTimeout(t,e);n.stop=function(){clearTimeout(r)}})},clearQueue:function(e){return this.queue(e||"fx",[])},promise:function(e,n){var r,i=1,o=b.Deferred(),a=this,s=this.length,u=function(){--i||o.resolveWith(a,[a])};"string"!=typeof e&&(n=e,e=t),e=e||"fx";while(s--)r=b._data(a[s],e+"queueHooks"),r&&r.empty&&(i++,r.empty.add(u));return u(),o.promise(n)}});var I,z,X=/[\t\r\n]/g,U=/\r/g,V=/^(?:input|select|textarea|button|object)$/i,Y=/^(?:a|area)$/i,J=/^(?:checked|selected|autofocus|autoplay|async|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped)$/i,G=/^(?:checked|selected)$/i,Q=b.support.getSetAttribute,K=b.support.input;b.fn.extend({attr:function(e,t){return b.access(this,b.attr,e,t,arguments.length>1)},removeAttr:function(e){return this.each(function(){b.removeAttr(this,e)})},prop:function(e,t){return b.access(this,b.prop,e,t,arguments.length>1)},removeProp:function(e){return e=b.propFix[e]||e,this.each(function(){try{this[e]=t,delete this[e]}catch(n){}})},addClass:function(e){var t,n,r,i,o,a=0,s=this.length,u="string"==typeof e&&e;if(b.isFunction(e))return this.each(function(t){b(this).addClass(e.call(this,t,this.className))});if(u)for(t=(e||"").match(w)||[];s>a;a++)if(n=this[a],r=1===n.nodeType&&(n.className?(" "+n.className+" ").replace(X," "):" ")){o=0;while(i=t[o++])0>r.indexOf(" "+i+" ")&&(r+=i+" ");n.className=b.trim(r)}return this},removeClass:function(e){var t,n,r,i,o,a=0,s=this.length,u=0===arguments.length||"string"==typeof e&&e;if(b.isFunction(e))return this.each(function(t){b(this).removeClass(e.call(this,t,this.className))});if(u)for(t=(e||"").match(w)||[];s>a;a++)if(n=this[a],r=1===n.nodeType&&(n.className?(" "+n.className+" ").replace(X," "):"")){o=0;while(i=t[o++])while(r.indexOf(" "+i+" ")>=0)r=r.replace(" "+i+" "," ");n.className=e?b.trim(r):""}return this},toggleClass:function(e,t){var n=typeof e,r="boolean"==typeof t;return b.isFunction(e)?this.each(function(n){b(this).toggleClass(e.call(this,n,this.className,t),t)}):this.each(function(){if("string"===n){var o,a=0,s=b(this),u=t,l=e.match(w)||[];while(o=l[a++])u=r?u:!s.hasClass(o),s[u?"addClass":"removeClass"](o)}else(n===i||"boolean"===n)&&(this.className&&b._data(this,"__className__",this.className),this.className=this.className||e===!1?"":b._data(this,"__className__")||"")})},hasClass:function(e){var t=" "+e+" ",n=0,r=this.length;for(;r>n;n++)if(1===this[n].nodeType&&(" "+this[n].className+" ").replace(X," ").indexOf(t)>=0)return!0;return!1},val:function(e){var n,r,i,o=this[0];{if(arguments.length)return i=b.isFunction(e),this.each(function(n){var o,a=b(this);1===this.nodeType&&(o=i?e.call(this,n,a.val()):e,null==o?o="":"number"==typeof o?o+="":b.isArray(o)&&(o=b.map(o,function(e){return null==e?"":e+""})),r=b.valHooks[this.type]||b.valHooks[this.nodeName.toLowerCase()],r&&"set"in r&&r.set(this,o,"value")!==t||(this.value=o))});if(o)return r=b.valHooks[o.type]||b.valHooks[o.nodeName.toLowerCase()],r&&"get"in r&&(n=r.get(o,"value"))!==t?n:(n=o.value,"string"==typeof n?n.replace(U,""):null==n?"":n)}}}),b.extend({valHooks:{option:{get:function(e){var t=e.attributes.value;return!t||t.specified?e.value:e.text}},select:{get:function(e){var t,n,r=e.options,i=e.selectedIndex,o="select-one"===e.type||0>i,a=o?null:[],s=o?i+1:r.length,u=0>i?s:o?i:0;for(;s>u;u++)if(n=r[u],!(!n.selected&&u!==i||(b.support.optDisabled?n.disabled:null!==n.getAttribute("disabled"))||n.parentNode.disabled&&b.nodeName(n.parentNode,"optgroup"))){if(t=b(n).val(),o)return t;a.push(t)}return a},set:function(e,t){var n=b.makeArray(t);return b(e).find("option").each(function(){this.selected=b.inArray(b(this).val(),n)>=0}),n.length||(e.selectedIndex=-1),n}}},attr:function(e,n,r){var o,a,s,u=e.nodeType;if(e&&3!==u&&8!==u&&2!==u)return typeof e.getAttribute===i?b.prop(e,n,r):(a=1!==u||!b.isXMLDoc(e),a&&(n=n.toLowerCase(),o=b.attrHooks[n]||(J.test(n)?z:I)),r===t?o&&a&&"get"in o&&null!==(s=o.get(e,n))?s:(typeof e.getAttribute!==i&&(s=e.getAttribute(n)),null==s?t:s):null!==r?o&&a&&"set"in o&&(s=o.set(e,r,n))!==t?s:(e.setAttribute(n,r+""),r):(b.removeAttr(e,n),t))},removeAttr:function(e,t){var n,r,i=0,o=t&&t.match(w);if(o&&1===e.nodeType)while(n=o[i++])r=b.propFix[n]||n,J.test(n)?!Q&&G.test(n)?e[b.camelCase("default-"+n)]=e[r]=!1:e[r]=!1:b.attr(e,n,""),e.removeAttribute(Q?n:r)},attrHooks:{type:{set:function(e,t){if(!b.support.radioValue&&"radio"===t&&b.nodeName(e,"input")){var n=e.value;return e.setAttribute("type",t),n&&(e.value=n),t}}}},propFix:{tabindex:"tabIndex",readonly:"readOnly","for":"htmlFor","class":"className",maxlength:"maxLength",cellspacing:"cellSpacing",cellpadding:"cellPadding",rowspan:"rowSpan",colspan:"colSpan",usemap:"useMap",frameborder:"frameBorder",contenteditable:"contentEditable"},prop:function(e,n,r){var i,o,a,s=e.nodeType;if(e&&3!==s&&8!==s&&2!==s)return a=1!==s||!b.isXMLDoc(e),a&&(n=b.propFix[n]||n,o=b.propHooks[n]),r!==t?o&&"set"in o&&(i=o.set(e,r,n))!==t?i:e[n]=r:o&&"get"in o&&null!==(i=o.get(e,n))?i:e[n]},propHooks:{tabIndex:{get:function(e){var n=e.getAttributeNode("tabindex");return n&&n.specified?parseInt(n.value,10):V.test(e.nodeName)||Y.test(e.nodeName)&&e.href?0:t}}}}),z={get:function(e,n){var r=b.prop(e,n),i="boolean"==typeof r&&e.getAttribute(n),o="boolean"==typeof r?K&&Q?null!=i:G.test(n)?e[b.camelCase("default-"+n)]:!!i:e.getAttributeNode(n);return o&&o.value!==!1?n.toLowerCase():t},set:function(e,t,n){return t===!1?b.removeAttr(e,n):K&&Q||!G.test(n)?e.setAttribute(!Q&&b.propFix[n]||n,n):e[b.camelCase("default-"+n)]=e[n]=!0,n}},K&&Q||(b.attrHooks.value={get:function(e,n){var r=e.getAttributeNode(n);return b.nodeName(e,"input")?e.defaultValue:r&&r.specified?r.value:t},set:function(e,n,r){return b.nodeName(e,"input")?(e.defaultValue=n,t):I&&I.set(e,n,r)}}),Q||(I=b.valHooks.button={get:function(e,n){var r=e.getAttributeNode(n);return r&&("id"===n||"name"===n||"coords"===n?""!==r.value:r.specified)?r.value:t},set:function(e,n,r){var i=e.getAttributeNode(r);return i||e.setAttributeNode(i=e.ownerDocument.createAttribute(r)),i.value=n+="","value"===r||n===e.getAttribute(r)?n:t}},b.attrHooks.contenteditable={get:I.get,set:function(e,t,n){I.set(e,""===t?!1:t,n)}},b.each(["width","height"],function(e,n){b.attrHooks[n]=b.extend(b.attrHooks[n],{set:function(e,r){return""===r?(e.setAttribute(n,"auto"),r):t}})})),b.support.hrefNormalized||(b.each(["href","src","width","height"],function(e,n){b.attrHooks[n]=b.extend(b.attrHooks[n],{get:function(e){var r=e.getAttribute(n,2);return null==r?t:r}})}),b.each(["href","src"],function(e,t){b.propHooks[t]={get:function(e){return e.getAttribute(t,4)}}})),b.support.style||(b.attrHooks.style={get:function(e){return e.style.cssText||t},set:function(e,t){return e.style.cssText=t+""}}),b.support.optSelected||(b.propHooks.selected=b.extend(b.propHooks.selected,{get:function(e){var t=e.parentNode;return t&&(t.selectedIndex,t.parentNode&&t.parentNode.selectedIndex),null}})),b.support.enctype||(b.propFix.enctype="encoding"),b.support.checkOn||b.each(["radio","checkbox"],function(){b.valHooks[this]={get:function(e){return null===e.getAttribute("value")?"on":e.value}}}),b.each(["radio","checkbox"],function(){b.valHooks[this]=b.extend(b.valHooks[this],{set:function(e,n){return b.isArray(n)?e.checked=b.inArray(b(e).val(),n)>=0:t}})});var Z=/^(?:input|select|textarea)$/i,et=/^key/,tt=/^(?:mouse|contextmenu)|click/,nt=/^(?:focusinfocus|focusoutblur)$/,rt=/^([^.]*)(?:\.(.+)|)$/;function it(){return!0}function ot(){return!1}b.event={global:{},add:function(e,n,r,o,a){var s,u,l,c,p,f,d,h,g,m,y,v=b._data(e);if(v){r.handler&&(c=r,r=c.handler,a=c.selector),r.guid||(r.guid=b.guid++),(u=v.events)||(u=v.events={}),(f=v.handle)||(f=v.handle=function(e){return typeof b===i||e&&b.event.triggered===e.type?t:b.event.dispatch.apply(f.elem,arguments)},f.elem=e),n=(n||"").match(w)||[""],l=n.length;while(l--)s=rt.exec(n[l])||[],g=y=s[1],m=(s[2]||"").split(".").sort(),p=b.event.special[g]||{},g=(a?p.delegateType:p.bindType)||g,p=b.event.special[g]||{},d=b.extend({type:g,origType:y,data:o,handler:r,guid:r.guid,selector:a,needsContext:a&&b.expr.match.needsContext.test(a),namespace:m.join(".")},c),(h=u[g])||(h=u[g]=[],h.delegateCount=0,p.setup&&p.setup.call(e,o,m,f)!==!1||(e.addEventListener?e.addEventListener(g,f,!1):e.attachEvent&&e.attachEvent("on"+g,f))),p.add&&(p.add.call(e,d),d.handler.guid||(d.handler.guid=r.guid)),a?h.splice(h.delegateCount++,0,d):h.push(d),b.event.global[g]=!0;e=null}},remove:function(e,t,n,r,i){var o,a,s,u,l,c,p,f,d,h,g,m=b.hasData(e)&&b._data(e);if(m&&(c=m.events)){t=(t||"").match(w)||[""],l=t.length;while(l--)if(s=rt.exec(t[l])||[],d=g=s[1],h=(s[2]||"").split(".").sort(),d){p=b.event.special[d]||{},d=(r?p.delegateType:p.bindType)||d,f=c[d]||[],s=s[2]&&RegExp("(^|\\.)"+h.join("\\.(?:.*\\.|)")+"(\\.|$)"),u=o=f.length;while(o--)a=f[o],!i&&g!==a.origType||n&&n.guid!==a.guid||s&&!s.test(a.namespace)||r&&r!==a.selector&&("**"!==r||!a.selector)||(f.splice(o,1),a.selector&&f.delegateCount--,p.remove&&p.remove.call(e,a));u&&!f.length&&(p.teardown&&p.teardown.call(e,h,m.handle)!==!1||b.removeEvent(e,d,m.handle),delete c[d])}else for(d in c)b.event.remove(e,d+t[l],n,r,!0);b.isEmptyObject(c)&&(delete m.handle,b._removeData(e,"events"))}},trigger:function(n,r,i,a){var s,u,l,c,p,f,d,h=[i||o],g=y.call(n,"type")?n.type:n,m=y.call(n,"namespace")?n.namespace.split("."):[];if(l=f=i=i||o,3!==i.nodeType&&8!==i.nodeType&&!nt.test(g+b.event.triggered)&&(g.indexOf(".")>=0&&(m=g.split("."),g=m.shift(),m.sort()),u=0>g.indexOf(":")&&"on"+g,n=n[b.expando]?n:new b.Event(g,"object"==typeof n&&n),n.isTrigger=!0,n.namespace=m.join("."),n.namespace_re=n.namespace?RegExp("(^|\\.)"+m.join("\\.(?:.*\\.|)")+"(\\.|$)"):null,n.result=t,n.target||(n.target=i),r=null==r?[n]:b.makeArray(r,[n]),p=b.event.special[g]||{},a||!p.trigger||p.trigger.apply(i,r)!==!1)){if(!a&&!p.noBubble&&!b.isWindow(i)){for(c=p.delegateType||g,nt.test(c+g)||(l=l.parentNode);l;l=l.parentNode)h.push(l),f=l;f===(i.ownerDocument||o)&&h.push(f.defaultView||f.parentWindow||e)}d=0;while((l=h[d++])&&!n.isPropagationStopped())n.type=d>1?c:p.bindType||g,s=(b._data(l,"events")||{})[n.type]&&b._data(l,"handle"),s&&s.apply(l,r),s=u&&l[u],s&&b.acceptData(l)&&s.apply&&s.apply(l,r)===!1&&n.preventDefault();if(n.type=g,!(a||n.isDefaultPrevented()||p._default&&p._default.apply(i.ownerDocument,r)!==!1||"click"===g&&b.nodeName(i,"a")||!b.acceptData(i)||!u||!i[g]||b.isWindow(i))){f=i[u],f&&(i[u]=null),b.event.triggered=g;try{i[g]()}catch(v){}b.event.triggered=t,f&&(i[u]=f)}return n.result}},dispatch:function(e){e=b.event.fix(e);var n,r,i,o,a,s=[],u=h.call(arguments),l=(b._data(this,"events")||{})[e.type]||[],c=b.event.special[e.type]||{};if(u[0]=e,e.delegateTarget=this,!c.preDispatch||c.preDispatch.call(this,e)!==!1){s=b.event.handlers.call(this,e,l),n=0;while((o=s[n++])&&!e.isPropagationStopped()){e.currentTarget=o.elem,a=0;while((i=o.handlers[a++])&&!e.isImmediatePropagationStopped())(!e.namespace_re||e.namespace_re.test(i.namespace))&&(e.handleObj=i,e.data=i.data,r=((b.event.special[i.origType]||{}).handle||i.handler).apply(o.elem,u),r!==t&&(e.result=r)===!1&&(e.preventDefault(),e.stopPropagation()))}return c.postDispatch&&c.postDispatch.call(this,e),e.result}},handlers:function(e,n){var r,i,o,a,s=[],u=n.delegateCount,l=e.target;if(u&&l.nodeType&&(!e.button||"click"!==e.type))for(;l!=this;l=l.parentNode||this)if(1===l.nodeType&&(l.disabled!==!0||"click"!==e.type)){for(o=[],a=0;u>a;a++)i=n[a],r=i.selector+" ",o[r]===t&&(o[r]=i.needsContext?b(r,this).index(l)>=0:b.find(r,this,null,[l]).length),o[r]&&o.push(i);o.length&&s.push({elem:l,handlers:o})}return n.length>u&&s.push({elem:this,handlers:n.slice(u)}),s},fix:function(e){if(e[b.expando])return e;var t,n,r,i=e.type,a=e,s=this.fixHooks[i];s||(this.fixHooks[i]=s=tt.test(i)?this.mouseHooks:et.test(i)?this.keyHooks:{}),r=s.props?this.props.concat(s.props):this.props,e=new b.Event(a),t=r.length;while(t--)n=r[t],e[n]=a[n];return e.target||(e.target=a.srcElement||o),3===e.target.nodeType&&(e.target=e.target.parentNode),e.metaKey=!!e.metaKey,s.filter?s.filter(e,a):e},props:"altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),fixHooks:{},keyHooks:{props:"char charCode key keyCode".split(" "),filter:function(e,t){return null==e.which&&(e.which=null!=t.charCode?t.charCode:t.keyCode),e}},mouseHooks:{props:"button buttons clientX clientY fromElement offsetX offsetY pageX pageY screenX screenY toElement".split(" "),filter:function(e,n){var r,i,a,s=n.button,u=n.fromElement;return null==e.pageX&&null!=n.clientX&&(i=e.target.ownerDocument||o,a=i.documentElement,r=i.body,e.pageX=n.clientX+(a&&a.scrollLeft||r&&r.scrollLeft||0)-(a&&a.clientLeft||r&&r.clientLeft||0),e.pageY=n.clientY+(a&&a.scrollTop||r&&r.scrollTop||0)-(a&&a.clientTop||r&&r.clientTop||0)),!e.relatedTarget&&u&&(e.relatedTarget=u===e.target?n.toElement:u),e.which||s===t||(e.which=1&s?1:2&s?3:4&s?2:0),e}},special:{load:{noBubble:!0},click:{trigger:function(){return b.nodeName(this,"input")&&"checkbox"===this.type&&this.click?(this.click(),!1):t}},focus:{trigger:function(){if(this!==o.activeElement&&this.focus)try{return this.focus(),!1}catch(e){}},delegateType:"focusin"},blur:{trigger:function(){return this===o.activeElement&&this.blur?(this.blur(),!1):t},delegateType:"focusout"},beforeunload:{postDispatch:function(e){e.result!==t&&(e.originalEvent.returnValue=e.result)}}},simulate:function(e,t,n,r){var i=b.extend(new b.Event,n,{type:e,isSimulated:!0,originalEvent:{}});r?b.event.trigger(i,null,t):b.event.dispatch.call(t,i),i.isDefaultPrevented()&&n.preventDefault()}},b.removeEvent=o.removeEventListener?function(e,t,n){e.removeEventListener&&e.removeEventListener(t,n,!1)}:function(e,t,n){var r="on"+t;e.detachEvent&&(typeof e[r]===i&&(e[r]=null),e.detachEvent(r,n))},b.Event=function(e,n){return this instanceof b.Event?(e&&e.type?(this.originalEvent=e,this.type=e.type,this.isDefaultPrevented=e.defaultPrevented||e.returnValue===!1||e.getPreventDefault&&e.getPreventDefault()?it:ot):this.type=e,n&&b.extend(this,n),this.timeStamp=e&&e.timeStamp||b.now(),this[b.expando]=!0,t):new b.Event(e,n)},b.Event.prototype={isDefaultPrevented:ot,isPropagationStopped:ot,isImmediatePropagationStopped:ot,preventDefault:function(){var e=this.originalEvent;this.isDefaultPrevented=it,e&&(e.preventDefault?e.preventDefault():e.returnValue=!1)},stopPropagation:function(){var e=this.originalEvent;this.isPropagationStopped=it,e&&(e.stopPropagation&&e.stopPropagation(),e.cancelBubble=!0)},stopImmediatePropagation:function(){this.isImmediatePropagationStopped=it,this.stopPropagation()}},b.each({mouseenter:"mouseover",mouseleave:"mouseout"},function(e,t){b.event.special[e]={delegateType:t,bindType:t,handle:function(e){var n,r=this,i=e.relatedTarget,o=e.handleObj; +return(!i||i!==r&&!b.contains(r,i))&&(e.type=o.origType,n=o.handler.apply(this,arguments),e.type=t),n}}}),b.support.submitBubbles||(b.event.special.submit={setup:function(){return b.nodeName(this,"form")?!1:(b.event.add(this,"click._submit keypress._submit",function(e){var n=e.target,r=b.nodeName(n,"input")||b.nodeName(n,"button")?n.form:t;r&&!b._data(r,"submitBubbles")&&(b.event.add(r,"submit._submit",function(e){e._submit_bubble=!0}),b._data(r,"submitBubbles",!0))}),t)},postDispatch:function(e){e._submit_bubble&&(delete e._submit_bubble,this.parentNode&&!e.isTrigger&&b.event.simulate("submit",this.parentNode,e,!0))},teardown:function(){return b.nodeName(this,"form")?!1:(b.event.remove(this,"._submit"),t)}}),b.support.changeBubbles||(b.event.special.change={setup:function(){return Z.test(this.nodeName)?(("checkbox"===this.type||"radio"===this.type)&&(b.event.add(this,"propertychange._change",function(e){"checked"===e.originalEvent.propertyName&&(this._just_changed=!0)}),b.event.add(this,"click._change",function(e){this._just_changed&&!e.isTrigger&&(this._just_changed=!1),b.event.simulate("change",this,e,!0)})),!1):(b.event.add(this,"beforeactivate._change",function(e){var t=e.target;Z.test(t.nodeName)&&!b._data(t,"changeBubbles")&&(b.event.add(t,"change._change",function(e){!this.parentNode||e.isSimulated||e.isTrigger||b.event.simulate("change",this.parentNode,e,!0)}),b._data(t,"changeBubbles",!0))}),t)},handle:function(e){var n=e.target;return this!==n||e.isSimulated||e.isTrigger||"radio"!==n.type&&"checkbox"!==n.type?e.handleObj.handler.apply(this,arguments):t},teardown:function(){return b.event.remove(this,"._change"),!Z.test(this.nodeName)}}),b.support.focusinBubbles||b.each({focus:"focusin",blur:"focusout"},function(e,t){var n=0,r=function(e){b.event.simulate(t,e.target,b.event.fix(e),!0)};b.event.special[t]={setup:function(){0===n++&&o.addEventListener(e,r,!0)},teardown:function(){0===--n&&o.removeEventListener(e,r,!0)}}}),b.fn.extend({on:function(e,n,r,i,o){var a,s;if("object"==typeof e){"string"!=typeof n&&(r=r||n,n=t);for(a in e)this.on(a,n,r,e[a],o);return this}if(null==r&&null==i?(i=n,r=n=t):null==i&&("string"==typeof n?(i=r,r=t):(i=r,r=n,n=t)),i===!1)i=ot;else if(!i)return this;return 1===o&&(s=i,i=function(e){return b().off(e),s.apply(this,arguments)},i.guid=s.guid||(s.guid=b.guid++)),this.each(function(){b.event.add(this,e,i,r,n)})},one:function(e,t,n,r){return this.on(e,t,n,r,1)},off:function(e,n,r){var i,o;if(e&&e.preventDefault&&e.handleObj)return i=e.handleObj,b(e.delegateTarget).off(i.namespace?i.origType+"."+i.namespace:i.origType,i.selector,i.handler),this;if("object"==typeof e){for(o in e)this.off(o,n,e[o]);return this}return(n===!1||"function"==typeof n)&&(r=n,n=t),r===!1&&(r=ot),this.each(function(){b.event.remove(this,e,r,n)})},bind:function(e,t,n){return this.on(e,null,t,n)},unbind:function(e,t){return this.off(e,null,t)},delegate:function(e,t,n,r){return this.on(t,e,n,r)},undelegate:function(e,t,n){return 1===arguments.length?this.off(e,"**"):this.off(t,e||"**",n)},trigger:function(e,t){return this.each(function(){b.event.trigger(e,t,this)})},triggerHandler:function(e,n){var r=this[0];return r?b.event.trigger(e,n,r,!0):t}}),function(e,t){var n,r,i,o,a,s,u,l,c,p,f,d,h,g,m,y,v,x="sizzle"+-new Date,w=e.document,T={},N=0,C=0,k=it(),E=it(),S=it(),A=typeof t,j=1<<31,D=[],L=D.pop,H=D.push,q=D.slice,M=D.indexOf||function(e){var t=0,n=this.length;for(;n>t;t++)if(this[t]===e)return t;return-1},_="[\\x20\\t\\r\\n\\f]",F="(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",O=F.replace("w","w#"),B="([*^$|!~]?=)",P="\\["+_+"*("+F+")"+_+"*(?:"+B+_+"*(?:(['\"])((?:\\\\.|[^\\\\])*?)\\3|("+O+")|)|)"+_+"*\\]",R=":("+F+")(?:\\(((['\"])((?:\\\\.|[^\\\\])*?)\\3|((?:\\\\.|[^\\\\()[\\]]|"+P.replace(3,8)+")*)|.*)\\)|)",W=RegExp("^"+_+"+|((?:^|[^\\\\])(?:\\\\.)*)"+_+"+$","g"),$=RegExp("^"+_+"*,"+_+"*"),I=RegExp("^"+_+"*([\\x20\\t\\r\\n\\f>+~])"+_+"*"),z=RegExp(R),X=RegExp("^"+O+"$"),U={ID:RegExp("^#("+F+")"),CLASS:RegExp("^\\.("+F+")"),NAME:RegExp("^\\[name=['\"]?("+F+")['\"]?\\]"),TAG:RegExp("^("+F.replace("w","w*")+")"),ATTR:RegExp("^"+P),PSEUDO:RegExp("^"+R),CHILD:RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+_+"*(even|odd|(([+-]|)(\\d*)n|)"+_+"*(?:([+-]|)"+_+"*(\\d+)|))"+_+"*\\)|)","i"),needsContext:RegExp("^"+_+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+_+"*((?:-\\d)?\\d*)"+_+"*\\)|)(?=[^-]|$)","i")},V=/[\x20\t\r\n\f]*[+~]/,Y=/^[^{]+\{\s*\[native code/,J=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,G=/^(?:input|select|textarea|button)$/i,Q=/^h\d$/i,K=/'|\\/g,Z=/\=[\x20\t\r\n\f]*([^'"\]]*)[\x20\t\r\n\f]*\]/g,et=/\\([\da-fA-F]{1,6}[\x20\t\r\n\f]?|.)/g,tt=function(e,t){var n="0x"+t-65536;return n!==n?t:0>n?String.fromCharCode(n+65536):String.fromCharCode(55296|n>>10,56320|1023&n)};try{q.call(w.documentElement.childNodes,0)[0].nodeType}catch(nt){q=function(e){var t,n=[];while(t=this[e++])n.push(t);return n}}function rt(e){return Y.test(e+"")}function it(){var e,t=[];return e=function(n,r){return t.push(n+=" ")>i.cacheLength&&delete e[t.shift()],e[n]=r}}function ot(e){return e[x]=!0,e}function at(e){var t=p.createElement("div");try{return e(t)}catch(n){return!1}finally{t=null}}function st(e,t,n,r){var i,o,a,s,u,l,f,g,m,v;if((t?t.ownerDocument||t:w)!==p&&c(t),t=t||p,n=n||[],!e||"string"!=typeof e)return n;if(1!==(s=t.nodeType)&&9!==s)return[];if(!d&&!r){if(i=J.exec(e))if(a=i[1]){if(9===s){if(o=t.getElementById(a),!o||!o.parentNode)return n;if(o.id===a)return n.push(o),n}else if(t.ownerDocument&&(o=t.ownerDocument.getElementById(a))&&y(t,o)&&o.id===a)return n.push(o),n}else{if(i[2])return H.apply(n,q.call(t.getElementsByTagName(e),0)),n;if((a=i[3])&&T.getByClassName&&t.getElementsByClassName)return H.apply(n,q.call(t.getElementsByClassName(a),0)),n}if(T.qsa&&!h.test(e)){if(f=!0,g=x,m=t,v=9===s&&e,1===s&&"object"!==t.nodeName.toLowerCase()){l=ft(e),(f=t.getAttribute("id"))?g=f.replace(K,"\\$&"):t.setAttribute("id",g),g="[id='"+g+"'] ",u=l.length;while(u--)l[u]=g+dt(l[u]);m=V.test(e)&&t.parentNode||t,v=l.join(",")}if(v)try{return H.apply(n,q.call(m.querySelectorAll(v),0)),n}catch(b){}finally{f||t.removeAttribute("id")}}}return wt(e.replace(W,"$1"),t,n,r)}a=st.isXML=function(e){var t=e&&(e.ownerDocument||e).documentElement;return t?"HTML"!==t.nodeName:!1},c=st.setDocument=function(e){var n=e?e.ownerDocument||e:w;return n!==p&&9===n.nodeType&&n.documentElement?(p=n,f=n.documentElement,d=a(n),T.tagNameNoComments=at(function(e){return e.appendChild(n.createComment("")),!e.getElementsByTagName("*").length}),T.attributes=at(function(e){e.innerHTML="";var t=typeof e.lastChild.getAttribute("multiple");return"boolean"!==t&&"string"!==t}),T.getByClassName=at(function(e){return e.innerHTML="",e.getElementsByClassName&&e.getElementsByClassName("e").length?(e.lastChild.className="e",2===e.getElementsByClassName("e").length):!1}),T.getByName=at(function(e){e.id=x+0,e.innerHTML="
",f.insertBefore(e,f.firstChild);var t=n.getElementsByName&&n.getElementsByName(x).length===2+n.getElementsByName(x+0).length;return T.getIdNotName=!n.getElementById(x),f.removeChild(e),t}),i.attrHandle=at(function(e){return e.innerHTML="",e.firstChild&&typeof e.firstChild.getAttribute!==A&&"#"===e.firstChild.getAttribute("href")})?{}:{href:function(e){return e.getAttribute("href",2)},type:function(e){return e.getAttribute("type")}},T.getIdNotName?(i.find.ID=function(e,t){if(typeof t.getElementById!==A&&!d){var n=t.getElementById(e);return n&&n.parentNode?[n]:[]}},i.filter.ID=function(e){var t=e.replace(et,tt);return function(e){return e.getAttribute("id")===t}}):(i.find.ID=function(e,n){if(typeof n.getElementById!==A&&!d){var r=n.getElementById(e);return r?r.id===e||typeof r.getAttributeNode!==A&&r.getAttributeNode("id").value===e?[r]:t:[]}},i.filter.ID=function(e){var t=e.replace(et,tt);return function(e){var n=typeof e.getAttributeNode!==A&&e.getAttributeNode("id");return n&&n.value===t}}),i.find.TAG=T.tagNameNoComments?function(e,n){return typeof n.getElementsByTagName!==A?n.getElementsByTagName(e):t}:function(e,t){var n,r=[],i=0,o=t.getElementsByTagName(e);if("*"===e){while(n=o[i++])1===n.nodeType&&r.push(n);return r}return o},i.find.NAME=T.getByName&&function(e,n){return typeof n.getElementsByName!==A?n.getElementsByName(name):t},i.find.CLASS=T.getByClassName&&function(e,n){return typeof n.getElementsByClassName===A||d?t:n.getElementsByClassName(e)},g=[],h=[":focus"],(T.qsa=rt(n.querySelectorAll))&&(at(function(e){e.innerHTML="",e.querySelectorAll("[selected]").length||h.push("\\["+_+"*(?:checked|disabled|ismap|multiple|readonly|selected|value)"),e.querySelectorAll(":checked").length||h.push(":checked")}),at(function(e){e.innerHTML="",e.querySelectorAll("[i^='']").length&&h.push("[*^$]="+_+"*(?:\"\"|'')"),e.querySelectorAll(":enabled").length||h.push(":enabled",":disabled"),e.querySelectorAll("*,:x"),h.push(",.*:")})),(T.matchesSelector=rt(m=f.matchesSelector||f.mozMatchesSelector||f.webkitMatchesSelector||f.oMatchesSelector||f.msMatchesSelector))&&at(function(e){T.disconnectedMatch=m.call(e,"div"),m.call(e,"[s!='']:x"),g.push("!=",R)}),h=RegExp(h.join("|")),g=RegExp(g.join("|")),y=rt(f.contains)||f.compareDocumentPosition?function(e,t){var n=9===e.nodeType?e.documentElement:e,r=t&&t.parentNode;return e===r||!(!r||1!==r.nodeType||!(n.contains?n.contains(r):e.compareDocumentPosition&&16&e.compareDocumentPosition(r)))}:function(e,t){if(t)while(t=t.parentNode)if(t===e)return!0;return!1},v=f.compareDocumentPosition?function(e,t){var r;return e===t?(u=!0,0):(r=t.compareDocumentPosition&&e.compareDocumentPosition&&e.compareDocumentPosition(t))?1&r||e.parentNode&&11===e.parentNode.nodeType?e===n||y(w,e)?-1:t===n||y(w,t)?1:0:4&r?-1:1:e.compareDocumentPosition?-1:1}:function(e,t){var r,i=0,o=e.parentNode,a=t.parentNode,s=[e],l=[t];if(e===t)return u=!0,0;if(!o||!a)return e===n?-1:t===n?1:o?-1:a?1:0;if(o===a)return ut(e,t);r=e;while(r=r.parentNode)s.unshift(r);r=t;while(r=r.parentNode)l.unshift(r);while(s[i]===l[i])i++;return i?ut(s[i],l[i]):s[i]===w?-1:l[i]===w?1:0},u=!1,[0,0].sort(v),T.detectDuplicates=u,p):p},st.matches=function(e,t){return st(e,null,null,t)},st.matchesSelector=function(e,t){if((e.ownerDocument||e)!==p&&c(e),t=t.replace(Z,"='$1']"),!(!T.matchesSelector||d||g&&g.test(t)||h.test(t)))try{var n=m.call(e,t);if(n||T.disconnectedMatch||e.document&&11!==e.document.nodeType)return n}catch(r){}return st(t,p,null,[e]).length>0},st.contains=function(e,t){return(e.ownerDocument||e)!==p&&c(e),y(e,t)},st.attr=function(e,t){var n;return(e.ownerDocument||e)!==p&&c(e),d||(t=t.toLowerCase()),(n=i.attrHandle[t])?n(e):d||T.attributes?e.getAttribute(t):((n=e.getAttributeNode(t))||e.getAttribute(t))&&e[t]===!0?t:n&&n.specified?n.value:null},st.error=function(e){throw Error("Syntax error, unrecognized expression: "+e)},st.uniqueSort=function(e){var t,n=[],r=1,i=0;if(u=!T.detectDuplicates,e.sort(v),u){for(;t=e[r];r++)t===e[r-1]&&(i=n.push(r));while(i--)e.splice(n[i],1)}return e};function ut(e,t){var n=t&&e,r=n&&(~t.sourceIndex||j)-(~e.sourceIndex||j);if(r)return r;if(n)while(n=n.nextSibling)if(n===t)return-1;return e?1:-1}function lt(e){return function(t){var n=t.nodeName.toLowerCase();return"input"===n&&t.type===e}}function ct(e){return function(t){var n=t.nodeName.toLowerCase();return("input"===n||"button"===n)&&t.type===e}}function pt(e){return ot(function(t){return t=+t,ot(function(n,r){var i,o=e([],n.length,t),a=o.length;while(a--)n[i=o[a]]&&(n[i]=!(r[i]=n[i]))})})}o=st.getText=function(e){var t,n="",r=0,i=e.nodeType;if(i){if(1===i||9===i||11===i){if("string"==typeof e.textContent)return e.textContent;for(e=e.firstChild;e;e=e.nextSibling)n+=o(e)}else if(3===i||4===i)return e.nodeValue}else for(;t=e[r];r++)n+=o(t);return n},i=st.selectors={cacheLength:50,createPseudo:ot,match:U,find:{},relative:{">":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(e){return e[1]=e[1].replace(et,tt),e[3]=(e[4]||e[5]||"").replace(et,tt),"~="===e[2]&&(e[3]=" "+e[3]+" "),e.slice(0,4)},CHILD:function(e){return e[1]=e[1].toLowerCase(),"nth"===e[1].slice(0,3)?(e[3]||st.error(e[0]),e[4]=+(e[4]?e[5]+(e[6]||1):2*("even"===e[3]||"odd"===e[3])),e[5]=+(e[7]+e[8]||"odd"===e[3])):e[3]&&st.error(e[0]),e},PSEUDO:function(e){var t,n=!e[5]&&e[2];return U.CHILD.test(e[0])?null:(e[4]?e[2]=e[4]:n&&z.test(n)&&(t=ft(n,!0))&&(t=n.indexOf(")",n.length-t)-n.length)&&(e[0]=e[0].slice(0,t),e[2]=n.slice(0,t)),e.slice(0,3))}},filter:{TAG:function(e){return"*"===e?function(){return!0}:(e=e.replace(et,tt).toLowerCase(),function(t){return t.nodeName&&t.nodeName.toLowerCase()===e})},CLASS:function(e){var t=k[e+" "];return t||(t=RegExp("(^|"+_+")"+e+"("+_+"|$)"))&&k(e,function(e){return t.test(e.className||typeof e.getAttribute!==A&&e.getAttribute("class")||"")})},ATTR:function(e,t,n){return function(r){var i=st.attr(r,e);return null==i?"!="===t:t?(i+="","="===t?i===n:"!="===t?i!==n:"^="===t?n&&0===i.indexOf(n):"*="===t?n&&i.indexOf(n)>-1:"$="===t?n&&i.slice(-n.length)===n:"~="===t?(" "+i+" ").indexOf(n)>-1:"|="===t?i===n||i.slice(0,n.length+1)===n+"-":!1):!0}},CHILD:function(e,t,n,r,i){var o="nth"!==e.slice(0,3),a="last"!==e.slice(-4),s="of-type"===t;return 1===r&&0===i?function(e){return!!e.parentNode}:function(t,n,u){var l,c,p,f,d,h,g=o!==a?"nextSibling":"previousSibling",m=t.parentNode,y=s&&t.nodeName.toLowerCase(),v=!u&&!s;if(m){if(o){while(g){p=t;while(p=p[g])if(s?p.nodeName.toLowerCase()===y:1===p.nodeType)return!1;h=g="only"===e&&!h&&"nextSibling"}return!0}if(h=[a?m.firstChild:m.lastChild],a&&v){c=m[x]||(m[x]={}),l=c[e]||[],d=l[0]===N&&l[1],f=l[0]===N&&l[2],p=d&&m.childNodes[d];while(p=++d&&p&&p[g]||(f=d=0)||h.pop())if(1===p.nodeType&&++f&&p===t){c[e]=[N,d,f];break}}else if(v&&(l=(t[x]||(t[x]={}))[e])&&l[0]===N)f=l[1];else while(p=++d&&p&&p[g]||(f=d=0)||h.pop())if((s?p.nodeName.toLowerCase()===y:1===p.nodeType)&&++f&&(v&&((p[x]||(p[x]={}))[e]=[N,f]),p===t))break;return f-=i,f===r||0===f%r&&f/r>=0}}},PSEUDO:function(e,t){var n,r=i.pseudos[e]||i.setFilters[e.toLowerCase()]||st.error("unsupported pseudo: "+e);return r[x]?r(t):r.length>1?(n=[e,e,"",t],i.setFilters.hasOwnProperty(e.toLowerCase())?ot(function(e,n){var i,o=r(e,t),a=o.length;while(a--)i=M.call(e,o[a]),e[i]=!(n[i]=o[a])}):function(e){return r(e,0,n)}):r}},pseudos:{not:ot(function(e){var t=[],n=[],r=s(e.replace(W,"$1"));return r[x]?ot(function(e,t,n,i){var o,a=r(e,null,i,[]),s=e.length;while(s--)(o=a[s])&&(e[s]=!(t[s]=o))}):function(e,i,o){return t[0]=e,r(t,null,o,n),!n.pop()}}),has:ot(function(e){return function(t){return st(e,t).length>0}}),contains:ot(function(e){return function(t){return(t.textContent||t.innerText||o(t)).indexOf(e)>-1}}),lang:ot(function(e){return X.test(e||"")||st.error("unsupported lang: "+e),e=e.replace(et,tt).toLowerCase(),function(t){var n;do if(n=d?t.getAttribute("xml:lang")||t.getAttribute("lang"):t.lang)return n=n.toLowerCase(),n===e||0===n.indexOf(e+"-");while((t=t.parentNode)&&1===t.nodeType);return!1}}),target:function(t){var n=e.location&&e.location.hash;return n&&n.slice(1)===t.id},root:function(e){return e===f},focus:function(e){return e===p.activeElement&&(!p.hasFocus||p.hasFocus())&&!!(e.type||e.href||~e.tabIndex)},enabled:function(e){return e.disabled===!1},disabled:function(e){return e.disabled===!0},checked:function(e){var t=e.nodeName.toLowerCase();return"input"===t&&!!e.checked||"option"===t&&!!e.selected},selected:function(e){return e.parentNode&&e.parentNode.selectedIndex,e.selected===!0},empty:function(e){for(e=e.firstChild;e;e=e.nextSibling)if(e.nodeName>"@"||3===e.nodeType||4===e.nodeType)return!1;return!0},parent:function(e){return!i.pseudos.empty(e)},header:function(e){return Q.test(e.nodeName)},input:function(e){return G.test(e.nodeName)},button:function(e){var t=e.nodeName.toLowerCase();return"input"===t&&"button"===e.type||"button"===t},text:function(e){var t;return"input"===e.nodeName.toLowerCase()&&"text"===e.type&&(null==(t=e.getAttribute("type"))||t.toLowerCase()===e.type)},first:pt(function(){return[0]}),last:pt(function(e,t){return[t-1]}),eq:pt(function(e,t,n){return[0>n?n+t:n]}),even:pt(function(e,t){var n=0;for(;t>n;n+=2)e.push(n);return e}),odd:pt(function(e,t){var n=1;for(;t>n;n+=2)e.push(n);return e}),lt:pt(function(e,t,n){var r=0>n?n+t:n;for(;--r>=0;)e.push(r);return e}),gt:pt(function(e,t,n){var r=0>n?n+t:n;for(;t>++r;)e.push(r);return e})}};for(n in{radio:!0,checkbox:!0,file:!0,password:!0,image:!0})i.pseudos[n]=lt(n);for(n in{submit:!0,reset:!0})i.pseudos[n]=ct(n);function ft(e,t){var n,r,o,a,s,u,l,c=E[e+" "];if(c)return t?0:c.slice(0);s=e,u=[],l=i.preFilter;while(s){(!n||(r=$.exec(s)))&&(r&&(s=s.slice(r[0].length)||s),u.push(o=[])),n=!1,(r=I.exec(s))&&(n=r.shift(),o.push({value:n,type:r[0].replace(W," ")}),s=s.slice(n.length));for(a in i.filter)!(r=U[a].exec(s))||l[a]&&!(r=l[a](r))||(n=r.shift(),o.push({value:n,type:a,matches:r}),s=s.slice(n.length));if(!n)break}return t?s.length:s?st.error(e):E(e,u).slice(0)}function dt(e){var t=0,n=e.length,r="";for(;n>t;t++)r+=e[t].value;return r}function ht(e,t,n){var i=t.dir,o=n&&"parentNode"===i,a=C++;return t.first?function(t,n,r){while(t=t[i])if(1===t.nodeType||o)return e(t,n,r)}:function(t,n,s){var u,l,c,p=N+" "+a;if(s){while(t=t[i])if((1===t.nodeType||o)&&e(t,n,s))return!0}else while(t=t[i])if(1===t.nodeType||o)if(c=t[x]||(t[x]={}),(l=c[i])&&l[0]===p){if((u=l[1])===!0||u===r)return u===!0}else if(l=c[i]=[p],l[1]=e(t,n,s)||r,l[1]===!0)return!0}}function gt(e){return e.length>1?function(t,n,r){var i=e.length;while(i--)if(!e[i](t,n,r))return!1;return!0}:e[0]}function mt(e,t,n,r,i){var o,a=[],s=0,u=e.length,l=null!=t;for(;u>s;s++)(o=e[s])&&(!n||n(o,r,i))&&(a.push(o),l&&t.push(s));return a}function yt(e,t,n,r,i,o){return r&&!r[x]&&(r=yt(r)),i&&!i[x]&&(i=yt(i,o)),ot(function(o,a,s,u){var l,c,p,f=[],d=[],h=a.length,g=o||xt(t||"*",s.nodeType?[s]:s,[]),m=!e||!o&&t?g:mt(g,f,e,s,u),y=n?i||(o?e:h||r)?[]:a:m;if(n&&n(m,y,s,u),r){l=mt(y,d),r(l,[],s,u),c=l.length;while(c--)(p=l[c])&&(y[d[c]]=!(m[d[c]]=p))}if(o){if(i||e){if(i){l=[],c=y.length;while(c--)(p=y[c])&&l.push(m[c]=p);i(null,y=[],l,u)}c=y.length;while(c--)(p=y[c])&&(l=i?M.call(o,p):f[c])>-1&&(o[l]=!(a[l]=p))}}else y=mt(y===a?y.splice(h,y.length):y),i?i(null,a,y,u):H.apply(a,y)})}function vt(e){var t,n,r,o=e.length,a=i.relative[e[0].type],s=a||i.relative[" "],u=a?1:0,c=ht(function(e){return e===t},s,!0),p=ht(function(e){return M.call(t,e)>-1},s,!0),f=[function(e,n,r){return!a&&(r||n!==l)||((t=n).nodeType?c(e,n,r):p(e,n,r))}];for(;o>u;u++)if(n=i.relative[e[u].type])f=[ht(gt(f),n)];else{if(n=i.filter[e[u].type].apply(null,e[u].matches),n[x]){for(r=++u;o>r;r++)if(i.relative[e[r].type])break;return yt(u>1&>(f),u>1&&dt(e.slice(0,u-1)).replace(W,"$1"),n,r>u&&vt(e.slice(u,r)),o>r&&vt(e=e.slice(r)),o>r&&dt(e))}f.push(n)}return gt(f)}function bt(e,t){var n=0,o=t.length>0,a=e.length>0,s=function(s,u,c,f,d){var h,g,m,y=[],v=0,b="0",x=s&&[],w=null!=d,T=l,C=s||a&&i.find.TAG("*",d&&u.parentNode||u),k=N+=null==T?1:Math.random()||.1;for(w&&(l=u!==p&&u,r=n);null!=(h=C[b]);b++){if(a&&h){g=0;while(m=e[g++])if(m(h,u,c)){f.push(h);break}w&&(N=k,r=++n)}o&&((h=!m&&h)&&v--,s&&x.push(h))}if(v+=b,o&&b!==v){g=0;while(m=t[g++])m(x,y,u,c);if(s){if(v>0)while(b--)x[b]||y[b]||(y[b]=L.call(f));y=mt(y)}H.apply(f,y),w&&!s&&y.length>0&&v+t.length>1&&st.uniqueSort(f)}return w&&(N=k,l=T),x};return o?ot(s):s}s=st.compile=function(e,t){var n,r=[],i=[],o=S[e+" "];if(!o){t||(t=ft(e)),n=t.length;while(n--)o=vt(t[n]),o[x]?r.push(o):i.push(o);o=S(e,bt(i,r))}return o};function xt(e,t,n){var r=0,i=t.length;for(;i>r;r++)st(e,t[r],n);return n}function wt(e,t,n,r){var o,a,u,l,c,p=ft(e);if(!r&&1===p.length){if(a=p[0]=p[0].slice(0),a.length>2&&"ID"===(u=a[0]).type&&9===t.nodeType&&!d&&i.relative[a[1].type]){if(t=i.find.ID(u.matches[0].replace(et,tt),t)[0],!t)return n;e=e.slice(a.shift().value.length)}o=U.needsContext.test(e)?0:a.length;while(o--){if(u=a[o],i.relative[l=u.type])break;if((c=i.find[l])&&(r=c(u.matches[0].replace(et,tt),V.test(a[0].type)&&t.parentNode||t))){if(a.splice(o,1),e=r.length&&dt(a),!e)return H.apply(n,q.call(r,0)),n;break}}}return s(e,p)(r,t,d,n,V.test(e)),n}i.pseudos.nth=i.pseudos.eq;function Tt(){}i.filters=Tt.prototype=i.pseudos,i.setFilters=new Tt,c(),st.attr=b.attr,b.find=st,b.expr=st.selectors,b.expr[":"]=b.expr.pseudos,b.unique=st.uniqueSort,b.text=st.getText,b.isXMLDoc=st.isXML,b.contains=st.contains}(e);var at=/Until$/,st=/^(?:parents|prev(?:Until|All))/,ut=/^.[^:#\[\.,]*$/,lt=b.expr.match.needsContext,ct={children:!0,contents:!0,next:!0,prev:!0};b.fn.extend({find:function(e){var t,n,r,i=this.length;if("string"!=typeof e)return r=this,this.pushStack(b(e).filter(function(){for(t=0;i>t;t++)if(b.contains(r[t],this))return!0}));for(n=[],t=0;i>t;t++)b.find(e,this[t],n);return n=this.pushStack(i>1?b.unique(n):n),n.selector=(this.selector?this.selector+" ":"")+e,n},has:function(e){var t,n=b(e,this),r=n.length;return this.filter(function(){for(t=0;r>t;t++)if(b.contains(this,n[t]))return!0})},not:function(e){return this.pushStack(ft(this,e,!1))},filter:function(e){return this.pushStack(ft(this,e,!0))},is:function(e){return!!e&&("string"==typeof e?lt.test(e)?b(e,this.context).index(this[0])>=0:b.filter(e,this).length>0:this.filter(e).length>0)},closest:function(e,t){var n,r=0,i=this.length,o=[],a=lt.test(e)||"string"!=typeof e?b(e,t||this.context):0;for(;i>r;r++){n=this[r];while(n&&n.ownerDocument&&n!==t&&11!==n.nodeType){if(a?a.index(n)>-1:b.find.matchesSelector(n,e)){o.push(n);break}n=n.parentNode}}return this.pushStack(o.length>1?b.unique(o):o)},index:function(e){return e?"string"==typeof e?b.inArray(this[0],b(e)):b.inArray(e.jquery?e[0]:e,this):this[0]&&this[0].parentNode?this.first().prevAll().length:-1},add:function(e,t){var n="string"==typeof e?b(e,t):b.makeArray(e&&e.nodeType?[e]:e),r=b.merge(this.get(),n);return this.pushStack(b.unique(r))},addBack:function(e){return this.add(null==e?this.prevObject:this.prevObject.filter(e))}}),b.fn.andSelf=b.fn.addBack;function pt(e,t){do e=e[t];while(e&&1!==e.nodeType);return e}b.each({parent:function(e){var t=e.parentNode;return t&&11!==t.nodeType?t:null},parents:function(e){return b.dir(e,"parentNode")},parentsUntil:function(e,t,n){return b.dir(e,"parentNode",n)},next:function(e){return pt(e,"nextSibling")},prev:function(e){return pt(e,"previousSibling")},nextAll:function(e){return b.dir(e,"nextSibling")},prevAll:function(e){return b.dir(e,"previousSibling")},nextUntil:function(e,t,n){return b.dir(e,"nextSibling",n)},prevUntil:function(e,t,n){return b.dir(e,"previousSibling",n)},siblings:function(e){return b.sibling((e.parentNode||{}).firstChild,e)},children:function(e){return b.sibling(e.firstChild)},contents:function(e){return b.nodeName(e,"iframe")?e.contentDocument||e.contentWindow.document:b.merge([],e.childNodes)}},function(e,t){b.fn[e]=function(n,r){var i=b.map(this,t,n);return at.test(e)||(r=n),r&&"string"==typeof r&&(i=b.filter(r,i)),i=this.length>1&&!ct[e]?b.unique(i):i,this.length>1&&st.test(e)&&(i=i.reverse()),this.pushStack(i)}}),b.extend({filter:function(e,t,n){return n&&(e=":not("+e+")"),1===t.length?b.find.matchesSelector(t[0],e)?[t[0]]:[]:b.find.matches(e,t)},dir:function(e,n,r){var i=[],o=e[n];while(o&&9!==o.nodeType&&(r===t||1!==o.nodeType||!b(o).is(r)))1===o.nodeType&&i.push(o),o=o[n];return i},sibling:function(e,t){var n=[];for(;e;e=e.nextSibling)1===e.nodeType&&e!==t&&n.push(e);return n}});function ft(e,t,n){if(t=t||0,b.isFunction(t))return b.grep(e,function(e,r){var i=!!t.call(e,r,e);return i===n});if(t.nodeType)return b.grep(e,function(e){return e===t===n});if("string"==typeof t){var r=b.grep(e,function(e){return 1===e.nodeType});if(ut.test(t))return b.filter(t,r,!n);t=b.filter(t,r)}return b.grep(e,function(e){return b.inArray(e,t)>=0===n})}function dt(e){var t=ht.split("|"),n=e.createDocumentFragment();if(n.createElement)while(t.length)n.createElement(t.pop());return n}var ht="abbr|article|aside|audio|bdi|canvas|data|datalist|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|summary|time|video",gt=/ jQuery\d+="(?:null|\d+)"/g,mt=RegExp("<(?:"+ht+")[\\s/>]","i"),yt=/^\s+/,vt=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,bt=/<([\w:]+)/,xt=/\s*$/g,At={option:[1,""],legend:[1,"
","
"],area:[1,"",""],param:[1,"",""],thead:[1,"","
"],tr:[2,"","
"],col:[2,"","
"],td:[3,"","
"],_default:b.support.htmlSerialize?[0,"",""]:[1,"X
","
"]},jt=dt(o),Dt=jt.appendChild(o.createElement("div"));At.optgroup=At.option,At.tbody=At.tfoot=At.colgroup=At.caption=At.thead,At.th=At.td,b.fn.extend({text:function(e){return b.access(this,function(e){return e===t?b.text(this):this.empty().append((this[0]&&this[0].ownerDocument||o).createTextNode(e))},null,e,arguments.length)},wrapAll:function(e){if(b.isFunction(e))return this.each(function(t){b(this).wrapAll(e.call(this,t))});if(this[0]){var t=b(e,this[0].ownerDocument).eq(0).clone(!0);this[0].parentNode&&t.insertBefore(this[0]),t.map(function(){var e=this;while(e.firstChild&&1===e.firstChild.nodeType)e=e.firstChild;return e}).append(this)}return this},wrapInner:function(e){return b.isFunction(e)?this.each(function(t){b(this).wrapInner(e.call(this,t))}):this.each(function(){var t=b(this),n=t.contents();n.length?n.wrapAll(e):t.append(e)})},wrap:function(e){var t=b.isFunction(e);return this.each(function(n){b(this).wrapAll(t?e.call(this,n):e)})},unwrap:function(){return this.parent().each(function(){b.nodeName(this,"body")||b(this).replaceWith(this.childNodes)}).end()},append:function(){return this.domManip(arguments,!0,function(e){(1===this.nodeType||11===this.nodeType||9===this.nodeType)&&this.appendChild(e)})},prepend:function(){return this.domManip(arguments,!0,function(e){(1===this.nodeType||11===this.nodeType||9===this.nodeType)&&this.insertBefore(e,this.firstChild)})},before:function(){return this.domManip(arguments,!1,function(e){this.parentNode&&this.parentNode.insertBefore(e,this)})},after:function(){return this.domManip(arguments,!1,function(e){this.parentNode&&this.parentNode.insertBefore(e,this.nextSibling)})},remove:function(e,t){var n,r=0;for(;null!=(n=this[r]);r++)(!e||b.filter(e,[n]).length>0)&&(t||1!==n.nodeType||b.cleanData(Ot(n)),n.parentNode&&(t&&b.contains(n.ownerDocument,n)&&Mt(Ot(n,"script")),n.parentNode.removeChild(n)));return this},empty:function(){var e,t=0;for(;null!=(e=this[t]);t++){1===e.nodeType&&b.cleanData(Ot(e,!1));while(e.firstChild)e.removeChild(e.firstChild);e.options&&b.nodeName(e,"select")&&(e.options.length=0)}return this},clone:function(e,t){return e=null==e?!1:e,t=null==t?e:t,this.map(function(){return b.clone(this,e,t)})},html:function(e){return b.access(this,function(e){var n=this[0]||{},r=0,i=this.length;if(e===t)return 1===n.nodeType?n.innerHTML.replace(gt,""):t;if(!("string"!=typeof e||Tt.test(e)||!b.support.htmlSerialize&&mt.test(e)||!b.support.leadingWhitespace&&yt.test(e)||At[(bt.exec(e)||["",""])[1].toLowerCase()])){e=e.replace(vt,"<$1>");try{for(;i>r;r++)n=this[r]||{},1===n.nodeType&&(b.cleanData(Ot(n,!1)),n.innerHTML=e);n=0}catch(o){}}n&&this.empty().append(e)},null,e,arguments.length)},replaceWith:function(e){var t=b.isFunction(e);return t||"string"==typeof e||(e=b(e).not(this).detach()),this.domManip([e],!0,function(e){var t=this.nextSibling,n=this.parentNode;n&&(b(this).remove(),n.insertBefore(e,t))})},detach:function(e){return this.remove(e,!0)},domManip:function(e,n,r){e=f.apply([],e);var i,o,a,s,u,l,c=0,p=this.length,d=this,h=p-1,g=e[0],m=b.isFunction(g);if(m||!(1>=p||"string"!=typeof g||b.support.checkClone)&&Ct.test(g))return this.each(function(i){var o=d.eq(i);m&&(e[0]=g.call(this,i,n?o.html():t)),o.domManip(e,n,r)});if(p&&(l=b.buildFragment(e,this[0].ownerDocument,!1,this),i=l.firstChild,1===l.childNodes.length&&(l=i),i)){for(n=n&&b.nodeName(i,"tr"),s=b.map(Ot(l,"script"),Ht),a=s.length;p>c;c++)o=l,c!==h&&(o=b.clone(o,!0,!0),a&&b.merge(s,Ot(o,"script"))),r.call(n&&b.nodeName(this[c],"table")?Lt(this[c],"tbody"):this[c],o,c);if(a)for(u=s[s.length-1].ownerDocument,b.map(s,qt),c=0;a>c;c++)o=s[c],kt.test(o.type||"")&&!b._data(o,"globalEval")&&b.contains(u,o)&&(o.src?b.ajax({url:o.src,type:"GET",dataType:"script",async:!1,global:!1,"throws":!0}):b.globalEval((o.text||o.textContent||o.innerHTML||"").replace(St,"")));l=i=null}return this}});function Lt(e,t){return e.getElementsByTagName(t)[0]||e.appendChild(e.ownerDocument.createElement(t))}function Ht(e){var t=e.getAttributeNode("type");return e.type=(t&&t.specified)+"/"+e.type,e}function qt(e){var t=Et.exec(e.type);return t?e.type=t[1]:e.removeAttribute("type"),e}function Mt(e,t){var n,r=0;for(;null!=(n=e[r]);r++)b._data(n,"globalEval",!t||b._data(t[r],"globalEval"))}function _t(e,t){if(1===t.nodeType&&b.hasData(e)){var n,r,i,o=b._data(e),a=b._data(t,o),s=o.events;if(s){delete a.handle,a.events={};for(n in s)for(r=0,i=s[n].length;i>r;r++)b.event.add(t,n,s[n][r])}a.data&&(a.data=b.extend({},a.data))}}function Ft(e,t){var n,r,i;if(1===t.nodeType){if(n=t.nodeName.toLowerCase(),!b.support.noCloneEvent&&t[b.expando]){i=b._data(t);for(r in i.events)b.removeEvent(t,r,i.handle);t.removeAttribute(b.expando)}"script"===n&&t.text!==e.text?(Ht(t).text=e.text,qt(t)):"object"===n?(t.parentNode&&(t.outerHTML=e.outerHTML),b.support.html5Clone&&e.innerHTML&&!b.trim(t.innerHTML)&&(t.innerHTML=e.innerHTML)):"input"===n&&Nt.test(e.type)?(t.defaultChecked=t.checked=e.checked,t.value!==e.value&&(t.value=e.value)):"option"===n?t.defaultSelected=t.selected=e.defaultSelected:("input"===n||"textarea"===n)&&(t.defaultValue=e.defaultValue)}}b.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(e,t){b.fn[e]=function(e){var n,r=0,i=[],o=b(e),a=o.length-1;for(;a>=r;r++)n=r===a?this:this.clone(!0),b(o[r])[t](n),d.apply(i,n.get());return this.pushStack(i)}});function Ot(e,n){var r,o,a=0,s=typeof e.getElementsByTagName!==i?e.getElementsByTagName(n||"*"):typeof e.querySelectorAll!==i?e.querySelectorAll(n||"*"):t;if(!s)for(s=[],r=e.childNodes||e;null!=(o=r[a]);a++)!n||b.nodeName(o,n)?s.push(o):b.merge(s,Ot(o,n));return n===t||n&&b.nodeName(e,n)?b.merge([e],s):s}function Bt(e){Nt.test(e.type)&&(e.defaultChecked=e.checked)}b.extend({clone:function(e,t,n){var r,i,o,a,s,u=b.contains(e.ownerDocument,e);if(b.support.html5Clone||b.isXMLDoc(e)||!mt.test("<"+e.nodeName+">")?o=e.cloneNode(!0):(Dt.innerHTML=e.outerHTML,Dt.removeChild(o=Dt.firstChild)),!(b.support.noCloneEvent&&b.support.noCloneChecked||1!==e.nodeType&&11!==e.nodeType||b.isXMLDoc(e)))for(r=Ot(o),s=Ot(e),a=0;null!=(i=s[a]);++a)r[a]&&Ft(i,r[a]);if(t)if(n)for(s=s||Ot(e),r=r||Ot(o),a=0;null!=(i=s[a]);a++)_t(i,r[a]);else _t(e,o);return r=Ot(o,"script"),r.length>0&&Mt(r,!u&&Ot(e,"script")),r=s=i=null,o},buildFragment:function(e,t,n,r){var i,o,a,s,u,l,c,p=e.length,f=dt(t),d=[],h=0;for(;p>h;h++)if(o=e[h],o||0===o)if("object"===b.type(o))b.merge(d,o.nodeType?[o]:o);else if(wt.test(o)){s=s||f.appendChild(t.createElement("div")),u=(bt.exec(o)||["",""])[1].toLowerCase(),c=At[u]||At._default,s.innerHTML=c[1]+o.replace(vt,"<$1>")+c[2],i=c[0];while(i--)s=s.lastChild;if(!b.support.leadingWhitespace&&yt.test(o)&&d.push(t.createTextNode(yt.exec(o)[0])),!b.support.tbody){o="table"!==u||xt.test(o)?""!==c[1]||xt.test(o)?0:s:s.firstChild,i=o&&o.childNodes.length;while(i--)b.nodeName(l=o.childNodes[i],"tbody")&&!l.childNodes.length&&o.removeChild(l) +}b.merge(d,s.childNodes),s.textContent="";while(s.firstChild)s.removeChild(s.firstChild);s=f.lastChild}else d.push(t.createTextNode(o));s&&f.removeChild(s),b.support.appendChecked||b.grep(Ot(d,"input"),Bt),h=0;while(o=d[h++])if((!r||-1===b.inArray(o,r))&&(a=b.contains(o.ownerDocument,o),s=Ot(f.appendChild(o),"script"),a&&Mt(s),n)){i=0;while(o=s[i++])kt.test(o.type||"")&&n.push(o)}return s=null,f},cleanData:function(e,t){var n,r,o,a,s=0,u=b.expando,l=b.cache,p=b.support.deleteExpando,f=b.event.special;for(;null!=(n=e[s]);s++)if((t||b.acceptData(n))&&(o=n[u],a=o&&l[o])){if(a.events)for(r in a.events)f[r]?b.event.remove(n,r):b.removeEvent(n,r,a.handle);l[o]&&(delete l[o],p?delete n[u]:typeof n.removeAttribute!==i?n.removeAttribute(u):n[u]=null,c.push(o))}}});var Pt,Rt,Wt,$t=/alpha\([^)]*\)/i,It=/opacity\s*=\s*([^)]*)/,zt=/^(top|right|bottom|left)$/,Xt=/^(none|table(?!-c[ea]).+)/,Ut=/^margin/,Vt=RegExp("^("+x+")(.*)$","i"),Yt=RegExp("^("+x+")(?!px)[a-z%]+$","i"),Jt=RegExp("^([+-])=("+x+")","i"),Gt={BODY:"block"},Qt={position:"absolute",visibility:"hidden",display:"block"},Kt={letterSpacing:0,fontWeight:400},Zt=["Top","Right","Bottom","Left"],en=["Webkit","O","Moz","ms"];function tn(e,t){if(t in e)return t;var n=t.charAt(0).toUpperCase()+t.slice(1),r=t,i=en.length;while(i--)if(t=en[i]+n,t in e)return t;return r}function nn(e,t){return e=t||e,"none"===b.css(e,"display")||!b.contains(e.ownerDocument,e)}function rn(e,t){var n,r,i,o=[],a=0,s=e.length;for(;s>a;a++)r=e[a],r.style&&(o[a]=b._data(r,"olddisplay"),n=r.style.display,t?(o[a]||"none"!==n||(r.style.display=""),""===r.style.display&&nn(r)&&(o[a]=b._data(r,"olddisplay",un(r.nodeName)))):o[a]||(i=nn(r),(n&&"none"!==n||!i)&&b._data(r,"olddisplay",i?n:b.css(r,"display"))));for(a=0;s>a;a++)r=e[a],r.style&&(t&&"none"!==r.style.display&&""!==r.style.display||(r.style.display=t?o[a]||"":"none"));return e}b.fn.extend({css:function(e,n){return b.access(this,function(e,n,r){var i,o,a={},s=0;if(b.isArray(n)){for(o=Rt(e),i=n.length;i>s;s++)a[n[s]]=b.css(e,n[s],!1,o);return a}return r!==t?b.style(e,n,r):b.css(e,n)},e,n,arguments.length>1)},show:function(){return rn(this,!0)},hide:function(){return rn(this)},toggle:function(e){var t="boolean"==typeof e;return this.each(function(){(t?e:nn(this))?b(this).show():b(this).hide()})}}),b.extend({cssHooks:{opacity:{get:function(e,t){if(t){var n=Wt(e,"opacity");return""===n?"1":n}}}},cssNumber:{columnCount:!0,fillOpacity:!0,fontWeight:!0,lineHeight:!0,opacity:!0,orphans:!0,widows:!0,zIndex:!0,zoom:!0},cssProps:{"float":b.support.cssFloat?"cssFloat":"styleFloat"},style:function(e,n,r,i){if(e&&3!==e.nodeType&&8!==e.nodeType&&e.style){var o,a,s,u=b.camelCase(n),l=e.style;if(n=b.cssProps[u]||(b.cssProps[u]=tn(l,u)),s=b.cssHooks[n]||b.cssHooks[u],r===t)return s&&"get"in s&&(o=s.get(e,!1,i))!==t?o:l[n];if(a=typeof r,"string"===a&&(o=Jt.exec(r))&&(r=(o[1]+1)*o[2]+parseFloat(b.css(e,n)),a="number"),!(null==r||"number"===a&&isNaN(r)||("number"!==a||b.cssNumber[u]||(r+="px"),b.support.clearCloneStyle||""!==r||0!==n.indexOf("background")||(l[n]="inherit"),s&&"set"in s&&(r=s.set(e,r,i))===t)))try{l[n]=r}catch(c){}}},css:function(e,n,r,i){var o,a,s,u=b.camelCase(n);return n=b.cssProps[u]||(b.cssProps[u]=tn(e.style,u)),s=b.cssHooks[n]||b.cssHooks[u],s&&"get"in s&&(a=s.get(e,!0,r)),a===t&&(a=Wt(e,n,i)),"normal"===a&&n in Kt&&(a=Kt[n]),""===r||r?(o=parseFloat(a),r===!0||b.isNumeric(o)?o||0:a):a},swap:function(e,t,n,r){var i,o,a={};for(o in t)a[o]=e.style[o],e.style[o]=t[o];i=n.apply(e,r||[]);for(o in t)e.style[o]=a[o];return i}}),e.getComputedStyle?(Rt=function(t){return e.getComputedStyle(t,null)},Wt=function(e,n,r){var i,o,a,s=r||Rt(e),u=s?s.getPropertyValue(n)||s[n]:t,l=e.style;return s&&(""!==u||b.contains(e.ownerDocument,e)||(u=b.style(e,n)),Yt.test(u)&&Ut.test(n)&&(i=l.width,o=l.minWidth,a=l.maxWidth,l.minWidth=l.maxWidth=l.width=u,u=s.width,l.width=i,l.minWidth=o,l.maxWidth=a)),u}):o.documentElement.currentStyle&&(Rt=function(e){return e.currentStyle},Wt=function(e,n,r){var i,o,a,s=r||Rt(e),u=s?s[n]:t,l=e.style;return null==u&&l&&l[n]&&(u=l[n]),Yt.test(u)&&!zt.test(n)&&(i=l.left,o=e.runtimeStyle,a=o&&o.left,a&&(o.left=e.currentStyle.left),l.left="fontSize"===n?"1em":u,u=l.pixelLeft+"px",l.left=i,a&&(o.left=a)),""===u?"auto":u});function on(e,t,n){var r=Vt.exec(t);return r?Math.max(0,r[1]-(n||0))+(r[2]||"px"):t}function an(e,t,n,r,i){var o=n===(r?"border":"content")?4:"width"===t?1:0,a=0;for(;4>o;o+=2)"margin"===n&&(a+=b.css(e,n+Zt[o],!0,i)),r?("content"===n&&(a-=b.css(e,"padding"+Zt[o],!0,i)),"margin"!==n&&(a-=b.css(e,"border"+Zt[o]+"Width",!0,i))):(a+=b.css(e,"padding"+Zt[o],!0,i),"padding"!==n&&(a+=b.css(e,"border"+Zt[o]+"Width",!0,i)));return a}function sn(e,t,n){var r=!0,i="width"===t?e.offsetWidth:e.offsetHeight,o=Rt(e),a=b.support.boxSizing&&"border-box"===b.css(e,"boxSizing",!1,o);if(0>=i||null==i){if(i=Wt(e,t,o),(0>i||null==i)&&(i=e.style[t]),Yt.test(i))return i;r=a&&(b.support.boxSizingReliable||i===e.style[t]),i=parseFloat(i)||0}return i+an(e,t,n||(a?"border":"content"),r,o)+"px"}function un(e){var t=o,n=Gt[e];return n||(n=ln(e,t),"none"!==n&&n||(Pt=(Pt||b("