1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-08-02 20:15:26 +02:00

Initial i18n experiment

This commit is contained in:
McMatts 2022-03-01 16:22:53 -05:00
parent 32a9528e6d
commit 245c538990
12 changed files with 103 additions and 38 deletions

View file

@ -0,0 +1,17 @@
// Copyright 2022 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// https://www.documize.com
import Helper from '@ember/component/helper';
import { inject as service } from '@ember/service';
export default Helper.extend({
i18n: service(),
compute([key, ...rest]) {
return this.i18n.localize(key, ...rest);
}
});

View file

@ -0,0 +1,19 @@
// Copyright 2022 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// https://www.documize.com
export function initialize(application) {
application.inject('route', 'i18n', 'service:i18n');
application.inject('controller', 'i18n', 'service:i18n');
application.inject('component', 'i18n', 'service:i18n');
application.inject('model', 'i18n', 'service:i18n');
}
export default {
name: 'i18n',
after: "application",
initialize: initialize
};

View file

@ -30,6 +30,7 @@ export default Model.extend({
theme: attr('string'),
created: attr(),
revised: attr(),
locale: attr('string', { defaultValue: "en-US" }),
fullname: computed('firstname', 'lastname', function () {
return `${this.get('firstname')} ${this.get('lastname')}`;

View file

@ -76,5 +76,4 @@ export default Controller.extend(AuthProvider, {
// }
}
}
});

View file

@ -23,7 +23,7 @@
<Layout::Grid::Sidebar>
<div class="sidebar-content">
<div class="section">
<div class="title">filter</div>
<div class="title">{{localize 'filter'}}</div>
<div class="list">
<div class="item {{if (eq selectedView "all") "selected"}}" {{action "onSelect" "all"}}>
<i class={{concat "dicon " constants.Icon.All}} />

View file

@ -44,6 +44,7 @@ export default Service.extend({
updateAvailable: false,
// empty theme uses default theme
theme: '',
locale: 'en-US',
getBaseUrl(endpoint) {
return [this.get('endpoint'), endpoint].join('/');

33
gui/app/services/i18n.js Normal file
View file

@ -0,0 +1,33 @@
// Copyright 2022 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// https://www.documize.com
import Service, { inject as service } from '@ember/service';
import $ from 'jquery';
export default Service.extend({
langs: { enUS: [] },
locales: [],
session: service(),
init() {
this._super(...arguments);
$.getJSON("/i18n/en-US.json", (data) => {
this.langs.enUS = data;
});
},
localize(key) {
console.log(this.session.locale);
switch(this.session.locale) {
case "fr-FR":
return "unsupported";
default:
return this.langs.enUS[key];
}
},
});

View file

@ -99,6 +99,11 @@ export default SimpleAuthSession.extend({
return this.get('session.content.authenticated.token');
}),
locale: computed('session.content.authenticated.user', function () {
let locale = this.get('session.content.authenticated.user.locale');
if (_.isUndefined(locale) || locale === "") return this.appMeta.locale;
}),
init() {
this._super(...arguments);
},