Move l10n functions to the bundle
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
This commit is contained in:
parent
2246003a3e
commit
a5ec4a9af4
8 changed files with 43 additions and 35 deletions
BIN
core/js/dist/login.js
vendored
BIN
core/js/dist/login.js
vendored
Binary file not shown.
BIN
core/js/dist/login.js.map
vendored
BIN
core/js/dist/login.js.map
vendored
Binary file not shown.
BIN
core/js/dist/main.js
vendored
BIN
core/js/dist/main.js
vendored
Binary file not shown.
BIN
core/js/dist/main.js.map
vendored
BIN
core/js/dist/main.js.map
vendored
Binary file not shown.
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue