; BabelResolver by Zapman ; ; Gestion des langues pour la diffusion internationale de vos programmes PureBasic ; Réalisé avec PureBasic 3.90 ; Pas de bibliothèque nécessaires ; ; L'intérêt principal de ce programme est de simplifier considérablement le support multilangue ; ; Il comprend une toute petite notice ; ; ; #DataFolder = "MonPianoDatas\Dictionnaries" #MaxTexts = 500 #IncludedLanguages="Français|English|Deutsch|" ; you can add more if you put ; more languages datas in datasection, but an easyest way to give more language ; possibility to your software is to give the "Dictionnary" folder to the user. ; (this folder will be automatically created by BabelResolver when you'll use it) ; ; Vous pouvez ajouter d'avantage de langues incluses si vous renseignez correctement ; la datasection, mais il y a une façon plus simple de transmettre des nouvelles langues ; à vos utilisateur : copiez simplement le contenu du dossier "Dictionnary" ; (ce dossier est créé automatiquement par BabelResolver quand vous l'utilisez) ; Vous pouvez démarrer avec une datasection vide. ; #VK_ENTER = 13 Global SELanguage.s , mDictionnary$, mlanguage$ Dim LocalTexts$(#MaxTexts) LocalTexts$(1)="EndText" ; Declare.s BRTranslate (EnglishText$) Declare SetStringManipulationBufferSize(Bytes) Declare.s ChooseLanguageWindow() Declare LanguageWindow() ; ; ; ; Mettez les 5 lignes de programmes qui suivent sous forme de commentaires pour pouvoir ; utiliser ce fichier en tant que "IncludeFile" dans votre programme ; ; Comment the 5 following program lines to be able to use this file as an "IncludeFile" ; in your program. ; ; ;* ------------ FROM HERE - A PARTIR d'ICI --------------- ; ; SetStringManipulationBufferSize(500000) ; SELanguage = ChooseLanguageWindow() MessageRequester(BRTranslate("Introduction"),BRTranslate("IntroBabel"),0) LanguageWindow() End ; ;* ---------------- TO HERE - JUSQUE LA ------------------ ; ; ; Ajoutez dans votre programme un appel à LanguageWindow() pour ; donner à l'utilisateur la possibilité de modifier les dictionnaires ; ; Add in your program a call to LanguageWindow() to allow users to ; modify dictionnaries. ; ; Procedure SetStringManipulationBufferSize(Bytes) ;Le truc de Fred pour augmenter la taille du buffer texte ;et éviter les plantage quand on manipule des grandes ;chaines de caractères. ;Fred tip to increase text buffer size and avoid problem ;when using big size strings PBStringBase.l = 0 PBMemoryBase.l = 0 !MOV eax, dword [PB_StringBase] !MOV [esp+4],eax !MOV eax, dword [PB_MemoryBase] !MOV [esp+8],eax HeapReAlloc_(PBMemoryBase, #GMEM_ZEROINIT, PBStringBase, Bytes) !MOV dword [_PB_StringBase],eax EndProcedure ; Procedure.s GetAvailableLanguages () Languages$ = #IncludedLanguages ExamineDirectory(0, #DataFolder, "") While NextDirectoryEntry() FName$ = DirectoryEntryName() If FName$ If FindString(FName$,".",1) FName$=Left(FName$,FindString(FName$,".",1)-1) EndIf If FName$ FName$+"|" If FindString("|"+Languages$,"|"+FName$,1)=0 Languages$ + FName$ EndIf EndIf EndIf Wend ProcedureReturn Languages$ EndProcedure ; Enumeration #CChoose = 1000 #BCOK EndEnumeration ; Procedure.s ChooseLanguageWindow() #LChoose = 30 Result$ = "Error" If OpenWindow(#LChoose, 216, 0, 192, 71, #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered, "Choose your language") If CreateGadgetList(WindowID()) ComboBoxGadget(#CChoose, 8, 8, 176, 100) Languages$ = GetAvailableLanguages () ct = 1 Repeat LName$ = StringField(Languages$, ct, "|") If LName$ AddGadgetItem(#CChoose,-1,LName$) EndIf ct + 1 Until LName$="" SetGadgetState(#CChoose,0) ButtonGadget(#BCOK, 104, 40, 80, 23, "OK") QuitC = 0 Repeat Event = WaitWindowEvent() If Event = #PB_EventGadget If EventGadgetID() = #BCOK QuitC = 1 EndIf ElseIf Event = #PB_EventCloseWindow QuitC = 1 EndIf Until QuitC EndIf Result$ = GetGadgetText(#CChoose) CloseWindow(#LChoose) EndIf ProcedureReturn Result$ EndProcedure ; Procedure.s GetDictionnary(Language.s) ; lit un dictionnaire enregistré sous forme de fichier If Language=mlanguage$ Dictionnary$=mDictionnary$ ; To save time - Pour gagner du temps Else Dictionnary$ = "Error" If Language If FileSize(#DataFolder+"\"+Language+".txt")<1 If ReadFile(0,#DataFolder+"\English.txt") And FindString(#IncludedLanguages,Language,1)=0 Dictionnary$ ="" Repeat RText$ = ReadString() If RText$ Dictionnary$ + RText$ + Chr(13)+ Chr(10) EndIf Until RText$="" Or FindString(RText$,"EndText",1) pos=FindString(Dictionnary$,"EndText[EOT]",pos) If Pos Dictionnary$=Left(Dictionnary$,pos-1) EndIf Dictionnary$ + "EndText[EOT]" CloseFile(0) Else If Language = "Français" Restore FraTexts ElseIf Language = "Deutsch" Restore DeuTexts Else Restore EngTexts EndIf Dictionnary$="" Repeat Read TTranslation$ Dictionnary$=Dictionnary$+TTranslation$+"[EOT]" Until TTranslation$="EndText" Or TTranslation$="" pos=FindString(Dictionnary$,"EndText[EOT]",pos) If TTranslation$="" Dictionnary$ + "EndText[EOT]" EndIf EndIf If ExamineDirectory(0, #DataFolder, "") = 0 CreateDirectory(#DataFolder) EndIf If OpenFile(0,#DataFolder+"\"+Language+".txt") WriteString(Dictionnary$) CloseFile(0) EndIf Else If ReadFile(0,#DataFolder+"\"+Language+".txt") Dictionnary$ ="" Repeat RText$ = ReadString() If RText$ Dictionnary$ + RText$ + Chr(13)+ Chr(10) EndIf Until RText$="" Or FindString(RText$,"EndText[EOT]",1) pos=FindString(Dictionnary$,"EndText[EOT]",pos) If Pos Dictionnary$=Left(Dictionnary$,pos-1) EndIf Dictionnary$ + "EndText[EOT]" CloseFile(0) EndIf EndIf EndIf EndIf mlanguage$=Language mDictionnary$=Dictionnary$ ProcedureReturn Dictionnary$ EndProcedure ; Procedure PutTextInOneDictionnary(Language.s,EnglishText$,LocalText$,InRef) Result = 0 If Language And EnglishText$ Dictionnary$ = GetDictionnary(Language) pos = FindString(LCase(Dictionnary$),"[eot]"+LCase(EnglishText$)+"|",1) If pos = 0 If Left(LCase(Dictionnary$),Len("[eot]"+LCase(EnglishText$)+"|"))="[eot]"+LCase(EnglishText$)+"|" pos = 1 EndIf Else pos+5 EndIf If pos If InRef = 0 pos2=FindString(Dictionnary$,"[EOT]",pos) If pos2 Dictionnary$=Left(Dictionnary$,pos-1)+EnglishText$+"|"+LocalText$+"[EOT]"+Right(Dictionnary$,Len(Dictionnary$)-pos2-4) EndIf EndIf Else Result = 1 pos=FindString(Dictionnary$,"EndText[EOT]",pos) If Pos Dictionnary$=Left(Dictionnary$,pos-1) EndIf Dictionnary$ = Dictionnary$ + EnglishText$+"|"+LocalText$+"[EOT]EndText[EOT]" EndIf If OpenFile(0,#DataFolder+"\"+Language+".txt") WriteString(Dictionnary$) CloseFile(0) EndIf EndIf mlanguage$=Language mDictionnary$=Dictionnary$ ProcedureReturn Result EndProcedure ; Procedure PutTextInDictionnary(Language.s,EnglishText$,LocalText$) If Language And EnglishText$ If LocalText$="" LocalText$ = EnglishText$ EndIf If PutTextInOneDictionnary(Language.s,EnglishText$,LocalText$,0) ExamineDirectory(0, #DataFolder, "") DirList$="" While NextDirectoryEntry() FName$ = GetFilePart(DirectoryEntryName()) If FName$<>Language+".txt" If LCase(Right(FName$,4))=".txt" FName$=Left(FName$,Len(FName$)-4) DirList$=DirList$+FName$+"|" EndIf EndIf Wend ct = 1 Repeat LName$ = StringField(#IncludedLanguages, ct, "|") If LName$ And FindString(DirList$,LName$+"|",1)=0 And LName$<>Language DirList$ + LName$+"|" EndIf ct + 1 Until LName$="" ct = 1 While DirList$ pos=FindString(DirList$,"|",1) FName$=Left(DirList$,pos-1) DirList$=Right(DirList$,Len(DirList$)-pos) PutTextInOneDictionnary(FName$,EnglishText$,EnglishText$,1) Wend EndIf EndIf EndProcedure ; Procedure DelTextFromOneDictionnary(Language.s,EnglishText$) Result = 0 If Language And EnglishText$ Dictionnary$ = GetDictionnary(Language) pos = FindString(LCase(Dictionnary$),"[eot]"+LCase(EnglishText$)+"|",1) If pos = 0 If Left(LCase(Dictionnary$),Len("[eot]"+LCase(EnglishText$)+"|"))="[eot]"+LCase(EnglishText$)+"|" pos = 1 EndIf Else pos+5 EndIf If pos pos2=FindString(Dictionnary$,"[EOT]",pos) If pos2 Dictionnary$=Left(Dictionnary$,pos-1)+Right(Dictionnary$,Len(Dictionnary$)-pos2-4) EndIf EndIf If OpenFile(0,#DataFolder+"\"+Language+".txt") WriteString(Dictionnary$) CloseFile(0) EndIf EndIf mlanguage$=Language mDictionnary$=Dictionnary$ ProcedureReturn Result EndProcedure ; Procedure DelTextFromDictionnaries(EnglishText$) If EnglishText$ ExamineDirectory(0, #DataFolder, "") DirList$="" While NextDirectoryEntry() FName$ = GetFilePart(DirectoryEntryName()) If LCase(Right(FName$,4))=".txt" FName$=Left(FName$,Len(FName$)-4) DirList$=DirList$+FName$+"|" EndIf Wend ct = 1 While DirList$ pos=FindString(DirList$,"|",1) FName$=Left(DirList$,pos-1) DirList$=Right(DirList$,Len(DirList$)-pos) DelTextFromOneDictionnary(FName$,EnglishText$) Wend EndIf EndProcedure ; Procedure.s BRTranslate(EnglishText$) EnglishText$ = ReplaceString(EnglishText$,Chr(10),"") EnglishText$ = ReplaceString(EnglishText$,Chr(13),"[EOL]") Localtext$ = EnglishText$ If EnglishText$ Dictionnary$ = GetDictionnary(SELanguage) pos = FindString("]"+LCase(Dictionnary$),"]"+LCase(EnglishText$)+"|",1) If pos pos + Len(EnglishText$+"|") pos2=FindString(Dictionnary$,"[EOT]",pos) If pos2 Localtext$=Mid(Dictionnary$,pos,pos2-pos) EndIf Else PutTextInDictionnary("English",EnglishText$,EnglishText$) PutTextInDictionnary(SELanguage,EnglishText$,EnglishText$) EndIf EndIf LocalText$ = ReplaceString(LocalText$,"[EOL]",Chr(13)) ProcedureReturn(LocalText$) EndProcedure ; Declare SetListFromDictionnary (Language.s) Declare SaveBiText (Language.s) ; Procedure LanguageWindow() #LanguageWindow = 30 ; Structure BiText EnglishText.s LocalText.s EndStructure Dim BiText.BiText(#MaxTexts) ; Enumeration #LLList = 1002 #TLEnglish #SLLocal #CLLanguage #TLLanguage #BLSave #BLNew #BLDelete #FLLook #SLLook #BLLook #BLNext #BLAbsorb #BLHidden #BLWebT #BLQuit EndEnumeration ; hw = OpenWindow(#LanguageWindow, 216, 0, 515, 448, #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered, BRTranslate("Modify languages")) If hw If CreateGadgetList(WindowID()) ListViewGadget(#LLList, 10, 39, 493, 247) TextGadget(#TLEnglish, 10, 288, 493, 17, "") TextGadget(#TLLanguage, 10, 12, 63, 20, BRTranslate("Language:"), #PB_Text_Right) ComboBoxGadget(#CLLanguage, 80, 9, 133, 100) Languages$ = GetAvailableLanguages () ct = 1 Repeat LName$ = StringField(Languages$, ct, "|") If LName$ AddGadgetItem(#CLLanguage,-1,LName$) EndIf ct + 1 Until LName$="" ; noi = CountGadgetItems(#CLLanguage) ct = 0 While ctGetGadgetItemText(#CLLanguage,ct,0) : ct + 1 : Wend If SELanguage.s=GetGadgetItemText(#CLLanguage,ct,0) SetGadgetState(#CLLanguage,ct) Else SetGadgetState(#CLLanguage,0) EndIf ButtonGadget(#BLSave, 439, 10, 64, 20, BRTranslate("Save")) ButtonGadget(#BLNew, 220, 10, 64, 20, BRTranslate("New")) ButtonGadget(#BLDelete, 292, 10, 64, 20, BRTranslate("Delete")) Frame3DGadget(#FLLook, 10, 368, 493, 44, BRTranslate("Look for")) StringGadget(#SLLook, 18, 385, 272, 20, "") ButtonGadget(#BLLook, 304, 385, 91, 20, BRTranslate("Look")) ButtonGadget(#BLNext, 402, 385, 91, 20, BRTranslate("Next")) ButtonGadget(#BLAbsorb, 10, 420, 140, 20, BRTranslate("Absorb a dictionnary")) ButtonGadget(#BLHidden, 157, 420, 127, 20, BRTranslate("Hidden commands")) ButtonGadget(#BLWebT, 291, 420, 120, 20, BRTranslate("Web Translation")) ButtonGadget(#BLQuit, 442, 420, 61, 20, BRTranslate("Quit")) StringGadget(#SLLocal, 10, 305, 493, 60, "",#PB_String_Multiline|#WS_VSCROLL) SetListFromDictionnary(GetGadgetText(#CLLanguage)) CurrentLanguage$ = GetGadgetText(#CLLanguage) ; QuitL = 0 ; Repeat Event = WaitWindowEvent() If Event = #PB_EventGadget GadgetID = EventGadgetID() ; If GadgetID = #LLList ct = GetGadgetState(#LLList) LName$ = BiText(ct)\EnglishText GetAsyncKeyState_(#VK_CONTROL) ; Empty Buffer GetAsyncKeyState_(#VK_CONTROL) ; Empty Buffer GetAsyncKeyState_(#VK_CONTROL) ; Empty Buffer GetAsyncKeyState_(#VK_MENU) ; Empty Buffer GetAsyncKeyState_(#VK_MENU) ; Empty Buffer GetAsyncKeyState_(#VK_MENU) ; Empty Buffer ; If GetAsyncKeyState_(#VK_CONTROL) Result = MessageRequester(BRTranslate("Caution!"),BRTranslate("Do you really want to delete this text from all dictionnaries ?"),#PB_MessageRequester_YesNo) If Result = 6 If Right(GetGadgetText(#CLLanguage),1)="*" ct = GetGadgetState(#CLLanguage) CurrentLanguage$ = GetGadgetText(#CLLanguage) CurrentLanguage$ = Left(CurrentLanguage$,Len(CurrentLanguage$)-1) SetGadgetItemText(#CLLanguage,ct,CurrentLanguage$,0) SetGadgetState(#CLLanguage,ct) SaveBiText (CurrentLanguage$) EndIf DelTextFromDictionnaries(LName$) SetListFromDictionnary(GetGadgetText(#CLLanguage)) If GetGadgetItemText(#LLList,ct,0)="" ct-1 EndIf SetGadgetState(#LLList,ct) EndIf ElseIf GetAsyncKeyState_(#VK_MENU) NewText$ = InputRequester(BRTranslate("New Text"), BRTranslate("Enter the english version of your new text:"), "") If NewText$ If Right(GetGadgetText(#CLLanguage),1)="*" ct = GetGadgetState(#CLLanguage) CurrentLanguage$ = GetGadgetText(#CLLanguage) CurrentLanguage$ = Left(CurrentLanguage$,Len(CurrentLanguage$)-1) SetGadgetItemText(#CLLanguage,ct,CurrentLanguage$,0) SetGadgetState(#CLLanguage,ct) SaveBiText (CurrentLanguage$) EndIf PutTextInDictionnary(CurrentLanguage$,NewText$,NewText$) SetListFromDictionnary(CurrentLanguage$) ct = 0 While BiText(ct)\EnglishText And BiText(ct)\EnglishText<>NewText$ : ct + 1 : Wend SetGadgetState(#LLList,ct) EndIf EndIf If GetGadgetState(#LLList)<0 SetGadgetState(#LLList,0) EndIf tx$ = ReplaceString(GetGadgetText(#LLList),"[EOL]",Chr(13)+Chr(10)) SetGadgetText(#SLLocal,tx$) SetGadgetText(#TLEnglish,BiText(GetGadgetState(#LLList))\EnglishText) ; ElseIf GadgetID = #SLLocal If BiText(GetGadgetState(#LLList))\LocalText <> GetGadgetText(#SLLocal) tx$ = ReplaceString(GetGadgetText(#SLLocal),Chr(10),"") tx$ = ReplaceString(tx$,Chr(13),"[EOL]") BiText(GetGadgetState(#LLList))\LocalText = tx$ ct = GetGadgetState(#LLList) SetGadgetItemText(#LLList,ct,tx$,0) SetGadgetState(#LLList,ct) ct = GetGadgetState(#CLLanguage) If Right(GetGadgetText(#CLLanguage),1)<>"*" SetGadgetItemText(#CLLanguage,ct,GetGadgetText(#CLLanguage)+"*",0) SetGadgetState(#CLLanguage,ct) CurrentLanguage$ = GetGadgetText(#CLLanguage) EndIf EndIf ; ElseIf GadgetID = #CLLanguage If GetGadgetState(#CLLanguage)>=0 If CurrentLanguage$<>GetGadgetText(#CLLanguage) If Right(CurrentLanguage$,1)="*" CurrentLanguage$ = Left(CurrentLanguage$,Len(CurrentLanguage$)-1) Result = MessageRequester(BRTranslate("Caution!"),CurrentLanguage$+BRTranslate(" has been modified. Do you want to save it before seeing another language ?"),#PB_MessageRequester_YesNo) If Result = 6 SaveBiText (CurrentLanguage$) BRTranslate("Caution!") ; to be sure to include those messages in the language BRTranslate(" has been modified. Do you want to save it before seeing another language ?") EndIf EndIf CurrentLanguage$ = GetGadgetText(#CLLanguage) ct = 0 Repeat LText$ = GetGadgetItemText(#CLLanguage,ct,0) If Right(LText$,1)="*" SetGadgetItemText(#CLLanguage,ct,Left(LText$,Len(LText$)-1),0) EndIf ct + 1 Until LText$="" SetListFromDictionnary(GetGadgetText(#CLLanguage)) EndIf EndIf ; ElseIf GadgetID = #BLNew Language.s = InputRequester(BRTranslate("New language"), BRTranslate("Enter the new language name"), "") If Language AddGadgetItem(#CLLanguage,-1,Language) ct = 0 While GetGadgetItemText(#CLLanguage,ct,0)<>Language : ct + 1 : Wend SetGadgetState(#CLLanguage,ct) SetListFromDictionnary(GetGadgetText(#CLLanguage)) EndIf ElseIf GadgetID = #BLDelete DName$ = GetGadgetText(#CLLanguage) If DName$ If Right(DName$,1)="*" DName$ = Left(DName$,Len(DName$)-1) EndIf Result = MessageRequester(BRTranslate("Caution!"),BRTranslate("Do you really want to delete this language (")+DName$+BRTranslate(") and all the associated texts ?"),#PB_MessageRequester_YesNo) If Result = 6 If FileSize(#DataFolder+"\"+DName$+".txt") DeleteFile(#DataFolder+"\"+DName$+".txt") EndIf ct = GetGadgetState(#CLLanguage) If FindString(#IncludedLanguages,DName$,1)=0 RemoveGadgetItem(#CLLanguage, ct) If GetGadgetItemText(#CLLanguage,ct,0)="" ct-1 EndIf SetGadgetState(#CLLanguage,ct) Else SetGadgetItemText(#CLLanguage,ct,DName$,0) SetGadgetState(#CLLanguage,ct) MessageRequester(BRTranslate("Caution!"),BRTranslate("This language can't be deleted."),0) EndIf SetListFromDictionnary(GetGadgetText(#CLLanguage)) EndIf EndIf ; ElseIf GadgetID = #BLLook Find = 1 SFind = -1 ; ElseIf GadgetID = #BLNext Find = 1 SFind = GetGadgetState(#LLList) ; ElseIf GadgetID = #BLSave If Right(GetGadgetText(#CLLanguage),1)="*" ct = GetGadgetState(#CLLanguage) CurrentLanguage$ = GetGadgetText(#CLLanguage) CurrentLanguage$ = Left(CurrentLanguage$,Len(CurrentLanguage$)-1) SetGadgetItemText(#CLLanguage,ct,CurrentLanguage$,0) SetGadgetState(#CLLanguage,ct) SaveBiText (CurrentLanguage$) EndIf GetAsyncKeyState_(#VK_CONTROL) ; Empty Buffer GetAsyncKeyState_(#VK_CONTROL) ; Empty Buffer GetAsyncKeyState_(#VK_CONTROL) ; Empty Buffer If GetAsyncKeyState_(#VK_CONTROL) suffixe$ = ".pb" Title$ = "PureBasic Datas" PNF$ = SaveFileRequester(Title$,"LanguageSet" , suffixe$,0) If PNF$ If Right(PNF$,Len(suffixe$))<>suffixe$ PNF$ + suffixe$ EndIf If OpenFile(1,PNF$) WriteString("DataSection"+Chr(13)+Chr(10)) ct = 0 Repeat Language=GetGadgetItemText(#CLLanguage,ct,0) If Language WriteString(Left(Language,3)+"Texts:"+Chr(13)+Chr(10)) Dictionnary$ = GetDictionnary(Language) UseFile(1) Repeat pos = FindString(Dictionnary$,"|",1) If pos EnglishText$=Left(Dictionnary$,pos-1) EnglishText$=ReplaceString(EnglishText$,Chr(34),"$guillemets$") EnglishText$=ReplaceString(EnglishText$,"$guillemets$",Chr(34)+"+Chr(34)+"+Chr(34)) EnglishText$=ReplaceString(EnglishText$,Chr(13)+Chr(10),Chr(34)+"+Chr(13)+Chr(10)+"+Chr(34)) EnglishText$=ReplaceString(EnglishText$,Chr(13),Chr(34)+"+Chr(13)+"+Chr(34)) EnglishText$=Chr(34)+EnglishText$+Chr(34) Dictionnary$=Right(Dictionnary$,Len(Dictionnary$)-pos) pos=FindString(Dictionnary$,"[EOT]",1) If pos LocalText$=Left(Dictionnary$,pos-1) LocalText$=Left(Dictionnary$,pos-1) LocalText$=ReplaceString(LocalText$,Chr(34),"$guillemets$") LocalText$=ReplaceString(LocalText$,"$guillemets$",Chr(34)+"+Chr(34)+"+Chr(34)) LocalText$=ReplaceString(LocalText$,Chr(13)+Chr(10),Chr(34)+"+Chr(13)+Chr(10)+"+Chr(34)) LocalText$=ReplaceString(LocalText$,Chr(13),Chr(34)+"+Chr(13)+"+Chr(34)) LocalText$=Chr(34)+LocalText$+Chr(34) WriteString(" Data$ "+EnglishText$+"+"+Chr(34)+"|"+Chr(34)+"+"+LocalText$+Chr(13)+Chr(10)) Dictionnary$=Right(Dictionnary$,Len(Dictionnary$)-pos-4) EndIf EndIf Until pos = 0 WriteString(" Data$ "+Chr(34)+"EndText"+Chr(34)+Chr(13)+Chr(10)+Chr(13)+Chr(10)) ct + 1 EndIf Until Language="" WriteString("EndDataSection") CloseFile(1) EndIf EndIf EndIf ; ElseIf GadgetID = #BLAbsorb If Right(CurrentLanguage$,1)="*" ct = GetGadgetState(#CLLanguage) CurrentLanguage$ = GetGadgetText(#CLLanguage) CurrentLanguage$ = Left(CurrentLanguage$,Len(CurrentLanguage$)-1) SetGadgetItemText(#CLLanguage,ct,CurrentLanguage$,0) SetGadgetState(#CLLanguage,ct) SaveBiText (CurrentLanguage$) EndIf Result = MessageRequester(BRTranslate("Absorb a dictionnary"),BRTranslate("You will be asked to open an external file named ")+CurrentLanguage$+".txt"+Chr(13)+BRTranslate("All words found in this file will be added to the actual dictionnary.")+Chr(13)+BRTranslate("Continue?"),#PB_MessageRequester_YesNo) If Result = 6 PNF$ = OpenFileRequester(BRTranslate("Open a file named ")+CurrentLanguage$+".txt",CurrentLanguage$+".txt" , CurrentLanguage$+".txt|"+CurrentLanguage$+".txt",0) If GetFilePart(PNF$)=CurrentLanguage$+".txt" If ReadFile(0,PNF$) Dictionnary$ ="" Repeat RText$ = ReadString() If RText$ Dictionnary$ + RText$ + Chr(13)+ Chr(10) EndIf Until RText$="" Or FindString(RText$,"EndText",1) CloseFile(0) Repeat pos = FindString(Dictionnary$,"|",1) If pos EnglishText$=Left(Dictionnary$,pos-1) Dictionnary$=Right(Dictionnary$,Len(Dictionnary$)-pos) pos=FindString(Dictionnary$,"[EOT]",1) If pos LocalText$=Left(Dictionnary$,pos-1) Dictionnary$=Right(Dictionnary$,Len(Dictionnary$)-pos-4) PutTextInDictionnary(CurrentLanguage$,EnglishText$,LocalText$) EndIf EndIf Until pos = 0 SetListFromDictionnary(GetGadgetText(#CLLanguage)) EndIf EndIf EndIf ; ElseIf GadgetID = #BLHidden MessageRequester(BRTranslate("Hidden Commands"),BRTranslate("This commands are for programmers only:"+Chr(13)+Chr(13)+"- Ctrl + Save : create a PureBasic data file with all the datas"+Chr(13)+"- Ctrl + clic on the list : delete a text"+Chr(13)+"- Alt + Clic on the list : add a text"),0) ; ElseIf GadgetID = #BLWebT ShellExecute_(hw,"open","http://www.foreignword.com/Tools/transnow.htm","","",#SW_SHOWNORMAL) ; ElseIf GadgetID = #BLQuit If Right(CurrentLanguage$,1)="*" CurrentLanguage$ = Left(CurrentLanguage$,Len(CurrentLanguage$)-1) Result = MessageRequester(BRTranslate("Caution!"),CurrentLanguage$+BRTranslate(" has been modified. Do you want to save it before quitting?"),#PB_MessageRequester_YesNo) If Result = 6 SaveBiText (CurrentLanguage$) BRTranslate("Caution!") ; to be sure to include those messages in the language BRTranslate(" has been modified. Do you want to save it before quitting?") EndIf EndIf QuitL = 1 ; EndIf ; ElseIf Event = #WM_KEYDOWN SendMessage_(GadgetID(#SLLocal),#EM_GETSEL,@StartS,@EndS) If StartS=mStartS And EndS=mEndS If GetFocus_()=GadgetID(#SLLocal) And GetAsyncKeyState_(#VK_DOWN) ct = GetGadgetState(#LLList) If GetGadgetItemText(#LLList,ct+1,0) SetGadgetState(#LLList,ct+1) SetGadgetText(#SLLocal,GetGadgetText(#LLList)) SetGadgetText(#TLEnglish,BiText(GetGadgetState(#LLList))\EnglishText) EndIf EndIf EndIf ; If StartS=mStartS And EndS=mEndS If GetFocus_()=GadgetID(#SLLocal) And GetAsyncKeyState_(#VK_UP) ct = GetGadgetState(#LLList) If ct SetGadgetState(#LLList,ct-1) SetGadgetText(#SLLocal,GetGadgetText(#LLList)) SetGadgetText(#TLEnglish,BiText(GetGadgetState(#LLList))\EnglishText) EndIf EndIf EndIf ; If GetFocus_()=GadgetID(#SLLook) And GetAsyncKeyState_(#VK_ENTER) Find = 1 SFind = GetGadgetState(#LLList) EndIf ; ElseIf Event = #PB_EventCloseWindow QuitL = 1 ; EndIf If Find Find = 0 ct = SFind +1 While BiText(ct)\EnglishText And FindString(LCase(BiText(ct)\EnglishText),LCase(GetGadgetText(#SLLook)),1)=0 : ct + 1 : Wend If FindString(LCase(BiText(ct)\EnglishText),LCase(GetGadgetText(#SLLook)),1)=0 ct = SFind +1 While BiText(ct)\EnglishText And FindString(LCase(BiText(ct)\LocalText),LCase(GetGadgetText(#SLLook)),1)=0 : ct + 1 : Wend EndIf If BiText(ct)\EnglishText SetGadgetState(#LLList,ct) SetGadgetText(#SLLocal,GetGadgetText(#LLList)) SetGadgetText(#TLEnglish,BiText(GetGadgetState(#LLList))\EnglishText) EndIf EndIf SetWindowPos_(hw,#HWND_TOP,0,0,0,0,#SWP_NOMOVE|#SWP_NOSIZE) ; keep the window over the main window - maintient If Right(GetGadgetText(#CLLanguage),1)="*" DisableGadget(#BLSave,0) Else DisableGadget(#BLSave,1) EndIf SendMessage_(GadgetID(#SLLocal),#EM_GETSEL,@mStartS,@mEndS) Until QuitL EndIf EndIf Dim BiText.BiText(1) CloseWindow(#LanguageWindow) mlanguage$="" ; to update mDictionnary$ EndProcedure ; Procedure SetListFromDictionnary (Language.s) If Language Dictionnary$ = GetDictionnary(Language) ct = 0 ClearGadgetItemList(#LLList) Repeat pos = FindString(Dictionnary$,"|",1) If pos BiText(ct)\EnglishText=Left(Dictionnary$,pos-1) Dictionnary$=Right(Dictionnary$,Len(Dictionnary$)-pos) pos=FindString(Dictionnary$,"[EOT]",1) If pos BiText(ct)\LocalText=Left(Dictionnary$,pos-1) AddGadgetItem(#LLList,-1,Left(Dictionnary$,pos-1)) Dictionnary$=Right(Dictionnary$,Len(Dictionnary$)-pos-4) ct + 1 EndIf EndIf Until pos = 0 BiText(ct)\EnglishText="" SetGadgetState(#LLLIst,0) SetGadgetText(#SLLocal,GetGadgetText(#LLList)) SetGadgetText(#TLEnglish,BiText(GetGadgetState(#LLList))\EnglishText) EndIf EndProcedure ; Procedure SaveBiText (Language.s) If Language Dictionnary$ = "" ct = 0 Repeat If BiText(ct)\EnglishText Dictionnary$=Dictionnary$+BiText(ct)\EnglishText+"|"+BiText(ct)\LocalText+"[EOT]" EndIf ct + 1 Until BiText(ct)\EnglishText="" Dictionnary$ + "EndText[EOT]" If OpenFile(0,#DataFolder+"\"+Language+".txt") WriteString(Dictionnary$) CloseFile(0) Else MessageRequester(BRTranslate("Error"),BRTranslate("Error while saving the dictionnary!"),0) EndIf EndIf EndProcedure ; ; This type of datas can be generated by this program itselfs !!! ; -> Start the program and press Ctrl while clicking on "Save" ; ; Ce type de datas peut être généré par ce programme lui-même !!! ; -> démarrez le programme et maintenez la touche Ctrl appuyée ; tout en cliquant sur "Enregistrer" ; DataSection FraTexts: Data$ "OK"+"|"+"OK" Data$ "Cancel"+"|"+"Annuler" Data$ "Error"+"|"+"Erreur" Data$ "New"+"|"+"Nouveau" Data$ "Modify languages"+"|"+"Modifier les langues" Data$ "Language:"+"|"+"Langue :" Data$ "Save"+"|"+"Enregistrer" Data$ "Delete"+"|"+"Supprimer" Data$ "Look for"+"|"+"Rechercher" Data$ "Look"+"|"+"Chercher" Data$ "Next"+"|"+"Suivant" Data$ "Absorb a dictionnary"+"|"+"Absorber un dictionnaire" Data$ "Hidden commands"+"|"+"Commandes cachées" Data$ "Quit"+"|"+"Quitter" Data$ "Do you really want to delete this text from all dictionnaries ?"+"|"+"Voulez-vous réellement effacer ce texte de tous les dictionnaires ?" Data$ "Caution!"+"|"+"Attention !" Data$ "Enter the new language name"+"|"+"Entrez le nom de la nouvelle langue" Data$ "Enter the english version of your new text:"+"|"+"Entrez la version anglaise de votre nouveau texte :" Data$ "New Text"+"|"+"Nouveau texte" Data$ "New language"+"|"+"Nouvelle langue" Data$ " has been modified. Do you want to save it before seeing another language ?"+"|"+" a été modifiée. Voulez-vous l'enregistrer avant d'examiner une autre langue ?" Data$ "Do you really want to delete this language ("+"|"+"Voulez-vous réellement supprimer cette langue (" Data$ ") and all the associated texts ?"+"|"+") et tous les textes associés ?" Data$ " has been modified. Do you want to save it before quitting?"+"|"+" a été modifiée. Voulez-vous enregistrer avant de quitter ?" Data$ "You will be asked to open an external file named "+"|"+"Vous allez devoir ouvrir un fichier externe nommé " Data$ "All words found in this file will be added to the actual dictionnary."+"|"+"Tous les textes qu'il contient seront ajoutés au dictionnaire actuel." Data$ "Continue?"+"|"+"Continuer ?" Data$ "Open a file named "+"|"+"Ouvrir un fichier nommé " Data$ "Introduction"+"|"+"Introduction" Data$ "IntroBabel"+"|"+"Ce programme a pour objectif de régler le problème des langues dans vos programmes."+Chr(13)+Chr(10)+"Pour l'utiliser, ajouter simplement IncludeFile "+Chr(34)+"BabelResolver.pb"+Chr(34)+" dans vos programmes, ajoutez une commande menu qui exécutera la commande "+Chr(34)+"ChooseLanguageWindow()"+Chr(34)+" et remplacez chaque instruction du type 'MessageResquester("+Chr(34)+"Error"+Chr(34)+","+Chr(34)+"Message"+Chr(34)+",0)' par : 'MessageResquester(BRTranslate("+Chr(34)+"Error"+Chr(34)+"),BRTranslate("+Chr(34)+"Message"+Chr(34)+"),0)'"+Chr(13)+Chr(10)+"Son principe à l'avantage de permettre une traduction des textes par l'utilisateur lui-même, ce qui ouvre votre programme à l'international même si vous ne parlez que l'anglais et le français."+Chr(13)+Chr(13)+"Si vous créez des dictionnaires, vous pourrez les ré-utiliser dans tous vos programmes !!" Data$ "Web Translation|Traduction Web" Data$ "Error While saving the dictionnary!|Erreur pendant l'enregistrement du dictionnaire !" Data$ "EndText" EngTexts: Data$ "OK"+"|"+"OK" Data$ "Cancel"+"|"+"Cancel" Data$ "Error"+"|"+"Error" Data$ "New"+"|"+"New" Data$ "Modify languages"+"|"+"Modify languages" Data$ "Language:"+"|"+"Language:" Data$ "Save"+"|"+"Save" Data$ "Delete"+"|"+"Delete" Data$ "Look for"+"|"+"Look for" Data$ "Look"+"|"+"Look" Data$ "Next"+"|"+"Next" Data$ "Absorb a dictionnary"+"|"+"Absorb a dictionnary" Data$ "Hidden commands"+"|"+"Hidden commands" Data$ "Quit"+"|"+"Quit" Data$ "Enter the english version of your new text:"+"|"+"Enter the english version of your new text:" Data$ "New Text"+"|"+"New Text" Data$ "Do you really want to delete this text from all dictionnaries ?"+"|"+"Do you really want to delete this text from all dictionnaries ?" Data$ "Caution!"+"|"+"Caution!" Data$ "Enter the new language name"+"|"+"Enter the new language name" Data$ "New language"+"|"+"New language" Data$ " has been modified. Do you want to save it before seeing another language ?"+"|"+" has been modified. Do you want to save it before seeing another language ?" Data$ "Do you really want to delete this language ("+"|"+"Do you really want to delete this language (" Data$ ") and all the associated texts ?"+"|"+") and all the associated texts ?" Data$ " has been modified. Do you want to save it before quitting?"+"|"+" has been modified. Do you want to save it before quitting?" Data$ "You will be asked to open an external file named "+"|"+"You will be asked to open an external file named " Data$ "All words found in this file will be added to the actual dictionnary."+"|"+"All words found in this file will be added to the actual dictionnary." Data$ "Continue?"+"|"+"Continue ?" Data$ "Open a file named "+"|"+"Open a file named " Data$ "Introduction"+"|"+"Introduction" Data$ "IntroBabel"+"|"+"This sofware tries to solve the language problems in your software."+Chr(13)+Chr(10)+"To use it, simply put IncludeFile "+Chr(34)+"BabelResolver.pb"+Chr(34)+" in your code, add a menu command which will execute "+Chr(34)+"ChooseLanguageWindow()"+Chr(34)+" and replace each relevant instruction. For example, 'MessageResquester("+Chr(34)+"Error"+Chr(34)+","+Chr(34)+"Message"+Chr(34)+",0)' would become: 'MessageResquester(BRTranslate("+Chr(34)+"Error"+Chr(34)+"),BRTranslate("+Chr(34)+"Message"+Chr(34)+"),0)'"+Chr(13)+Chr(10)+"It will allow a translation by the user and then you can distribute your software internationally even if you only speack english!"+Chr(13)+Chr(13)+"If you create dictionnaries, you could use them in all your codes !!" Data$ "Web Translation|Web Translation" Data$ "Error While saving the dictionnary!|Error While saving the dictionnary!" Data$ "EndText" DeuTexts: Data$ "OK"+"|"+"Ok" Data$ "Cancel"+"|"+"Abbrechen" Data$ "Error"+"|"+"Fehler" Data$ "New"+"|"+"Neu" Data$ "Modify languages"+"|"+"Modify languages" Data$ "Language:"+"|"+"Sprache:" Data$ "Save"+"|"+"Speichern" Data$ "Delete"+"|"+"Löschen" Data$ "Look for"+"|"+"Suchen" Data$ "Look"+"|"+"Suche" Data$ "Next"+"|"+"Nächster" Data$ "Absorb a dictionnary"+"|"+"Absorb a dictionnary" Data$ "Hidden commands"+"|"+"Hidden commands" Data$ "Quit"+"|"+"Schließen" Data$ "Enter the english version of your new text:"+"|"+"Enter the english version of your new text:" Data$ "New Text"+"|"+"New Text" Data$ "New language"+"|"+"New language" Data$ "Do you really want to delete this text from all dictionnaries ?"+"|"+"Do you really want to delete this text from all dictionnaries ?" Data$ "Caution!"+"|"+"Achtung!" Data$ "Enter the new language name"+"|"+"Enter the new language name" Data$ " has been modified. Do you want to save it before seeing another language ?"+"|"+" has been modified. Do you want to save it before seeing another language ?" Data$ "Do you really want to delete this language ("+"|"+"Do you really want to delete this language (" Data$ ") and all the associated texts ?"+"|"+") and all the associated texts ?" Data$ " has been modified. Do you want to save it before quitting?"+"|"+" has been modified. Do you want to save it before quitting?" Data$ "You will be asked to open an external file named "+"|"+"You will be asked to open an external file named " Data$ "All words found in this file will be added to the actual dictionnary."+"|"+"All words found in this file will be added to the actual dictionnary." Data$ "Continue?"+"|"+"Continue ?" Data$ "Open a file named "+"|"+"Open a file named " Data$ "Introduction"+"|"+"Introduction" Data$ "IntroBabel"+"|"+"This sofware tries to solve the language problems in your software."+Chr(13)+Chr(10)+"To use it, simply put IncludeFile "+Chr(34)+"BabelResolver.pb"+Chr(34)+" in your code, add a menu command which will execute "+Chr(34)+"ChooseLanguageWindow()"+Chr(34)+" and replace each relevant instruction. For example, 'MessageResquester("+Chr(34)+"Error"+Chr(34)+","+Chr(34)+"Message"+Chr(34)+",0)' would become: 'MessageResquester(BRTranslate("+Chr(34)+"Error"+Chr(34)+"),BRTranslate("+Chr(34)+"Message"+Chr(34)+"),0)'"+Chr(13)+Chr(10)+"It will allow a translation by the user and then you can distribute your software internationally even if you only speack english!"+Chr(13)+Chr(13)+"If you create dictionnaries, you could use them in all your codes !!" Data$ "Web Translation|Web Translation" Data$ "Error While saving the dictionnary!|Error While saving the dictionnary!" Data$ "EndText" EndDataSection ; ExecutableFormat=Windows ; CursorPosition=926 ; FirstLine=882 ; EOF