def use(self, **kwargs): from pylons.i18n import get_lang from r2.lib.template_helpers import static from r2.lib.filters import SC_OFF, SC_ON if g.uncompressedJS: if c.lang == "en" or c.lang not in g.all_languages: # in this case, the msgids *are* the translated strings and we # can save ourselves the pricey step of lexing the js source return Module.use(self, **kwargs) msgids = extract_javascript_msgids(Module.get_source(self)) localized_appendices = self.localized_appendices + [ StringsSource(msgids) ] lines = [Module.use(self, **kwargs)] for appendix in localized_appendices: line = SC_OFF + inline_script_tag.format( content=appendix.get_localized_source(c.lang)) + SC_ON lines.append(line) return "\n".join(lines) else: langs = get_lang() or [g.lang] url = LocalizedModule.languagize_path(self.name, langs[0]) return script_tag.format(src=static(url), **kwargs)
def build(self, minifier): Module.build(self, minifier) with open(self.path) as f: reddit_source = f.read() localized_appendices = self.localized_appendices msgids = extract_javascript_msgids(reddit_source) if msgids: localized_appendices = localized_appendices + [ StringsSource(msgids) ] print >> sys.stderr, "Creating language-specific files:" for lang, unused in iter_langs(): lang_path = LocalizedModule.languagize_path(self.path, lang) # make sure we're not rewriting a different mangled file # via symlink if os.path.islink(lang_path): os.unlink(lang_path) with open(lang_path, "w") as out: print >> sys.stderr, " " + lang_path out.write(reddit_source) for appendix in localized_appendices: out.write(appendix.get_localized_source(lang) + ";")
def build(self, minifier): Module.build(self, minifier) with open(self.path) as f: reddit_source = f.read() localized_appendices = self.localized_appendices msgids = extract_javascript_msgids(reddit_source) if msgids: localized_appendices = localized_appendices + [StringsSource(msgids)] print >> sys.stderr, "Creating language-specific files:" for lang, unused in iter_langs(): lang_path = LocalizedModule.languagize_path(self.path, lang) # make sure we're not rewriting a different mangled file # via symlink if os.path.islink(lang_path): os.unlink(lang_path) with open(lang_path, "w") as out: print >> sys.stderr, " " + lang_path out.write(reddit_source) for appendix in localized_appendices: out.write(appendix.get_localized_source(lang) + ";")
def use(self): from pylons.i18n import get_lang from r2.lib.template_helpers import static if g.uncompressedJS: if c.lang == "en": # in this case, the msgids *are* the translated strings and we # can save ourselves the pricey step of lexing the js source return Module.use(self) msgids = extract_javascript_msgids(Module.get_source(self)) strings = StringsSource(c.lang, msgids) return "\n".join( (Module.use(self), inline_script_tag.format(content=strings.get_plural_forms()), strings.use()) ) else: langs = get_lang() or [g.lang] url = LocalizedModule.languagize_path(self.name, langs[0]) return script_tag.format(src=static(url))
def use(self): from pylons.i18n import get_lang from r2.lib.template_helpers import static if g.uncompressedJS: if c.lang == "en": # in this case, the msgids *are* the translated strings and we # can save ourselves the pricey step of lexing the js source return Module.use(self) msgids = extract_javascript_msgids(Module.get_source(self)) strings = StringsSource(c.lang, msgids) return "\n".join(( Module.use(self), inline_script_tag.format(content=strings.get_plural_forms()), strings.use(), )) else: langs = get_lang() or [g.lang] url = LocalizedModule.languagize_path(self.name, langs[0]) return script_tag.format(src=static(url))
def use(self): from pylons.i18n import get_lang from r2.lib.template_helpers import static from r2.lib.filters import SC_OFF, SC_ON if g.uncompressedJS: if c.lang == "en" or c.lang not in g.all_languages: # in this case, the msgids *are* the translated strings and we # can save ourselves the pricey step of lexing the js source return Module.use(self) msgids = extract_javascript_msgids(Module.get_source(self)) localized_appendices = self.localized_appendices + [StringsSource(msgids)] lines = [Module.use(self)] for appendix in localized_appendices: line = SC_OFF + inline_script_tag.format(content=appendix.get_localized_source(c.lang)) + SC_ON lines.append(line) return "\n".join(lines) else: langs = get_lang() or [g.lang] url = LocalizedModule.languagize_path(self.name, langs[0]) return script_tag.format(src=static(url))
def build(self, closure): Module.build(self, closure) with open(self.path) as f: reddit_source = f.read() msgids = extract_javascript_msgids(reddit_source) print >> sys.stderr, "Creating language-specific files:" for lang, unused in iter_langs(): strings = StringsSource(lang, msgids) lang_path = LocalizedModule.languagize_path(self.path, lang) # make sure we're not rewriting a different mangled file # via symlink if os.path.islink(lang_path): os.unlink(lang_path) with open(lang_path, "w") as out: print >> sys.stderr, " " + lang_path out.write(reddit_source) if self.inject_plural_forms: out.write(strings.get_plural_forms()) out.write(strings.get_source())