]> git.evergreen-ils.org Git - working/Evergreen.git/blob - build/i18n/scripts/basel10n.py
Forward port r16670 and r16672 to avoid directory creation errors in Dojo resource...
[working/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, date=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         if date is None:
40             date = time.strftime("%Y-%m-%d %H:%M:%S") + '-0400'
41         self.pot.metadata['Project-Id-Version'] = version
42         self.pot.metadata['Report-Msgid-Bugs-To'] = \
43             'open-ils-dev@list.georgialibraries.org'
44         # Cheat and hard-code the time zone offset
45         self.pot.metadata['POT-Creation-Date'] = date
46         self.pot.metadata['PO-Revision-Date'] = 'YEAR-MO-DA HO:MI+ZONE'
47         self.pot.metadata['Last-Translator'] = 'FULL NAME <EMAIL@ADDRESS>'
48         self.pot.metadata['Language-Team'] = 'LANGUAGE <LL@li.org>'
49         self.pot.metadata['MIME-Version'] = '1.0'
50         self.pot.metadata['Content-Type'] = 'text/plain; charset=utf-8'
51         self.pot.metadata['Content-Transfer-Encoding'] = '8-bit'
52
53     def savepot(self, destination):
54         """
55         Saves the POT file to a specified file.
56         """
57         self.pot.save(destination)
58         
59     def loadpo(self, source):
60         """
61         Loads a translated PO file so we can generate the corresponding SQL or entity definitions.
62         """
63         self.pot = polib.pofile(source)
64
65     def __str__(self):
66         """
67         Returns the PO representation of the strings.
68         """
69         return self.pot.__str__()
70