Forum > Translations
My multilingual method for apps
jwdietrich:
As a first step, it may be helpful to automatically detect the language of the system. If a translation for the current language is available then use it, otherwise use e.g. English.
For one of my projects (SPINA Thyr) I developed the following solution:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses // ... {$IFDEF LCLCarbon} , MacOSAll {$ELSE} {$IFDEF LCLCocoa} , MacOSAll, CocoaAll, CocoaUtils {$ENDIF} {$ENDIF} ; function GetOSLanguage: string; {platform-independent method to read the language of the user interface}var l, fbl: string; {$IFDEF Darwin} theLocaleRef: CFLocaleRef; locale: CFStringRef; buffer: StringPtr; bufferSize: CFIndex; encoding: CFStringEncoding; success: boolean; {$ENDIF}begin {$IFDEF Darwin} theLocaleRef := CFLocaleCopyCurrent; locale := CFLocaleGetIdentifier(theLocaleRef); encoding := 0; bufferSize := 256; buffer := new(StringPtr); success := CFStringGetPascalString(locale, buffer, bufferSize, encoding); if success then l := string(buffer^) else l := ''; fbl := Copy(l, 1, 2); dispose(buffer); {$ELSE} {$IFDEF UNIX} fbl := Copy(GetEnvironmentVariable('LC_CTYPE'), 1, 2); {$ELSE} GetLanguageIDs(l, fbl); {$ENDIF} {$ENDIF} Result := fbl;end;
This platform-independent method is able to detect the language as specified by currently logged-in user. With this information it is possible to automatically set the language of the app with the methods suggestd by @Raul_ES, @PascalDragon and @kupferstecher.
Raul_ES:
Thank you all for your replies :)
Raul_ES:
Thanks Roland57
Google may not be the best option, but it's very handy and I have the feeling that their translation algorithms are improving, at least for the languages I know. I think that for isolated words and short sentences actually performs pretty well (sometimes you get a wierd result though). But of course, nothing like a human native speaker to ask for a translation ;-)
regards
--- Quote from: Roland57 on April 03, 2020, 02:48:29 am ---Hello!
@Raul_ES
Interesting example. I didn't know the "cvar, export, external" trick. :)
I have done something like your example (with little differences) in a project:
https://github.com/rchastain/eschecs/blob/master/source/language.pas
By the way (since you ask for opinions), I don't like translations made with Google. Only a person who is a native speaker of the language and who is an user of the software can do a good translation (IMHO).
Good luck with your project.
--- End quote ---
Raul_ES:
--- Quote ---For one of my projects (SPINA Thyr)
--- End quote ---
Cool!
Raul_ES:
--- Quote from: jwdietrich on April 03, 2020, 05:27:14 pm ---As a first step, it may be helpful to automatically detect the language of the system. If a translation for the current language is available then use it, otherwise use e.g. English.
...
--- End quote ---
Thanks, really nice. I'm going to add it inmediatly to my proyect.
regards
Navigation
[0] Message Index
[#] Next page
[*] Previous page