Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
illuna-minetest
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Illuna-Minetest
illuna-minetest
Commits
d3026293
Commit
d3026293
authored
10 years ago
by
BlockMen
Browse files
Options
Downloads
Patches
Plain Diff
Fix gettext on MSVC
parent
e102cbd8
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/gettext.cpp
+13
-13
13 additions, 13 deletions
src/gettext.cpp
src/gettext.h
+5
-2
5 additions, 2 deletions
src/gettext.h
src/util/string.cpp
+13
-10
13 additions, 10 deletions
src/util/string.cpp
with
31 additions
and
25 deletions
src/gettext.cpp
+
13
−
13
View file @
d3026293
...
...
@@ -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
<
W
in
Nl
s.h>
#include
<
w
in
dow
s.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,7 +96,7 @@ 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
;
}
...
...
@@ -148,8 +148,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
=
""
;
...
...
@@ -169,7 +169,7 @@ void init_gettext(const char *path, const std::string &configured_language) {
/** 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"
;
}
...
...
@@ -260,7 +260,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
;
}
...
...
This diff is collapsed.
Click to expand it.
src/gettext.h
+
5
−
2
View file @
d3026293
...
...
@@ -41,16 +41,19 @@ void init_gettext(const char *path, const std::string &configured_language);
extern
const
wchar_t
*
narrow_to_wide_c
(
const
char
*
mbs
);
extern
std
::
wstring
narrow_to_wide
(
const
std
::
string
&
mbs
);
// You must free the returned string!
inline
const
wchar_t
*
wgettext
(
const
char
*
str
)
{
return
narrow_to_wide_c
(
gettext
(
str
));
}
// Gettext under MSVC needs this strange way. Just don't ask...
inline
std
::
wstring
wstrgettext
(
const
std
::
string
&
text
)
{
return
narrow_to_wide
(
gettext
(
text
.
c_str
()));
const
wchar_t
*
tmp
=
wgettext
(
text
.
c_str
());
std
::
wstring
retval
=
(
std
::
wstring
)
tmp
;
delete
[]
tmp
;
return
retval
;
}
inline
std
::
string
strgettext
(
const
std
::
string
&
text
)
...
...
This diff is collapsed.
Click to expand it.
src/util/string.cpp
+
13
−
10
View file @
d3026293
...
...
@@ -99,11 +99,13 @@ const wchar_t *narrow_to_wide_c(const char *mbs)
{
wchar_t
*
wcs
=
NULL
;
#if defined(_WIN32)
int
wcl
=
MultiByteToWideChar
(
CP_UTF8
,
0
,
(
LPCSTR
)
mbs
,
-
1
,
NULL
,
0
);
if
(
!
wcl
)
return
NULL
;
wcs
=
new
wchar_t
[
wcl
];
MultiByteToWideChar
(
CP_UTF8
,
0
,
(
LPCSTR
)
mbs
,
-
1
,
(
WCHAR
*
)
wcs
,
wcl
);
int
nResult
=
MultiByteToWideChar
(
CP_UTF8
,
0
,
(
LPCSTR
)
mbs
,
-
1
,
0
,
0
);
if
(
nResult
==
0
)
{
errorstream
<<
"gettext: MultiByteToWideChar returned null"
<<
std
::
endl
;
}
else
{
wcs
=
new
wchar_t
[
nResult
];
MultiByteToWideChar
(
CP_UTF8
,
0
,
(
LPCSTR
)
mbs
,
-
1
,
(
WCHAR
*
)
wcs
,
nResult
);
}
#else
size_t
wcl
=
mbstowcs
(
NULL
,
mbs
,
0
);
if
(
wcl
==
(
size_t
)
-
1
)
...
...
@@ -121,12 +123,13 @@ const wchar_t *narrow_to_wide_c(const char *mbs)
std
::
wstring
narrow_to_wide
(
const
std
::
string
&
mbs
)
{
const
wchar_t
*
wcs
=
narrow_to_wide_c
(
mbs
.
c_str
());
if
(
!
wcs
)
size_t
wcl
=
mbs
.
size
();
Buffer
<
wchar_t
>
wcs
(
wcl
+
1
);
size_t
l
=
mbstowcs
(
*
wcs
,
mbs
.
c_str
(),
wcl
);
if
(
l
==
(
size_t
)(
-
1
))
return
L"<invalid multibyte string>"
;
std
::
wstring
wstr
(
wcs
);
delete
[]
wcs
;
return
wstr
;
wcs
[
l
]
=
0
;
return
*
wcs
;
}
#ifdef __ANDROID__
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment