tools/grit/grit/node/structure.py
def FileForLanguage(self, lang, output_dir, create_file=True,
                      return_if_not_generated=True):
    '''Returns the filename of the file associated with this structure,
    for the specified language.

    Args:
      lang: 'fr'
      output_dir: 'c:\temp'
      create_file: True
    '''
    assert self.HasFileForLanguage()
    # If the source language is requested, and no extra changes are requested,
    # use the existing file.
    if ((not lang or lang == self.GetRoot().GetSourceLanguage()) and
        self.attrs['expand_variables'] != 'true' and
        (not self.attrs['run_command'] or
         not self.RunCommandOnCurrentPlatform())):
      if return_if_not_generated:
        input_path = self.GetInputPath()
        if input_path is None:
          return None
        return self.ToRealPath(input_path)
      else:
        return None

    if self.attrs['output_filename'] != '':
      filename = self.attrs['output_filename']
    else:
      filename = os.path.basename(self.attrs['file'])
    assert len(filename)
    filename = '%s_%s' % (lang, filename)
    filename = os.path.join(output_dir, filename)

    # Only create the output if it was requested by the call.
    if create_file:
      text = self.gatherer.Translate(
          lang,
          pseudo_if_not_available=self.PseudoIsAllowed(),
          fallback_to_english=self.ShouldFallbackToEnglish(),
          skeleton_gatherer=self.GetSkeletonGatherer())

      file_contents = util.FixLineEnd(text, self.GetLineEnd())
      if self.ExpandVariables():
        # Note that we reapply substitution a second time here.
        # This is because a) we need to look inside placeholders
        # b) the substitution values are language-dependent
        file_contents = self._Substitute(file_contents)

      with open(filename, 'wb') as file_object:
        output_stream = util.WrapOutputStream(file_object,
                                              self.attrs['output_encoding'])
        output_stream.write(file_contents)

      if self.attrs['run_command'] and self.RunCommandOnCurrentPlatform():
        # Run arbitrary commands after translation is complete so that it
        # doesn't interfere with what's in translation console.
        command = self.attrs['run_command'] % {'filename': filename}
        result = os.system(command)
        assert result == 0, '"%s" failed.' % command

    return filename
Returns the filename of the file associated with this structure,
    for the specified language.

    Args:
      lang: 'fr'
      output_dir: 'c:\temp'
      create_file: True
    
Returns the filename of the file associated with this structure,
for the specified language.
Returns the filename of the file associated with this structure for the specified language .
def FileForLanguage(self, lang, output_dir, create_file=True,
                      return_if_not_generated=True):
    assert self.HasFileForLanguage()
    if ((not lang or lang == self.GetRoot().GetSourceLanguage()) and
        self.attrs['expand_variables'] != 'true' and
        (not self.attrs['run_command'] or
         not self.RunCommandOnCurrentPlatform())):
      if return_if_not_generated:
        input_path = self.GetInputPath()
        if input_path is None:
          return None
        return self.ToRealPath(input_path)
      else:
        return None
    if self.attrs['output_filename'] != '':
      filename = self.attrs['output_filename']
    else:
      filename = os.path.basename(self.attrs['file'])
    assert len(filename)
    filename = '%s_%s' % (lang, filename)
    filename = os.path.join(output_dir, filename)
    if create_file:
      text = self.gatherer.Translate(
          lang,
          pseudo_if_not_available=self.PseudoIsAllowed(),
          fallback_to_english=self.ShouldFallbackToEnglish(),
          skeleton_gatherer=self.GetSkeletonGatherer())
      file_contents = util.FixLineEnd(text, self.GetLineEnd())
      if self.ExpandVariables():
        file_contents = self._Substitute(file_contents)
      with open(filename, 'wb') as file_object:
        output_stream = util.WrapOutputStream(file_object,
                                              self.attrs['output_encoding'])
        output_stream.write(file_contents)
      if self.attrs['run_command'] and self.RunCommandOnCurrentPlatform():
        command = self.attrs['run_command'] % {'filename': filename}
        result = os.system(command)
        assert result == 0, '"%s" failed.' % command
    return filename
def FileForLanguage ( self , lang , output_dir , create_file = True , return_if_not_generated = True ) : assert self . HasFileForLanguage ( ) if ( ( not lang or lang == self . GetRoot ( ) . GetSourceLanguage ( ) ) and self . attrs [ 'expand_variables' ] != 'true' and ( not self . attrs [ 'run_command' ] or not self . RunCommandOnCurrentPlatform ( ) ) ) : if return_if_not_generated : input_path = self . GetInputPath ( ) if input_path is None : return None return self . ToRealPath ( input_path ) else : return None if self . attrs [ 'output_filename' ] != '' : filename = self . attrs [ 'output_filename' ] else : filename = os . path . basename ( self . attrs [ 'file' ] ) assert len ( filename ) filename = '%s_%s' % ( lang , filename ) filename = os . path . join ( output_dir , filename ) if create_file : text = self . gatherer . Translate ( lang , pseudo_if_not_available = self . PseudoIsAllowed ( ) , fallback_to_english = self . ShouldFallbackToEnglish ( ) , skeleton_gatherer = self . GetSkeletonGatherer ( ) ) file_contents = util . FixLineEnd ( text , self . GetLineEnd ( ) ) if self . ExpandVariables ( ) : file_contents = self . _Substitute ( file_contents ) with open ( filename , 'wb' ) as file_object : output_stream = util . WrapOutputStream ( file_object , self . attrs [ 'output_encoding' ] ) output_stream . write ( file_contents ) if self . attrs [ 'run_command' ] and self . RunCommandOnCurrentPlatform ( ) : command = self . attrs [ 'run_command' ] % { 'filename' : filename } result = os . system ( command ) assert result == 0 , '"%s" failed.' % command return filename
Returns the filename of the file associated with this structure,
for the specified language.
Returns the filename of the file associated with this structure for the specified language .
'''Returns the filename of the file associated with this structure,
    for the specified language.

    Args:
      lang: 'fr'
      output_dir: 'c:\temp'
      create_file: True
    ''' # If the source language is requested, and no extra changes are requested, # use the existing file. # Only create the output if it was requested by the call. # Note that we reapply substitution a second time here. # This is because a) we need to look inside placeholders # b) the substitution values are language-dependent # Run arbitrary commands after translation is complete so that it # doesn't interfere with what's in translation console.
self
lang
None
output_dir
None
create_file
None
return_if_not_generated