Translated using Weblate (Japanese)
[oweals/minetest.git] / src / gettext.cpp
index 688a225707f642e74ff66aea048720e34fd06880..e8819f1319be0d8cabd53255698c396df4371922 100644 (file)
@@ -26,24 +26,24 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "log.h"
 
 #if USE_GETTEXT && defined(_MSC_VER)
-#include <WinNls.h>
+#include <windows.h>
 #include <map>
 #include <direct.h>
 #include "filesys.h"
 
-#define setlocale(category,localename) \
-       setlocale(category,MSVC_LocaleLookup(localename))
+#define setlocale(category, localename) \
+       setlocale(category, MSVC_LocaleLookup(localename))
 
-static std::map<std::wstring,std::wstring> glb_supported_locales;
+static std::map<std::wstring, std::wstring> glb_supported_locales;
 
 /******************************************************************************/
 BOOL CALLBACK UpdateLocaleCallback(LPTSTR pStr)
 {
        char* endptr = 0;
-       int LOCALEID = strtol(pStr,&endptr,16);
+       int LOCALEID = strtol(pStr, &endptr,16);
 
        wchar_t buffer[LOCALE_NAME_MAX_LENGTH];
-       memset(buffer,0,sizeof(buffer));
+       memset(buffer, 0, sizeof(buffer));
        if (GetLocaleInfoW(
                LOCALEID,
                LOCALE_SISO639LANGNAME,
@@ -52,7 +52,7 @@ BOOL CALLBACK UpdateLocaleCallback(LPTSTR pStr)
 
                std::wstring name = buffer;
 
-               memset(buffer,0,sizeof(buffer));
+               memset(buffer, 0, sizeof(buffer));
                GetLocaleInfoW(
                LOCALEID,
                LOCALE_SISO3166CTRYNAME,
@@ -61,7 +61,7 @@ BOOL CALLBACK UpdateLocaleCallback(LPTSTR pStr)
 
                std::wstring country = buffer;
 
-               memset(buffer,0,sizeof(buffer));
+               memset(buffer, 0, sizeof(buffer));
                GetLocaleInfoW(
                LOCALEID,
                LOCALE_SENGLISHLANGUAGENAME,
@@ -96,14 +96,15 @@ const char* MSVC_LocaleLookup(const char* raw_shortname) {
        }
 
        if (first_use) {
-               EnumSystemLocalesA(UpdateLocaleCallback,LCID_SUPPORTED | LCID_ALTERNATE_SORTS);
+               EnumSystemLocalesA(UpdateLocaleCallback, LCID_SUPPORTED | LCID_ALTERNATE_SORTS);
                first_use = false;
        }
 
        last_raw_value = shortname;
 
-       if (glb_supported_locales.find(narrow_to_wide(shortname)) != glb_supported_locales.end()) {
-               last_full_name = wide_to_narrow(glb_supported_locales[narrow_to_wide(shortname)]);
+       if (glb_supported_locales.find(utf8_to_wide(shortname)) != glb_supported_locales.end()) {
+               last_full_name = wide_to_utf8(
+                       glb_supported_locales[utf8_to_wide(shortname)]);
                return last_full_name.c_str();
        }
 
@@ -148,8 +149,8 @@ void init_gettext(const char *path, const std::string &configured_language) {
                if (current_language_var != configured_language) {
                        STARTUPINFO startupinfo;
                        PROCESS_INFORMATION processinfo;
-                       memset(&startupinfo,0,sizeof(startupinfo));
-                       memset(&processinfo,0,sizeof(processinfo));
+                       memset(&startupinfo, 0, sizeof(startupinfo));
+                       memset(&processinfo, 0, sizeof(processinfo));
                        errorstream << "MSVC localization workaround active restating minetest in new environment!" << std::endl;
 
                        std::string parameters = "";
@@ -166,10 +167,10 @@ void init_gettext(const char *path, const std::string &configured_language) {
                        if (parameters != "") {
                                ptr_parameters = parameters.c_str();
                        }
-                       
+
                        /** users may start by short name in commandline without extention **/
                        std::string appname = argv[0];
-                       if (appname.substr(appname.length() -4) != ".exe") {
+                       if (appname.substr(appname.length() - 4) != ".exe") {
                                appname += ".exe";
                        }
 
@@ -183,7 +184,7 @@ void init_gettext(const char *path, const std::string &configured_language) {
                                        NULL,
                                        &startupinfo,
                                        &processinfo)) {
-                               char buffer[1024];              
+                               char buffer[1024];
                                FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
                                        NULL,
                                        GetLastError(),
@@ -201,14 +202,14 @@ void init_gettext(const char *path, const std::string &configured_language) {
                        else {
                                exit(0);
                        }
+               }
 #else
-                       errorstream << "*******************************************************" << std::endl;
-                       errorstream << "Can't apply locale workaround for server!" << std::endl;
-                       errorstream << "Expect language to be broken!" << std::endl;
-                       errorstream << "*******************************************************" << std::endl;
+               errorstream << "*******************************************************" << std::endl;
+               errorstream << "Can't apply locale workaround for server!" << std::endl;
+               errorstream << "Expect language to be broken!" << std::endl;
+               errorstream << "*******************************************************" << std::endl;
 
 #endif
-               }
 
                setlocale(LC_ALL,configured_language.c_str());
 #else // Mingw
@@ -236,8 +237,9 @@ void init_gettext(const char *path, const std::string &configured_language) {
 #endif
 #endif
 
-       bindtextdomain(PROJECT_NAME, path);
-       textdomain(PROJECT_NAME);
+       static std::string name = lowercase(PROJECT_NAME);
+       bindtextdomain(name.c_str(), path);
+       textdomain(name.c_str());
 
 #if defined(_WIN32)
        // Set character encoding for Win32
@@ -260,7 +262,7 @@ void init_gettext(const char *path, const std::string &configured_language) {
        /* no matter what locale is used we need number format to be "C" */
        /* to ensure formspec parameters are evaluated correct!          */
 
-       setlocale(LC_NUMERIC,"C");
+       setlocale(LC_NUMERIC, "C");
        infostream << "Message locale is now set to: "
                        << setlocale(LC_ALL, 0) << std::endl;
 }