Skip to content

Commit

Permalink
Added support for Format.JS files
Browse files Browse the repository at this point in the history
  • Loading branch information
nijel committed Jan 4, 2024
1 parent 5bcbeb0 commit 35f829f
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Changelog
----

* Not yet released.
* Added support for Format.JS files.

2.16
----
Expand Down
20 changes: 20 additions & 0 deletions translation_finder/discovery/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,3 +558,23 @@ class TBXDiscovery(BaseDiscovery):

file_format = "tbx"
mask = "*.tbx"


@register_discovery
class FormatJSDiscovery(BaseDiscovery):
"""Format.JS JSON files discovery."""

file_format = "formatjs"

def get_masks(self, eager: bool = False, hint: Optional[str] = None):
"""
Return all file masks found in the directory.
It is expected to contain duplicates.
"""
for path in self.finder.filter_files(r"en.json", ".*/extracted"):
mask = list(path.parts)
mask[-1] = "*.json"
mask[-2] = "lang"

yield {"filemask": "/".join(mask), "template": path.as_posix()}
42 changes: 42 additions & 0 deletions translation_finder/test_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
MOKODiscovery,
AppStoreDiscovery,
ARBDiscovery,
FormatJSDiscovery,
CSVDiscovery,
FluentDiscovery,
GettextDiscovery,
Expand Down Expand Up @@ -1363,3 +1364,44 @@ def test_hint(self):
},
],
)


class FormatJSDiscoveryTest(DiscoveryTestCase):
def test_basic(self):
discovery = FormatJSDiscovery(
self.get_finder(
[
"src/lang/cs.json",
"src/extracted/en.json",
]
)
)
self.assert_discovery(
discovery.discover(),
[
{
"filemask": "src/lang/*.json",
"template": "src/extracted/en.json",
"file_format": "formatjs",
}
],
)

def test_nontranslated(self):
discovery = FormatJSDiscovery(
self.get_finder(
[
"src/extracted/en.json",
]
)
)
self.assert_discovery(
discovery.discover(),
[
{
"filemask": "src/lang/*.json",
"template": "src/extracted/en.json",
"file_format": "formatjs",
}
],
)

0 comments on commit 35f829f

Please sign in to comment.