|
33 | 33 | # Import Fluent Python library |
34 | 34 | import_library( |
35 | 35 | libraries_path, 'git', 'python-fluent', |
36 | | - 'https://github.com/projectfluent/python-fluent', '0.4.2') |
| 36 | + 'https://github.com/projectfluent/python-fluent', '0.4.4') |
37 | 37 | try: |
38 | 38 | import fluent.syntax |
39 | 39 | except ImportError as e: |
|
44 | 44 | # Import compare-locales |
45 | 45 | import_library( |
46 | 46 | libraries_path, 'hg', 'compare-locales', |
47 | | - 'https://hg.mozilla.org/l10n/compare-locales', 'RELEASE_2_1') |
| 47 | + 'https://hg.mozilla.org/l10n/compare-locales', 'RELEASE_2_5_1') |
48 | 48 | try: |
49 | 49 | from compare_locales import parser |
50 | 50 | except ImportError as e: |
51 | 51 | print('Error importing compare-locales library') |
52 | 52 | print(e) |
53 | 53 | sys.exit(1) |
54 | 54 |
|
| 55 | + |
55 | 56 | class StringExtraction(): |
56 | 57 |
|
57 | 58 | def __init__(self, storage_path, locale, reference_locale, repository_name): |
58 | 59 | ''' Initialize object ''' |
59 | 60 |
|
60 | 61 | # Set defaults |
61 | | - self.supported_formats = ['.dtd', '.properties', '.ini', '.inc'] |
| 62 | + self.supported_formats = [ |
| 63 | + '.dtd', |
| 64 | + '.ftl', |
| 65 | + '.inc', |
| 66 | + '.ini', |
| 67 | + '.properties', |
| 68 | + ] |
62 | 69 | self.storage_mode = '' |
63 | 70 | self.storage_prefix = '' |
64 | 71 | self.file_list = [] |
@@ -139,9 +146,20 @@ def extractStrings(self): |
139 | 146 | try: |
140 | 147 | entities, map = file_parser.parse() |
141 | 148 | for entity in entities: |
| 149 | + # Ignore Junk |
| 150 | + if isinstance(entity, parser.Junk): |
| 151 | + continue |
142 | 152 | string_id = u'{0}:{1}'.format( |
143 | 153 | self.getRelativePath(file_name), unicode(entity)) |
144 | | - if not isinstance(entity, parser.Junk): |
| 154 | + if file_extension == '.ftl': |
| 155 | + if entity.raw_val is not None: |
| 156 | + self.translations[string_id] = entity.raw_val |
| 157 | + # Store attributes |
| 158 | + for attribute in entity.attributes: |
| 159 | + attr_string_id = u'{0}:{1}.{2}'.format( |
| 160 | + self.getRelativePath(file_name), unicode(entity), unicode(attribute)) |
| 161 | + self.translations[attr_string_id] = attribute.raw_val |
| 162 | + else: |
145 | 163 | self.translations[string_id] = entity.raw_val |
146 | 164 | except Exception as e: |
147 | 165 | print('Error parsing file: {0}'.format(file_name)) |
|
0 commit comments