def SetOutputContext(self, output_language, defines): """Set the output context: language and defines. Prepares substitutions. The substitutions are reset every time the OutputContext is changed. They include messages designated as variables, and language codes for html and rc files. Args: output_language: a two-letter language code (eg: 'en', 'ar'...) or '' defines: a map of names to values (strings or booleans.) """ # We do not specify the output language for .grh files; so we get an empty # string as the default. The value should match # grit.clique.MessageClique.source_language. self.output_language = output_language or self.GetSourceLanguage() self.defines = defines self.substituter.AddMessages(self.GetSubstitutionMessages(), self.output_language) if self.output_language in _RTL_LANGS: direction = 'dir="RTL"' else: direction = 'dir="LTR"' self.substituter.AddSubstitutions({ 'GRITLANGCODE': self.output_language, 'GRITDIR': direction, }) from grit.format import rc # avoid circular dep rc.RcSubstitutions(self.substituter, self.output_language)
def GetSubstituter(self): if self.substituter is None: self.substituter = util.Substituter() self.substituter.AddMessages(self.GetSubstitutionMessages(), self.output_language) if self.output_language in _RTL_LANGS: direction = 'dir="RTL"' else: direction = 'dir="LTR"' self.substituter.AddSubstitutions({ 'GRITLANGCODE': self.output_language, 'GRITDIR': direction, }) from grit.format import rc # avoid circular dep rc.RcSubstitutions(self.substituter, self.output_language) return self.substituter