Skip to content

Conversation

Lxeon
Copy link
Contributor

@Lxeon Lxeon commented Jun 6, 2025

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

@peace-maker
Copy link
Member

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.

@Lxeon
Copy link
Contributor Author

Lxeon commented Jun 12, 2025

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";
		}
	}
}

@F1F88
Copy link
Contributor

F1F88 commented Jun 13, 2025

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;
		}
	}
}

@Lxeon
Copy link
Contributor Author

Lxeon commented Jun 13, 2025

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.

@F1F88
Copy link
Contributor

F1F88 commented Jun 13, 2025

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:

for (size_t i = 0; i < mmdb.metadata.languages.count; i++)
{
if (strcmp(code, mmdb.metadata.languages.names[i]) == 0)
{
return code;
}
}
}
}
return "en";
}

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.

@Lxeon
Copy link
Contributor Author

Lxeon commented Jun 14, 2025

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:

for (size_t i = 0; i < mmdb.metadata.languages.count; i++)
{
if (strcmp(code, mmdb.metadata.languages.names[i]) == 0)
{
return code;
}
}
}
}
return "en";
}

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.

@peace-maker
Copy link
Member

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?

@Lxeon
Copy link
Contributor Author

Lxeon commented Aug 16, 2025

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

Copy link
Member

@peace-maker peace-maker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, I wonder if there are more such cases of valve and maxmind using other codes.

@peace-maker peace-maker merged commit 5c1a5e3 into alliedmodders:master Aug 16, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants