Skip to content

Commit

Permalink
Code review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Mar 27, 2024
1 parent 1daf4fa commit 6b56072
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/weblate-merge-po.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ jobs:
if: steps.check_changes.outputs.po_updated == 'true'
working-directory: ./agama
run: |
web/share/update-languages.py web/src/languages.json
web/share/update-languages.py > web/src/languages.json
# use a unique branch to avoid possible conflicts with already existing branches
git checkout -b "po_merge_${GITHUB_RUN_ID}"
git commit -a -m "Update web PO files"$'\n\n'"Agama-weblate commit: `git -C ../agama-weblate rev-parse HEAD`"
Expand Down
9 changes: 9 additions & 0 deletions web/package/cockpit-agama.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
-------------------------------------------------------------------
Wed Mar 27 12:41:11 UTC 2024 - Ladislav Slezák <lslezak@suse.com>

- Dropping Cockpit dependency:
- Do not use Cockpit gettext functionality
(gh#openSUSE/agama#1118)
- Do not store the list of supported languages to the Cockpit
manifest file (gh#openSUSE/agama#1121)

-------------------------------------------------------------------
Tue Mar 19 14:15:30 UTC 2024 - José Iván López González <jlopez@suse.com>

Expand Down
30 changes: 16 additions & 14 deletions web/share/update-languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

#
# This script generates the list of supported languages in JSON format.
#

from argparse import ArgumentParser
from langtable import language_name
from pathlib import Path
import json
import subprocess
import sys

class Locale:
language: str
Expand Down Expand Up @@ -77,8 +82,7 @@ def language(self):
class Languages:
""" This class takes care of generating the supported languages file"""

def __init__(self, path: Path):
self.path = path
def __init__(self):
self.content = dict()

def update(self, po_files, lang2territory: str, threshold: int):
Expand All @@ -105,14 +109,16 @@ def update(self, po_files, lang2territory: str, threshold: int):
if locale.territory is None:
print(
"could not find a territory for '{language}'"
.format(language=locale.language)
.format(language=locale.language),
file=sys.stderr
)
elif po_file.coverage() < threshold:
print(
"not enough coverage for '{language}' ({coverage}%)"
.format(
language=locale.code(),
coverage=po_file.coverage())
coverage=po_file.coverage()),
file=sys.stderr
)
else:
supported.append(locale)
Expand All @@ -122,28 +128,24 @@ def update(self, po_files, lang2territory: str, threshold: int):
include_territory = languages.count(locale.language) > 1
self.content[locale.code()] = locale.name(include_territory)

def write(self):
with open(self.path, "w+") as file:
json.dump(self.content, file, indent=4, ensure_ascii=False,
sort_keys=True)
def dump(self):
json.dump(self.content, sys.stdout, indent=4, ensure_ascii=False,
sort_keys=True)


def update_languages(args):
"""Command to update the manifest.json file"""
languages = Languages(Path(args.file))
"""Print the supported languages in JSON format"""
languages = Languages()
paths = [path for path in Path(args.po_directory).glob("*.po")]
with open(args.territories) as file:
lang2territory = json.load(file)
languages.update(paths, lang2territory, args.threshold)
languages.write()
languages.dump()


if __name__ == "__main__":
parser = ArgumentParser(prog="update-languages.py")
parser.set_defaults(func=update_languages)
parser.add_argument(
"file", type=str, help="Path to the output file",
)
parser.add_argument(
"--po-directory", type=str, help="Directory containing the po files",
default="web/po"
Expand Down

0 comments on commit 6b56072

Please sign in to comment.