def test_bad_outfile(self): with self.assertRaises(ValueError): translate_util.register_translatesafe_compile( 'BAD OUTFILE', '{{path}}.min.js', [ 'genfiles/translate_util_test/en/{{path}}.min.js', 'genfiles/extracted_strings/boxes/{{path}}.small_mo.pickle' ], None)
original_css = f.readlines() mirrored_css = mirror_css(original_css) with open(self.abspath(outfile_name), 'w') as f: f.write("".join(mirrored_css)) # Most languages don't need any CSS translation, so we just 'copy' the # input to the output. (The languages that do need translation are # special-cased below.) # CSS files are translated after autoprefixing (which happens after LESS # compilation, when appropriate) translate_util.register_translatesafe_compile( 'TRANSLATED AUTOPREFIXED CSS', 'genfiles/compiled_autoprefixed_css/{lang}/{{path}}.css', ['genfiles/compiled_autoprefixed_css/en/{{path}}.css'], symlink_util.CreateSymlink()) # Generate rules for right-to-left languages # These differ in that they: # 1) mirror the CSS, # 2) symlink to each other rather than 'en' symlink_lang = intl.data.right_to_left_languages()[0] for lang in intl.data.right_to_left_languages(): translate_util.register_translatesafe_compile( 'TRANSLATED AUTOPREFIXED CSS (%s)' % lang, 'genfiles/compiled_autoprefixed_css/%s/{{path}}.css' % lang, ['genfiles/compiled_autoprefixed_css/en/{{path}}.css'], TranslateAndMirrorCss(), maybe_symlink_to=(
# small_mo.pickle files are recreatd every time {lang}.po files # change, but their contents usually don't change, so crc's are # good for us. compute_crc=True) # This catches files that are compiled (or transpiled) into js. dirs_with_js = ('genfiles/compiled_{type}', # This is a special case (calculator.js has its own directory) 'genfiles/khan-exercises', ) for d in dirs_with_js: translate_util.register_translatesafe_compile( 'TRANSLATED JS FILES (%s)' % d, '%s/{lang}/{{path}}.js' % d, ['%s/en/{{path}}.js' % d, ('genfiles/extracted_strings/{lang}/' '%s/{lang}/{{path}}.js.small_mo.pickle' % d)], TranslateJavascript(), compute_crc=True) # This is the rule used in prod, where we only translate javascript # after it's been compressed. The exception is handlebars files, # which are translated before they're even converted to javascript, in # compile_handlebars.py. Luckily, the special-case rule for the # handlebars files (in compress_js.py) has higher precedence than this # rule, so we can be fully general here. # We use 'trumped_by' to make sure this rule doesn't apply when lang=en, # and also to make sure this rule doesn't apply when translating handlebars. translate_util.register_translatesafe_compile( 'TRANSLATED COMPRESSED JS FILES',
"""Tests for translate_util.py.""" from __future__ import absolute_import from shared.testutil import testsize from kake import translate_util from kake.lib import compile_rule import kake.lib.testutil translate_util.register_translatesafe_compile( 'LANG', 'genfiles/translate_util_test/{lang}/{{path}}.min.js', [ 'genfiles/translate_util_test/en/{{path}}.min.js', 'genfiles/extracted_strings/{lang}/{{path}}.small_mo.pickle' ], None) translate_util.register_translatesafe_compile( 'BOXES', 'genfiles/translate_util_test/boxes/{{path}}.min.js', [ 'genfiles/translate_util_test/en/{{path}}.min.js', ('genfiles/extracted_strings/boxes/' 'genfiles/translate_util_test/boxes/{{path}}.small_mo.pickle') ], None) @testsize.tiny class TestRegisterTranslatesafeCompile(kake.lib.testutil.KakeTestBase): def test_var_for_language(self): """Test a rule where the lang is specified as a variable: {lang}.""" # I test by making sure the different nestings all get their own rule. rules = [ compile_rule.find_compile_rule( 'genfiles/translate_util_test/es/foo.min.js'),