Skip to content

Commit 463f65f

Browse files
authored
Set resource_name in .tx/config files to preserve resource naming behavior prior to 2.1.0 (#90)
1 parent 56b09b1 commit 463f65f

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Incompatibility
1313

1414
Features
1515
--------
16+
- #90: ``update-txconfig-resources`` command sets ``resource_name`` in the ``.tx/config`` file to match the resource's slug.
1617

1718
Documentation
1819
-------------

sphinx_intl/transifex.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ def update_txconfig_resources(transifex_organization_name, transifex_project_nam
153153
'add',
154154
'--organization', '%(transifex_organization_name)s',
155155
'--project', '%(transifex_project_name)s',
156-
'--resource', '%(resource_name)s',
156+
'--resource', '%(resource_slug)s',
157+
'--resource-name', '%(resource_name)s',
157158
'--file-filter', '%(locale_dir)s/<lang>/LC_MESSAGES/%(resource_path)s.po',
158159
'--type', 'PO',
159160
'%(pot_dir)s/%(resource_path)s.pot',
@@ -174,7 +175,7 @@ def update_txconfig_resources(transifex_organization_name, transifex_project_nam
174175
) as progress_bar:
175176
for pot_path in progress_bar:
176177
resource_path = str(pot_path.relative_to(pot_dir).with_suffix(''))
177-
resource_name = normalize_resource_name(resource_path)
178+
resource_slug = resource_name = normalize_resource_name(resource_path)
178179
pot = load_po(str(pot_path))
179180
if len(pot):
180181
lv = locals()

tests/test_cmd_transifex.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def test_update_txconfig_resources_with_config(home_in_temp, temp):
7373

7474
data = (tx_dir / 'config').text()
7575
assert re.search(r'\[o:eggs-org:p:ham-project:r:README\]', data)
76+
assert re.search(r'\nresource_name = README\n', data)
7677

7778

7879
def test_update_txconfig_resources_with_pot_dir_argument(home_in_temp, temp):
@@ -95,6 +96,7 @@ def test_update_txconfig_resources_with_pot_dir_argument(home_in_temp, temp):
9596

9697
data = (tx_dir / 'config').text().replace('\\', '/')
9798
assert re.search(r'\[o:eggs-org:p:ham-project:r:README\]', data)
99+
assert re.search(r'\nresource_name = README\n', data)
98100
assert re.search(r'source_file\W*=\W*_build/locale/README.pot', data)
99101

100102

@@ -118,6 +120,7 @@ def test_update_txconfig_resources_with_project_name_including_dots(home_in_temp
118120

119121
data = (tx_dir / 'config').text()
120122
assert re.search(r'\[o:eggs-org:p:ham-projectcom:r:README\]', data)
123+
assert re.search(r'\nresource_name = README\n', data)
121124

122125

123126
def test_update_txconfig_resources_with_project_name_including_spaces(home_in_temp, temp):
@@ -140,6 +143,7 @@ def test_update_txconfig_resources_with_project_name_including_spaces(home_in_te
140143

141144
data = (tx_dir / 'config').text()
142145
assert re.search(r'\[o:eggs-org:p:ham-project-com:r:README\]', data)
146+
assert re.search(r'\nresource_name = README\n', data)
143147

144148

145149
def test_update_txconfig_resources_with_potfile_including_symbols(home_in_temp, temp):
@@ -170,3 +174,33 @@ def test_update_txconfig_resources_with_potfile_including_symbols(home_in_temp,
170174
data = (tx_dir / 'config').text()
171175
assert re.search(r'\[o:eggs-org:p:ham-project-com:r:example_document\]', data)
172176
assert re.search(r'\[o:eggs-org:p:ham-project-com:r:test_document\]', data)
177+
assert re.search(r'\nresource_name = example_document\n', data)
178+
assert re.search(r'\nresource_name = test_document\n', data)
179+
180+
181+
def test_update_txconfig_resources_with_potfile_including_path_separators(home_in_temp, temp):
182+
tx_dir = temp / '.tx'
183+
tx_dir.makedirs()
184+
(tx_dir / 'config').write_text(dedent("""\
185+
[main]
186+
host = https://www.transifex.com
187+
"""))
188+
189+
(temp / '_build' / 'locale').copytree(temp / 'locale' / 'pot')
190+
191+
# copy README.pot to 'example document.pot'
192+
readme = (temp / '_build' / 'locale' / 'README.pot').text()
193+
(temp / '_build' / 'locale' / 'example').makedirs()
194+
(temp / '_build' / 'locale' / 'example' / 'document.pot').write_text(readme)
195+
196+
r1 = runner.invoke(commands.main,
197+
['update-txconfig-resources',
198+
'-d', 'locale',
199+
'--transifex-organization-name', 'eggs-org',
200+
'--transifex-project-name', 'ham project com',
201+
])
202+
assert r1.exit_code == 0
203+
204+
data = (tx_dir / 'config').text()
205+
assert re.search(r'\[o:eggs-org:p:ham-project-com:r:example--document\]', data)
206+
assert re.search(r'\nresource_name = example--document\n', data)

0 commit comments

Comments
 (0)