Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added draft api

  • Loading branch information...
commit 460c55ccb584875b117947216566bcdd2c3b824e 1 parent a6e2870
Alexey Zapparov ixti authored
1  index.js
View
@@ -0,0 +1 @@
+module.exports = require('./lib/babelfish');
80 lib/babelfish.js
View
@@ -0,0 +1,80 @@
+/**
+ * class BabelFish
+ *
+ * ##### Example
+ *
+ * var i18n = new BabelFish();
+ **/
+
+
+/**
+ * new BabelFish()
+ **/
+function BabelFish() {
+ throw {message: "Not implemented yet"};
+}
+
+
+/** chainable
+ * BabelFish#addTranslation(locale, scope, value) -> BabelFish
+ * - locale (String): Locale as it defined in locales.yml, e.g. `ru-RU`
+ * - scope (String|Null): Scope of value, e.g. `apps.forum`
+ * - value (String|Object): Value or nested scopes with values.
+ *
+ * ##### Example
+ *
+ * i18n.addTranslation('ru-RU',
+ * 'apps.forums.replies_count',
+ * '#{count} %{ответ|ответа|ответов}:count в теме');
+ *
+ * // equals to:
+ * i18n.addTranslation('ru-RU',
+ * 'apps.forums',
+ * { replies_count: '#{count} %{ответ|ответа|ответов}:count в теме' });
+ **/
+BabelFish.prototype.addTranslation = function addTranslation(locale, scope, value) {
+ throw {message: "Not implemented yet"};
+};
+
+
+/**
+ * BabelFish#getTranslation(locale[, scope = null[, deep = true]]) -> Object
+ * - locale (String): Locale as it defined in locales.yml, e.g. `ru-RU`
+ * - scope (String|Null): Retreive phrases of given scope (`null` means global)
+ * - deep (Boolean): Whenever retreive nested scopes or not
+ *
+ * Retreives translation of the scope for given locale.
+ **/
+BabelFish.prototype.getTranslation = function getTranslation(locale, scope, deep) {
+ throw {message: "Not implemented yet"};
+};
+
+
+/** chainable
+ * BabelFish#setLocaleFallback(locale, fallback) -> BabelFish
+ *
+ * Set fallback for given locale.
+ *
+ * ##### Example
+ *
+ * i18n.setLocaleFallback('ru-UK', 'ua');
+ **/
+BabelFish.prototype.setLocaleFallback = function setLocaleFallback(locale, fallback) {
+ throw {message: "Not implemented yet"};
+};
+
+
+/**
+ * I18n#translate(locale, scope[, params]) -> String
+ * - locale (String): Locale as it defined in locales.yml, e.g. `ru-RU`
+ * - scope (String): Full phrase path, e.g. `app.forums.replies_count`
+ * - parmas (Object): Params for translation
+ *
+ * ##### Example
+ *
+ * i18n.translate('ru-RU', 'app.forums.replies_count', {count: 1});
+ * // -> '1 ответ'
+ **/
+BabelFish.prototype.translate = function translate(locale, scope, params) {
+ throw {message: "Not implemented yet"};
+};
14 lib/babelfish/extras/jade.js
View
@@ -0,0 +1,14 @@
+var REGEXP = /=\s*__\(['"]([^'"]+)['"](?:,[^)]+)?\)/g
+module.exports.preprocess = function preprocess(locale, string) {
+ var babelfish = this;
+ return string.replace(REGEXP, function (m, g) {
+ var result = babelfish.getTranslation(locale, g);
+
+ if ('string' === result) {
+ return ' ' + result; // we a removing = statement
+ }
+
+ var idx = m.indexOf('(') + 1;
+ return m.slice(0, idx) + "'" + locale + "', " + m.slice(idx);
+ });
+};
14 lib/babelfish/locales.yml
View
@@ -0,0 +1,14 @@
+---
+# this file contains locales and some rules they use (pluralization,
+# date-time formats etc)
+en-GB:
+ pluralization: en
+
+en-US:
+ pluralization: en
+
+ru-RU:
+ pluralization: ru
+
+ru-US:
+ pluralization: ua
13 lib/babelfish/pluralization.js
View
@@ -0,0 +1,13 @@
+// defines pluraliation rules. based on:
+// http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html
+
+
+var pluralization = module.exports = {};
+
+pluralization.en = function (count, forms) {
+ return (1 === count) ? (forms.one) : (forms.other);
+};
+
+pluralization.ru = function (count, forms) {
+ return forms.other;
+};
Please sign in to comment.
Something went wrong with that request. Please try again.