예제 #1
0
파일: misc.py 프로젝트: uhack0730/pak-tools
    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)
예제 #2
0
 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