i18n-abide
Advanced tools
Comparing version 0.0.8-beta5 to 0.0.8-beta8
@@ -51,2 +51,3 @@ /* This Source Code Form is subject to the terms of the Mozilla Public | ||
options = options || {}; | ||
if (! options.gettext_alias) options.gettext_alias = 'gettext'; | ||
@@ -60,15 +61,11 @@ if (! options.supported_languages) options.supported_languages = ['en-US']; | ||
var existsSync = fs.existsSync || path.existsSync; | ||
logger = options.logger; | ||
var json_file_path = function(locale) { | ||
return path.resolve( | ||
path.join(__dirname, '..', '..', '..'), | ||
options.translation_directory, | ||
path.join(locale, 'messages.json')); | ||
}, | ||
debug_locale = localeFrom(options.debug_lang); | ||
function json_file_path(locale) { | ||
return path.resolve(path.join(__dirname, '..', '..', '..'), | ||
options.translation_directory, | ||
path.join(locale, 'messages.json')); | ||
} | ||
options.supported_languages.forEach(function(lang, i) { | ||
options.supported_languages.forEach(function(lang) { | ||
var l = localeFrom(lang); | ||
@@ -79,13 +76,4 @@ | ||
try { | ||
// TODO: Have po2json write json files, not .js files | ||
// also https://github.com/mozilla/i18n-abide/issues/15 | ||
var rawMessages = fs.readFileSync(json_file_path(l)).toString(); | ||
if (rawMessages.length < JS_PRE_LEN + JS_POST_LEN + 1) { | ||
throw new Error('Bad Locale messages.json ' + l); | ||
} | ||
// Chop JSON out of the middle of a JavaScript formatted file | ||
var json_locale_data = JSON.parse( | ||
rawMessages.slice(JS_PRE_LEN, rawMessages.length - JS_POST_LEN)); | ||
translations[l] = json_locale_data.messages; | ||
translations[l] = JSON.parse(rawMessages).messages; | ||
} catch (e) { | ||
@@ -118,7 +106,5 @@ // an exception here means that there was a problem with the translation | ||
console.log(langs); | ||
if (lang && lang.toLowerCase && lang.toLowerCase() === debug_lang) { | ||
// What? http://www.youtube.com/watch?v=rJLnGjhPT1Q | ||
lang = DAVID_B_LABYRN; | ||
// What? http://www.youtube.com/watch?v=rJLnGjhPT1Q | ||
lang = DAVID_B_LABYRN; | ||
} | ||
@@ -131,3 +117,3 @@ // Express 2 support | ||
} else { | ||
Object.keys(args).forEach(function(key, i) { | ||
Object.keys(args).forEach(function(key) { | ||
resp.local(key, args[key]); | ||
@@ -166,3 +152,3 @@ }); | ||
// default lang in a non gettext environment... fake it | ||
gt = function(a, b) { return a; }; | ||
gt = function(a) { return a; }; | ||
} | ||
@@ -197,20 +183,20 @@ locals[options.gettext_alias] = gt; | ||
exports.parseAcceptLanguage = parseAcceptLanguage = function(header) { | ||
// pl,fr-FR;q=0.3,en-US;q=0.1 | ||
if (! header || ! header.split) { | ||
return []; | ||
// pl,fr-FR;q=0.3,en-US;q=0.1 | ||
if (! header || ! header.split) { | ||
return []; | ||
} | ||
var raw_langs = header.split(','); | ||
var langs = raw_langs.map(function(raw_lang) { | ||
var parts = raw_lang.split(';'); | ||
var q = 1; | ||
if (parts.length > 1 && parts[1].indexOf('q=') === 0) { | ||
var qval = parseFloat(parts[1].split('=')[1]); | ||
if (isNaN(qval) === false) { | ||
q = qval; | ||
} | ||
} | ||
var raw_langs = header.split(','); | ||
var langs = raw_langs.map(function(raw_lang) { | ||
var parts = raw_lang.split(';'); | ||
var q = 1; | ||
if (parts.length > 1 && parts[1].indexOf('q=') === 0) { | ||
var qval = parseFloat(parts[1].split('=')[1]); | ||
if (isNaN(qval) === false) { | ||
q = qval; | ||
} | ||
} | ||
return { lang: parts[0].trim(), quality: q }; | ||
}); | ||
langs.sort(qualityCmp); | ||
return langs; | ||
return { lang: parts[0].trim(), quality: q }; | ||
}); | ||
langs.sort(qualityCmp); | ||
return langs; | ||
}; | ||
@@ -245,3 +231,3 @@ | ||
if (! language || ! language.split) { | ||
return ""; | ||
return ""; | ||
} | ||
@@ -248,0 +234,0 @@ var parts = language.split('-'); |
@@ -5,3 +5,3 @@ { | ||
"description": "Express/connect module for Node i18n and l10n support", | ||
"version": "0.0.8beta5", | ||
"version": "0.0.8beta8", | ||
"homepage": "https://github.com/mozilla/i18n-abide", | ||
@@ -22,3 +22,3 @@ "repository": { | ||
"gobbledygook": "0.0.3", | ||
"jsxgettext": "0.0.5", | ||
"jsxgettext": "0.1.2", | ||
"optimist": "0.3.4" | ||
@@ -25,0 +25,0 @@ }, |
@@ -12,8 +12,22 @@ # i18n-abide | ||
This module is under development, currently being extracted from [BrowserID](https://github.com/mozilla/browserid). | ||
This module is under development, but frozen parts of it power the [Mozilla Persona](https://github.com/mozilla/browserid) service in 40+ languages. | ||
# Pre-requisites | ||
# Tutorial | ||
Mozilla Hacks blog has a three part introduction. | ||
* [Localize Your Node.js Service](https://hacks.mozilla.org/2013/04/localize-your-node-js-service-part-1-of-3-a-node-js-holiday-season-part-9/) | ||
* [Localization community, tools & process](https://hacks.mozilla.org/2013/04/localization-community-tools-process-part-2-of-3-a-node-js-holiday-season-part-10/) | ||
* [Localization in Action](https://hacks.mozilla.org/2013/04/localization-in-action-part-3-of-3-a-node-js-holiday-season-part-11/) | ||
# Pre-requisites for Developers | ||
`npm install` has got your back | ||
# Pre-requisites for String Wranglers | ||
You should install Gnu gettext to get msginit, xgettext, and other tools. | ||
What is a string wrangler? A person or an automated build process that will merge and delete strings between releases. | ||
# Usage | ||
@@ -136,2 +150,2 @@ | ||
See docs/USAGE.md for full details. | ||
See docs/USAGE.md for full details. |
Sorry, the diff of this file is not supported yet
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
150
41
1662072
710
37569
+ Addedamdefine@1.0.1(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@2.0.1(transitive)
+ Addedcharacter-parser@1.0.2(transitive)
+ Addedcommander@1.1.1(transitive)
+ Addedcss@1.0.8(transitive)
+ Addedcss-parse@1.0.4(transitive)
+ Addedcss-stringify@1.0.5(transitive)
+ Addedescodegen@0.0.23(transitive)
+ Addedesprima@1.0.3(transitive)
+ Addedestraverse@0.0.41.1.2-1(transitive)
+ Addedis-promise@1.0.1(transitive)
+ Addedjade@0.30.0(transitive)
+ Addedjsxgettext@0.1.2(transitive)
+ Addedkeypress@0.1.0(transitive)
+ Addedminimatch@10.0.1(transitive)
+ Addedmkdirp@0.3.5(transitive)
+ Addedmonocle@0.1.50(transitive)
+ Addedoptimist@0.3.7(transitive)
+ Addedpromise@2.0.0(transitive)
+ Addedreaddirp@0.2.5(transitive)
+ Addedsource-map@0.1.430.7.4(transitive)
+ Addedtransformers@2.0.1(transitive)
+ Addeduglify-js@2.2.5(transitive)
- Removedescodegen@2.1.0(transitive)
- Removedesprima@4.0.1(transitive)
- Removedestraverse@5.3.0(transitive)
- Removedesutils@2.0.3(transitive)
- Removedjsxgettext@0.0.5(transitive)
- Removedsource-map@0.6.1(transitive)
Updatedjsxgettext@0.1.2