Index misscalculation issue
- bahattintancoskuner
- Topic Author
- Offline
- New Member
Less
More
- Posts: 1
- Thank you received: 1
6 years 10 months ago #2755
by bahattintancoskuner
Index misscalculation issue was created by bahattintancoskuner
Hi,
I have noticed an index misscalculation bug that prevents me to use multiple local parameters.
In LocalizationManager_Parameters.cs :
Change to this instead :
Please consider this bug in your new versions.
Have a good day.
I have noticed an index misscalculation bug that prevents me to use multiple local parameters.
In LocalizationManager_Parameters.cs :
private static void ApplyLocalizationParamsInternal(ref string translation, _GetParam getParam)
{
if (translation == null)
return;
string pluralType=null;
int idx0 = 0;
int idx1 = translation.Length;
int index = 0;
while (index>=0 && index<translation.Length)
{
int iParamStart = translation.IndexOf("{[", index);
if (iParamStart < 0) break;
int iParamEnd = translation.IndexOf("]}", iParamStart);
if (iParamEnd < 0) break;
// there is a sub param, so, skip this one: "this {[helo{[hi]} end"
int isubParam = translation.IndexOf("{[", iParamStart+1);
if (isubParam>0 && isubParam<iParamEnd)
{
index = isubParam;
continue;
}
var param = translation.Substring(iParamStart + 2, iParamEnd - iParamStart - 2);
var result = (string)getParam(param);
if (result != null)
{
var paramTag = translation.Substring(iParamStart, iParamEnd - iParamStart + 2);
translation = translation.Replace(paramTag, result);
int amount = 0;
if (int.TryParse(result, out amount))
{
pluralType = GoogleLanguages.GetPluralType(CurrentLanguageCode, amount).ToString();
}
}
index = iParamEnd + 2; //<== HERE : when the first parameter replaced, the size of thw word changed too so it should be recalculated
}
Change to this instead :
private static void ApplyLocalizationParamsInternal(ref string translation, _GetParam getParam)
{
if (translation == null)
return;
string pluralType=null;
int idx0 = 0;
int idx1 = translation.Length;
int index = 0;
while (index>=0 && index<translation.Length)
{
int iParamStart = translation.IndexOf("{[", index);
if (iParamStart < 0) break;
int iParamEnd = translation.IndexOf("]}", iParamStart);
if (iParamEnd < 0) break;
// there is a sub param, so, skip this one: "this {[helo{[hi]} end"
int isubParam = translation.IndexOf("{[", iParamStart+1);
if (isubParam>0 && isubParam<iParamEnd)
{
index = isubParam;
continue;
}
var param = translation.Substring(iParamStart + 2, iParamEnd - iParamStart - 2);
var result = (string)getParam(param);
if (result != null)
{
var paramTag = translation.Substring(iParamStart, iParamEnd - iParamStart + 2);
translation = translation.Replace(paramTag, result);
int amount = 0;
if (int.TryParse(result, out amount))
{
pluralType = GoogleLanguages.GetPluralType(CurrentLanguageCode, amount).ToString();
}
index = iParamEnd - (param.Length - result.Length) - 2; //TODO: This calculation is fixed, index calculation was wrong after replacing
}
else //TODO: wrapped with else
{
index = iParamEnd + 2;
}
}
Please consider this bug in your new versions.
Have a good day.
The following user(s) said Thank You: Frank
Please Log in or Create an account to join the conversation.
6 years 10 months ago #2758
by Frank
Are you Give I2L 5 stars!
Are you Please lets us know how to improve it!
Replied by Frank on topic Index misscalculation issue
Hi,
Thanks for looking into that.
I verified the issue and added the fix.
I also created a Unity Test to verify all possible Parameters and tag combinations, so that this error doesn't repeat in any future update.
Again, Thanks a lot for the suggestion!
Frank
Thanks for looking into that.
I verified the issue and added the fix.
I also created a Unity Test to verify all possible Parameters and tag combinations, so that this error doesn't repeat in any future update.
Again, Thanks a lot for the suggestion!
Frank
Are you Give I2L 5 stars!
Are you Please lets us know how to improve it!
To get the betas as soon as they are ready,
check this out
Please Log in or Create an account to join the conversation.
Time to create page: 0.247 seconds