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

Fixes #17263 - move jed (i18n) to webpack #5342

Merged
merged 1 commit into from
Oct 8, 2018

Conversation

amirfefer
Copy link
Member

No description provided.

@theforeman-bot
Copy link
Member

Issues: #17263

Copy link
Contributor

@sharvit sharvit left a 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.

@@ -19,6 +19,7 @@ require('./bundle_datatables');
require('./bundle_lodash');

import compute from './foreman_compute_resource';
import i18n from './foreman_jed';
Copy link
Contributor

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', {
Copy link
Contributor

@sharvit sharvit Mar 21, 2018

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');

Copy link
Member

@tstrachota tstrachota left a 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}`;
Copy link
Member

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}`;
Copy link
Member

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()]);
Copy link
Member

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

@ohadlevy
Copy link
Member

test foreman

@ohadlevy
Copy link
Member

[test foreman]

@@ -1,10 +1,11 @@
import $ from 'jquery';
import { t_ } from './foreman_i18n';
Copy link
Contributor

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';

@ohadlevy
Copy link
Member

ohadlevy commented May 9, 2018

@amirfefer @tstrachota what is the status of this pr? thanks

@ohadlevy
Copy link
Member

@amirfefer what is the status of this PR? I would love to merge it prior to 1.19 branch.

@ohadlevy
Copy link
Member

ohadlevy commented Jul 8, 2018

@amirfefer bump!

@amirfefer
Copy link
Member Author

amirfefer commented Jul 26, 2018

There were more prioritized tasks, i'll continue work on this soon.

@amirfefer
Copy link
Member Author

@tstrachota , @ohadlevy
PR rebased and updated.

@amirfefer
Copy link
Member Author

@ohadlevy could you have another look please?

@ohadlevy
Copy link
Member

ohadlevy commented Oct 4, 2018

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') {
Copy link
Member

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, '_');
Copy link
Member

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?

@ohadlevy
Copy link
Member

ohadlevy commented Oct 4, 2018

@amirfefer also note the test failures, they seems related?


export const { sprintf } = jed;

const i18n = { translate, ngettext, jed };
Copy link
Member

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...?)

@ohadlevy
Copy link
Member

ohadlevy commented Oct 7, 2018

@amirfefer please rebase - thanks

@amirfefer
Copy link
Member Author

@ohadlevy rebased

@ohadlevy
Copy link
Member

ohadlevy commented Oct 8, 2018

@ohadlevy
Copy link
Member

ohadlevy commented Oct 8, 2018

test failures not related, imho ready for merge, bonus points if you can get the missing test for depreciation.

ekohl
ekohl previously approved these changes Oct 8, 2018
Copy link
Member

@ekohl ekohl left a 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

@amirfefer
Copy link
Member Author

@ohadlevy I've added a test for deprecateObjectProperty

@ohadlevy
Copy link
Member

ohadlevy commented Oct 8, 2018

since @ekohl already approved, I'll merge once tests are 💚

@ohadlevy
Copy link
Member

ohadlevy commented Oct 8, 2018

test failures not relevant, thanks @amirfefer

@ohadlevy ohadlevy merged commit 60e4da4 into theforeman:develop Oct 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants