question

digitalmkt avatar image
digitalmkt asked

Any ideas and/or code examples on how to change the user language using Unity?

I'm using the code below with the following error:

Entity Error:: /Profile/GetProfile PlayFabError(InvalidParams, Invalid input parameters, 400 BadRequest - Details: EntityKey: Type or TypeString is required., Id is required., is not an allowed value of Type. | )



publicvoidSetLanguage()
{

Debug.Log("Started to set Language");

//string langString = PlayerPrefs.GetString("language");

Debug.Log("Reading Language settings: "+language);

if(PlayFabClientAPI.IsClientLoggedIn())
{
Debug.Log("Identity Discovered");
EntityKeyentity=newEntityKey
{
Id=playerID,
Type=typeID

};

Debug.Log("Charged IDS");
PlayFabProfilesAPI.GetProfile(newGetEntityProfileRequest

{

Entity=newEntityKey
//Entity = new EntityKey

{
Id=playerID,
Type=typeID

}
},result=>
{
Debug.Log("Deu Certo");
myProfileVersion=result.Profile.VersionNumber;
myplayerID=result.Profile.Entity.Id;

},
error=>
{
Debug.Log("Deu Ruim");
Debug.Log("Entity Error:: "+error);
});


}
}


publicvoidSetProfileLanguage()
{
PlayFabProfilesAPI.GetProfile(newGetEntityProfileRequest
{
Entity=newEntityKey
{
Id=playerID,
Type=typeID
}
},result=>
{
profileExpectedVersion=result.Profile.VersionNumber;
varrequest=newSetProfileLanguageRequest
{
Language=language,
ExpectedVersion=profileExpectedVersion,


};
PlayFabProfilesAPI.SetProfileLanguage(request,res=>
{
Debug.Log("The language on the entity's profile has been updated.");
},FailureCallback);
},
error=>
{
Debug.Log("Entity Error:: "+error.ErrorMessage);
}
);
}

voidFailureCallback(PlayFabErrorerror)
{

Debug.Log("Language coudn't be changed");
}

}

Thank you very much...

10 |1200

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

Seth Du avatar image
Seth Du answered

I have tried to call SetProfileLanguage and here is a successful case:

You need to check:

  • The Entity ID matches the Entity Type. Player has 2 PlayFab IDs (title player ID and master player ID) and both of them can be used as EntityKey for the request but correct match is a must.
  • The Language key in the request is a string variable but the format is not given. This is not an official announcement but I have tried plenty of cases in ISO 639-1 and it works. For those languages still reports “/Profile/SetProfileLanguage: Invalid input parameters”, it is simply because PlayFab doesn’t support. I will report to our team about the lack of the documentation, meanwhile replying to this answer if you find any unsupported language in the API call will be appreciated.

10 |1200

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

digitalmkt avatar image
digitalmkt answered

Thanks for the explanation. It works like a charm. I was using the wrong Type (master_player_account) and the PlayfabId. I changed to "title_player_account" and the Entitykey.entity.id and it works like a charm. I also used your piece of code more clean. Thanks again.

10 |1200

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

Super.tt avatar image
Super.tt answered

Hi @digitalmkt @SethDu, how can the client get the playfab id title?

1 comment
10 |1200

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

Super.tt avatar image Super.tt commented ·

I got SethDu help here if someone needs it in the future :))

0 Likes 0 ·

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.