Text missing when app run on Android device with other language?

I didn't intend to run my app on a device with another default language yet, but had a friend try it out. Her OS language is Greek. Text in labels which I display via an IValueConverter are blank. Does this have something to do with the alphabet being different? Other labels that have text set directly in XAML appear correctly (normal English/Roman alphabet), the IValueConverters for the bound labels are being used, and an OS language of e.g. Spanish doesn't have the same problem.

For context, I have an IValueConverter that is bound to an enum, which looks up the string from a pipe-separated list in the ConverterParameter.

Best Answer

  • NicholasBauerNicholasBauer US ✭✭
    Accepted Answer

    Oops. Turns out the issue was that I was using a converter to set the FontSize using a ConverterParameter of 1.5. In cultures where a decimal is specified by a comma, this was being parsed as 15, making the text so big it couldn't be seen.

Answers

  • Eric_LiraEric_Lira USMember ✭✭✭

    Hi @NicholasBauer according to your description I would say the problem is the logic inside your IValueConverter, not the fact the you're using it to display the text.
    Just to be sure, force your IValueConverter to return something straight way, with no logic and check if the text is displayed.

  • NicholasBauerNicholasBauer USMember ✭✭

    Hi @Eric_Lira. I've debugged the ValueConverter and it follows the correct and expected paths. Returning a string immediately also doesn't display the string.

    If I bind directly with no converter to a collection containing the values of an Enum, the Enum string appears when the language is English (US) or Spanish (US). However, it does not appear when the language is Spanish (Spain) or Greek (Greece).

  • Gigex42Gigex42 USMember ✭✭✭✭

    How about trying localizing with resource files accoring to this article?

    Else we need some code.

  • NicholasBauerNicholasBauer USMember ✭✭

    I'll localize later; right now I'm just concerned that no text is visible without express localization. If I get a chance I'll get a reproduction project.

  • NicholasBauerNicholasBauer USMember ✭✭
    Accepted Answer

    Oops. Turns out the issue was that I was using a converter to set the FontSize using a ConverterParameter of 1.5. In cultures where a decimal is specified by a comma, this was being parsed as 15, making the text so big it couldn't be seen.

  • JamesLaveryJamesLavery GBBeta, University ✭✭✭✭✭
    Ouch! Isn't that a worrying behaviour or bug in Xamarin? We can't have internal code behaviour changing like this when the culture changes. When accepting input from the user, we need to cater for different culture settings, but not interally, surely.

    I'd be interested in other people's views.
  • NicholasBauerNicholasBauer USMember ✭✭

    I suppose it's a tradeoff. Most parsing is likely to be user input. The function is documented to use the current culture (https://docs.microsoft.com/en-us/dotnet/api/system.int32.tryparse?view=netframework-4.7.1#System_Int32_TryParse_System_String_System_Globalization_NumberStyles_System_IFormatProvider_System_Int32__).

    I suppose the lesson is that when using parsing/formatting functions, if you really care that it isn't user-culture-variant, specify InvariantCulture.

  • JamesLaveryJamesLavery GBBeta, University ✭✭✭✭✭
    edited April 2018
    Ah! You were parsing in your converter. I'd got the wrong end it the stick or had misread your post and thought that the XAML parsing was exhibiting this behaviour.

    As you say - when using TryParse you need to be culture aware.
Sign In or Register to comment.