-
Notifications
You must be signed in to change notification settings - Fork 25
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
Namespaced Javascript Catalog #41
Namespaced Javascript Catalog #41
Conversation
f8713b5
to
8276082
Compare
fab34a6
to
48de5cd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tested this branch and it works as expected, and the added tests cover the feature. Just a few changes requested before I can approve.
Also: please bump the version in setup.py to e.g. 1.7.1
(Though note that the upstream maintainer may want a different version number).
- I tested this using a virtualenv created for [MCKIN-7389-js-i18n] Adding i18n support in JS files openedx/xblock-drag-and-drop-v2#156
- I read through the code
-
I checked for accessibility issuesN/A, command-line only - Includes documentation
docs/commands.rst
Outdated
@@ -36,6 +36,14 @@ Some commonly used options are: | |||
|
|||
Defaults to ``js``. | |||
|
|||
``-n OUTPUT_FORMAT`` or ``--namespace=SpecialBlock`` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: change OUTPUT_FORMAT
to NAMESPACE
docs/settings.rst
Outdated
and the namespaced contexts. The final gettext will be put under | ||
window.<namespace>.gettext | ||
rather than the | ||
window.gettext |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: fix word wrap
docs/settings.rst
Outdated
|
||
:default: ``None`` | ||
|
||
The namespace under which the static javascipt will be put. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: capitalise javascript
src/statici18n/conf.py
Outdated
@@ -15,3 +15,5 @@ class StaticFilesConf(AppConf): | |||
OUTPUT_DIR = 'jsi18n' | |||
# The dotted path to the function that creates the filename | |||
FILENAME_FUNCTION = 'statici18n.utils.default_filename' | |||
# The namespace |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please expand this comment to explain what the namespace is used for. As it stands, the current comment adds nothing that the variable name doesn't already say.
def _get_namespaced_catalog(self, rendered_js, namespace): | ||
template = u''' | ||
(function(global){{ | ||
var {namespace}I18n = {{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the I18n
suffix added here -- {namespace}
should contain the full name of the var. As a developer, I want to be able to specify the full namespace used.
@@ -89,6 +107,7 @@ def _create_output(self, outputdir, outputformat, locale, domain, packages): | |||
|
|||
if outputformat == 'js': | |||
data = self._create_javascript_catalog(locale, domain, packages) | |||
data = self._get_namespaced_catalog(data, namespace) if namespace else data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you make this line clearer please?
if namespace:
data = self._get_namespaced_catalog(data, namespace)
init: function() {{ | ||
{text} | ||
}} | ||
}}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make using this easier, could you please add this line right below here:
{namespace}.init()
docs/settings.rst
Outdated
|
||
:default: ``None`` | ||
|
||
The namespace under which the static JAVASCRIPT will be put. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry @afzaledx -- I meant title case Javascript, not all caps 😄
@pomegranited, let me know if you have more suggestions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@afzaledx Works well and looks good! 👍
Couple more little nits, but it's ready for upstream review once they're addressed, and your changes are squashed.
- I tested this using the settings and translations for [MCKIN-7389-js-i18n] Adding i18n support in JS files openedx/xblock-drag-and-drop-v2#156.
- I read through the code
-
I checked for accessibility issuesN/A, command line only - Includes documentation
docs/settings.rst
Outdated
This is useful for pluggable modules which need Javascript i18n. | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove empty lines at end of file
src/statici18n/conf.py
Outdated
@@ -15,3 +15,5 @@ class StaticFilesConf(AppConf): | |||
OUTPUT_DIR = 'jsi18n' | |||
# The dotted path to the function that creates the filename | |||
FILENAME_FUNCTION = 'statici18n.utils.default_filename' | |||
# The namespace under which the static JAVASCRIPT will be put. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Javascript, not JAVASCRIPT
@@ -49,6 +49,25 @@ def add_arguments(self, parser): | |||
default='js', | |||
help="Format of the output catalog. " | |||
"Options are: js, json. Defaults to js.") | |||
parser.add_argument('-n', '--namespace', dest='namespace', | |||
metavar='NAMESPACE', default=settings.STATICI18N_NAMESPACE, | |||
help="value for the namespace. " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove trailing space
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: "Javascript identifier to use as namespace" ?
If a namespace is provided, the gettext is assigned to window.namespace.gettext instead of window.gettext.
f9593d2
to
bfc51e8
Compare
@zyegfryed, This is PR is ready for your review. |
@afzaledx @pomegranited Thanks for your work! I'll have a look this week-end. |
Hi @zyegfryed -- sorry to bother you, but we were wondering if you needed any changes made here? We've got time allocated this week and next if there's anything we can do? |
Hi @pomegranited , I'm sorry but I haven't have a look into the PR, yet :( Will try tomorrow evening. Cheers |
No worries @zyegfryed ! Thank you for your time. |
@afzaledx @pomegranited I released v1.8.0 with your patch. |
@zyegfryed, You are welcome, and thank you for incorporating our contribution. |
This PR adds the namespace parameter to the command line, and can also be read from the STATICI18N_NAMESPACE
The concept behind the change is that the javascript catalog generated by django put the gettext against window.gettext. If, however, we have a modular system in which there are many pluggable modules that require the catalog, it does not make sense to combine the entire catalog into a single catalog. This becomes especially problematic for future modules that will be created.
This PR addresses the issue such that the generated javascript catalog is modified so that the gettext is put against window.NAMESPACE.gettext. The module can use the gettext from its own NAMESPACE rather than use the global namespace of the project.
Reviewers