Skip to content

Commit 00600cc

Browse files
authored
Parse Fluent (.ftl) files for products (#924)
1 parent 12d06a8 commit 00600cc

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

app/scripts/setup.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function echogreen() {
2525

2626
function setupExternalLibraries() {
2727
# Check out or update compare-locales library
28-
version="RELEASE_2_1"
28+
version="RELEASE_2_5_1"
2929
if [ ! -d $libraries/compare-locales/.hg ]
3030
then
3131
echogreen "Checking out compare-locales in $libraries"
@@ -41,7 +41,7 @@ function setupExternalLibraries() {
4141
fi
4242

4343
# Check out or update python-fluent library
44-
version="0.4.2"
44+
version="0.4.4"
4545
if [ ! -d $libraries/python-fluent/.git ]
4646
then
4747
echogreen "Checking out the python-fluent library in $libraries"

app/scripts/tmx/tmx_products.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
# Import Fluent Python library
3434
import_library(
3535
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')
3737
try:
3838
import fluent.syntax
3939
except ImportError as e:
@@ -44,21 +44,28 @@
4444
# Import compare-locales
4545
import_library(
4646
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')
4848
try:
4949
from compare_locales import parser
5050
except ImportError as e:
5151
print('Error importing compare-locales library')
5252
print(e)
5353
sys.exit(1)
5454

55+
5556
class StringExtraction():
5657

5758
def __init__(self, storage_path, locale, reference_locale, repository_name):
5859
''' Initialize object '''
5960

6061
# 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+
]
6269
self.storage_mode = ''
6370
self.storage_prefix = ''
6471
self.file_list = []
@@ -139,9 +146,20 @@ def extractStrings(self):
139146
try:
140147
entities, map = file_parser.parse()
141148
for entity in entities:
149+
# Ignore Junk
150+
if isinstance(entity, parser.Junk):
151+
continue
142152
string_id = u'{0}:{1}'.format(
143153
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:
145163
self.translations[string_id] = entity.raw_val
146164
except Exception as e:
147165
print('Error parsing file: {0}'.format(file_name))

0 commit comments

Comments
 (0)