Skip to content

Commit

Permalink
feat: improved template detection for text files
Browse files Browse the repository at this point in the history
  • Loading branch information
nijel committed Nov 13, 2024
1 parent a071ed2 commit 156ae5a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Changelog
* Not yet released.
* Fixed crash on corrupted Transifex configuration.
* Improved app store metadata detection.
* Improved template detection for text files.

2.17
----
Expand Down
9 changes: 9 additions & 0 deletions translation_finder/discovery/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,12 @@ def adjust_format(self, result: dict[str, str]):
if encoding in self.encoding_map:
result["file_format"] = self.encoding_map[encoding]
return


class EnglishVariantsDiscovery(BaseDiscovery):
def get_language_aliases(self, language: str):
"""Language code aliases."""
result = super().get_language_aliases(language)
if language == "en":
result.extend(["en-US", "en-GB", "en-AU"])
return result
18 changes: 8 additions & 10 deletions translation_finder/discovery/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@

from translation_finder.api import register_discovery

from .base import BaseDiscovery, EncodingDiscovery, MonoTemplateDiscovery
from .base import (
BaseDiscovery,
EncodingDiscovery,
MonoTemplateDiscovery,
EnglishVariantsDiscovery,
)

LARAVEL_RE = re.compile(r"=>.*\|")

Expand Down Expand Up @@ -262,7 +267,7 @@ class ResourceDictionaryDiscovery(BaseDiscovery):


@register_discovery
class AppStoreDiscovery(BaseDiscovery):
class AppStoreDiscovery(EnglishVariantsDiscovery):
"""App store metadata."""

file_format = "appstore"
Expand All @@ -280,13 +285,6 @@ def has_storage(self, name: str):
"""Check whether finder has a storage."""
return self.finder.has_dir(name)

def get_language_aliases(self, language: str):
"""Language code aliases."""
result = super().get_language_aliases(language)
if language == "en":
result.extend(["en-US", "en-GB", "en-AU"])
return result


@register_discovery
class JSONDiscovery(BaseDiscovery):
Expand Down Expand Up @@ -474,7 +472,7 @@ class HTMLDiscovery(MonoTemplateDiscovery):


@register_discovery
class TXTDiscovery(MonoTemplateDiscovery):
class TXTDiscovery(MonoTemplateDiscovery, EnglishVariantsDiscovery):
"""TXT files discovery."""

file_format = "txt"
Expand Down

0 comments on commit 156ae5a

Please sign in to comment.