question

Kim Strasser avatar image
Kim Strasser asked

How can I add translations to a shop item?

I want to display my items display name and my items description in the same language than the players title account preferred language. I want to support 3 languages, English, French and German. If the players title account preferred language is not set or if it is different than those 3 languages, then I want to display the English translation in my game.

How can I add translations to my items? I want to create translations for item display name and item description.

How can I get the corresponding translation in the client when I call PlayFabClientAPI.GetCatalogItems?

My client code:

string MyCatalog;
private async Task GetCatalog()
{
    var result = await PlayFabClientAPI.GetCatalogItemsAsync(new PlayFab.ClientModels.GetCatalogItemsRequest()
    {
        CatalogVersion = MyCatalog
    });

    foreach (var entry in result.Result.Catalog)
    {
        Console.WriteLine($"{entry.ItemId} {entry.DisplayName} {entry.Description} {entry.VirtualCurrencyPrices}");
    }

    if (result.Error != null)
        Console.WriteLine(result.Error.GenerateErrorReport());
    else
        Console.WriteLine("Listed items successful!");
}
In-Game Economy
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Sarah Zhang avatar image
Sarah Zhang answered

>> How can I get the corresponding translation in the client when I call PlayFabClientAPI.GetCatalogItems?

Currently, PlayFab does not natively support items translation. Translation features should be implemented by developers selves. You can search the translation/localization service or plug-ins for your game platforms by yourself. Game developers need to prepare online or offline language packs for the game themselves, then let clients choose the language packs based on the player’s language code on PlayFab backend or based on the player’s operation system language.

If you plan to translate the descriptions manually then add them in items’ descriptions, you can refer to the following content and modify it to suit your console application.

    private void OnGetitemSuccess(PlayFab.ClientModels.GetCatalogItemsResult result)
    {
        foreach (var item in result.Catalog)
        {
            if (item.Description == ""|| item.Description == null)
            {
                return;
            }
                if (PlayFabSimpleJson.TryDeserializeObject(item.Description, out object des))
                {
                    JsonObject descripObject = (JsonObject)des;
                   
                    switch (systemLanguage)
                    {
                        case "en":
                            getDescription("English", descripObject);
                            break;
                        case "de":
                            getDescription("German", descripObject);
                            break;
                        case "fr":
                            getDescription("French", descripObject);
                            break;
                        default:
                            getDescription("English", descripObject);
                            break;
                    }
                }
            }
        }
    
    private void getDescription(string key,JsonObject descripObject)
    {
        object desObj;
        if (descripObject.TryGetValue(key, out desObj))
        {
            Debug.Log(Convert.ToString(desObj));
        }
    }

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.