Skip to content

Commit

Permalink
feat(emeis-options): add setting to force the locale of models
Browse files Browse the repository at this point in the history
This makes the already existing override for field locales configurable
via the emeis-options service. The existing override on model level has
been removed, because it's not accessible when ember-emeis is used as an
engine.

The override is useful for cases when translations for specific models
are not required / wanted.
  • Loading branch information
czosel committed Feb 17, 2022
1 parent eeb1b0c commit 2c30e54
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ export default class EmeisOptionsService extends Service {
// number of items in list views
pageSize = 10;

// force the locale of models to a specific value (i.e. to make it "untranslated")
forceLocale = {
scope: "en",
};

// hide "username" field
emailAsUsername = false;

Expand Down
3 changes: 2 additions & 1 deletion addon/models/localized.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import { inject as service } from "@ember/service";

export default class LocalizedModel extends Model {
@service intl;
@service emeisOptions;

getUnlocalizedField(field) {
return this[`_${field}`];
}

getFieldLocale() {
return (
this.localizedFieldLocale ||
this.emeisOptions.forceLocale?.[this.constructor.modelName] ||
this.intl.localizedFieldLocale ||
this.intl.primaryLocale
);
Expand Down
4 changes: 2 additions & 2 deletions addon/templates/scopes/edit.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
@updateModel={{this.updateModel}}
@listViewRouteName="scopes.index"
>
<EditForm::Element @label={{t "emeis.scopes.headings.name"}}>
<EditForm::Element @label={{t "emeis.scopes.headings.fullName"}}>
<input
class="uk-input"
type="text"
name="name"
placeholder="{{t "emeis.scopes.headings.name"}}..."
placeholder="{{t "emeis.scopes.headings.fullName"}}..."
required
value={{@model.name}}
/>
Expand Down
3 changes: 3 additions & 0 deletions tests/dummy/app/services/emeis-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import Service from "@ember/service";
export default class EmeisOptionsService extends Service {
emailAsUsername = false;
pageSize = 10;
// forceLocale = {
// scope: "en",
// };
// additionalUserFields = {
// phone: "optional",
// language: "optional",
Expand Down

0 comments on commit 2c30e54

Please sign in to comment.