-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
Use jinja2 to load i18n strings from settings #2
Conversation
Thanks for submitting your first pull request! You are awesome! 🤗 |
Wohoo @fcollonval thanks for this. So how will this be used :) do you have an example we can put somewhere? |
The first use would be related to jupyterlab/jupyterlab#10254 to support translation of (sub)menu labels. I based the test example on it: {
"jupyter.lab.menus": {
"main": [
{
"id": "jp-mainmenu-view",
"items": [
{
"type": "submenu",
"submenu": {
"id": "jp-mainmenu-view-codemirror-theme",
"label": "{{ _('Text Editor Syntax Highlighting') }}"
},
"rank": 40
}
]
}
]
}
} |
Ok some thoughts:
We should probably have a translator object for consistency (what we use on server and frontend)
Now this can be used for scrapping strings, but how do we used it in the frontend/backend? |
And I would recommend we also use context so "label": "{{ trans._p('menu-settings', 'Text Editor Syntax Highlighting') }}"
Now this can be used for scrapping strings, but how do we used it in the frontend/backend? |
1 similar comment
And I would recommend we also use context so "label": "{{ trans._p('menu-settings', 'Text Editor Syntax Highlighting') }}"
Now this can be used for scrapping strings, but how do we used it in the frontend/backend? |
The So it will add some complexity to use another name.
I think to do that at the schema file loading step - I still have to figure out how to have the translation loaded and available at that time: |
Yes but the tooling we use relies on a Well I would do something like: from jinja2 import Template
template = Template(JSON_FILE)
new_json = template.render(trans=trans) Or just use babel directly, so that we can provide the objects (
That should not be too hard. The question is. Are we parsing that on the server so the frontend will receive a translated JSON file? |
Sorry I saw the example with context after. So yes it make sense to bring our own function to handle the translation.
I had that in mind. But I did not though about doing it in the frontend actually... What would you suggest? |
Well I read that
And now I am thinking that... it might be tricky. So doing it on the frontend might actually make it a bit easier? @blink1073 , @afshin what do you think about this? |
I know that for jupyterlite if this is done on the frontend will be easier 😉 |
Hahaham, well we would need to bundle the translations so jupyterlite could use them, so that brings an interesting question. Now that you mentioned it, how could we approach that? Making npm packages for the language-packs as well? |
Closing this one as a better mechanism will be coming with #8 |
This introduces jinja2 has preprocessor on settings file to transform the internationalized strings.
title
anddescription
are still read directly from the json file except if they match jinja2 transform structure.Fixes #1