Skip to content
This repository has been archived by the owner on Mar 30, 2023. It is now read-only.

Commit

Permalink
Documenting current workflow while writing blog post
Browse files Browse the repository at this point in the history
  • Loading branch information
ozten committed Jan 30, 2013
1 parent f2db522 commit 2bec592
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 5 deletions.
5 changes: 4 additions & 1 deletion bin/compile-json.sh
Expand Up @@ -28,8 +28,11 @@ for pofile in `find $1 -type f -name "*.po"`; do
stem=`basename $pofile .po`
jsonfile="$2/${lang}/${stem}.json"
mkdir -p $2/${lang}
echo "I am working in "
pwd
echo "and 1 is $1 and 2 is $2"
echo -n ";var json_locale_data = " > $jsonfile
$1/po2json.js -p $pofile >> $jsonfile
./node_modules/.bin/po2json.js -p $pofile >> $jsonfile
echo ";" >> $jsonfile
done
rm $lockfile
4 changes: 4 additions & 0 deletions docs/USAGE.md
Expand Up @@ -40,6 +40,10 @@ config file which you'll like to validate. Examples:
CONFIG_FILES=/home/ozten/Projects/browserid/config/l10n-prod.json node ./scripts/check-l10n-config.js
CONFIG_FILES=/home/ozten/Projects/browserid/config/l10n-all.json node ./scripts/check-l10n-config.js

## Contributions

``scripts/check-po.sh`` - Prints statistics on various .po files, assumes `locale` directory.

## Debugging

If code is evaluated in node.js (server-side) then node-gettext is providing the string
Expand Down
2 changes: 1 addition & 1 deletion examples/express2/app.js
Expand Up @@ -38,6 +38,6 @@ app.configure('production', function(){

app.get('/', routes.index);

app.listen(3000, function(){
app.listen(3001, function(){
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
});
12 changes: 12 additions & 0 deletions examples/express2/i18n/db_LB/messages.json
@@ -0,0 +1,12 @@
;var json_locale_data = {
"messages": {
"": {
"Project-Id-Version": " express 2\nReport-Msgid-Bugs-To: \nPOT-Creation-Date: 2012-06-24 09:50+0200\nPO-Revision-Date: 2012-06-24 09:50+0200\nLast-Translator: Automatically generated\nLanguage-Team: none\nLanguage: db_LB\nMIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8\nContent-Transfer-Encoding: 8bit\n"
},
"Hello, world!": [
null,
""
]
}
}
;
12 changes: 12 additions & 0 deletions examples/express2/i18n/de/messages.json
@@ -0,0 +1,12 @@
;var json_locale_data = {
"messages": {
"": {
"Project-Id-Version": " express 2\nReport-Msgid-Bugs-To: \nPOT-Creation-Date: 2012-06-24 09:50+0200\nPO-Revision-Date: 2012-06-24 09:50+0200\nLast-Translator: Automatically generated\nLanguage-Team: none\nLanguage: de\nMIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8\nContent-Transfer-Encoding: 8bit\nPlural-Forms: nplurals=2; plural=(n != 1);\n"
},
"Hello, world!": [
null,
""
]
}
}
;
12 changes: 12 additions & 0 deletions examples/express2/i18n/en_US/messages.json
@@ -0,0 +1,12 @@
;var json_locale_data = {
"messages": {
"": {
"Project-Id-Version": " express 2\nReport-Msgid-Bugs-To: \nPOT-Creation-Date: 2012-06-24 09:50+0200\nPO-Revision-Date: 2012-06-24 09:50+0200\nLast-Translator: Automatically generated\nLanguage-Team: none\nLanguage: en_US\nMIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8\nContent-Transfer-Encoding: 8bit\nPlural-Forms: nplurals=2; plural=(n != 1);\n"
},
"Hello, world!": [
null,
"Hello, world!"
]
}
}
;
12 changes: 12 additions & 0 deletions examples/express2/i18n/es/messages.json
@@ -0,0 +1,12 @@
;var json_locale_data = {
"messages": {
"": {
"Project-Id-Version": " express 2\nReport-Msgid-Bugs-To: \nPOT-Creation-Date: 2012-06-24 09:50+0200\nPO-Revision-Date: 2012-06-24 09:50+0200\nLast-Translator: Automatically generated\nLanguage-Team: none\nLanguage: es\nMIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8\nContent-Transfer-Encoding: 8bit\nPlural-Forms: nplurals=2; plural=(n != 1);\n"
},
"Hello, world!": [
null,
""
]
}
}
;
22 changes: 22 additions & 0 deletions examples/express2/scripts/extract-json-only.sh
@@ -0,0 +1,22 @@
#!/bin/bash

echo "Extracting strings"
mkdir -p locale/templates/LC_MESSAGES
./node_modules/i18n-abide/bin/extract-pot -l ./locale .

# Create PO files
for locale in en_US es de db_LB; do
echo "Creating ${locale} language files"
mkdir -p locale/${locale}/LC_MESSAGES
mkdir -p i18n/${locale}
msginit --input=./locale/templates/LC_MESSAGES/messages.pot \
--output-file=./locale/${locale}/LC_MESSAGES/messages.po \
-l ${locale} --no-translator
echo "You can translate i18n/${locale}/messages.json"
done

# Convert PO files to JSON
./node_modules/i18n-abide/bin/compile-json.sh locale i18n

# Make current version of the code happy
./node_modules/i18n-abide/bin/compile-mo.sh locale
9 changes: 7 additions & 2 deletions lib/i18n.js
Expand Up @@ -68,16 +68,21 @@ exports.abide = function (options) {
options.supported_languages.forEach(function (lang, i) {
var l = localeFrom(lang),
default_locale = localeFrom(options.default_lang);

console.log(l, mo_file_path(l), exists(mo_file_path(l)));
mo_cache[l] = {
mo_exists: path.exists(mo_file_path(l)),
mo_exists: exists(mo_file_path(l)),
/* json_exists: path.exists(json_file_path(l)), */
gt: null
};
if (l !== debug_locale) {
if (! mo_cache[l] || ! mo_cache[l].mo_exists /* || ! mo_cache[l].json_exists*/ ) {

console.log('mo_cache?', mo_cache[l], ' for ', l);
if (mo_cache[l]) console.log('mo_exists?', mo_cache[l].mo_exists);
var msg = util.format('Bad locale=[%s] file(s) do not exist [%s]. See locale/README',
l, mo_file_path(l)/*, json_file_path(l)*/);

console.log(l, default_locale);
if (/* mo_cache[l].json_exists && */ l == default_locale) {
// mo files aren't critical... carry on
if (! options.disable_locale_check) logger.warn(msg);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -2,7 +2,7 @@
"author": "Austin King <shout@ozten.com> (http://ozten.com)",
"name": "i18n-abide",
"description": "Express/connect module for Node i18n and l10n support",
"version": "0.0.7",
"version": "0.0.8beta",
"homepage": "https://github.com/mozilla/i18n-abide",
"repository": {
"type": "git",
Expand Down

0 comments on commit 2bec592

Please sign in to comment.