def build(): try: mappings, _ = parse_mapping(open(cli.babelconf)) except IOError: sys.exit("Could not find Babel conf ({0})".format(cli.babelconf)) search_paths = [search_path for (search_path, _) in mappings] def is_template(name): full_name = os.path.join(cli.templates, name) for path in search_paths: if pathmatch(path, full_name): return True locales = get_locales() context = dict(locales=locales, ) for locale in locales: activate_locale(locale) if cli.verbose: print "Processing locale:", get_locale() for name in env.list_templates(): if not is_template(name): continue folder = get_locale().language if cli.verbose > 1: print "Writing template: ", name context = dict(context, now=datetime.now(), current_locale=get_locale()) write_template(name, folder, context)
def test_parse_mapping(): buf = StringIO('[extractors]\n' 'custom = mypackage.module:myfunc\n' '\n' '# Python source files\n' '[python: **.py]\n' '\n' '# Genshi templates\n' '[genshi: **/templates/**.html]\n' 'include_attrs =\n' '[genshi: **/templates/**.txt]\n' 'template_class = genshi.template:TextTemplate\n' 'encoding = latin-1\n' '\n' '# Some custom extractor\n' '[custom: **/custom/*.*]\n') method_map, options_map = frontend.parse_mapping(buf) assert len(method_map) == 4 assert method_map[0] == ('**.py', 'python') assert options_map['**.py'] == {} assert method_map[1] == ('**/templates/**.html', 'genshi') assert options_map['**/templates/**.html']['include_attrs'] == '' assert method_map[2] == ('**/templates/**.txt', 'genshi') assert (options_map['**/templates/**.txt']['template_class'] == 'genshi.template:TextTemplate') assert options_map['**/templates/**.txt']['encoding'] == 'latin-1' assert method_map[3] == ('**/custom/*.*', 'mypackage.module:myfunc') assert options_map['**/custom/*.*'] == {}
def test_parse_mapping(): buf = StringIO( '[extractors]\n' 'custom = mypackage.module:myfunc\n' '\n' '# Python source files\n' '[python: **.py]\n' '\n' '# Genshi templates\n' '[genshi: **/templates/**.html]\n' 'include_attrs =\n' '[genshi: **/templates/**.txt]\n' 'template_class = genshi.template:TextTemplate\n' 'encoding = latin-1\n' '\n' '# Some custom extractor\n' '[custom: **/custom/*.*]\n') method_map, options_map = frontend.parse_mapping(buf) assert len(method_map) == 4 assert method_map[0] == ('**.py', 'python') assert options_map['**.py'] == {} assert method_map[1] == ('**/templates/**.html', 'genshi') assert options_map['**/templates/**.html']['include_attrs'] == '' assert method_map[2] == ('**/templates/**.txt', 'genshi') assert (options_map['**/templates/**.txt']['template_class'] == 'genshi.template:TextTemplate') assert options_map['**/templates/**.txt']['encoding'] == 'latin-1' assert method_map[3] == ('**/custom/*.*', 'mypackage.module:myfunc') assert options_map['**/custom/*.*'] == {}
def test_parse_mapping(): buf = StringIO( "[extractors]\n" "custom = mypackage.module:myfunc\n" "\n" "# Python source files\n" "[python: **.py]\n" "\n" "# Genshi templates\n" "[genshi: **/templates/**.html]\n" "include_attrs =\n" "[genshi: **/templates/**.txt]\n" "template_class = genshi.template:TextTemplate\n" "encoding = latin-1\n" "\n" "# Some custom extractor\n" "[custom: **/custom/*.*]\n" ) method_map, options_map = frontend.parse_mapping(buf) assert len(method_map) == 4 assert method_map[0] == ("**.py", "python") assert options_map["**.py"] == {} assert method_map[1] == ("**/templates/**.html", "genshi") assert options_map["**/templates/**.html"]["include_attrs"] == "" assert method_map[2] == ("**/templates/**.txt", "genshi") assert options_map["**/templates/**.txt"]["template_class"] == "genshi.template:TextTemplate" assert options_map["**/templates/**.txt"]["encoding"] == "latin-1" assert method_map[3] == ("**/custom/*.*", "mypackage.module:myfunc") assert options_map["**/custom/*.*"] == {}
def _get_mappings(self): """Override to check js_message_extractors keywords and not message_extractors """ mappings = {} if self.mapping_file: mappings = babel.extract_messages._get_mappings(self) elif getattr(self.distribution, 'js_message_extractors', None): message_extractors = self.distribution.js_message_extractors for dirname, mapping in message_extractors.items(): if isinstance(mapping, string_types): method_map, options_map = \ babel.parse_mapping(StringIO(mapping)) else: method_map, options_map = [], {} for pattern, method, options in mapping: method_map.append((pattern, method)) options_map[pattern] = options or {} mappings[dirname] = method_map, options_map else: mappings = babel.extract_messages._get_mappings(self) return mappings
def build(): try: mappings, _ = parse_mapping(open(cli.babelconf)) except IOError: sys.exit("Could not find Babel conf ({0})".format(cli.babelconf)) search_paths = [search_path for (search_path, _) in mappings] def is_template(name): full_name = os.path.join(cli.templates, name) for path in search_paths: if pathmatch(path, full_name): return True locales = get_locales() context = dict( locales=locales, ) for locale in locales: activate_locale(locale) if cli.verbose: print "Processing locale:", get_locale() for name in env.list_templates(): if not is_template(name): continue folder = get_locale().language if cli.verbose > 1: print "Writing template: ", name context = dict(context, now=datetime.now(), current_locale=get_locale() ) write_template(name, folder, context)
def get_mappings(): fileobj = open(resource_filename('nextgisweb', 'babel.cfg'), 'r') return parse_mapping(fileobj)