Updated 035 Translation Mananger in JCB explained (markdown)

Amigo
2019-07-23 16:47:44 +02:00
parent e185a275ef
commit c56e6b8385

@@ -31,20 +31,24 @@ Your language tags need to be in accordance with the correct prefixes used in Jo
[00:03:50](https://www.youtube.com/watch?v=zzAcVkn_cWU&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m50s)
In the code the following takes place. In the 'a_Get.php' class, is a function called 'setLangStrings'. It gets the content from wherever JCB is handing it and it parses it to see whether it has either this 'sprintf' language string or that one 'Jtext'. It does some gymnastics to grab all the actual strings into an array. Then it parses this array. Once it has it, it converts it to a language string, and adds it back into the content and returns the content.[00:04:34](https://www.youtube.com/watch?v=zzAcVkn_cWU&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m34s) With this object array, it is adding the language string, and the language key to the 'langContent' array. So that is a first thing, this 'langContent' array which is all over the place and it just gets bulkier. The 'lang' is basically the target. [00:05:04](https://www.youtube.com/watch?v=zzAcVkn_cWU&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h05m04s) It is the area which this 'lang' strings belong to, either the Site or the Site system or the Admin or the Admin system area. There are also such a thing as both while JCB compiles. Some strings, it knows must go to both. This 'keyLang' is the actual language string, the capitalized string, which is generated up here(see video).<<<<<,
[00:05:34](https://www.youtube.com/watch?v=zzAcVkn_cWU&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h05m34s) I trimmed and placed in it's place. This array gets placed into the files at a certain point. That point is very much at the very end of the compilation when everything is being done. We actually get to the place where [00:05:58](https://www.youtube.com/watch?v=zzAcVkn_cWU&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h05m58s) we going to add two strings to the files.
In the code the following takes place. In the 'a_Get.php' class, is a function called 'setLangStrings'. It gets the content from wherever JCB is handing it and it parses it to see whether it has either this 'sprintf' language string or that one 'Jtext'. It does some gymnastics to grab all the actual strings into an array. Then it parses this array. Once it has it, it converts it to a language string, and adds it back into the content and returns the content.[00:04:34](https://www.youtube.com/watch?v=zzAcVkn_cWU&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m34s) With this object array, it is adding the language string, and the language key to the 'langContent' array. So that is a first thing, this 'langContent' array which is all over the place and it just gets bulkier. The 'lang' is basically the target. [00:05:04](https://www.youtube.com/watch?v=zzAcVkn_cWU&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h05m04s) It is the area which this 'lang' strings belong to, either the Site or the Site system or the Admin or the Admin system area. There are also such a thing as both while JCB compiles. Some strings, it knows must go to both. This 'keyLang' is the actual language string, the capitalized string, which is generated up here(see video). [00:05:34](https://www.youtube.com/watch?v=zzAcVkn_cWU&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h05m34s) I trimmed and put it in its place. This array gets placed into the files at a certain point. That point is very much at the very end of the compilation when everything is being done. Now two strings are going to be added to the files.
### Adding Strings To The Files
First we are calling a function called setLangAdmin, setLangSys this is in the interpreter. You can see these methods are here, setLangSite, here is setLangAdmin. Basically adds a bunch of strings that are default always being added. And then also all the other strings have been built. [00:06:37](https://www.youtube.com/watch?v=zzAcVkn_cWU&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h06m37s) Moves them over to a string called language, the British English, and it's for the admin area. It does for all the various areas. In the infusion class, it brings it together. We grab the values of this strings, we add it to our value array. We basically have the old multi language implementation running down from here from line 1097. [00:07:09](https://www.youtube.com/watch?v=zzAcVkn_cWU&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h07m09s)
[00:06:04](https://www.youtube.com/watch?v=zzAcVkn_cWU&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h06m04s)
First a function is called 'setLangAdmin'/ 'setLangSys' this is in the Interpreter. These methods may be seen here, 'setLangSite', here is 'setLangAdmin' and a bunch of strings that are always being added by default and then also all the other strings that have been built which then moves them over to a string called language, the British English, and it is for the Admin area.[00:06:37](https://www.youtube.com/watch?v=zzAcVkn_cWU&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h06m37s) So it does for all the various areas. In the infusion class, it brings it together. The values of this strings are grabbed and added to the value array. The old multi language implementation running down from line 1097.
### Multi Language String Implementation
We start running into the multi language string implementation. Now what does this do basically? It queries the database to see whether there is such a English language string in the database. Whether there is been any translations made for it. So it doesn't really use the placeholders. Because the placeholders are so ambiguous between various components and our idea was to prevent a very bloated over sized database, we must try to share strings among components. [00:07:43](https://www.youtube.com/watch?v=zzAcVkn_cWU&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h07m43s) Currently when you compile a component it gathers it's English strings like I have explained, it checks the database whether these English strings already exist in the database, and if they do, it then checks whether they have translations already linked to them. If they do, then it starts grabbing that translation strings and adds them to this Language object array, also by tag and by area and here(see video) we are parsing this array. By this [00:08:22](https://www.youtube.com/watch?v=zzAcVkn_cWU&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h08m22s) time we already have all the languages in place and we are now able to put them into the component. It's these functions getMultipleLangStrings, setLangPlaceholders, purgeLanguageStrings. These are the functions that actually does the work. So you could go look at these they are all found in the a_Get.php class, the one where everything really starts. [00:08:51](https://www.youtube.com/watch?v=zzAcVkn_cWU&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h08m51s) They are found there and you can look at them. All their doings are open source you can see. By the point we get to this line 1109, we already have all the language strings in their various areas and various languages.
[00:07:09](https://www.youtube.com/watch?v=zzAcVkn_cWU&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h07m09s)
What is the function of the multi language string implementation? It searches the database to see whether there is such a English language string in the database and whether there has been any translations made for it. So it does not use the placeholders since the placeholders are so ambiguous between various components and a attempt had been made to share strings among components to prevent a overpopulated database. [00:07:43](https://www.youtube.com/watch?v=zzAcVkn_cWU&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h07m43s) Currently when a component gets compiled it gathers its English strings as explained, it checks the database whether these English strings already exist in the database, and if they do, it then checks whether they have translations already linked to them. If they do, then it starts grabbing that translation strings and adds them to this 'Language object' array, also by tag and by area and here(see video) this array is parsed. By this time all the languages are already in place and it is now possible to put them into the component.[00:08:22](https://www.youtube.com/watch?v=zzAcVkn_cWU&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h08m22s) It is these functions; 'getMultipleLangStrings', 'setLangPlaceholders', 'purgeLanguageStrings' that does the work. So these are all found in the 'a_Get.php' class which is open source. By the point we get to this line 1109, we already have all the language strings in their various areas and various languages.
### Adding Language Back To Component
[00:09:13](https://www.youtube.com/watch?v=zzAcVkn_cWU&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m13s)
<<<<<<<<<<<<<<<<<<<<<
We can now start adding them back into the component. And that's really what this part is doing. [00:09:19](https://www.youtube.com/watch?v=zzAcVkn_cWU&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m19s) It just adding it into the component. Let's go back to the user interface to see this in action. I'm going to compile a component, any component, let's say this document manager. While I'm compiling it, keep in mind it will be running through, and grabbing all the English strings, then eventually will check this [00:09:47](https://www.youtube.com/watch?v=zzAcVkn_cWU&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m47s) Language translation table, whether those strings exist. If they do, they've been translated. It compiles it, and it does most of the work for you.
### How Purging Works