Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not use Cockpit manifest for storing supported languages #1121

Merged
merged 2 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <[email protected]>

- 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 <[email protected]>

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 for writting errors to 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
Loading