Skip to content

Commit

Permalink
Add LTR/RTL tooling for help maintaining sandboxes
Browse files Browse the repository at this point in the history
  • Loading branch information
sarina committed Jul 8, 2014
1 parent f5303e8 commit 6d9af01
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 3 deletions.
23 changes: 23 additions & 0 deletions i18n/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,27 @@ def translated_locales(self):
"""
return sorted(set(self.locales) - set([self.source_locale]))

@property
def rtl_langs(self):
"""
Returns the set of translated RTL language codes present in self.locales.
Ignores source locale.
"""
def is_rtl(lang):
# Base RTL langs are Arabic, Farsi, Hebrew, and Urdu
base_rtl = ['ar', 'fa', 'he', 'ur']

# do this to capture both 'fa' and 'fa_IR'
return any([lang.startswith(base_code) for base_code in base_rtl])

return sorted(set([lang for lang in self.translated_locales if is_rtl(lang)]))

@property
def ltr_langs(self):
"""
Returns the set of translated LTR language codes present in self.locales.
Ignores source locale.
"""
return sorted(set(self.translated_locales) - set(self.rtl_langs))

CONFIGURATION = Configuration()
11 changes: 10 additions & 1 deletion i18n/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,23 @@ class Generate(Runner):
def add_args(self):
self.parser.description = "Generate merged and compiled message files."
self.parser.add_argument("--strict", action='store_true', help="Complain about missing files.")
self.parser.add_argument("--ltr", action='store_true', help="Only generate for LTR languages.")
self.parser.add_argument("--rtl", action='store_true', help="Only generate for RTL languages.")

def run(self, args):
"""
Main entry point for script
"""
logging.basicConfig(stream=sys.stdout, level=logging.INFO)

for locale in config.CONFIGURATION.translated_locales:
if args.ltr:
langs = config.CONFIGURATION.ltr_langs
elif args.rtl:
langs = config.CONFIGURATION.rtl_langs
else:
langs = config.CONFIGURATION.translated_locales

for locale in langs:
merge_files(locale, fail_if_missing=args.strict)
# Dummy text is not required. Don't raise exception if files are missing.
for locale in config.CONFIGURATION.dummy_locales:
Expand Down
32 changes: 30 additions & 2 deletions i18n/transifex.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,36 @@ def pull():
clean_translated_locales()


def clean_translated_locales():
def pull_all_ltr():
"""
Pulls all translations - reviewed or not - for LTR languages
"""
print("Pulling all translated LTR languages from transifex...")
for lang in config.CONFIGURATION.ltr_langs:
print ('rm -rf conf/locale/' + lang)
execute('rm -rf conf/locale/' + lang)
execute('tx pull -l ' + lang)
clean_translated_locales(langs=config.CONFIGURATION.ltr_langs)


def pull_all_rtl():
"""
Pulls all translations - reviewed or not - for RTL languages
"""
print("Pulling all translated RTL languages from transifex...")
for lang in config.CONFIGURATION.rtl_langs:
print ('rm -rf conf/locale/' + lang)
execute('rm -rf conf/locale/' + lang)
execute('tx pull -l ' + lang)
clean_translated_locales(langs=config.CONFIGURATION.rtl_langs)


def clean_translated_locales(langs=config.CONFIGURATION.translated_locales):
"""
Strips out the warning from all translated po files
about being an English source file.
"""
for locale in config.CONFIGURATION.translated_locales:
for locale in langs:
clean_locale(locale)


Expand Down Expand Up @@ -81,6 +105,10 @@ def run(self, args):
push()
elif args.command == "pull":
pull()
elif args.command == "ltr":
pull_all_ltr()
elif args.command == "rtl":
pull_all_rtl()
else:
raise Exception("unknown command ({cmd})".format(cmd=args.command))

Expand Down

0 comments on commit 6d9af01

Please sign in to comment.