Localization and Custom Keys

Announcements, support questions, and discussion for Quest Machine.
Post Reply
jcfalcone
Posts: 3
Joined: Wed Jan 09, 2019 11:17 am

Localization and Custom Keys

Post by jcfalcone »

Hi.

I'm using Quest Machine to handle quests in my game, but I'm having problems to change the language or at least I don't know how. I've two language in my text tables and I'm using the following code to handle the language:

Code: Select all

	PixelCrushers.DialogueSystem.Localization.language = this.m_currLanguage;
        PixelCrushers.DialogueSystem.DialogueManager.SetLanguage(this.m_currLanguage);
I'm sure the m_currLanguage is using a valid string.

Obs: I'm using the DialogueManager as well and it's not changing the language as well.

Another thing is that I need to create some custom keys to use inside the Quest Log, like build names or characters, from my other systems. How can I create it? I couldn't find anything in the manual.

Thanks
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Localization and Custom Keys

Post by Tony Li »

Hi,
jcfalcone wrote: Fri Jun 21, 2019 6:41 pmI'm using Quest Machine to handle quests in my game, but I'm having problems to change the language or at least I don't know how. I've two language in my text tables and I'm using the following code to handle the language:

Code: Select all

	PixelCrushers.DialogueSystem.Localization.language = this.m_currLanguage;
        PixelCrushers.DialogueSystem.DialogueManager.SetLanguage(this.m_currLanguage);
I'm sure the m_currLanguage is using a valid string.
You only need the second line. Internally, DialogueManager.SetLanguage also sets Localization.language.

As a test, temporarily disable your code, and set the Dialogue Manager's Display Settings > Localization Settings > Language field to the name of the language as defined in your text table.

Then make sure your main text table is assigned to the the Dialogue Manager's Display Settings > Localization Settings > Text Table field. (This will assign it to the shared UILocalizationManager so Quest Machine will also know about it. The Dialogue Manager will add a UILocalizationManager component at runtime if one doesn't exist.)

Make sure your quest's text uses a text table:

questTextUsesTable.png
questTextUsesTable.png (11.59 KiB) Viewed 1077 times

If your text is written into the quest, you can move it into a text table by selecting (gear menu) > Text > Move Text To Table.

Also keep in mind that when you set a language (even by setting the Dialogue Manager's Language field and playing the scene), it stores the current language in PlayerPrefs. You can click the Reset Language PlayerPrefs button to clear it.
jcfalcone wrote: Fri Jun 21, 2019 6:41 pmAnother thing is that I need to create some custom keys to use inside the Quest Log, like build names or characters, from my other systems. How can I create it? I couldn't find anything in the manual.
It may depend on what you need to do. Generally speaking, you can't put a {key} inside the text of another key. Otherwise you could write infinite loops like this:
  • A: "Same as {B}"
  • B: "Same as {A}"
If you were to get the value of the key A it would try to replace {B} with the value of the key B.

But since B's text has {A}, it would try to replace {A} with the value of the key A, and so on until the universe implodes.

This means you're not allowed to do this:
  • Quest Description: "Download build number {BUILD}"
  • BUILD: "3.14159"
However, you can add entries to a quest's tagDictionary. The tagDictionary contains tags such as {QUESTGIVER} and {#rabbits} (a counter). These are replaced after the text is retrieved from the text table. For example:

Code: Select all

var playerJournal = QuestMachine.GetQuestJournal();
var quest = playerJournal.FindQuest("Some Quest ID");
quest.tagDictionary.SetTag(@"{BUILD}", "3.14159");
jcfalcone
Posts: 3
Joined: Wed Jan 09, 2019 11:17 am

Re: Localization and Custom Keys

Post by jcfalcone »

One thing, how can I handle many text table? Or should I have just one?
Our game is kind of big and just one was getting messy.

I'll try the tag dictionary, I didn't know about it.
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Localization and Custom Keys

Post by Tony Li »

You'll typically have one text table for global info. If I recall correctly, you're using the Dialogue System. So if you call DialogueManager.GetLocalizedText, it will look in this text table. The LocalizeUI component will also look in this text table.

You can also assign a text table to each quest giver. Quest text will look in the quest giver's text table first. If it doesn't find the key there, it will look in the global text table. (And before both text tables, it will check the quest's tag dictionary.)

For your own purposes, you can use as many additional text tables as you want. If you have a reference to a text table, you can use any of the TextTable methods to access its content.

BTW, the Text Table Editor window is getting some performance optimizations in the next updates of Quest Machine and the Dialogue System.
jcfalcone
Posts: 3
Joined: Wed Jan 09, 2019 11:17 am

Re: Localization and Custom Keys

Post by jcfalcone »

Great. I'll take a look

One last thing, about the text tables, you told in the first reply that I need to set it up on the dialogue manager for it to work ( the localization ), but how the extra text tables knows that i changed the language? Do I need to do something else?

It's just that it's not clear how it works, the docs doesn't explain it that well.

Thanks again
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Localization and Custom Keys

Post by Tony Li »

Since you're using the Dialogue System and Quest Machine, you can use just about any method to set the current language. They will set the language for both products.

I recommend adding a UILocalizationManager to the Dialogue Manager GameObject. Then set the language in the Dialogue Manager's Localization Settings. To change the language in code:

Code: Select all

DialogueManager.SetLanguage("es"); // Change to Spanish
More info: How to Check & Switch Languages
Post Reply