Bug with multiple parameters in the same term

More
6 years 9 months ago #2851 by Niaobu
Hi,

I found a bug in I2 Localization v2.8.2 f2.
LocalizationManager.ApplyLocalizationParamsInternal does not properly account for the fact that replacing a parameter can change the length of the string.

After replacing a term, the index is changed to
index = iParamEnd + 2;
In the case where the parameter was replaced, this should be
index = iParamStart + result.Length;

In cases with long parameter names being replaced with shorter values, this might cause the function to skip over other parameters later in the string.

The bug is easily reproduced.

1. Create a term with the following translation: {[PARAMETER_NAME_1]} {[PARAMETER_NAME_2]}
2. Create a text object and attach an I2 Localize component and a LocalizationParamsManager component.
3. Add two parameters to the LocalizationParamsManager: PARAMETER_NAME_1 => 1, PARAMETER_NAME_2 => 2
4. Set the term in the I2 Localize component
5. The text will change to "1 {[PARAMETER_NAME_2]}" as the second parameter is skipped.


My temporary fix:
@@ -78,9 +78,13 @@ namespace I2.Loc
                    {
                        pluralType = GoogleLanguages.GetPluralType(CurrentLanguageCode, amount).ToString();
                    }
-                }
 
-                index = iParamEnd + 2;
+                    index = iParamStart + result.Length;
+                }
+                else
+                {
+                    index = iParamEnd + 2;
+                }
            }
 
            if (pluralType != null)

The fix seems to work, but does not try to account for the case of plurals right beneath this block.

Please Log in or Create an account to join the conversation.

More
6 years 9 months ago #2855 by Frank
Hi,
Thanks for looking into this!

This issue was fixed in one of the v2.8.4 releases, and its handled correctly in the current AssetStore version.
inter-illusion.com/forum/i2-localization...lculation-issue#2758

If you update to the latest, all will work as expected.

Hope that helps,
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.145 seconds
Template by JoomlaShine