-
Notifications
You must be signed in to change notification settings - Fork 1k
Fixes #17263 - move jed (i18n) to webpack #5342
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| providerSpecificNICInfo = function(form) { | ||
| if (form.find('select.libvirt_network').val() == 'network') { | ||
| return Jed.sprintf(__('physical @ NAT %s'), form.find('select.libvirt_nat').val()); | ||
| return tfm.i18n.sprintf(__('physical @ NAT %s'), form.find('select.libvirt_nat').val()); | ||
| } else { | ||
| return Jed.sprintf(__('physical @ bridge %s'), form.find('select.libvirt_bridge').val()); | ||
| return tfm.i18n.sprintf(__('physical @ bridge %s'), form.find('select.libvirt_bridge').val()); | ||
| } | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import $ from 'jquery'; | ||
| import URI from 'urijs'; | ||
| import { translate as __ } from './react_app/common/I18n'; | ||
|
|
||
| import { showLoading, hideLoading } from './foreman_navigation'; | ||
|
|
||
|
|
@@ -125,3 +126,14 @@ export function updateTable(element) { | |
| Turbolinks.visit(uri.toString()); | ||
| return false; | ||
| } | ||
|
|
||
| export function deprecateObjectProperty(obj, oldProp, newProp, version = '1.20') { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you please add a test for this new function? |
||
| const oldPropPointer = obj[oldProp]; | ||
|
|
||
| Object.defineProperty(obj, oldProp, { | ||
| get: () => { | ||
| deprecate(oldProp, newProp, version); | ||
| return oldPropPointer; | ||
| }, | ||
| }); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import Jed from 'jed'; | ||
| import { deprecateObjectProperty } from '../../foreman_tools'; | ||
|
|
||
| const cheveronPrefix = () => (window.I18N_MARK ? '\u00BB' : ''); | ||
| const cheveronSuffix = () => (window.I18N_MARK ? '\u00AB' : ''); | ||
|
|
||
| const emptyLocales = { | ||
| en: { domain: 'app', locale_data: { app: { '': {} } } }, | ||
| }; | ||
|
|
||
| const locales = window.locales || emptyLocales; | ||
| let locale = document.getElementsByTagName('html')[0].lang; | ||
|
|
||
| locale = locale.length === 0 ? 'en' : locale.replace(/-/g, '_'); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
| export const jed = new Jed(locales[locale]); | ||
|
|
||
| export const translate = (...args) => `${cheveronPrefix()}${jed.gettext(...args)}${cheveronSuffix()}`; | ||
| export const ngettext = (...args) => `${cheveronPrefix()}${jed.ngettext(...args)}${cheveronSuffix()}`; | ||
|
|
||
| export const { sprintf } = jed; | ||
|
|
||
| const i18n = { | ||
| translate, ngettext, jed, sprintf, | ||
| }; | ||
| export default i18n; | ||
| window.__ = translate; | ||
| window.n__ = ngettext; | ||
| window.Jed = jed; | ||
| window.i18n = jed; | ||
|
|
||
| deprecateObjectProperty(window, 'i18n', 'tfm.i18n'); | ||
| deprecateObjectProperty(window, 'Jed', 'tfm.i18n.jed'); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import Jed from 'jed'; | ||
| import { translate, ngettext } from './I18n'; | ||
|
|
||
| jest.unmock('./I18n'); | ||
| jest.unmock('jed'); | ||
|
|
||
| describe('gettext', () => { | ||
| Jed.gettext = jest.fn(s => s); | ||
| it('chevrons should not be presented', () => { | ||
| expect(translate('should not be with chevrons')).toMatchSnapshot(); | ||
| }); | ||
| it('chevrons should be presented', () => { | ||
| global.I18N_MARK = true; | ||
| expect(translate('should be with chevrons')).toMatchSnapshot(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('ngettext', () => { | ||
| Jed.ngettext = jest.fn(s => s); | ||
| it('chevrons should not be presented', () => { | ||
| expect(ngettext('should not be with chevrons')).toMatchSnapshot(); | ||
| }); | ||
| it('chevrons should be presented', () => { | ||
| global.I18N_MARK = true; | ||
| expect(ngettext('should be with chevrons')).toMatchSnapshot(); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`gettext chevrons should be presented 1`] = `"»should be with chevrons«"`; | ||
|
|
||
| exports[`gettext chevrons should not be presented 1`] = `"should not be with chevrons"`; | ||
|
|
||
| exports[`ngettext chevrons should be presented 1`] = `"»should be with chevrons«"`; | ||
|
|
||
| exports[`ngettext chevrons should not be presented 1`] = `"»should not be with chevrons«"`; |
Uh oh!
There was an error while loading. Please reload this page.