]> git.evergreen-ils.org Git - Evergreen.git/blob - build/i18n/scripts/basel10n.py
Split out localization base class into basel10n.py
[Evergreen.git] / build / i18n / scripts / basel10n.py
1 #!/usr/bin/env python
2 # basel10n.py
3 """
4 This class enables translation of Evergreen's seed database strings
5 and fieldmapper IDL XML.
6
7 Requires polib from http://polib.googlecode.com
8 """
9 # Copyright 2007 Dan Scott <dscott@laurentian.ca>
10 #
11 # This program is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License
13 # as published by the Free Software Foundation; either version 2
14 # of the License, or (at your option) any later version.
15 #
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
20
21 import polib
22 import time
23
24 class BaseL10N:
25     """
26     Define the base class for localization support in Evergreen
27     """
28
29     def __init__(self):
30         self.pot = polib.POFile()
31
32     def pothead(self, version=None):
33         """
34         Initializes the header for a POT file to reasonable defaults
35         """
36         # We should be smarter about the Project-Id-Version attribute
37         if version is None:
38             version = 'Evergreen 1.4'
39         date = time.strftime("%Y-%m-%d %H:%M:%S")
40         self.pot.metadata['Project-Id-Version'] = version
41         self.pot.metadata['Report-Msgid-Bugs-To'] = \
42             'open-ils-dev@list.georgialibraries.org'
43         # Cheat and hard-code the time zone offset
44         self.pot.metadata['POT-Creation-Date'] = "%s %s" % (date, '-0400')
45         self.pot.metadata['PO-Revision-Date'] = 'YEAR-MO-DA HO:MI+ZONE'
46         self.pot.metadata['Last-Translator'] = 'FULL NAME <EMAIL@ADDRESS>'
47         self.pot.metadata['Language-Team'] = 'LANGUAGE <LL@li.org>'
48         self.pot.metadata['MIME-Version'] = '1.0'
49         self.pot.metadata['Content-Type'] = 'text/plain; charset=utf-8'
50         self.pot.metadata['Content-Transfer-Encoding'] = '8-bit'
51
52     def savepot(self, destination):
53         """
54         Saves the POT file to a specified file.
55         """
56         self.pot.save(destination)
57         
58     def loadpo(self, source):
59         """
60         Loads a translated PO file so we can generate the corresponding SQL or entity definitions.
61         """
62         self.pot = polib.pofile(source)
63
64     def __str__(self):
65         """
66         Returns the PO representation of the strings.
67         """
68         return self.pot.__str__()
69