OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/python2.4 |
| 2 # Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. |
| 5 |
| 6 '''Supports making amessage from a text file. |
| 7 ''' |
| 8 |
| 9 import types |
| 10 |
| 11 from grit.gather import interface |
| 12 from grit import tclib |
| 13 from grit import util |
| 14 |
| 15 |
| 16 class TxtFile(interface.GathererBase): |
| 17 '''A text file gatherer. Very simple, all text from the file becomes a |
| 18 single clique. |
| 19 ''' |
| 20 |
| 21 def __init__(self, contents): |
| 22 super(type(self), self).__init__() |
| 23 self.text_ = contents |
| 24 self.clique_ = None |
| 25 |
| 26 def Parse(self): |
| 27 self.clique_ = self.uberclique.MakeClique(tclib.Message(text=self.text_)) |
| 28 pass |
| 29 |
| 30 def GetText(self): |
| 31 '''Returns the text of what is being gathered.''' |
| 32 return self.text_ |
| 33 |
| 34 def GetTextualIds(self): |
| 35 return [] |
| 36 |
| 37 def GetCliques(self): |
| 38 '''Returns the MessageClique objects for all translateable portions.''' |
| 39 return [self.clique_] |
| 40 |
| 41 def Translate(self, lang, pseudo_if_not_available=True, |
| 42 skeleton_gatherer=None, fallback_to_english=False): |
| 43 return self.clique_.MessageForLanguage(lang, |
| 44 pseudo_if_not_available, |
| 45 fallback_to_english).GetRealContent() |
| 46 |
| 47 def FromFile(filename_or_stream, extkey=None, encoding = 'cp1252'): |
| 48 if isinstance(filename_or_stream, types.StringTypes): |
| 49 filename_or_stream = util.WrapInputStream(file(filename_or_stream, 'rb'),
encoding) |
| 50 return TxtFile(filename_or_stream.read()) |
| 51 FromFile = staticmethod(FromFile) |
| 52 |
OLD | NEW |