-
Notifications
You must be signed in to change notification settings - Fork 993
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
Fixes #17263 - move jed (i18n) to webpack #5342
Conversation
Issues: #17263 |
02746ea
to
a6255e9
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.
Thanks @amirfefer! love seeing staff moving into the webpack stack.
webpack/assets/javascripts/bundle.js
Outdated
@@ -19,6 +19,7 @@ require('./bundle_datatables'); | |||
require('./bundle_lodash'); | |||
|
|||
import compute from './foreman_compute_resource'; | |||
import i18n from './foreman_jed'; |
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.
Should we name it as foreman_i18n.js
?
return i18n; | ||
}, | ||
}); | ||
Object.defineProperty(window, 'Jed', { |
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.
Does it make sense to add a new function to foreman_tools
call deprecateObjectProperty
?
export const deprecateObjectProperty = (obj, oldProp, newProp, version = '1.19') =>
Object.defineProperty(obj, oldProp, {
get: () => {
deprecate(oldProp, newProp, version);
return obj[oldProp];
},
});
deprecateObjectProperty(window, 'i18n', 'tfm.i18n');
deprecateObjectProperty(window, 'Jed', 'tfm.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.
Thank you @amirfefer, it works nicely. I have only couple of comments in the code.
And then I have one special request. There's a concurrent PR, where I'm adding some more i18n functionality, which is mostly complementary, but it touches the same area so there's going to be name clashes: #5184
It's been there for some time and currently it's blocked by broken tests, but we know that we want to merge it one day. Therefore I wanted to ask if you could make sure that both things can be merged with minimal conflicts one day. That means it should ideally use the same files and already use the same functions for the common functionality like fetching locale codes.
The most conflicting part is probably: https://github.com/theforeman/foreman/pull/5184/files#diff-1551b3b23e104a39b3f69746fe110eae
I'll be happy to help you with this.
|
||
window.__ = t_; | ||
window.n__ = (...args) => | ||
`${cheveronPrefix} ${i18n.ngettext(...args)} ${cheveronSuffix}`; |
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.
This one should imho be exported as well.
const cheveronPrefix = window.I18N_MARK ? '\u00BB' : ''; | ||
const cheveronSuffix = window.I18N_MARK ? '\u00AB' : ''; | ||
export const t_ = (...args) => | ||
`${cheveronPrefix} ${i18n.gettext(...args)} ${cheveronSuffix}`; |
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.
If we want to keep the wrapping blank spaces, they should be part of the prefix/suffix so that we don't pollute the translated strings when I18N_MARK
is turned off.
}; | ||
|
||
const locales = window.locales || emptyLocales; | ||
const i18n = new Jed(locales[getLocale()]); |
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 we export Jed as i18n.jed or something similar? I'd like to avoid exporting it as default, since there's a concurrent PR, where I'm adding some more functionality:
https://github.com/theforeman/foreman/pull/5184/files#diff-1551b3b23e104a39b3f69746fe110eae
test foreman |
[test foreman] |
@@ -1,10 +1,11 @@ | |||
import $ from 'jquery'; | |||
import { t_ } from './foreman_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.
When i look at this file, does it make sense to call it translate
?
import { translate } from './foreman_i18n';
const warningMessage = translate('Some Puppet Classes are unavailable in the selected environment');
Some consumers can still use it as
import { translate as __ } from './foreman_i18n';
// or
import { translate as t_ } from './foreman_i18n';
@amirfefer @tstrachota what is the status of this pr? thanks |
@amirfefer what is the status of this PR? I would love to merge it prior to 1.19 branch. |
@amirfefer bump! |
There were more prioritized tasks, i'll continue work on this soon. |
@tstrachota , @ohadlevy |
@ohadlevy could you have another look please? |
please have a look at the tests, i believe you didn't update PaginationHelper.js file? |
@@ -123,3 +124,14 @@ export function updateTable(element) { | |||
Turbolinks.visit(uri.toString()); | |||
return false; | |||
} | |||
|
|||
export function deprecateObjectProperty(obj, oldProp, newProp, version = '1.20') { |
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.
can you please add a test for this new function?
const locales = window.locales || emptyLocales; | ||
let locale = document.getElementsByTagName('html')[0].lang; | ||
|
||
locale = locale.length === 0 ? 'en' : locale.replace(/-/g, '_'); |
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 think this has no tests (for other locales) does it make sense to add one?
@amirfefer also note the test failures, they seems related? |
|
||
export const { sprintf } = jed; | ||
|
||
const i18n = { translate, ngettext, jed }; |
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.
this should include sprintf? (if i understand the errors correctly this is the cause...?)
@amirfefer please rebase - thanks |
@ohadlevy rebased |
@amirfefer still missing a test for https://coveralls.io/builds/19399473/source?filename=webpack/assets/javascripts/foreman_tools.js#L130 ? |
test failures not related, imho ready for merge, bonus points if you can get the missing test for depreciation. |
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.
👍 from a packaging perspective
@ohadlevy I've added a test for |
since @ekohl already approved, I'll merge once tests are 💚 |
test failures not relevant, thanks @amirfefer |
No description provided.