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

add translation system to pygeoapi #725

Merged
merged 4 commits into from Aug 23, 2021

Conversation

pvgenuchten
Copy link
Contributor

@pvgenuchten pvgenuchten commented Jul 10, 2021

this pr adds a translation system to pygeoapi, see locale/readme.md on how to set up

  • extract latest keys in .pot file with: pybabel extract -F babel-mapping.ini -o locale/messages.pot ./
  • then update .po language file: pybabel update -d locale -l fr -i locale/messages.pot
  • update translations and compile .mo file: pybabel compile -d locale -l fr

Run pygeoapi and switch language to french ?lang=fr, notice some hardcoded strings translated.

Copy link
Contributor

@GeoSander GeoSander left a comment

Choose a reason for hiding this comment

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

Good start @pvgenuchten and happy to see that it was easy to put the translations in place!
For the links sections (as generated by api.py) we should have a look how to properly build in the Babel/gettext stuff there, but it might be better to do this after the API refactor, don't you agree @tomkralidis?

Comment on lines +349 to +351
translations = Translations.load('locale', [locale_])
env.install_gettext_translations(translations)
Copy link
Contributor

@GeoSander GeoSander Jul 12, 2021

Choose a reason for hiding this comment

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

We might need to check how efficient this is (loading all translations each time when render_j2_template is called). If the locale has not changed, there's no need to reload all translations. But perhaps Babel and/or install_gettext_translations already has such a mechanism in place.

Copy link
Member

Choose a reason for hiding this comment

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

Good start @pvgenuchten and happy to see that it was easy to put the translations in place!
For the links sections (as generated by api.py) we should have a look how to properly build in the Babel/gettext stuff there, but it might be better to do this after the API refactor, don't you agree @tomkralidis?

+1

pygeoapi/util.py Outdated
@@ -44,7 +44,8 @@

import dateutil.parser
# from babel.support import Translations
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove this line :)


#: pygeoapi/templates/landing_page.html:35
msgid "License"
msgstr "License"
Copy link
Contributor

Choose a reason for hiding this comment

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

License in French is spelled Licence, thanks

Copy link
Member

@tomkralidis tomkralidis left a comment

Choose a reason for hiding this comment

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

Great work here @pvgenuchten ! Minor comments. I would also add a sentence or two in https://docs.pygeoapi.io/en/latest/language.html

locale/readme.md Outdated
@@ -0,0 +1,32 @@
# Howto set up language files
Copy link
Member

Choose a reason for hiding this comment

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

Rename file to locale/README.md

@GeoSander
Copy link
Contributor

@tomkralidis is it okay to merge this (after rebase)?

@tomkralidis
Copy link
Member

@GeoSander +1, let me know when rebased.

@pvgenuchten
Copy link
Contributor Author

just did a rebase

@tomkralidis tomkralidis merged commit 995ab2f into geopython:master Aug 23, 2021
webb-ben pushed a commit to webb-ben/pygeoapi that referenced this pull request Aug 26, 2021
commit 70edc3c
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Thu Aug 26 16:30:46 2021 -0400

    update TinyDB q= support for multiple terms (geopython#765)

commit 1ff9dfa
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Wed Aug 25 08:24:28 2021 -0400

    update id field passing to HTML template (geopython#764)

commit 6fb64e6
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Wed Aug 25 07:22:53 2021 -0400

    fix JSON filter in HTML items/item templates (geopython#761) (geopython#763)

commit 6dcd10b
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Wed Aug 25 06:34:39 2021 -0400

    test for item prev and next links on item queries (geopython#752) (geopython#757)

commit 7192012
Author: Alexandre Leroux <alexandreleroux@gmail.com>
Date:   Tue Aug 24 06:37:03 2021 -0400

    updates to French translation (geopython#759)

commit 995ab2f
Author: paul van genuchten <paul.vangenuchten@geocat.net>
Date:   Mon Aug 23 02:42:10 2021 +0200

    add translation system to pygeoapi (geopython#725)

    * adds translation keys to templates

    * adds translation keys to templates

    * suggestions from github pr 2

commit bc97ed4
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Sun Aug 22 08:28:56 2021 -0400

    add geometry to queryables (geopython#755)

commit 9d92090
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Wed Aug 18 15:28:55 2021 -0400

    update OAProc execute handling (geopython#754)

    * fix OAProc default output to raw

    * control outputs list from api machinery

    * fix tests
webb-ben pushed a commit to webb-ben/pygeoapi that referenced this pull request Sep 3, 2021
commit 774ff49
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Wed Sep 1 09:02:28 2021 -0400

    update translations (geopython#760) (geopython#762)

    * update translations (geopython#760)

    * fix syntax

    * update translations

    * update docs

    * fix typos

commit cf9bd22
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Tue Aug 31 10:11:31 2021 -0400

    Update plugins.rst (geopython#770)

commit 70edc3c
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Thu Aug 26 16:30:46 2021 -0400

    update TinyDB q= support for multiple terms (geopython#765)

commit 1ff9dfa
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Wed Aug 25 08:24:28 2021 -0400

    update id field passing to HTML template (geopython#764)

commit 6fb64e6
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Wed Aug 25 07:22:53 2021 -0400

    fix JSON filter in HTML items/item templates (geopython#761) (geopython#763)

commit 6dcd10b
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Wed Aug 25 06:34:39 2021 -0400

    test for item prev and next links on item queries (geopython#752) (geopython#757)

commit 7192012
Author: Alexandre Leroux <alexandreleroux@gmail.com>
Date:   Tue Aug 24 06:37:03 2021 -0400

    updates to French translation (geopython#759)

commit 995ab2f
Author: paul van genuchten <paul.vangenuchten@geocat.net>
Date:   Mon Aug 23 02:42:10 2021 +0200

    add translation system to pygeoapi (geopython#725)

    * adds translation keys to templates

    * adds translation keys to templates

    * suggestions from github pr 2

commit bc97ed4
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Sun Aug 22 08:28:56 2021 -0400

    add geometry to queryables (geopython#755)

commit 9d92090
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Wed Aug 18 15:28:55 2021 -0400

    update OAProc execute handling (geopython#754)

    * fix OAProc default output to raw

    * control outputs list from api machinery

    * fix tests
webb-ben added a commit to internetofwater/pygeoapi that referenced this pull request Nov 4, 2021
* Update plugin.py for SPARQL

* Create sparql.py

* Update requirements-provider.txt

* Add files via upload

* Update requirements-provider.txt

* Update api.py

* Update plugin.py

* Update plugin.py

* Update plugin.py

* Squashed commit of the following:

commit 70edc3c
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Thu Aug 26 16:30:46 2021 -0400

    update TinyDB q= support for multiple terms (geopython#765)

commit 1ff9dfa
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Wed Aug 25 08:24:28 2021 -0400

    update id field passing to HTML template (geopython#764)

commit 6fb64e6
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Wed Aug 25 07:22:53 2021 -0400

    fix JSON filter in HTML items/item templates (geopython#761) (geopython#763)

commit 6dcd10b
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Wed Aug 25 06:34:39 2021 -0400

    test for item prev and next links on item queries (geopython#752) (geopython#757)

commit 7192012
Author: Alexandre Leroux <alexandreleroux@gmail.com>
Date:   Tue Aug 24 06:37:03 2021 -0400

    updates to French translation (geopython#759)

commit 995ab2f
Author: paul van genuchten <paul.vangenuchten@geocat.net>
Date:   Mon Aug 23 02:42:10 2021 +0200

    add translation system to pygeoapi (geopython#725)

    * adds translation keys to templates

    * adds translation keys to templates

    * suggestions from github pr 2

commit bc97ed4
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Sun Aug 22 08:28:56 2021 -0400

    add geometry to queryables (geopython#755)

commit 9d92090
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Wed Aug 18 15:28:55 2021 -0400

    update OAProc execute handling (geopython#754)

    * fix OAProc default output to raw

    * control outputs list from api machinery

    * fix tests

* Squashed commit of the following:

commit 774ff49
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Wed Sep 1 09:02:28 2021 -0400

    update translations (geopython#760) (geopython#762)

    * update translations (geopython#760)

    * fix syntax

    * update translations

    * update docs

    * fix typos

commit cf9bd22
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Tue Aug 31 10:11:31 2021 -0400

    Update plugins.rst (geopython#770)

commit 70edc3c
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Thu Aug 26 16:30:46 2021 -0400

    update TinyDB q= support for multiple terms (geopython#765)

commit 1ff9dfa
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Wed Aug 25 08:24:28 2021 -0400

    update id field passing to HTML template (geopython#764)

commit 6fb64e6
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Wed Aug 25 07:22:53 2021 -0400

    fix JSON filter in HTML items/item templates (geopython#761) (geopython#763)

commit 6dcd10b
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Wed Aug 25 06:34:39 2021 -0400

    test for item prev and next links on item queries (geopython#752) (geopython#757)

commit 7192012
Author: Alexandre Leroux <alexandreleroux@gmail.com>
Date:   Tue Aug 24 06:37:03 2021 -0400

    updates to French translation (geopython#759)

commit 995ab2f
Author: paul van genuchten <paul.vangenuchten@geocat.net>
Date:   Mon Aug 23 02:42:10 2021 +0200

    add translation system to pygeoapi (geopython#725)

    * adds translation keys to templates

    * adds translation keys to templates

    * suggestions from github pr 2

commit bc97ed4
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Sun Aug 22 08:28:56 2021 -0400

    add geometry to queryables (geopython#755)

commit 9d92090
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Wed Aug 18 15:28:55 2021 -0400

    update OAProc execute handling (geopython#754)

    * fix OAProc default output to raw

    * control outputs list from api machinery

    * fix tests

* Prepare for merge into internetofwater/pygeoapi
webb-ben added a commit to internetofwater/pygeoapi that referenced this pull request Dec 7, 2021
* Update plugin.py for SPARQL

* Create sparql.py

* Update requirements-provider.txt

* Add files via upload

* Update requirements-provider.txt

* Update api.py

* Update plugin.py

* Update plugin.py

* Update plugin.py

* Squashed commit of the following:

commit 70edc3c
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Thu Aug 26 16:30:46 2021 -0400

    update TinyDB q= support for multiple terms (geopython#765)

commit 1ff9dfa
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Wed Aug 25 08:24:28 2021 -0400

    update id field passing to HTML template (geopython#764)

commit 6fb64e6
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Wed Aug 25 07:22:53 2021 -0400

    fix JSON filter in HTML items/item templates (geopython#761) (geopython#763)

commit 6dcd10b
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Wed Aug 25 06:34:39 2021 -0400

    test for item prev and next links on item queries (geopython#752) (geopython#757)

commit 7192012
Author: Alexandre Leroux <alexandreleroux@gmail.com>
Date:   Tue Aug 24 06:37:03 2021 -0400

    updates to French translation (geopython#759)

commit 995ab2f
Author: paul van genuchten <paul.vangenuchten@geocat.net>
Date:   Mon Aug 23 02:42:10 2021 +0200

    add translation system to pygeoapi (geopython#725)

    * adds translation keys to templates

    * adds translation keys to templates

    * suggestions from github pr 2

commit bc97ed4
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Sun Aug 22 08:28:56 2021 -0400

    add geometry to queryables (geopython#755)

commit 9d92090
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Wed Aug 18 15:28:55 2021 -0400

    update OAProc execute handling (geopython#754)

    * fix OAProc default output to raw

    * control outputs list from api machinery

    * fix tests

* Squashed commit of the following:

commit 774ff49
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Wed Sep 1 09:02:28 2021 -0400

    update translations (geopython#760) (geopython#762)

    * update translations (geopython#760)

    * fix syntax

    * update translations

    * update docs

    * fix typos

commit cf9bd22
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Tue Aug 31 10:11:31 2021 -0400

    Update plugins.rst (geopython#770)

commit 70edc3c
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Thu Aug 26 16:30:46 2021 -0400

    update TinyDB q= support for multiple terms (geopython#765)

commit 1ff9dfa
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Wed Aug 25 08:24:28 2021 -0400

    update id field passing to HTML template (geopython#764)

commit 6fb64e6
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Wed Aug 25 07:22:53 2021 -0400

    fix JSON filter in HTML items/item templates (geopython#761) (geopython#763)

commit 6dcd10b
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Wed Aug 25 06:34:39 2021 -0400

    test for item prev and next links on item queries (geopython#752) (geopython#757)

commit 7192012
Author: Alexandre Leroux <alexandreleroux@gmail.com>
Date:   Tue Aug 24 06:37:03 2021 -0400

    updates to French translation (geopython#759)

commit 995ab2f
Author: paul van genuchten <paul.vangenuchten@geocat.net>
Date:   Mon Aug 23 02:42:10 2021 +0200

    add translation system to pygeoapi (geopython#725)

    * adds translation keys to templates

    * adds translation keys to templates

    * suggestions from github pr 2

commit bc97ed4
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Sun Aug 22 08:28:56 2021 -0400

    add geometry to queryables (geopython#755)

commit 9d92090
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Wed Aug 18 15:28:55 2021 -0400

    update OAProc execute handling (geopython#754)

    * fix OAProc default output to raw

    * control outputs list from api machinery

    * fix tests

* Prepare for merge into internetofwater/pygeoapi
webb-ben added a commit to internetofwater/pygeoapi that referenced this pull request Feb 23, 2022
* Update plugin.py for SPARQL

* Create sparql.py

* Update requirements-provider.txt

* Add files via upload

* Update requirements-provider.txt

* Update api.py

* Update plugin.py

* Update plugin.py

* Update plugin.py

* Squashed commit of the following:

commit 70edc3c
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Thu Aug 26 16:30:46 2021 -0400

    update TinyDB q= support for multiple terms (geopython#765)

commit 1ff9dfa
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Wed Aug 25 08:24:28 2021 -0400

    update id field passing to HTML template (geopython#764)

commit 6fb64e6
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Wed Aug 25 07:22:53 2021 -0400

    fix JSON filter in HTML items/item templates (geopython#761) (geopython#763)

commit 6dcd10b
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Wed Aug 25 06:34:39 2021 -0400

    test for item prev and next links on item queries (geopython#752) (geopython#757)

commit 7192012
Author: Alexandre Leroux <alexandreleroux@gmail.com>
Date:   Tue Aug 24 06:37:03 2021 -0400

    updates to French translation (geopython#759)

commit 995ab2f
Author: paul van genuchten <paul.vangenuchten@geocat.net>
Date:   Mon Aug 23 02:42:10 2021 +0200

    add translation system to pygeoapi (geopython#725)

    * adds translation keys to templates

    * adds translation keys to templates

    * suggestions from github pr 2

commit bc97ed4
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Sun Aug 22 08:28:56 2021 -0400

    add geometry to queryables (geopython#755)

commit 9d92090
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Wed Aug 18 15:28:55 2021 -0400

    update OAProc execute handling (geopython#754)

    * fix OAProc default output to raw

    * control outputs list from api machinery

    * fix tests

* Squashed commit of the following:

commit 774ff49
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Wed Sep 1 09:02:28 2021 -0400

    update translations (geopython#760) (geopython#762)

    * update translations (geopython#760)

    * fix syntax

    * update translations

    * update docs

    * fix typos

commit cf9bd22
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Tue Aug 31 10:11:31 2021 -0400

    Update plugins.rst (geopython#770)

commit 70edc3c
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Thu Aug 26 16:30:46 2021 -0400

    update TinyDB q= support for multiple terms (geopython#765)

commit 1ff9dfa
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Wed Aug 25 08:24:28 2021 -0400

    update id field passing to HTML template (geopython#764)

commit 6fb64e6
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Wed Aug 25 07:22:53 2021 -0400

    fix JSON filter in HTML items/item templates (geopython#761) (geopython#763)

commit 6dcd10b
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Wed Aug 25 06:34:39 2021 -0400

    test for item prev and next links on item queries (geopython#752) (geopython#757)

commit 7192012
Author: Alexandre Leroux <alexandreleroux@gmail.com>
Date:   Tue Aug 24 06:37:03 2021 -0400

    updates to French translation (geopython#759)

commit 995ab2f
Author: paul van genuchten <paul.vangenuchten@geocat.net>
Date:   Mon Aug 23 02:42:10 2021 +0200

    add translation system to pygeoapi (geopython#725)

    * adds translation keys to templates

    * adds translation keys to templates

    * suggestions from github pr 2

commit bc97ed4
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Sun Aug 22 08:28:56 2021 -0400

    add geometry to queryables (geopython#755)

commit 9d92090
Author: Tom Kralidis <tomkralidis@gmail.com>
Date:   Wed Aug 18 15:28:55 2021 -0400

    update OAProc execute handling (geopython#754)

    * fix OAProc default output to raw

    * control outputs list from api machinery

    * fix tests

* Prepare for merge into internetofwater/pygeoapi
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.

None yet

4 participants