Skip to content

Commit 1ecb3c0

Browse files
committed
Move lang files into the data directory
1 parent d0fb5d4 commit 1ecb3c0

18 files changed

+71
-52
lines changed

bedrock/base/tests/test_accepted_locales.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from django.conf import settings
55
from django.test import TestCase
66

7-
from bedrock.settings.base import get_dev_languages, path
7+
from bedrock.settings.base import get_dev_languages, data_path
88

99

1010
class AcceptedLocalesTest(TestCase):
@@ -15,8 +15,8 @@ class AcceptedLocalesTest(TestCase):
1515
DEV_LANGUAGES or PROD_LANGUAGES should be used.
1616
1717
"""
18-
locale = path('locale')
19-
locale_bkp = path('locale_bkp')
18+
locale = data_path('locale')
19+
locale_bkp = data_path('locale_bkp')
2020

2121
@classmethod
2222
def setup_class(cls):

bedrock/settings/base.py

+14-13
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,18 @@
1919

2020

2121
# ROOT path of the project. A pathlib.Path object.
22+
DATA_PATH = config('DATA_PATH', default='data')
2223
ROOT_PATH = Path(__file__).resolve().parents[2]
23-
GIT_REPOS_PATH = ROOT_PATH / 'git-repos'
24+
DATA_PATH = ROOT_PATH / DATA_PATH
2425
ROOT = str(ROOT_PATH)
2526

2627

2728
def path(*args):
2829
return abspath(str(ROOT_PATH.joinpath(*args)))
2930

3031

31-
def git_repo_path(*args):
32-
return abspath(str(GIT_REPOS_PATH.joinpath(*args)))
32+
def data_path(*args):
33+
return abspath(str(DATA_PATH.joinpath(*args)))
3334

3435

3536
# Is this a dev instance?
@@ -41,7 +42,7 @@ def git_repo_path(*args):
4142
DATABASES = {
4243
'default': {
4344
'ENGINE': 'django_prometheus.db.backends.sqlite3',
44-
'NAME': path('bedrock.db'),
45+
'NAME': data_path('bedrock.db'),
4546
},
4647
}
4748

@@ -112,7 +113,7 @@ def git_repo_path(*args):
112113
default='product_details.storage.PDDatabaseStorage')
113114
# path into which to clone the p-d json repo
114115
PROD_DETAILS_JSON_REPO_PATH = config('PROD_DETAILS_JSON_REPO_PATH',
115-
default=git_repo_path('product_details_json'))
116+
default=data_path('product_details_json'))
116117
PROD_DETAILS_JSON_REPO_URI = config('PROD_DETAILS_JSON_REPO_URI',
117118
default='https://github.com/mozilla-releng/product-details.git')
118119
PROD_DETAILS_JSON_REPO_BRANCH = config('PROD_DETAILS_JSON_REPO_BRANCH', default='production')
@@ -134,7 +135,7 @@ def git_repo_path(*args):
134135
'sr', 'sv-SE', 'ta', 'te', 'th', 'tl', 'tr', 'trs', 'uk', 'ur',
135136
'uz', 'vi', 'xh', 'zh-CN', 'zh-TW', 'zu')
136137

137-
LOCALES_PATH = ROOT_PATH / 'locale'
138+
LOCALES_PATH = DATA_PATH / 'locale'
138139
default_locales_repo = 'www.mozilla.org' if DEV else 'bedrock-l10n'
139140
default_locales_repo = 'https://github.com/mozilla-l10n/{}'.format(default_locales_repo)
140141
LOCALES_REPO = config('LOCALES_REPO', default=default_locales_repo)
@@ -260,13 +261,13 @@ def lazy_langs():
260261
FLUENT_DEFAULT_PERCENT_REQUIRED = config('FLUENT_DEFAULT_PERCENT_REQUIRED', default='80', parser=int)
261262
FLUENT_REPO = config('FLUENT_REPO', default='mozmeao/www-l10n')
262263
FLUENT_REPO_URL = f'https://github.com/{FLUENT_REPO}'
263-
FLUENT_REPO_PATH = GIT_REPOS_PATH / 'www-l10n'
264+
FLUENT_REPO_PATH = DATA_PATH / 'www-l10n'
264265
# will be something like "<github username>:<github token>"
265266
FLUENT_REPO_AUTH = config('FLUENT_REPO_AUTH', default='')
266267
FLUENT_LOCAL_PATH = ROOT_PATH / 'l10n'
267268
FLUENT_L10N_TEAM_REPO = config('FLUENT_L10N_TEAM_REPO', default='mozilla-l10n/www-l10n')
268269
FLUENT_L10N_TEAM_REPO_URL = f'https://github.com/{FLUENT_L10N_TEAM_REPO}'
269-
FLUENT_L10N_TEAM_REPO_PATH = GIT_REPOS_PATH / 'l10n-team'
270+
FLUENT_L10N_TEAM_REPO_PATH = DATA_PATH / 'l10n-team'
270271
# 10 seconds during dev and 10 min in prod
271272
FLUENT_CACHE_TIMEOUT = config('FLUENT_CACHE_TIMEOUT', default='10' if DEBUG else '600', parser=int)
272273
# order matters. first sting found wins.
@@ -703,7 +704,7 @@ def get_app_name(hostname):
703704
# Google Analytics
704705
GA_ACCOUNT_CODE = ''
705706

706-
EXTERNAL_FILES_PATH = config('EXTERNAL_FILES_PATH', default=git_repo_path('community_data'))
707+
EXTERNAL_FILES_PATH = config('EXTERNAL_FILES_PATH', default=data_path('community_data'))
707708
EXTERNAL_FILES_BRANCH = config('EXTERNAL_FILES_BRANCH', default='master')
708709
EXTERNAL_FILES_REPO = config('EXTERNAL_FILES_REPO', default='https://github.com/mozilla/community-data.git')
709710
EXTERNAL_FILES = {
@@ -1352,16 +1353,16 @@ def get_app_name(hostname):
13521353
else:
13531354
content_cards_default_branch = 'prod-processed'
13541355

1355-
CONTENT_CARDS_PATH = config('CONTENT_CARDS_PATH', default=git_repo_path('content_cards'))
1356+
CONTENT_CARDS_PATH = config('CONTENT_CARDS_PATH', default=data_path('content_cards'))
13561357
CONTENT_CARDS_REPO = config('CONTENT_CARDS_REPO', default='https://github.com/mozmeao/www-admin.git')
13571358
CONTENT_CARDS_BRANCH = config('CONTENT_CARDS_BRANCH', default=content_cards_default_branch)
13581359
CONTENT_CARDS_URL = config('CONTENT_CARDS_URL', default=STATIC_URL)
13591360

1360-
RELEASE_NOTES_PATH = config('RELEASE_NOTES_PATH', default=git_repo_path('release_notes'))
1361+
RELEASE_NOTES_PATH = config('RELEASE_NOTES_PATH', default=data_path('release_notes'))
13611362
RELEASE_NOTES_REPO = config('RELEASE_NOTES_REPO', default='https://github.com/mozilla/release-notes.git')
13621363
RELEASE_NOTES_BRANCH = config('RELEASE_NOTES_BRANCH', default='master')
13631364

1364-
WWW_CONFIG_PATH = config('WWW_CONFIG_PATH', default=git_repo_path('www_config'))
1365+
WWW_CONFIG_PATH = config('WWW_CONFIG_PATH', default=data_path('www_config'))
13651366
WWW_CONFIG_REPO = config('WWW_CONFIG_REPO', default='https://github.com/mozmeao/www-config.git')
13661367
WWW_CONFIG_BRANCH = config('WWW_CONFIG_BRANCH', default='master')
13671368

@@ -1372,7 +1373,7 @@ def get_app_name(hostname):
13721373
LEGAL_DOCS_CACHE_TIMEOUT = config('LEGAL_DOCS_CACHE_TIMEOUT', default='60' if DEV else '600', parser=int)
13731374

13741375
MOFO_SECURITY_ADVISORIES_PATH = config('MOFO_SECURITY_ADVISORIES_PATH',
1375-
default=git_repo_path('mofo_security_advisories'))
1376+
default=data_path('mofo_security_advisories'))
13761377
MOFO_SECURITY_ADVISORIES_REPO = config('MOFO_SECURITY_ADVISORIES_REPO',
13771378
default='https://github.com/mozilla/'
13781379
'foundation-security-advisories.git')

bin/db_s3_utils.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
from subprocess import check_output, CalledProcessError
55

66

7-
JSON_DATA_FILE = getenv('AWS_DB_JSON_DATA_FILE', 'bedrock_db_info.json')
8-
DB_FILE = 'bedrock.db'
7+
DATA_PATH = getenv('DATA_PATH', 'data')
8+
JSON_DATA_FILE = getenv('AWS_DB_JSON_DATA_FILE', f'{DATA_PATH}/bedrock_db_info.json')
9+
DB_FILE = f'{DATA_PATH}/bedrock.db'
910
CACHE = {}
1011
BLOCKSIZE = 65536
1112

bin/run-db-download.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
set_db_data,
1313
JSON_DATA_FILE,
1414
DB_FILE,
15+
DATA_PATH,
1516
)
1617

1718

@@ -29,7 +30,7 @@ def get_file_url(filename):
2930

3031
def download_db_info():
3132
try:
32-
resp = requests.get(get_file_url(JSON_DATA_FILE))
33+
resp = requests.get(get_file_url(os.path.basename(JSON_DATA_FILE)))
3334
resp.raise_for_status()
3435
except requests.RequestException:
3536
return None
@@ -42,7 +43,7 @@ def download_db_info():
4243

4344

4445
def download_db_file(filename):
45-
resp = requests.get(get_file_url(filename), stream=True)
46+
resp = requests.get(get_file_url(os.path.basename(filename)), stream=True)
4647
with open(filename, 'wb') as fp:
4748
for chunk in resp.iter_content(chunk_size=128):
4849
fp.write(chunk)
@@ -76,6 +77,7 @@ def main(args):
7677
return 0
7778

7879
new_db_file = db_info['file_name']
80+
new_db_file = f'{DATA_PATH}/{new_db_file}'
7981
download_db_file(new_db_file)
8082
checksum = get_db_checksum(new_db_file)
8183
if checksum == db_info['checksum']:

bin/run-sync-all.sh

+3
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,8 @@ if [ ! -e ./manage.py ]; then
66
cd $script_parent_dir
77
fi
88

9+
# ensure the data dir exists
10+
mkdir -p data
11+
912
# use honcho to inject the proper env vars
1013
honcho run --env docker/envfiles/prod.env ./bin/sync-all.sh

data/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
**/*
2+
!.gitignore

docker-compose.yml

-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ services:
4343
- ./wsgi/:/app/wsgi:delegated
4444
- ./locale/:/app/locale:delegated
4545
- ./l10n/:/app/l10n:delegated
46-
- ./git-repos/:/app/git-repos:delegated
4746

4847
# run the tests against local changes
4948
test:
@@ -61,7 +60,6 @@ services:
6160
- ./tests/:/app/tests:delegated
6261
- ./wsgi/:/app/wsgi:delegated
6362
- ./l10n/:/app/l10n:delegated
64-
- ./git-repos/:/app/git-repos:delegated
6563

6664
# run tests with no volumes
6765
test-image:
@@ -93,7 +91,6 @@ services:
9391
- ./wsgi/:/app/wsgi:delegated
9492
- ./locale/:/app/locale:delegated
9593
- ./l10n/:/app/l10n:delegated
96-
- ./git-repos/:/app/git-repos:delegated
9794

9895
builder:
9996
build:

docs/fluent-conversion.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ recipe path.
163163
Before you run this, make sure to update the local clones of your l10n repositories.
164164

165165
This command will use the Fluent file you edited as template, read the legacy translations
166-
from ``locale`` and write the generated Fluent files for each locale into the ``git-repos/www-l10n/`` directory.
166+
from ``locale`` and write the generated Fluent files for each locale into the ``data/www-l10n/`` directory.
167167

168168
Append each locale you wish to convert in a space-separated list. You can find the full
169169
list of supported locales in the `Pontoon configuration file`_ and below in a space-separated

docs/l10n.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ If you don't already have a ``locale`` directory, this command will clone the
2020
git repo containing the .lang translation files (either the dev or prod files
2121
depending on your ``DEV`` setting). If the folder is already present, it will
2222
update the repository to the latest version. It do the same thing for the
23-
repository for the .ftl translation files in ``git-repos/www-l10n`` directory.
23+
repository for the .ftl translation files in ``data/www-l10n`` directory.
2424

2525
Fluent
2626
======

lib/l10n_utils/dotlang.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,9 @@ def translate(text, files):
114114

115115
for file_ in files:
116116
key = "dotlang-%s-%s" % (lang, file_)
117-
rel_path = os.path.join('locale', lang, '%s.lang' % file_)
118-
117+
path = str(settings.LOCALES_PATH / lang / f'{file_}.lang')
119118
trans = cache.get(key)
120119
if trans is None:
121-
path = os.path.join(settings.ROOT, rel_path)
122120
trans = parse(path)
123121
cache.set(key, trans)
124122

@@ -130,7 +128,7 @@ def translate(text, files):
130128
'replaced text (aka %s)')
131129
message = '%s\n\n%s\n%s' % (explanation, text,
132130
trans[tweaked_text])
133-
mail_error(rel_path, message)
131+
mail_error(path, message)
134132
return Markup(text)
135133
return Markup(trans[tweaked_text])
136134
return Markup(text)
@@ -225,12 +223,11 @@ def lang_file_tag_set(path, lang=None):
225223
return ALL_THE_THINGS
226224

227225
lang = lang or translation.get_language(True)
228-
rel_path = os.path.join('locale', lang, '%s.lang' % path)
229-
cache_key = 'tag:%s' % rel_path
226+
fpath = settings.LOCALES_PATH / lang / f'{path}.lang'
227+
cache_key = f'tag:locale/{lang}/{path}.lang'
230228
tag_set = cache.get(cache_key)
231229
if tag_set is None:
232230
tag_set = set()
233-
fpath = os.path.join(settings.ROOT, rel_path)
234231
try:
235232
with codecs.open(fpath, 'r', 'utf-8', errors='replace') as lines:
236233
for line in lines:

lib/l10n_utils/gettext.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,18 @@ def extract_content(s):
7676

7777

7878
def po_msgs(domain):
79-
return parse_po(join(settings.ROOT, 'locale', 'templates', 'LC_MESSAGES',
80-
'{}.pot'.format(domain)))
79+
path = settings.LOCALES_PATH / 'templates' / 'LC_MESSAGES' / f'{domain}.pot'
80+
return parse_po(str(path))
8181

8282

8383
def translated_strings(file_):
84-
path = join(settings.ROOT, 'locale', 'templates', file_)
84+
path = str(settings.LOCALES_PATH / 'templates', file_)
8585
trans = list(parse_lang(path, skip_untranslated=False).keys())
8686
return trans
8787

8888

8989
def lang_file(name, lang):
90-
return join(settings.ROOT, 'locale', lang, name)
90+
return str(settings.LOCALES_PATH / lang / name)
9191

9292

9393
def is_template(path):

lib/l10n_utils/management/commands/l10n_check.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121

2222
def l10n_file(*args):
23-
return path.join(settings.ROOT, 'locale', *args)
23+
return str(settings.LOCALES_PATH.joinpath(*args))
2424

2525

2626
def list_templates():

lib/l10n_utils/management/commands/l10n_extract.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ def handle(self, *args, **options):
150150
filenames = options['filenames']
151151
if filenames:
152152
# mimics puente.management.commands.extract for a list of files
153-
outputdir = os.path.join(settings.ROOT, 'locale', 'templates',
154-
'LC_MESSAGES')
153+
outputdir = str(settings.LOCALES_PATH / 'templates' / 'LC_MESSAGES')
155154
if not os.path.isdir(outputdir):
156155
os.makedirs(outputdir)
157156

lib/l10n_utils/management/commands/l10n_merge.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def add_arguments(self, parser):
2020
def handle(self, *args, **options):
2121
langs = options['langs']
2222
if not langs:
23-
langs = os.listdir(os.path.join(settings.ROOT, 'locale'))
23+
langs = os.listdir(str(settings.LOCALES_PATH))
2424
langs = [x for x in langs if x != 'templates']
2525
langs = [x for x in langs if x[0] != '.']
2626

lib/l10n_utils/tests/test_commands.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import codecs
77
from os import path
88
from io import StringIO, IOBase
9+
from pathlib import Path
910
from textwrap import dedent
1011

1112
from django.conf import settings
@@ -23,9 +24,10 @@
2324
from lib.l10n_utils.management.commands.l10n_extract import extract_from_files
2425
from lib.l10n_utils.tests import capture_stdio
2526

26-
27-
ROOT = path.join(path.dirname(path.abspath(__file__)), 'test_files')
28-
TEMPLATE_DIRS = (path.join(ROOT, 'templates'),)
27+
ROOT_PATH = Path(__file__).with_name('test_files')
28+
ROOT = str(ROOT_PATH)
29+
LOCALES_PATH = ROOT_PATH / 'locale'
30+
TEMPLATE_DIRS = (str(ROOT_PATH / 'templates'),)
2931

3032
METHODS = [
3133
('templates/**.html',
@@ -38,7 +40,7 @@
3840
TRUE_MOCK.return_value = True
3941

4042

41-
@override_settings(ROOT=ROOT)
43+
@override_settings(ROOT=ROOT, LOCALES_PATH=LOCALES_PATH)
4244
class TestL10nExtract(TestCase):
4345
def test_extract_from_files(self):
4446
"""
@@ -116,7 +118,7 @@ def test_extract_from_files_callback_works(self):
116118
callback.assert_called_once_with(testfile[0], METHODS[0][1], ANY)
117119

118120

119-
@override_settings(ROOT=ROOT)
121+
@override_settings(LOCALES_PATH=LOCALES_PATH)
120122
class TestL10nCheck(TestCase):
121123
def _get_block(self, blocks, name):
122124
"""Out of all blocks, grab the one with the specified name."""
@@ -328,7 +330,7 @@ def test_copy_template(self):
328330
self.assertEqual(open_buffer.getvalue(), good_value)
329331

330332

331-
@override_settings(ROOT=ROOT)
333+
@override_settings(LOCALES_PATH=LOCALES_PATH)
332334
class Testl10nMerge(TestCase):
333335
@patch('lib.l10n_utils.gettext.settings.ROOT', ROOT)
334336
@patch('lib.l10n_utils.gettext._append_to_lang_file')
@@ -338,7 +340,7 @@ def test_merge_lang_files(self, write_mock):
338340
Bug 861168.
339341
"""
340342
merge_lang_files(['de'])
341-
dest_file = path.join(ROOT, 'locale', 'de', 'firefox', 'fx.lang')
343+
dest_file = str(LOCALES_PATH / 'de' / 'firefox' / 'fx.lang')
342344
write_mock.assert_called_once_with(dest_file,
343345
[[None, u'Find out if your device is '
344346
u'supported &nbsp;\xbb']])

0 commit comments

Comments
 (0)