Skip to content

fix geoip chi and zho not return chinese translation #2335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Lxeon
Copy link

@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
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
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
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.

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