Reputation: 197
I am in the initial step of implementing the multi language support for my angular web app.
Have following 2 approaches. Both has pros & cons. But need your input on that.
Have Master json file for each language which has key-value pair in json format. Load the whole master file based on the language selection. Use it in a $scope variable for that particular page.
Pros
One File changes for each language.
Less Maintenance.
Client Memory is more utilized.
Cons
Need to load/keep unused key-value pairs from the json file.
Have Master json file for each language which has key-value pair in json format. Have a local json file which has only keys which is only needed for the current page being displayed.
Pros
Extract the only needed key-value pair from Master file using local json file.Keep only these in the memory.
Client Memory is less utilized.
Cons
Since we are maintaining the Local file , we need to make sure that to add any new key are introduced.
Maintenance is more.
Need your input.
Thanks Gokul
Upvotes: 0
Views: 694
Reputation: 691715
Use the simplest approach. Optimize only if needed.
I have an AngularJS application (not very big, but not a toy app either) where every translation for a given language is in the same JSON file. The JSON file size is 40 KB, which is already quite small. Gzipped, that makes it 8.5 KB, which is tiny.
The time needed to download the file (excluding latency) on my decent DSL line is less than 1 millisecond. This is done once when the app starts. If you configure caching correctly and change the name of the file each time it changes, the browser can keep it in cache forever.
Upvotes: 1