Welcome to the nuBuilder Forums!
Register and log in to access exclusive forums and content available only to registered users.
Questions related to using nuBuilder Forte.
apmuthu
Posts: 249 Joined: Sun Dec 06, 2020 6:50 am
Location: Chennai, India, Singapore
Unread post
by apmuthu » Sat Dec 12, 2020 5:03 pm
The current code for translation is in
nucommon.js at lines 644 to 656 :
Code: Select all
function nuTranslate(s){
for(var i = 0 ; i < nuLANGUAGE.length ; i ++){
if(nuLANGUAGE[i].english == s){
return nuLANGUAGE[i].translation;
}
}
return s;
}
This can be improved by avoiding the
for loop and directly getting the translation using the likes of
nuLANGUAGE.find(s) or similar construct. Alternatively store it in an array where the
english string is the
index - it can then be a mere lookup.
Also refer:
https://attacomsian.com/blog/javascript-array-search
Last edited by
apmuthu on Sat Dec 12, 2020 5:41 pm, edited 1 time in total.
apmuthu
Posts: 249 Joined: Sun Dec 06, 2020 6:50 am
Location: Chennai, India, Singapore
Unread post
by apmuthu » Sat Dec 12, 2020 5:26 pm
The translation function for PHP code is in nucommon.php at lines 1560 to 1576:
Code: Select all
function nuTranslate($e){
$l = nuUserLanguage();
$s = "
SELECT *
FROM zzzzsys_translate
WHERE trl_language = ?
AND trl_english = ?
";
$t = nuRunQuery($s, [$l, $e]);
$tr = db_fetch_object($t)->trl_translation;
return $tr == '' ? $e : $tr;
}
As this is a PDO SQL query, with the right indexes, it should churn out fine.
kev1n
nuBuilder Team
Posts: 4307 Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 448 times
Contact:
Unread post
by kev1n » Sat Dec 12, 2020 6:25 pm
Hi,
Thanks for your suggestion!
How about this?
Code: Select all
function nuTranslate(s) {
var l = nuLANGUAGE.find(elem => elem.english === s);
return !l ? s : l.translation;
}
Tests:
Returns the translated string.
Returns Something_Else
apmuthu
Posts: 249 Joined: Sun Dec 06, 2020 6:50 am
Location: Chennai, India, Singapore
Unread post
by apmuthu » Sat Dec 12, 2020 7:04 pm
Need to try out missing translations, invalid translations and other edge cases like case sensitivity.
Nubuilder4 just has too many DB requests just to put up a screen!
Translation strings are spread all over!
Missing translations, unknown usage strings translated and locations of strings fathomed and attached.
You do not have the required permissions to view the files attached to this post.
kev1n
nuBuilder Team
Posts: 4307 Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 448 times
Contact:
Unread post
by kev1n » Mon Dec 14, 2020 5:48 am
Thanks for that! I will look into it.
Suggestions for improvement are very welcome.
apmuthu
Posts: 249 Joined: Sun Dec 06, 2020 6:50 am
Location: Chennai, India, Singapore
Unread post
by apmuthu » Fri Dec 18, 2020 7:51 am
Nubuilder file based translation resources culled using:
Code: Select all
SET @LANG:='Vietnamese';
SELECT CONCAT('$',"t['",trl_english,"']=",'"',trl_translation,'";') AS Translation FROM `zzzzsys_translate` WHERE trl_language=@LANG ORDER BY trl_english;
Attachment has all 14 languages parsed from table into files with sample code and links.
You do not have the required permissions to view the files attached to this post.
kev1n
nuBuilder Team
Posts: 4307 Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 448 times
Contact:
Unread post
by kev1n » Fri Dec 18, 2020 8:54 am
Hi,
Thanks for that! How would you include the language files and also merge in the user-translated strings?
apmuthu
Posts: 249 Joined: Sun Dec 06, 2020 6:50 am
Location: Chennai, India, Singapore
Unread post
by apmuthu » Mon Dec 28, 2020 5:25 pm
The setup page has the language setting. Map that to the language files you need on demand and create a cache, overwriting the earlier one that exists with the complete English set as an auto fallback (the key).
Made one
commit to just optimise the js translation function now.
Later we can work on the split language files and files and cache.