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

Experiments with gettext #328

Merged
merged 1 commit into from
Dec 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 7 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,20 @@ env:
jobs:
lint:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python:
- "3.7"
- "3.10"
steps:
- uses: actions/checkout@v2
- run: |
git fetch --prune --unshallow
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: 3.7
python-version: ${{ matrix.python }}
- name: Install python dependencies
run: |
pip install pygithub
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ build/
tests/cli.toml
/.ci/settings/certs
site/
dist/
*.po~
1 change: 1 addition & 0 deletions CHANGES/328.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added facilities to create, load and distribute translations.
1 change: 1 addition & 0 deletions CHANGES/328.translation
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added some German translations.
26 changes: 25 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
LANGUAGES=de
Copy link
Contributor

Choose a reason for hiding this comment

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

We only adding German support for now?

Copy link
Member Author

Choose a reason for hiding this comment

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

We would add them as we go.

PLUGINS=$(notdir $(wildcard pulpcore/cli/*))

info:
@echo Pulp CLI
@echo plugins: $(PLUGINS)

black:
isort .
black .
Expand All @@ -23,4 +30,21 @@ servedocs:
site:
mkdocs build

.PHONY: black lint servedocs
pulpcore/cli/%/locale/messages.pot: pulpcore/cli/%/*.py
xgettext -d $* -o $@ pulpcore/cli/$*/*.py
sed -i 's/charset=CHARSET/charset=UTF-8/g' $@

extract_messages: $(foreach PLUGIN,$(PLUGINS),pulpcore/cli/$(PLUGIN)/locale/messages.pot)

$(foreach LANGUAGE,$(LANGUAGES),pulpcore/cli/%/locale/$(LANGUAGE)/LC_MESSAGES/messages.po): pulpcore/cli/%/locale/messages.pot
[ -e $(@D) ] || mkdir -p $(@D)
[ ! -e $@ ] || msgmerge --update $@ $<
[ -e $@ ] || cp $< $@

%.mo: %.po
msgfmt -o $@ $<

compile_messages: $(foreach LANGUAGE,$(LANGUAGES),$(foreach PLUGIN,$(PLUGINS),pulpcore/cli/$(PLUGIN)/locale/$(LANGUAGE)/LC_MESSAGES/messages.mo))

.PHONY: info black lint test servedocs
.PRECIOUS: $(foreach LANGUAGE,$(LANGUAGES),$(foreach PLUGIN,$(PLUGINS),pulpcore/cli/$(PLUGIN)/locale/$(LANGUAGE)/LC_MESSAGES/messages.po))
6 changes: 3 additions & 3 deletions pulpcore/cli/ansible/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import gettext

from pulpcore.cli.ansible.content import content
from pulpcore.cli.ansible.distribution import distribution
from pulpcore.cli.ansible.remote import remote
from pulpcore.cli.ansible.repository import repository
from pulpcore.cli.common import main
from pulpcore.cli.common.context import PluginRequirement, PulpContext, pass_pulp_context
from pulpcore.cli.common.i18n import get_translation

_ = gettext.gettext
translation = get_translation(__name__)
_ = translation.gettext


@main.group()
Expand Down
5 changes: 3 additions & 2 deletions pulpcore/cli/ansible/content.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import gettext
from typing import IO, Any, Union

import click
Expand All @@ -19,9 +18,11 @@
pulp_option,
show_command,
)
from pulpcore.cli.common.i18n import get_translation
from pulpcore.cli.core.context import PulpArtifactContext

_ = gettext.gettext
translation = get_translation(__name__)
_ = translation.gettext


def _content_callback(ctx: click.Context, param: click.Parameter, value: Any) -> Any:
Expand Down
5 changes: 3 additions & 2 deletions pulpcore/cli/ansible/context.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import gettext
from typing import IO, Any, ClassVar

from pulpcore.cli.common.context import (
Expand All @@ -11,8 +10,10 @@
PulpRepositoryVersionContext,
registered_repository_contexts,
)
from pulpcore.cli.common.i18n import get_translation

_ = gettext.gettext
translation = get_translation(__name__)
_ = translation.gettext


class PulpAnsibleCollectionVersionContext(PulpContentContext):
Expand Down
5 changes: 3 additions & 2 deletions pulpcore/cli/ansible/distribution.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import gettext
from typing import Optional

import click
Expand Down Expand Up @@ -28,8 +27,10 @@
resource_option,
show_command,
)
from pulpcore.cli.common.i18n import get_translation

_ = gettext.gettext
translation = get_translation(__name__)
_ = translation.gettext


repository_option = resource_option(
Expand Down
Binary file not shown.
195 changes: 195 additions & 0 deletions pulpcore/cli/ansible/locale/de/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
# Translations for the pulp-cli ansible plugin.
# Copyright (C) 2021
# This file is distributed under the same license as the pulp-cli package.
# Matthias Dellweg <mdellweg@redhat.com>, 2021.
#
msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-11-06 20:29+0100\n"
"PO-Revision-Date: 2021-12-06 11:29+0100\n"
"Language: de\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Last-Translator: Matthias Dellweg <mdellweg@redhat.com>\n"
"Language-Team: \n"
"X-Generator: Poedit 3.0\n"

#: pulpcore/cli/ansible/content.py:55 pulpcore/cli/ansible/content.py:87
#: pulpcore/cli/ansible/repository.py:116
#, python-brace-format
msgid "Name of {entity}"
msgstr "Name von {entity}"

#: pulpcore/cli/ansible/content.py:56 pulpcore/cli/ansible/content.py:95
#: pulpcore/cli/ansible/repository.py:124
#, python-brace-format
msgid "Namespace of {entity}"
msgstr "Namensraum von {entity}"

#: pulpcore/cli/ansible/content.py:57 pulpcore/cli/ansible/content.py:102
#: pulpcore/cli/ansible/repository.py:131
#, python-brace-format
msgid "Version of {entity}"
msgstr "Version von {entity}"

#: pulpcore/cli/ansible/content.py:64
msgid ""
"Only show highest version of collection version (only works for collection "
"versions)"
msgstr ""

#: pulpcore/cli/ansible/content.py:70
msgid ""
"Comma separated list of tags that must all match (only works for collection "
"versions)"
msgstr ""

#: pulpcore/cli/ansible/content.py:76
msgid "String list of fields to include in the result"
msgstr ""

#: pulpcore/cli/ansible/content.py:80
msgid "String list of fields to exclude from result"
msgstr ""

#: pulpcore/cli/ansible/content.py:117
#, python-brace-format
msgid "Name of {entity}, only required for Roles"
msgstr ""

#: pulpcore/cli/ansible/content.py:118
#, python-brace-format
msgid "Namespace of {entity}, only required for Roles"
msgstr ""

#: pulpcore/cli/ansible/content.py:119
#, python-brace-format
msgid "Version of {entity}, only required for Roles"
msgstr ""

#: pulpcore/cli/ansible/context.py:20
msgid "ansible collection version"
msgstr ""

#: pulpcore/cli/ansible/context.py:21
msgid "ansible collection versions"
msgstr ""

#: pulpcore/cli/ansible/context.py:34
msgid "ansible role"
msgstr ""

#: pulpcore/cli/ansible/context.py:35
msgid "ansible roles"
msgstr ""

#: pulpcore/cli/ansible/context.py:43
msgid "ansible distribution"
msgstr ""

#: pulpcore/cli/ansible/context.py:44
msgid "ansible distributions"
msgstr ""

#: pulpcore/cli/ansible/context.py:62
msgid "role remote"
msgstr ""

#: pulpcore/cli/ansible/context.py:63
msgid "role remotes"
msgstr ""

#: pulpcore/cli/ansible/context.py:73
msgid "collection remote"
msgstr ""

#: pulpcore/cli/ansible/context.py:74
msgid "collection remotes"
msgstr ""

#: pulpcore/cli/ansible/distribution.py:68
msgid "the base (relative) path component of the published url."
msgstr ""

#: pulpcore/cli/ansible/distribution.py:72
msgid "a repository version number, leave blank for latest"
msgstr ""
"Versionsnummer des Repositories, leer lassen um die letzte zu verwenden"

#: pulpcore/cli/ansible/distribution.py:92
msgid "new base_path"
msgstr ""

#: pulpcore/cli/ansible/distribution.py:93
msgid "new repository to be served"
msgstr ""

#: pulpcore/cli/ansible/distribution.py:98
msgid "version of new repository to be served, leave blank for always latest"
msgstr ""

#: pulpcore/cli/ansible/distribution.py:147
#, python-brace-format
msgid ""
"Distribution {name} doesn't have a repository set, please specify the "
"repository to use with --repository"
msgstr ""

#: pulpcore/cli/ansible/remote.py:36
#, python-brace-format
msgid "Option {parameter} not valid for Role remote, see --help"
msgstr ""

#: pulpcore/cli/ansible/remote.py:69
msgid "policy to use when downloading"
msgstr ""

#: pulpcore/cli/ansible/remote.py:76
msgid "Collections only: a Collection requirements yaml"
msgstr ""

#: pulpcore/cli/ansible/remote.py:81
msgid "Collections only: a string of a requirements yaml"
msgstr ""

#: pulpcore/cli/ansible/remote.py:86
msgid "Collections only: URL to receive a session token"
msgstr ""

#: pulpcore/cli/ansible/remote.py:91
msgid "Collections only: token key use for authentication"
msgstr ""

#: pulpcore/cli/ansible/repository.py:55
msgid ""
"Remote used for synching in the form '[[<plugin>:]<resource_type>:]<name>' "
"or by href."
msgstr ""

#: pulpcore/cli/ansible/repository.py:154
msgid ""
"JSON string with a list of objects to add to the repository.\n"
" Each object must contain the following keys: \"name\", \"namespace\", "
"\"version\".\n"
" The argument prefixed with the '@' can be the path to a JSON file with a "
"list of objects."
msgstr ""

#: pulpcore/cli/ansible/repository.py:163
msgid ""
"JSON string with a list of objects to remove from the repository.\n"
" Each object must contain the following keys: \"name\", \"namespace\", "
"\"version\".\n"
" The argument prefixed with the '@' can be the path to a JSON file with a "
"list of objects."
msgstr ""

#: pulpcore/cli/ansible/repository.py:223
#, python-brace-format
msgid ""
"Repository '{name}' does not have a default remote. Please specify with '--"
"remote'."
msgstr ""
Loading