Many of the software is now supported in multiple languages, and our project is no exception. Angular $translate is very easy to use, simple configuration can be used in many languages, here does not elaborate on its configuration what, Baidu a bit too much ...
We used the $translate. Use (language) to implement the language switch, then it will automatically load the corresponding. json file, to achieve the translation of the language switch, really very useful oh ~
We can also get access to the currently applied language by $translate. Use ().
Then go to the detailed problem of the emergence and resolution process!
At first, the regression test after the completion of the project did not find this problem, it may be really small, and does not affect the use of the recent changes in English translation support, only occasionally found this problem: Refresh the interface, the first time to switch language preview language effect, the dimension display configuration of the instruction tree header translation has not been translated successfully.
So began to find the reason, break point, found the first switch language, entered the method of switching languages, but also switched the language, while changing the table header binding variable translation, but did not trigger the command of the property monitoring, carefully look at its value found, the translation of the content and not switch the language translation is the same, This means that after the language switch, when the header translation is performed, the translation of the header during the translation is still in the previous language version. json file.
The problem is roughly determined by the scope of the cause, which may be translated. The JSON did not complete the load on the table header translation, resulting in the same language as the original translation content.
And then a little bit, and then there was a small problem, supported in 3 languages: Simplified Chinese, Traditional Chinese, English. The system is supported by default in Simplified Chinese, and set to the English language save after the refresh interface, and then switch back to Simplified Chinese, found that the table header translation refreshed, became Simplified Chinese, and tried to switch to traditional Chinese after the refresh, the results of the table header translation is not normal refresh. Looked at the request, found the problem, because the project default support is Simplified Chinese, so in the page initialization is applied to the simplified Chinese. json file, then the page completely loaded complete, after the user information, found that the user is English configuration, and then modified into English translation, loaded the English. json file.
The problem here is basically a preliminary speculation that the translation of the table header is not refreshed because of the. json file. There is no other possibility, think of several solutions, $q order of execution Ah, what, but for no return value of the $translate, it seems useless. Then you can only manually delay the translation.
Using the $timeout, the delay of 200 milliseconds to perform the translation of the table header, tried, sure enough useful, but the timer is not the kind of sequential implementation of the method, in case the speed is very slow, 200 milliseconds. json file does not load complete what to do, not the first refresh after the switch language or there will be a problem? So the timer was changed to 1 milliseconds to execute, the result ... Still works.
In fact, the problem is ultimately not sure what is the reason, but added a timer really, can only wait until later became a Daniel and then look back at their blog, maybe still can untie it, haha ~
$translate change the language without immediately performing the translation