Skip to content
This repository has been archived by the owner on Dec 1, 2017. It is now read-only.

Commit

Permalink
Bug 1237662 - Set up a script to automatically import from the loop-c…
Browse files Browse the repository at this point in the history
…lient-l10n directory. r=Standard8
  • Loading branch information
Mardak committed Jan 19, 2016
1 parent f6755be commit f684322
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 13 deletions.
26 changes: 20 additions & 6 deletions Makefile
Expand Up @@ -185,6 +185,15 @@ $(BUILT)/standalone/content/js/%.js: standalone/content/js/%.jsx
@mkdir -p $(@D)
$(BABEL) $< --out-file $@

standalone_l10n_files=$(wildcard locale/*/standalone.properties)
built_standalone_l10n_files=$(patsubst locale/%/standalone.properties, \
$(BUILT)/standalone/content/l10n/%/loop.properties, \
$(standalone_l10n_files))

$(BUILT)/standalone/content/l10n/%/loop.properties: locale/%/standalone.properties locale/%/shared.properties
@mkdir -p $(@D)
cat $^ > $@

# add-on
add_on_jsx_files=$(wildcard add-on/panels/js/*.jsx)
built_add_on_js_files=$(patsubst add-on/panels/js/%.jsx, \
Expand All @@ -195,6 +204,15 @@ $(BUILT)/add-on/chrome/content/panels/js/%.js: add-on/panels/js/%.jsx
@mkdir -p $(@D)
$(BABEL) $< --out-file $@

add_on_l10n_files=$(wildcard locale/*/add-on.properties)
built_add_on_l10n_files=$(patsubst locale/%/add-on.properties, \
$(BUILT)/add-on/chrome/locale/%/loop.properties, \
$(add_on_l10n_files))

$(BUILT)/add-on/chrome/locale/%/loop.properties: locale/%/add-on.properties locale/%/shared.properties
@mkdir -p $(@D)
cat $^ > $@

# XXX maybe just build one copy of shared in standalone, and then use
# server.js magic to redirect?
# XXX ecma3 transform for IE?
Expand All @@ -206,16 +224,14 @@ ui: node_modules $(built_ui_js_files) $(built_ui_shared_js_files)
$(RSYNC) shared $(BUILT)/$@

.PHONY: standalone
standalone: node_modules $(built_standalone_js_files) $(built_standalone_shared_js_files)
standalone: node_modules $(built_standalone_js_files) $(built_standalone_shared_js_files) $(built_standalone_l10n_files)
mkdir -p $(BUILT)/$@
$(RSYNC) $@ $(BUILT)
mkdir -p $(BUILT)/$@/content/shared
$(RSYNC) shared $(BUILT)/$@/content
mkdir -p $(BUILT)/$@/content/l10n/en-US
cat locale/en-US/$@.properties locale/en-US/shared.properties > $(BUILT)/$@/content/l10n/en-US/loop.properties

.PHONY: add-on
add-on: node_modules $(built_add_on_js_files) $(built_add_on_shared_js_files) $(BUILT)/$(ADD-ON)/chrome.manifest $(BUILT)/add-on/chrome/content/preferences/prefs.js
add-on: node_modules $(built_add_on_js_files) $(built_add_on_shared_js_files) $(built_add_on_l10n_files) $(BUILT)/$(ADD-ON)/chrome.manifest $(BUILT)/add-on/chrome/content/preferences/prefs.js
mkdir -p $(BUILT)/$@
$(RSYNC) $@/chrome/bootstrap.js $(BUILT)/$@
sed "s/@FIREFOX_VERSION@/$(FIREFOX_VERSION)/g" add-on/install.rdf.in | \
Expand All @@ -229,8 +245,6 @@ add-on: node_modules $(built_add_on_js_files) $(built_add_on_shared_js_files) $(
mkdir -p $(BUILT)/$@/chrome/content/shared
$(RSYNC) shared $(BUILT)/$@/chrome/content
$(RSYNC) $@/chrome/skin $(BUILT)/$@/chrome/
mkdir -p $(BUILT)/$@/chrome/locale/en-US
cat locale/en-US/$@.properties locale/en-US/shared.properties > $(BUILT)/$@/chrome/locale/en-US/loop.properties

$(BUILT)/$(ADD-ON)/chrome.manifest: $(ADD-ON)/jar.mn
mkdir -p $(BUILT)/$(ADD-ON)
Expand Down
20 changes: 13 additions & 7 deletions add-on/chrome/modules/MozLoopService.jsm
Expand Up @@ -770,14 +770,20 @@ var MozLoopServiceInternal = {
return gLocalizedStrings;
}

let stringBundle =
Services.strings.createBundle("chrome://loop/locale/loop.properties");

let enumerator = stringBundle.getSimpleEnumeration();
while (enumerator.hasMoreElements()) {
let string = enumerator.getNext().QueryInterface(Ci.nsIPropertyElement);
gLocalizedStrings.set(string.key, string.value);
// Load all strings from a bundle location preferring strings loaded later.
function loadAllStrings(location) {
let bundle = Services.strings.createBundle(location);
let enumerator = bundle.getSimpleEnumeration();
while (enumerator.hasMoreElements()) {
let string = enumerator.getNext().QueryInterface(Ci.nsIPropertyElement);
gLocalizedStrings.set(string.key, string.value);
}
}

// Load fallback/en-US strings then prefer the localized ones if available.
loadAllStrings("chrome://loop-locale-fallback/content/loop.properties");
loadAllStrings("chrome://loop/locale/loop.properties");

// Supply the strings from the branding bundle on a per-need basis.
let brandBundle =
Services.strings.createBundle("chrome://branding/locale/brand.properties");
Expand Down
1 change: 1 addition & 0 deletions add-on/jar.mn
Expand Up @@ -4,6 +4,7 @@

[features/loop@mozilla.org] chrome.jar:
% content loop %content/ contentaccessible=yes
% content loop-locale-fallback %locale/en-US/
% locale loop en-US %locale/en-US/
% skin loop classic/1.0 %skin/linux/ os=Linux
% skin loop classic/1.0 %skin/osx/ os=Darwin
Expand Down
93 changes: 93 additions & 0 deletions bin/locale_update.py
@@ -0,0 +1,93 @@
#!/usr/bin/python

##
# This script is designed to update the l10n files and locale registration for
# the standalone loop client and loop add-on. The source of the localization
# files is https://github.com/mozilla/loop-client-l10n repository.
# The loop repo is assumed to be https://github.com/mozilla/loop.
#
# Run this script from the local version of loop. It assumes that a local
# version of loop-client-l10n is in a parallel directory: ../loop-client-l10n.
##

from __future__ import print_function

import argparse
import io
import os
import re
import shutil

# defaults
DEF_L10N_SRC = os.path.join(os.pardir, "loop-client-l10n", "l10n")
DEF_L10N_DST = os.path.join("locale")
DEF_INDEX_FILE_NAME = os.path.join("standalone", "content", os.extsep.join(["index", "html"]))
DEF_JAR_FILE_NAME = os.path.join("add-on", os.extsep.join(["jar", "mn"]))


def main(l10n_src, l10n_dst, index_file_name, jar_file_name):
print("deleting existing l10n content tree:", l10n_dst)
shutil.rmtree(l10n_dst, ignore_errors=True)

print("updating l10n tree from", l10n_src)

def create_locale(src_dir):
# Convert loop-client-l10n repo names to loop repo names.
dst_dir = src_dir.replace('_', '-').replace('templates', 'en-US')

shutil.copytree(os.path.join(l10n_src, src_dir), os.path.join(l10n_dst, dst_dir))
return dst_dir

locale_dirs = os.listdir(l10n_src)
locale_list = sorted([create_locale(x) for x in locale_dirs if x[0] != "."])

print("updating locales list in", index_file_name)
with io.open(index_file_name, "r+") as index_file:
index_html = index_file.read()

# Replace the one meta line with new locales.
new_content = re.sub(
'<meta name=(["|\'])locales\\1.*? content=(["|\']).*?\\2.*? />',
'<meta name="locales" content="' + ",".join(locale_list) + '" />',
index_html, 1, re.M | re.S)

index_file.seek(0)
index_file.truncate(0)
index_file.write(new_content)

print("updating locales list in", jar_file_name)
with io.open(jar_file_name, "r+") as jar_file:
jar_mn = jar_file.read()

# Replace multiple locale registrations with new locales.
jar_locales = ['% locale loop {0} %locale/{0}/'.format(x) for x in locale_list]
new_content = re.sub(
'(% locale loop .+\n)+',
'\n'.join(jar_locales) + '\n',
jar_mn)

jar_file.seek(0)
jar_file.truncate(0)
jar_file.write(new_content)

if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Loop Stand-alone Client localization update script")
parser.add_argument('--src',
default=DEF_L10N_SRC,
metavar="path",
help="Source path for l10n resources. Default = " + DEF_L10N_SRC)
parser.add_argument('--dst',
default=DEF_L10N_DST,
metavar="path",
help="Destination path for l10n resources. Default = " + DEF_L10N_DST)
parser.add_argument('--index-file',
default=DEF_INDEX_FILE_NAME,
metavar="name",
help="File to be updated with the locales list. Default = " + DEF_INDEX_FILE_NAME)
parser.add_argument('--jar-file',
default=DEF_JAR_FILE_NAME,
metavar="name",
help="Jar file to be updated with the locales list. Default = " + DEF_JAR_FILE_NAME)
args = parser.parse_args()
main(args.src, args.dst, args.index_file, args.jar_file)

0 comments on commit f684322

Please sign in to comment.