Skip to content

TagSpaces is an offline, open source, document manager with tagging support

adding require-i18next to the project

Iliancd50a264a0ec
diff --git a/data/libs/requirei18n/LICENSE[mit] b/data/libs/requirei18n/LICENSE[mit]
new file mode 100644
index 000000000..141882c6c
--- /dev/null
+++ b/data/libs/requirei18n/LICENSE[mit]
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2013 Jacob van Mourik
+
+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.
\ No newline at end of file
diff --git a/data/libs/requirei18n/i18next.js b/data/libs/requirei18n/i18next.js
new file mode 100644
index 000000000..0c840e03d
--- /dev/null
+++ b/data/libs/requirei18n/i18next.js
@@ -0,0 +1,157 @@
+/**
+ * RequireJS i18next Plugin
+ *
+ * Version 0.4.0 (01-19-2014)
+ * Copyright 2013-2014 Jacob van Mourik
+ * Released under the MIT license
+ */
+define(["i18next"], function(i18next) {
+ "use strict";
+
+ var plugin,
+ supportedLngs,
+ resStore = {},
+ f = i18next.functions,
+ o = i18next.options;
+
+ plugin = {
+ version: "0.4.0",
+ pluginBuilder: "./i18next-builder",
+
+ /**
+ * Checks to see if there exists a resource with the given
+ * module, language and namespace in the store.
+ *
+ * @param {String} module The module name
+ * @param {String} lng The language
+ * @param {String} ns The namespace
+ * @returns {Boolean} If the resource exists in the store
+ */
+ resourceExists: function(module, lng, ns) {
+ return resStore[module] && resStore[module][lng] && resStore[module][lng][ns];
+ },
+
+ /**
+ * Adds a resource to the store (overrides existing one).
+ *
+ * @param {String} module The module name
+ * @param {String} lng The language
+ * @param {String} ns The namespace
+ * @param {Object} data The resource data
+ */
+ addResource: function(module, lng, ns, data) {
+ resStore[module] = resStore[module] || {};
+ resStore[module][lng] = resStore[module][lng] || {};
+ resStore[module][lng][ns] = data;
+ },
+
+ /**
+ * Gets all resources by the given language and namespace.
+ *
+ * @param {String} lng The language
+ * @param {String} ns The namespace
+ * @returns {Object} The resource data
+ */
+ getResources: function(lng, ns) {
+ var data = {};
+ f.each(resStore, function(module) {
+ if (resStore[module][lng] && resStore[module][lng][ns]) {
+ f.extend(data, resStore[module][lng][ns]);
+ }
+ });
+ return data;
+ },
+
+ /**
+ * Parses a resource name into its component parts.
+ * For example: resource:namespace1,namespace2 where resource is the path to
+ * the locales and the part after the : the additional namespace(s) to load.
+ *
+ * @param {String} name The resource name
+ * @returns {Object} Object containing module name and namespaces
+ */
+ parseName: function(name) {
+ var splitted = name.split(":");
+ return {
+ module: splitted[0],
+ namespaces: splitted[1] ? splitted[1].split(",") : []
+ };
+ },
+
+ load: function(name, req, onload, config) {
+ var parsedName = plugin.parseName(name),
+ options = f.extend({}, config.i18next),
+ namespaces = parsedName.namespaces,
+ module = parsedName.module,
+ supportedLngs = options.supportedLngs;
+
+ // Check for scoped supported languages value
+ if (supportedLngs && supportedLngs[module]) {
+ supportedLngs = supportedLngs[module];
+ }
+
+ // Set namespaces
+ if (typeof o.ns == "string") {
+ namespaces.unshift(options.ns || o.ns);
+ options.ns = {
+ defaultNs: namespaces[0],
+ namespaces: namespaces
+ };
+ } else {
+ options.ns = o.ns;
+ f.each(namespaces, function(idx, namespace) {
+ if (options.ns.namespaces.indexOf(namespace) == -1) {
+ options.ns.namespaces.push(namespace);
+ }
+ });
+ }
+
+ // Set a custom load function
+ options.customLoad = function(lng, ns, opts, done) {
+
+ // Check for already loaded resource
+ if (plugin.resourceExists(module, lng, ns)) {
+ done(null, plugin.getResources(lng, ns));
+ return;
+ }
+
+ // Check for language/namespace support
+ if (supportedLngs && (!supportedLngs[lng] || supportedLngs[lng].indexOf(ns) == -1)) {
+ f.log("no locale support found for " + lng + " with namespace " + ns);
+ done(null, {});
+ return;
+ }
+
+ // Define resource url
+ var url = req.toUrl(module + (module.substr(module.length - 1) !== "/" ? "/" : "") +
+ f.applyReplacement(opts.resGetPath, {lng : lng, ns : ns}));
+
+ // Make the request
+ f.ajax({
+ url: url,
+ dataType: "json",
+ async: opts.async,
+ success: function(data, status, xhr) {
+ plugin.addResource(module, lng, ns, data);
+ f.log("loaded: " + url);
+ done(null, plugin.getResources(lng, ns));
+ },
+ error: function(xhr, status, error) {
+ f.log("failed loading: " + url);
+ done(error, {});
+ }
+ });
+ };
+
+ // Delete supported languages, they are only needed by this plugin
+ delete options.supportedLngs;
+
+ // Initialize i18next and return the i18next instance
+ i18next.init(options, function() {
+ onload(i18next);
+ });
+ }
+ };
+
+ return plugin;
+});
diff --git a/data/loader.js b/data/loader.js
index be1155998..775ffacf6 100644
--- a/data/loader.js
+++ b/data/loader.js
@@ -62,7 +62,8 @@ requirejs.config({
map: {
'*': {
'css': 'libs/requirecss/css',
- 'text': 'libs/requiretext/text'
+ 'text': 'libs/requiretext/text',
+ 'i18n': 'libs/requirei18n/i18next'
}
},
paths: {
diff --git a/usedjslibs.md b/usedjslibs.md
index 78c331e6a..a2c0e6528 100644
--- a/usedjslibs.md
+++ b/usedjslibs.md
@@ -8,6 +8,7 @@ DataTables - http://datatables.net/ - http://datatables.net/releases/DataTables-
UnderscoreJS - http://underscorejs.org - https://github.com/jashkenas/underscore/blob/1.5.1/underscore.js
Mousetrap - http://craig.is/killing/mice - https://raw.githubusercontent.com/ccampbell/mousetrap/1.4.6/mousetrap.min.js
i18next - http://i18next.com/ - https://github.com/jamuhl/i18next/releases/tag/1.7.2
+requiere-i18next - https://github.com/jcbvm/require-i18next - https://github.com/jcbvm/require-i18next/releases/tag/v0.4.0
hammerjs - http://eightmedia.github.io/hammer.js/ - https://github.com/EightMedia/hammer.js/blob/v1.0.5/dist/jquery.hammer.js
Select2 - http://ivaynberg.github.io/select2/ - https://github.com/ivaynberg/select2/blob/3.4.5/select2.min.js
x-editable - http://vitalets.github.io/x-editable/ - https://github.com/vitalets/x-editable/archive/1.5.1.zip