diff --git a/core/js/dist/login.js b/core/js/dist/login.js index 45a7be6facbe32cd0ecbf923a3ba6e6953ea43bb..3c748bfd7ab9a620aca9235ab15043f39ea05686 100644 Binary files a/core/js/dist/login.js and b/core/js/dist/login.js differ diff --git a/core/js/dist/login.js.map b/core/js/dist/login.js.map index 06e1c8f8abd566d3cab6297cd73ae4c32f889fbf..b043d1aa9fd80f818dca1c3600d99203ae4d2b7b 100644 Binary files a/core/js/dist/login.js.map and b/core/js/dist/login.js.map differ diff --git a/core/js/dist/main.js b/core/js/dist/main.js index 008d97e2b4584a408639b7e83ab60a9ceb7e12b8..1c6e261857af192973b07027385e0e787f779e25 100644 Binary files a/core/js/dist/main.js and b/core/js/dist/main.js differ diff --git a/core/js/dist/main.js.map b/core/js/dist/main.js.map index 9a0e1c518d8ee9f9c9236bad944163cba15e5b36..447a3e59fb301b764da0f4701f03b1f0f46cdb20 100644 Binary files a/core/js/dist/main.js.map and b/core/js/dist/main.js.map differ diff --git a/core/js/js.js b/core/js/js.js index 127d293cd4cabd0931a2fcb65675be2d542a7959..6a5c04fd2c6aede9361a89c9aa95074f6fece19f 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -220,34 +220,6 @@ Object.assign(window.OC, { } }, - /** - * Returns the user's locale as a BCP 47 compliant language tag - * - * @return {String} locale string - */ - getCanonicalLocale: function() { - var locale = this.getLocale(); - return typeof locale === 'string' ? locale.replace(/_/g, '-') : locale; - }, - - /** - * Returns the user's locale - * - * @return {String} locale string - */ - getLocale: function() { - return $('html').data('locale'); - }, - - /** - * Returns the user's language - * - * @returns {String} language string - */ - getLanguage: function () { - return $('html').prop('lang'); - }, - /** * Warn users that the connection to the server was lost temporarily * diff --git a/core/js/tests/specs/coreSpec.js b/core/js/tests/specs/coreSpec.js index a785cf49db817e767d7a9ab865d2bac5ae3cd65f..cd7850453e12191b4c34811d39c33c6b3a6d0a83 100644 --- a/core/js/tests/specs/coreSpec.js +++ b/core/js/tests/specs/coreSpec.js @@ -274,25 +274,25 @@ describe('Core base tests', function() { }); }); describe('getCanonicalLocale', function() { - var localeStub; + var oldLocale; beforeEach(function() { - localeStub = sinon.stub(OC, 'getLocale'); + oldLocale = $('html').data('locale') }); afterEach(function() { - localeStub.restore(); + $('html').data('locale', oldLocale) }); it("Returns primary locales as is", function() { - localeStub.returns('de'); + $('html').data('locale', 'de') expect(OC.getCanonicalLocale()).toEqual('de'); - localeStub.returns('zu'); + $('html').data('locale', 'zu') expect(OC.getCanonicalLocale()).toEqual('zu'); }); it("Returns extended locales with hyphens", function() { - localeStub.returns('az_Cyrl_AZ'); + $('html').data('locale', 'az_Cyrl_AZ') expect(OC.getCanonicalLocale()).toEqual('az-Cyrl-AZ'); - localeStub.returns('de_DE'); + $('html').data('locale', 'de_DE') expect(OC.getCanonicalLocale()).toEqual('de-DE'); }); }); diff --git a/core/src/OC/index.js b/core/src/OC/index.js index 9838e63b0f8c689915ca32f452046ee68847c997..3a76361d476f8ddf1873ddf002c6c3d02e921bdc 100644 --- a/core/src/OC/index.js +++ b/core/src/OC/index.js @@ -61,6 +61,11 @@ import { } from './menu' import {isUserAdmin} from './admin' import L10N from './l10n' +import { + getCanonicalLocale, + getLanguage, + getLocale, +} from './l10n' import { filePath, generateUrl, @@ -142,6 +147,13 @@ export default { isSamePath, joinPaths, + /** + * L10n + */ + getCanonicalLocale, + getLocale, + getLanguage, + msg, Notification, PasswordConfirmation, diff --git a/core/src/OC/l10n.js b/core/src/OC/l10n.js index 73c239569a0a090d69d7e84b29d31162d1d0d8c1..30089b3427a3b5884b5857b048e4649f7cef78d3 100644 --- a/core/src/OC/l10n.js +++ b/core/src/OC/l10n.js @@ -329,6 +329,30 @@ const L10n = { export default L10n; +/** + * Returns the user's locale as a BCP 47 compliant language tag + * + * @return {String} locale string + */ +export const getCanonicalLocale = () => { + const locale = getLocale() + return typeof locale === 'string' ? locale.replace(/_/g, '-') : locale +} + +/** + * Returns the user's locale + * + * @return {String} locale string + */ +export const getLocale = () => $('html').data('locale') + +/** + * Returns the user's language + * + * @returns {String} language string + */ +export const getLanguage = () => $('html').prop('lang') + Handlebars.registerHelper('t', function(app, text) { return L10n.translate(app, text); });