Change namespace in RESTAdapter

I use ember-i18n for translating my app, but how can I change namespace, when user switches a language, cause i have two different api for each language.

In app/route.js, i do'application').set('namespace',api/rest/${apiLangPath[this.get('i18n.locale')]}/);,

when i observe property service i18n.locale and then this.refresh(), cause my app reload for a new api namespace. But, it’s not working.

How are you loading your models from your API? I’d read carefully the documentation on store.findAll – depending on your settings, it may not query the back-end API again after the first time; it’ll just return the objects already in the store.

1 Like

I would suggest injecting your i18n service into your adapter and then reading the language property in overrides there. Adjusting your adapter from your route isn’t likely to work nicely …


In adapters/applications.js

export default DS.RESTAdapter.extend({
  i18n: Ember.inject.service(),
  namespace: `api//${this.get('i18n.locale')}/`

But, Uncaught TypeError: this.get is not a function

How can I get service for my namespace? Thanks, for our response =)

I did it!

i18n: Ember.inject.service(),
namespace: Ember.computed('i18n.locale', function() {
        return `api/${apiLangPath[this.get('i18n.locale')]}`;