@@ -97,16 +97,62 @@ var app = new Vue({
9797You can specify a custom module name for vuex (default is 'i18n') or a callback that is triggered
9898when a key has no translation for the current locale. Please note, that the function
9999supplied for onTranslationNotFound will be called if the key is not in the actual
100- locale, however, the key might still be available in the fallback locale or a
101- localized locale version. This might need some further work in the future.
100+ locale or a parent locale (ie. en for en-us), however, the key might still be available
101+ in the fallback locale.
102+
103+ If a return value is given, this will be used as translation text for the key
104+ that was not found. It is also possible to return a promise. This will allow you
105+ to dynamically fetch the data from an api. Be aware, that the key will only
106+ be resolved once and then written like any other key into the store. Therefore
107+ subsequent calls of the same key will not trigger the onTranslationNotFound method.
102108
103109``` javascript
110+
111+ // without return value (will use fallback translation, default translation or key)
104112Vue .use (vuexI18n .plugin , store, {
105113 moduleName: ' i18n' ,
106114 onTranslationNotFound (locale , key ) {
107115 console .warn (` i18n :: Key '${ key} ' not found for locale '${ locale} '` );
108116 }}
109117);
118+
119+ // with string as return value. this will write the new value as translation
120+ // into the store
121+ // note: synchronous resolving of keys is not recommended as this functionality
122+ // should be implemented in a different way
123+ Vue .use (vuexI18n .plugin , store, {
124+ moduleName: ' i18n' ,
125+ onTranslationNotFound (locale , key ) {
126+ switch (key) {
127+ case : ' 200' :
128+ return ' Everything went fine' ;
129+ break ;
130+ default :
131+ return ' There was a problem' ;
132+ }
133+ }}
134+ );
135+
136+ // with promise as return value. this will write the new value into the store,
137+ // after the promise is resolved
138+ Vue .use (vuexI18n .plugin , store, {
139+ moduleName: ' i18n' ,
140+ onTranslationNotFound (locale , key ) {
141+
142+ return new Promise ((resolve , reject ) => {
143+ axios .get (' /api/translations/async' , {locale: locale, key: key})
144+ .then ((result ) => {
145+ resolve (result .data );
146+
147+ }).catch () {
148+ reject ();
149+ }
150+
151+ })
152+
153+ }}
154+ );
155+
110156```
111157
112158## Usage
0 commit comments