; _______________________________________________________________________________________
;|                                                                                       |
;| ..::FreshLib::..  Free, open source. Licensed under "BSD 2-clause" license."          |
;|_______________________________________________________________________________________|
;
;   Description: Internationalization strings library.
;
;   Target OS: Any
;
;   Dependencies: None
;
;   Notes:
;_________________________________________________________________________________________


; Switches the itext strings array to some language.
; Arguments:
;   .lang - dword containing the language name in human readable char form. For example: "EN", "BG", etc.
;           The names of the languages are defined by the user, when creating internationalized strings with
;           "itext" macro.
; Returns:
;    CF = 0 - the language is switched successfuly.
;    CF = 1 - unknown language.
;

proc SetLanguage, .lang
begin
        pushad
        mov     esi, I18nLanguages

; search for the language strings set address.
.loop:
        lodsd
        test    eax, eax
        jz      .language_not_found

        cmp     eax, [.lang]
        je      .found

        lea     esi, [esi+4]
        jmp     .loop

; copy the language strings set to the itext placeholder array.
.found:
        lodsd
        mov     esi, eax
        mov     edi, I18nStrings
        mov     ecx, I18nStrings.length

        rep movsb

        clc
        popad
        return

.language_not_found:
        stc
        popad
        return
endp
