Using FontFamily and Font for Text Elements with Foreign Language In Forms

alaskanroguealaskanrogue USMember ✭✭✭
edited February 13 in Xamarin.Forms

I understand the specification for Font Family and Fonts by platform, i.e. <OnPlatform x:TypeArguments=x:String>. However there isn't a <OnLanguage> type. How can I select the Font Family and Font to be used for each language and platform? Is there already a plugin to help do this based on the current Azure Cognitive Services Text Translation supported languages in order to support the translated content?

Answers

  • igorkr_10igorkr_10 Member ✭✭✭
    edited February 14

    Do you talk about multilangual application? You can use extension for xaml. Here is good examle
    In second part of article there is Multilingual plugin example but I recommend use only first part for better understanding of xaml extensions.

  • NMackayNMackay GBInsider, University mod

    @igorkr_10 said:
    Do you talk about multilangual application? You can use extension for xaml. Here is good examle
    In second part of article there is Multilingual plugin example but I recommend use only first part for better understanding of xaml extensions.

    That link seems to be dead

  • igorkr_10igorkr_10 Member ✭✭✭

    @NMackay said:

    @igorkr_10 said:
    Do you talk about multilangual application? You can use extension for xaml. Here is good examle
    In second part of article there is Multilingual plugin example but I recommend use only first part for better understanding of xaml extensions.

    That link seems to be dead

    Thanks. I fixed it.

  • alaskanroguealaskanrogue USMember ✭✭✭

    I looked at the Multilingual plugin, but it really for embedment of translated text to create language specific apps, not real-time translation.

    I guess I really needed to ask if there are specific fonts that are needed to be specified for "text displaying" components to display the numerous languages being received from the Azure translation services?

  • alaskanroguealaskanrogue USMember ✭✭✭

    From testing, it appears that the appropriate font for the language in use is automatically selected.

  • igorkr_10igorkr_10 Member ✭✭✭

    Do you want to get the text depending on the language from the service? Or do you want to set specific font depending on the language?
    Is second case you can create static property somewhere in your project and get Font depending on language. For example:

    public static string FontName
        {
            get
            {
                string fontName = string.Empty;
                var culture = CultureInfo.CurrentCulture;
                //Or you can use other property from culture to get font
                if (culture.LCID == 1033)
                {
                    switch (Device.RuntimePlatform)
                    {
                        case Device.Android:
                //For example Font Awesome (but you can use Calibri or Tahoma, etc)
                            fontName= "Font Awesome 5 Free-Solid-900.otf#Font Awesome 5 Free Solid";
                            break;
                        case Device.iOS:
                            fontName= "Font Awesome 5 Free";
                            break;
                        default:
                            fontName= "Font Awesome 5 Free-Solid-900";
                            break;
                    }
                    fontName = "Font Awesome 5 Free";
                }
                return fontName;
            }
    }
    

    Note, that font name will be several for each platform.
    Then in xaml:

    <Label Text="Text" FontFamily="{x:Static yourNamespace:yourStaticClass.FontName}"/>

    I hope this will help you

Sign In or Register to comment.