Documentation

Did you find this helpful?

Setting Default Languages

PlayFab is introducing the support for storing localized strings on behalf of game developers. We are also adding the necessary logic to provide your players with the correct strings for the language they prefer. To accomplish this, we will be leveraging two new language settings: one is associated with your title and the other is stored on each of your players’ Entity profiles:  

  • Title default language: Indicates your title’s primary supported language. Once set, we will require your title to support at least this language for features using localized strings.
  • Player language: Indicates the player’s preferred language. Can be set per title.

Using these two settings, PlayFab logic will match up localized strings with the players who prefer that language. Players without a language preference will receive strings in your title’s specified default language. Players with a preference for a language your title doesn’t support will also receive strings based on your title’s default.

This tutorial walks you through how to set the default language of your title and the preferred language of your players.

Requirements:

This tutorial assumes you have the following working knowledge about using PlayFab:

  • Basic knowledge of how to create a player will be necessary since there will need to be players with a username and password before calling preferred language logic. Refer to the Getting Started with PlayFab which will run you through the process of creating a player for the title.
  • Read the Game Manager Tour if you are unfamiliar with the Game Manager as it is the place where language information is viewed.
  • Knowledge of how to work with player profiles will be necessary to confirm that a preferred language has been added to a player’s profile. Please read up on how to get a player’s profile in the Getting Player Profiles tutorial.

Section 1 – Player’s Preferred Language

Before setting your player’s preferred language, you’ll need to figure out how you want to collect it.  You have a couple options:

  • Ask them: Add an option on your game’s menu
  • Intuit their language: Use the language of the player’s device by calling the provided platform API (e.g. Locale.getDefault.getLanguage() for Android) There are a lot of languages out there and your title may not support them all.  While not required, we recommend future-proofing your title and storing the player’s actual preference. If you come back and add support for that language later, PlayFab’s logic will automatically start serving up the new strings (rather than the default).

Step 1 – Set the language

PlayFab allows you to choose from a specific list of languages that you want to support. You can make a call to GetLanguageList to see the language codes.

First, we will update a player’s profile to include the language they prefer getting content from your title in.

C# Code Example

void SetProfileLanguage(string language, int? profileExpectedVersion, EntityKey entity)
{
	var request = new SetProfileLanguageRequest
	{
		Language = language,
		ExpectedVersion = profileExpectedVersion,
		Entity = entity
	};
	PlayFabServerAPI.SetProfileLanguage(request, res =>
	{
		Debug.Log("The language on the entity's profile has been updated.");
	}, FailureCallback);
}

void FailureCallback(PlayFabError error)
{
    Debug.LogWarning("Something went wrong with your API call. Here's some debug information:");
    Debug.LogError(error.GenerateErrorReport());
}

Step 2 – See that the language was updated

The first thing you can do is go to the player’s Overview. In Game Manager go to Player -> Overview and see that their contact info section is updated with their preferred language.

The language can also be updated with the dropdown displayed above.

Next, you can navigate to the player’s PlayStream, and it will show an “Entity language updated” event.

Clicking on the info icon on the event should show JSON similar to:

{
    "EventName": "entity_language_updated",
    "Source": "PlayFab",
    "Language": "en",
    "EntityChain": "title_player_account!4CDA57A14A596E70/<YourTitleId>/C9458B4D3A115F4B/36163DA3783B0C8A/",
    "EntityLineage": {
        "NamespaceId": "4CDA57A14A596E70",
        "TitleId": "YourTitleId",
        "MasterPlayerAccountId": "C9458B4D3A115F4B",
        "TitlePlayerAccountId": "36163DA3783B0C8A",
        "CharacterId": null,
        "GroupId": null
    },
    "EventNamespace": "com.playfab",
    "EventId": "f643e22a2a76462aaeaa3469afa31434",
    "EntityType": "title_player_account",
    "EntityId": "36163DA3783B0C8A",
    "SourceType": "BackEnd",
    "Timestamp": "2018-08-24T18:49:47.8755292Z",
    "History": null,
    "CustomTags": null,
    "Reserved": null
}

Section 2 – Set a Title Default Language

The next thing we will do is set a default language for your title. All localization features will now associate a language with every translated version of the content. The title needs a default language so that if any player doesn’t have a preferred language set, or their preferred language isn’t supported, they can still receive the default version of the content. To start, go to Settings.

Under the new “title defaults” header you will see the dropdown to pick a language from. You will need to set a default language before you can to use any of the add localization features. Click SAVE and you will see a message stating that your update was successful.

If you return to the dashboard, you will see a “title api settings changed” event in your PlayStream.

Clicking on the info icon on the event should show JSON similar to:

{
    "EventName": "title_api_settings_changed",
    "PreviousSettingsValues": {
        "DefaultLanguage": null
    },
    "SettingsValues": {
        "DefaultLanguage": "en"
    },
    "UserId": "EAF83D52E282C291",
    "DeveloperId": null,
    "EventNamespace": "com.playfab",
    "EntityType": "title",
    "Source": "PlayFab",
    "EventId": "108849a5e1424051b42256bc75b2e34b",
    "EntityId": "YourTitleId",
    "SourceType": "BackEnd",
    "Timestamp": "2018-08-24T21:51:02.2215614Z",
    "History": null,
    "CustomTags": null,
    "Reserved": null
}

Section 3 - Updating a Title Default Language

Remember, setting a default for your title tells PlayFab to use that language when you issue communications to players who don’t have a preferred language set (or have chosen a language which doesn’t match one you support).

Because the title’s default is used as a “fallback” language, PlayFab will expect that all your communications support your default language. You can always change your title default, but PlayFab will require that your current communications templates support the language you’re changing to. 

If you decide to update your title’s default language, you’ll see that the interface now shows a link to an edit page:

Following this link, you will see the same dropdown as before. However, if you try to save a default language that isn’t fully supported by your email templates, you will see certain error messages.

If there are errors, you can follow the links provided to update your content to support the language which is missing. When all errors have been addressed, we’ll accept the default language change.

Conclusion

So that’s it for this tutorial. You’ve seen how to set and update your title’s default language and your players’ preferred language.

If you have any questions or feedback on this tutorial, please contact us through our forums or slack channel.



Did you find this helpful?