Skip to content

Commit

Permalink
Fix append logic in TMX script (#1025)
Browse files Browse the repository at this point in the history
  • Loading branch information
flodolo authored Jan 26, 2023
1 parent ad3fe46 commit d4f970c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion app/scripts/glossaire.sh
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ function updateAndroidl10n() {
echogreen "Extract strings for android-l10n"
cd $install
nice -20 $install/app/scripts/tmx/tmx_projectconfig.py $android_l10n/mozilla-mobile.toml --ref en-US --repo android_l10n
nice -20 $install/app/scripts/tmx/tmx_projectconfig.py $android_l10n/mozilla-mobile/focus-android/l10n.toml --ref en-US --repo android_l10n --mode append --prefix mozilla-mobile/focus-android
nice -20 $install/app/scripts/tmx/tmx_projectconfig.py $android_l10n/mozilla-mobile/focus-android/l10n.toml --ref en-US --repo android_l10n --append --prefix mozilla-mobile/focus-android
}

function updateMozOrg() {
Expand Down
20 changes: 10 additions & 10 deletions app/scripts/tmx/tmx_products.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(self, storage_path, locale, reference_locale, repository_name):
".ini",
".properties",
]
self.storage_mode = ""
self.storage_append = False
self.storage_prefix = ""
self.file_list = []
self.translations = {}
Expand All @@ -76,10 +76,10 @@ def setRepositoryPath(self, path):
# Strip trailing '/' from repository path
self.repository_path = path.rstrip(os.path.sep)

def setStorageMode(self, mode, prefix):
def setStorageAppendMode(self, prefix):
"""Set storage mode and prefix."""

self.storage_mode = mode
self.storage_append = True
# Strip trailing '/' from storage_prefix
self.storage_prefix = prefix.rstrip(os.path.sep)

Expand Down Expand Up @@ -109,9 +109,9 @@ def getRelativePath(self, file_name):
def extractStrings(self):
"""Extract strings from all files."""

# If storage_mode is append, read existing translations (if available)
# If storage mode is append, read existing translations (if available)
# before overriding them
if self.storage_mode == "append":
if self.storage_append:
file_name = f"{self.storage_file}.json"
if os.path.isfile(file_name):
with open(file_name) as f:
Expand Down Expand Up @@ -237,11 +237,10 @@ def main():
"--repo", dest="repository_name", help="Repository name", required=True
)
parser.add_argument(
"--mode",
dest="storage_mode",
nargs="?",
"--append",
dest="append_mode",
action="store_true",
help="If set to 'append', translations will be added to an existing cache file",
default="",
)
parser.add_argument(
"--prefix",
Expand All @@ -266,7 +265,8 @@ def main():
)

extracted_strings.setRepositoryPath(args.repo_path)
extracted_strings.setStorageMode("append", args.storage_prefix)
if args.append_mode:
extracted_strings.setStorageAppendMode(args.storage_prefix)

extracted_strings.extractStrings()
extracted_strings.storeTranslations(args.output)
Expand Down
20 changes: 10 additions & 10 deletions app/scripts/tmx/tmx_projectconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(self, toml_path, storage_path, reference_locale, repository_name):

# Set defaults
self.translations = {}
self.storage_mode = ""
self.storage_append = False
self.storage_prefix = ""

# Set instance variables
Expand All @@ -53,10 +53,10 @@ def __init__(self, toml_path, storage_path, reference_locale, repository_name):
self.reference_locale = reference_locale
self.repository_name = repository_name

def setStorageMode(self, mode, prefix):
def setStorageAppendMode(self, prefix):
"""Set storage mode and prefix."""

self.storage_mode = mode
self.storage_append = True
# Strip trailing '/' from storage_prefix
self.storage_prefix = prefix.rstrip(os.path.sep)

Expand All @@ -73,8 +73,8 @@ def extractStrings(self):
self.translations[self.reference_locale] = {}
for locale in project_config.all_locales:

# If storage_mode is append, read existing translations (if available)
if self.storage_mode == "append":
# If storage mode is append, read existing translations (if available)
if self.storage_append:
storage_file = os.path.join(
os.path.join(self.storage_path, locale),
f"cache_{locale}_{self.repository_name}",
Expand Down Expand Up @@ -204,11 +204,10 @@ def main():
"--repo", dest="repository_name", help="Repository name", required=True
)
parser.add_argument(
"--mode",
dest="storage_mode",
nargs="?",
"--append",
dest="append_mode",
action="store_true",
help="If set to 'append', translations will be added to an existing cache file",
default="",
)
parser.add_argument(
"--prefix",
Expand All @@ -234,7 +233,8 @@ def main():
args.reference_code,
args.repository_name,
)
extracted_strings.setStorageMode(args.storage_mode, args.storage_prefix)
if args.append_mode:
extracted_strings.setStorageAppendMode(args.storage_prefix)

extracted_strings.extractStrings()
extracted_strings.storeTranslations(args.output)
Expand Down

0 comments on commit d4f970c

Please sign in to comment.