Move l10n functions to the bundle

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
This commit is contained in:
Christoph Wurst 2019-05-13 18:42:49 +02:00
parent 2246003a3e
commit a5ec4a9af4
No known key found for this signature in database
GPG Key ID: CC42AC2A7F0E56D8
8 changed files with 55 additions and 47 deletions

10
core/js/dist/login.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

10
core/js/dist/main.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -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
*

View File

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

View File

@ -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,

View File

@ -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);
});