From 374020a30ad2ed32351a914b6773667d76b61d2a Mon Sep 17 00:00:00 2001 From: Pablo Marquez Tello Date: Thu, 21 Nov 2024 21:49:32 +0000 Subject: [PATCH] Fixed OS language detection Fixed OS language detection The language is chosen based on the value of the field Localization in Recursos\OUTPUTConfiguracion.ini. If the value is absent the game will use the same language as the OS and save the setting to Configuracion.ini. Refactor and clean up of the code to detect OS language Deleted unused function GetLocaleLanguage() --- Argentum20.vbp | 2 +- CODIGO/ModLanguage.bas | 75 ++++++++++++++++++ CODIGO/ModLenguaje.bas | 172 ----------------------------------------- 3 files changed, 76 insertions(+), 173 deletions(-) create mode 100644 CODIGO/ModLanguage.bas delete mode 100644 CODIGO/ModLenguaje.bas diff --git a/Argentum20.vbp b/Argentum20.vbp index 5b30226e..3e9f2fa5 100644 --- a/Argentum20.vbp +++ b/Argentum20.vbp @@ -107,7 +107,6 @@ Class=clsFormMovementManager; CODIGO\clsFormMovementManager.cls Module=Protocol_Writes; CODIGO\Protocol_Writes.bas Form=CODIGO\frmCrafteo.frm Module=modNetwork; CODIGO\modNetwork.bas -Module=ModLenguaje; CODIGO\ModLenguaje.bas Module=basCryptoSys; CODIGO\basCryptoSys.bas Module=AO20CryptoSysWrapper; CODIGO\AO20CryptoSysWrapper.bas Module=ModAuth; CODIGO\ModAuth.bas @@ -146,6 +145,7 @@ Module=ao20config; CODIGO\ao20config.bas Form=CODIGO\frmCreateBattleground.frm Form=CODIGO\frmLobbyBattleground.frm Module=ModValidateResources; CODIGO\ModValidateResources.bas +Module=ModLanguage; CODIGO\ModLanguage.bas ResFile32="AO20.res" IconForm="frmMain" Startup="Sub Main" diff --git a/CODIGO/ModLanguage.bas b/CODIGO/ModLanguage.bas new file mode 100644 index 00000000..9f413efd --- /dev/null +++ b/CODIGO/ModLanguage.bas @@ -0,0 +1,75 @@ +Attribute VB_Name = "ModLanguage" +' Argentum 20 - Game Client Program +' Copyright (C) 2022 - Noland Studios +' +' This program is free software: you can redistribute it and/or modify +' it under the terms of the GNU Affero General Public License as published by +' the Free Software Foundation, either version 3 of the License, or +' (at your option) any later version. +' +' This program is distributed in the hope that it will be useful, +' but WITHOUT ANY WARRANTY; without even the implied warranty of +' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +' GNU Affero General Public License for more details. +' You should have received a copy of the GNU Affero General Public License +' along with this program. If not, see . +' +' +Option Explicit + +Const LOCALE_USER_DEFAULT = &H400 + +Private Declare Function GetUserDefaultLCID Lib "kernel32" () As Long +Private Declare Function GetLocaleInfo Lib "kernel32" Alias "GetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String, ByVal cchData As Long) As Long + +Private Const LOCALE_SCOUNTRY = &H6 +Private Const LOCALE_SLANGUAGE = &H2 +Private Const LOCALE_SENGLANGUAGE = &H1001 +Private Const MAX_BUF As Long = 260 + +Public Enum e_language + Spanish = 1 + English = 2 +End Enum + +Public language As e_language + +Private Function GetCountryName() As String + Dim lID As Long, sBuf As String, lRet As Long + lID = GetUserDefaultLCID + sBuf = String$(MAX_BUF, Chr(0)) + lRet = GetLocaleInfo(lID, LOCALE_SCOUNTRY, sBuf, MAX_BUF) + GetCountryName = Left$(sBuf, lRet - 1) +End Function + +Private Function GetLocaleEngLanguage() As String + Dim lID As Long, sBuf As String, lRet As Long + lID = GetUserDefaultLCID + sBuf = String$(MAX_BUF, Chr(0)) + lRet = GetLocaleInfo(lID, LOCALE_SENGLANGUAGE, sBuf, MAX_BUF) + GetLocaleEngLanguage = Left$(sBuf, lRet - 1) +End Function + +Public Function FileToString(strFileName As String) As String + Dim IFile As Variant + IFile = FreeFile + Open strFileName For Input As #IFile + FileToString = StrConv(InputB(LOF(IFile), IFile), vbUnicode) + Close #IFile +End Function + +Public Sub SetLanguageApplication() + Dim Localization As String + Localization = GetSetting("OPCIONES", "Localization") + If Len(Localization) = 0 Then + Select Case GetLocaleEngLanguage + Case "English" + language = e_language.English + Case "Spanish" + language = e_language.Spanish + End Select + Call SaveSetting("OPCIONES", "Localization", language) + Else + language = Localization + End If +End Sub diff --git a/CODIGO/ModLenguaje.bas b/CODIGO/ModLenguaje.bas deleted file mode 100644 index 88f26906..00000000 --- a/CODIGO/ModLenguaje.bas +++ /dev/null @@ -1,172 +0,0 @@ -Attribute VB_Name = "ModLenguaje" -' Argentum 20 - Game Client Program -' Copyright (C) 2022 - Noland Studios -' -' This program is free software: you can redistribute it and/or modify -' it under the terms of the GNU Affero General Public License as published by -' the Free Software Foundation, either version 3 of the License, or -' (at your option) any later version. -' -' This program is distributed in the hope that it will be useful, -' but WITHOUT ANY WARRANTY; without even the implied warranty of -' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -' GNU Affero General Public License for more details. -' You should have received a copy of the GNU Affero General Public License -' along with this program. If not, see . -' -' -Option Explicit - -'Constantes para el Api GetLocaleInfo -'************************************ -Const LOCALE_USER_DEFAULT = &H400 -'Const LOCALE_SENGLANGUAGE = &H1001 - -'Declaracion de la funcion Api GetLocaleInfo -Private Declare Function GetLocaleInfo _ - Lib "kernel32" _ - Alias "GetLocaleInfoA" (ByVal Locale As Long, _ - ByVal LCType As Long, _ - ByVal lpLCData As String, _ - ByVal cchData As Long) As Long - -Private Declare Function GetThreadLocale Lib "kernel32" () As Long - -Public JsonLanguage As Object - -Public Enum e_language - Spanish = 1 - English = 2 -End Enum - -Public language As e_language - -Public Function FileToString(strFileName As String) As String - '################################################################################### - ' Convierte un archivo entero a una cadena de texto para almacenarla en una variable - '################################################################################### - Dim IFile As Variant - - IFile = FreeFile - Open strFileName For Input As #IFile - FileToString = StrConv(InputB(LOF(IFile), IFile), vbUnicode) - Close #IFile -End Function - -Public Function ObtainOperativeSystemLanguage(ByVal lInfo As Long) As String - '******************************************* - ' Funcion que obtiene el idioma del sistema - '******************************************* - - Dim Buffer As String, Ret As String - - Buffer = String$(256, 0) - - Ret = GetLocaleInfo(LOCALE_USER_DEFAULT, lInfo, Buffer, Len(Buffer)) - - 'Si Ret devuelve 0 es porque fallo la llamada al Api - If Ret > 0 Then - ObtainOperativeSystemLanguage = Left$(Buffer, Ret - 1) - Else - ObtainOperativeSystemLanguage = "No se pudo obtener el idioma del sistema." - - End If - -End Function - -Public Sub SetLanguageApplication() - '************************************************************************************. - ' Carga el JSON con las traducciones en un objeto para su uso a lo largo del proyecto - '************************************************************************************ - - Dim LangFile As String - Dim Localization As String - Localization = GetSetting("OPCIONES", "Localization") - - ' Si no se especifica el idioma en el archivo de configuracion, se le pregunta si quiere usar castellano - ' y escribimos el archivo de configuracion con el idioma seleccionado - If LenB(Localization) = 0 Then - - Select Case UCase(ObtainOperativeSystemLanguage(1)) - 'English US - Case "0409" - language = e_language.English - 'Otros english - Case "0809" - language = e_language.English - Case "0C09" - language = e_language.English - Case "1009" - language = e_language.English - Case "1409" - language = e_language.English - Case "1809" - language = e_language.English - Case "1c09" - language = e_language.English - Case "2009" - language = e_language.English - Case "2409" - language = e_language.English - Case "2809" - language = e_language.English - Case "2C09" - language = e_language.English - Case "3009" - language = e_language.English - Case "3409" - language = e_language.English - Case "4009" - language = e_language.English - Case "4409" - language = e_language.English - Case "040A" - language = e_language.Spanish - Case "080A" - language = e_language.Spanish - Case "0C0A" - language = e_language.Spanish - Case "100A" - language = e_language.Spanish - Case "140A" - language = e_language.Spanish - Case "180A" - language = e_language.Spanish - Case "1C0A" - language = e_language.Spanish - Case "200A" - language = e_language.Spanish - Case "240A" - language = e_language.Spanish - Case "280A" - language = e_language.Spanish - Case "2C0A" - language = e_language.Spanish - Case "300A" - language = e_language.Spanish - Case "380A" - language = e_language.Spanish - Case "3C0A" - language = e_language.Spanish - Case "400A" - language = e_language.Spanish - Case "440A" - language = e_language.Spanish - Case "480A" - language = e_language.Spanish - Case "4C0A" - language = e_language.Spanish - Case "500A" - language = e_language.Spanish - Case "540A" - language = e_language.Spanish - Case Else - language = e_language.English - End Select - - Call SaveSetting("OPCIONES", "Localization", language) - Else - language = Localization - End If - -End Sub