International language in Linux

Just starting out? Need help? Post your questions and find answers here.
AZJIO
Addict
Addict
Posts: 2193
Joined: Sun May 14, 2017 1:48 am

International language in Linux

Post by AZJIO »

How to enable international language in Linux using .mo files?
Olli
Addict
Addict
Posts: 1244
Joined: Wed May 27, 2020 12:26 pm

Re: International language in Linux

Post by Olli »

If the 'mo' file extension you are describing, has a functionnal link with this (source : https://file.org/ ), it seems that this type of file is used by Audacity. In this way, libraries are downloadable here. Note that you can access to the source codes and their authors in the official site.
AZJIO
Addict
Addict
Posts: 2193
Joined: Sun May 14, 2017 1:48 am

Re: International language in Linux

Post by AZJIO »

Olli
Nope!
.mo files is a binary file created from a text .po file using the poedit program.
The files are located in the /usr/share/locale/ru/LC_MESSAGES folder. Instead of "ru", it can be "en". It depends on the language of the operating system

Image
Olli
Addict
Addict
Posts: 1244
Joined: Wed May 27, 2020 12:26 pm

Re: International language in Linux

Post by Olli »

My apologize...

In this way, maybe you can find a library in the available packs here, and also contact the authors...
https://poedit.net/download
AZJIO
Addict
Addict
Posts: 2193
Joined: Sun May 14, 2017 1:48 am

Re: International language in Linux

Post by AZJIO »

Olli
1. I know how to use poedit
2. I can compile the .mo binary

problem:
I need an engine or module or procedure that can pull lines from a .mo file and insert into a program interface.
For example, you have French. The program itself will pull the strings from the French localization file. The program interface will be in French.
I do not think that the authors of poedit will write a module for PureBasic. poedit is just a program to create a localization file

The Format of PO Files

I can make my own file format, just a list of strings. But there is the problem of determining the language of the system. That is, I will have to solve this issue. Maybe there is a ready-made solution and I will get rid of 2 problems at once.
Olli
Addict
Addict
Posts: 1244
Joined: Wed May 27, 2020 12:26 pm

Re: International language in Linux

Post by Olli »

Can you execute 'locale' ?

other way : could you execute the pb example on this page ?
#NULL
Addict
Addict
Posts: 1499
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: International language in Linux

Post by #NULL »

Can you not just call gettext (as a c function or commandline program) after installing your mo files in the system? I think the 'library' is already there in linux, you just have to learn which commands to use. But i just used mo files and gettext in php, so I don't know exactly how this works for a binary application. Maybe wiki/Gettext#Running helps.
AZJIO
Addict
Addict
Posts: 2193
Joined: Sun May 14, 2017 1:48 am

Re: International language in Linux

Post by AZJIO »

Olli
Thanks, I got the OS language

Code: Select all

If ExamineEnvironmentVariables()
    While NextEnvironmentVariable()
        Debug EnvironmentVariableName() + " = " + EnvironmentVariableValue()
    Wend
EndIf
LANGUAGE = ru
and 44 more variables.

#NULL

Code: Select all

ImportC "???"
  ...
EndImport
#NULL
Addict
Addict
Posts: 1499
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: International language in Linux

Post by #NULL »

AZJIO wrote: #NULL

Code: Select all

ImportC "???"
  ...
EndImport
It seems the functions are already available like gettext_() for example, but I don't know how to use them.
But I found this: Translator/Multilanguage with locale support, post by djes.
I had to comment out 3 parts (the line with GetThreadLocale_() and 2 Cases) and it would run on linux and the translation works (after fixing the slash in sample.pb as well).
AZJIO
Addict
Addict
Posts: 2193
Joined: Sun May 14, 2017 1:48 am

Re: International language in Linux

Post by AZJIO »

Did this:

Code: Select all

EnableExplicit

; Determination of the interface language and apply
Global UserIntLang, UserIntLang$, PathLang$, tmp$, i, *Lang

; Defines the OS language
CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Windows
		If OpenLibrary(0, "kernel32.dll")
			*Lang = GetFunction(0, "GetUserDefaultUILanguage")
			If *Lang
				UserIntLang = CallFunctionFast(*Lang)
			EndIf
			CloseLibrary(0)
		EndIf
    CompilerCase #PB_OS_Linux
		If ExamineEnvironmentVariables()
		    While NextEnvironmentVariable()
		    	If Left(EnvironmentVariableName(), 4) = "LANG"
; 		    		LANG=ru_RU.UTF-8
; 		    		LANGUAGE=ru
				UserIntLang$ = Left(EnvironmentVariableValue(), 2)
				Break
			EndIf
		    Wend
		EndIf
CompilerEndSelect

#CountStrLang = 3 ; number of translation strings and correspondingly array
Global Dim Lng.s(#CountStrLang)
; Interface strings even if the language file is not found
Lng(1) = "Signal"
Lng(2) = "Hours"
Lng(3) = "Minutes"
; ...

; defines the paths to the language file
CompilerSelect #PB_Compiler_OS
	CompilerCase #PB_OS_Windows
		PathLang$ = GetPathPart(ProgramFilename()) + GetFilePart(ProgramFilename(), #PB_FileSystem_NoExtension) + "_Lang.txt"
    CompilerCase #PB_OS_Linux
		PathLang$ ="/usr/share/locale/" + UserIntLang$ + "/LC_MESSAGES/" + GetFilePart(ProgramFilename(), #PB_FileSystem_NoExtension) + ".txt"
CompilerEndSelect

; If the language file exists, then it uses it
If FileSize(PathLang$) > 1
	
	If ReadFile(0, PathLang$) ; If the file descriptor was opened, then ...
		i=0
	    While Eof(0) = 0        ; Loop until end of file is reached.
	    	tmp$ =  ReadString(0) ; reading the line
; 	    	If Left(tmp$, 1) = ";"
; 	    		Continue
; 	    	EndIf
	    	tmp$ = ReplaceString(tmp$ , #CR$ , "") ; correction if in windows
	    	If tmp$ And Left(tmp$, 1) <> ";"
	    		i+1
	    		If i > #CountStrLang ; the Lng() array is already set, but if there are more rows than you need, then we do not allow unnecessary ones
	    			Break
	    		EndIf
	    		Lng(i) = tmp$
	    	Else
	    		Continue
	    	EndIf
	    Wend
	    CloseFile(0)
	EndIf
; Else
; 	SaveFile_Buff(PathLang$, ?LangFile, ?LangFileend - ?LangFile)
EndIf
; End => Language Definition
For universality, it is necessary to allow in the ini-file to specify the path to the localization file, since there may be a problem in the language definition.
Post Reply