fix geoip chi and zho not return chinese translation
GeoLite2-City.mmdb supports zh-CN, but does not support chi and zho in sourcemod
The Chinese translation cannot be returned.
This is a fix when GetLanguageInfo got chi or zho, convert to zh-CN to match GeoLite2-City.mmdb
Good catch! Can we be sure that the mmdb always contains the zh-CN locale? It might be safer to check that and fallback properly if not.
i already check the GeoLite2-City.mmdb in sourcemod, date 2019/12/17.
and the first comment pictrue is this version.(download from sourcemod latest release)
I also checked maxmind webside, although it is a csv version, I think it apply to mmdb too.
or maybe for code robustness, change the code like this:
if (translator->GetLanguageInfo(langid, &code, NULL))
{
for (size_t i = 0; i < mmdb.metadata.languages.count; i++)
{
if (strcmp(code, mmdb.metadata.languages.names[i]) == 0)
{
return code;
}
// Not sure whether mmdb will include chi or zho in the future, so multiple judgments
if ((strcmp(code, "chi") == 0 || strcmp(code, "zho") == 0) && strcmp(mmdb.metadata.languages.names[i], "zh-CN"))
{
return "zh-CN";
}
}
}
If it is confirmed that the simplified Chinese language code of mmdb is "zh-CN", would it be better to modify the variable code directly?
Even if mmdb does not contain the "zh-CN" language, we can return "en" as a fallback.
if (translator->GetLanguageInfo(langid, &code, NULL))
{
if (strcmp(code, "chi") == 0)
{
code = "zh-CN";
}
else if (strcmp(code, "zho") == 0)
{
code = "zh-TW";
}
for (size_t i = 0; i < mmdb.metadata.languages.count; i++)
{
if (strcmp(code, mmdb.metadata.languages.names[i]) == 0)
{
return code;
}
}
}
If it is confirmed that the simplified Chinese language code of mmdb is "zh-CN", would it be better to modify the variable code directly?
Even if mmdb does not contain the "zh-CN" language, we can return "en" as a fallback.
if (translator->GetLanguageInfo(langid, &code, NULL)) { if (strcmp(code, "chi") == 0) { code = "zh-CN"; } else if (strcmp(code, "zho") == 0) { code = "zh-TW"; } for (size_t i = 0; i < mmdb.metadata.languages.count; i++) { if (strcmp(code, mmdb.metadata.languages.names[i]) == 0) { return code; } } }
sourcemod default mmdb version didnt contain zh-TW, so it will cause error.
i not sure if mmdb is customizable.
sourcemod default mmdb version didnt contain zh-TW, so it will cause error.
i not sure if mmdb is customizable.
This does not cause an error, but returns the default language "en".
See line 196:
https://github.com/alliedmodders/sourcemod/blob/20642a8518904ccfa0d36905471a313fcca2db7a/extensions/geoip/geoip_util.cpp#L186-L197
I checked GeoLite2-City_20250610 and it doesn't include zh-TW either.
~~When I asked chatgpt what languages geoip returns, gpt's answer included zh-TW. Sorry, I should have verified this answer myself first.~~
sourcemod default mmdb version didnt contain zh-TW, so it will cause error. i not sure if mmdb is customizable.
This does not cause an error, but returns the default language "en".
See line 196:
https://github.com/alliedmodders/sourcemod/blob/20642a8518904ccfa0d36905471a313fcca2db7a/extensions/geoip/geoip_util.cpp#L186-L197
I checked GeoLite2-City_20250610 and it doesn't include zh-TW either.
~When I asked chatgpt what languages geoip returns, gpt's answer included zh-TW. Sorry, I should have verified this answer myself first.~
ye i miss the final return. and i think mmdb must include zh-cn.
I think normalizing the language code before looking it up in the available languages in the mmdb is the way to go as @F1F88 suggested is the way to go. Falling back to English is what we do everywhere else. Can you please adjust your code accordingly?
I think normalizing the language code before looking it up in the available languages in the mmdb is the way to go as @F1F88 suggested is the way to go. Falling back to English is what we do everywhere else. Can you please adjust your code accordingly?
code optimized. please check