Partial Loader failing when preferred language .json files are missing.
See original GitHub issueWhen I set the $translateProvider to use the partialLoader it crashes and burns when it can’t find a file that matches the preferredLanguage rather than gracefully handling that scenario and using the fallbackLanguage.
e.g.
$translateProvider.useLoader("$translatePartialLoader", {
urlTemplate: "{part}.{lang}.json"
});
$translatePartialLoaderProvider.addPart("app/i18n/shared");
$translateProvider.preferredLanguage("en-AU");
$translateProvider.fallbackLanguage("en");
/app
/i18n
/shared.en.json
... missing shared.en-AU.json
I noticed that there may be a way to pass in a loadFailHandler for the $translatePartialLoader but can’t figure out how to supply that handler and more importantly if that’s the recommended way I should be handling this situation.
Issue Analytics
- State:
- Created 10 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
angular-translate didn't attempt to use the fallback language if ...
When using angular-translate to localize my Angular app, the fallback language is not attempted if the preferred language (via static file loader) failed...
Read more >Configure schema inference and evolution in Auto Loader
The column is missing from the schema. Type mismatches. Case mismatches. The rescued data column contains a JSON containing the rescued columns ...
Read more >Python Tutorial: json.dump(s) & json.load(s) - 2021
dumps()" returns a string as indicated by the "s" at the end of "dumps". This process is called encoding. Let's write it to...
Read more >Apache Tomcat 9 (9.0.70) - Changelog
In a normal Tomcat configuration, this will be the system class loader. ... Use client's preferred language for the Server Status page of...
Read more >Content Types - ESBuild
This loader is enabled by default for .js , .cjs , and .mjs files. The .cjs extension is used by node for CommonJS...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
For anyone who comes across this post, this is how I created an error handler that will resolve an empty translation table when the loader can’t find a server side file. This will allow your fallback file translation tables to be used.
If you use this approach with physical files however the browser will report a 404 in the error console/network tab which isn’t ideal.
The solution I ended up going with was to use a server side endpoint that dynamically returned the contents of the file (if it existed) otherwise just returned an empty translation table “{}”.
e.g.
Instead of something like this:
http://app.website.com/i18n/string.en-AU.js
I used something like this:
http://app.website.com/i18n/strings/en-AU
And had the server resolve that address to a physical file if it existed and returned the contents as “application/json”. If the file didn’t exist, I just returned “{}”.
Hope this makes sense.
@knalli, I’d say this one can be closed.