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

Support I18n #2135

Closed
wants to merge 6 commits into from
Closed

Support I18n #2135

wants to merge 6 commits into from

Conversation

Constantin1489
Copy link
Contributor

@Constantin1489 Constantin1489 commented Jan 28, 2024

image

closes #2124

You can debug it with curl http://192.168.1.134:8895/edit -X 'GET' -H 'Accept-Language: ko-kr,ko;'
But just follow this. #2135 (comment)

To create new language support, pybabel init -i messages.pot -d translations -l es (es is an example. See also https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language)

If you changed texts in html and so on, then run pybabel extract -F babel.cfg -k _l -o messages.pot . && pybabel update -i messages.pot -d translations in changedetectionio dir. and translate text.

Todos

  • language url api
    • consider scalability so just write explicitly
  • considering low-ends. do some profiling.
  • language change api for language menu
  • think about compiling method for PyPI
  • support simple test.
  • babel.cfg for py file
  • mark the text to translate
  • flash()
  • remove tab indent in htmls
  • how to compile only one language(english) by default. considering low-ends.

EDIT: pybabel extract -F babel.cfg -k _l -o messages.pot . && pybabel update -i messages.pot -d translations
EDIT: add tasks
See also: https://stackoverflow.com/questions/12555692/flask-babel-translations-de-lc-messages-messages-po-is-marked-as-fuzzy-skip

@@ -64,6 +64,7 @@ ARG LOGGER_LEVEL=''
ENV LOGGER_LEVEL "$LOGGER_LEVEL"

WORKDIR /app
RUN pybabel compile -d changedetectionio/translations
Copy link
Contributor Author

Choose a reason for hiding this comment

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

compiling happens here

@Constantin1489 Constantin1489 marked this pull request as draft January 28, 2024 13:48
@Constantin1489 Constantin1489 marked this pull request as draft January 28, 2024 13:48
@@ -55,6 +57,12 @@
static_folder="static",
template_folder="templates")

def get_locale():
# Debug i8n with simple trick
#return 'ko'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you want to debug conveniently.

Co-authored-by: dgtlmoon <leigh@morresi.net>
@dgtlmoon
Copy link
Owner

Amazing! yeah first version doesnt need to have totally everything translated, as long as the basic UI has translations.

What do you think is "nicer", a flag icon in the toolbar with a pop-up to choose another language? or some settings page option?

(in the case they want to override it)

@dgtlmoon
Copy link
Owner

btw, this super cool! thanks again, it is appreciated!

@@ -0,0 +1,399 @@
# Translations template for PROJECT.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Autogenerated file.

@@ -0,0 +1,402 @@
# Korean translations for PROJECT.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Autogenerated file but translation by humans.

@Constantin1489
Copy link
Contributor Author

Constantin1489 commented Jan 28, 2024

What do you think is "nicer", a flag icon in the toolbar with a pop-up to choose another language? or some settings page option?

@dgtlmoon Yes, that is needed.

EDIT: If you can, just change the language of the current page without going to another page, please.

ex) english-edit page for somepage.com --> korean-edit page for somepage.com
--X-> korean overview page

EDIT: language in url is also good.( /ko/ or /en/ )

@@ -342,8 +343,8 @@ def __call__(self, form, field):
try:
elementpath.select(tree, line.strip(), parser=XPath3Parser)
except elementpath.ElementPathError as e:
message = field.gettext('\'%s\' is not a valid XPath expression. (%s)')
raise ValidationError(message % (line, str(e)))
message = _("'{}' is not a valid XPath expression. ({})")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tested with wrong xpath syntax and worked. But am I right?
I'm totally unaware of the field.gettext. If it is come from wtforms, the gettext is from python builtin lib.

@dgtlmoon
Copy link
Owner

why closed? :(

@Constantin1489
Copy link
Contributor Author

Constantin1489 commented May 16, 2024

pybabel or babel has some bug for the specific feature and the bug applies on the many human languages. But I didn't checked but believe the bug exists over decades again. I won't delete this branch. You can use it freely.

@dgtlmoon
Copy link
Owner

woha :( what was the bug?

@Constantin1489
Copy link
Contributor Author

This video describes the bug.
https://www.youtube.com/watch?v=qTKBX7KVM_s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature] user interface Multilanguage/translation support
2 participants