This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
en:tutorials:localization [2018/12/24 02:42 (5 years ago)] – created sausage | en:tutorials:localization:localization [2020/08/31 05:37 (4 years ago)] (current) – ↷ Links adapted because of a move operation sausage | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | <WRAP center round info 60%> | ||
- | In Progress | ||
- | </ | ||
- | |||
====== Localization and Multiple Languages ====== | ====== Localization and Multiple Languages ====== | ||
Line 15: | Line 11: | ||
This tutorial will be done in two steps: | This tutorial will be done in two steps: | ||
- | 1. Create a simple game with characters with their own look, speech and music. | + | - Create a simple game with characters with their own look, speech and music. |
- | 2. Add in a second locale, and be able to switch between them. | + | |
===== Starting a new project ===== | ===== Starting a new project ===== | ||
- | Begin with a blank project created using the [[en: | + | Begin with a blank project created using the [[en: |
- | Name your project something like the-conversation (or whatever you wish). | + | Name your project something like '' |
Our game will be about two polite gentlemen having a conversation. They continually greet each other all day. | Our game will be about two polite gentlemen having a conversation. They continually greet each other all day. | ||
+ | |||
+ | {{ tutorials: | ||
Eventually, we want to be able to switch their nationality, | Eventually, we want to be able to switch their nationality, | ||
- | ===== Assets ===== | + | ===== French |
Let's begin with the French assets, building the French version first. | Let's begin with the French assets, building the French version first. | ||
+ | Frenchman sprite for the data/ | ||
- | Object | + | {{ tutorials: |
- | Speech | + | Speech |
- | Music | + | {{ tutorials: |
+ | {{ tutorials: | ||
+ | Music for the same folder: | ||
- | Delete the default config | + | {{ tutorials: |
+ | |||
+ | |||
+ | Delete the default config | ||
+ | |||
+ | Set up a smaller resolution for this demo by changing the Camera Frustum: | ||
+ | |||
+ | <code ini> | ||
+ | [MainCamera] | ||
+ | FrustumWidth | ||
+ | FrustumHeight | ||
+ | </ | ||
+ | |||
+ | Also turn off the smoothing effect to suit our pixel graphic style: | ||
+ | |||
+ | <code ini> | ||
+ | [Display] | ||
+ | Smoothing = false | ||
+ | </ | ||
Create the default '' | Create the default '' | ||
- | [] | + | <code ini> |
+ | [Person1] | ||
+ | Graphic | ||
+ | Texture | ||
+ | Pivot = center | ||
+ | Scale = 5.0 | ||
+ | Position | ||
+ | KeepInCache | ||
+ | </ | ||
+ | |||
+ | The above config uses section inheritance. You can [[en: | ||
Create a second person from the first, but one that stands on the other side and faces the other way: | Create a second person from the first, but one that stands on the other side and faces the other way: | ||
- | [] | + | <code ini> |
+ | [Person2@Person1] | ||
+ | Position | ||
+ | Scale = (-5, 5, 1) | ||
+ | </ | ||
Next, create a '' | Next, create a '' | ||
- | [] | + | <code ini> |
+ | [Scene] | ||
+ | ChildList = Person1 # Person2 | ||
+ | </ | ||
Create the scene in the game in code. This will create all the child objects onscreen. You can just change the existing '' | Create the scene in the game in code. This will create all the child objects onscreen. You can just change the existing '' | ||
- | [] | + | <code c> |
+ | orxObject_CreateFromConfig(" | ||
+ | </ | ||
to: | to: | ||
- | [] | + | <code c> |
+ | orxObject_CreateFromConfig(" | ||
+ | </ | ||
Create all the text objects to go onscreen. You will need text objects for: | Create all the text objects to go onscreen. You will need text objects for: | ||
- | - The speech | + | |
- | - The player instructions | + | - The player instructions |
- | - The current language indicator | + | - The current language indicator |
Create these as: | Create these as: | ||
- | [] | + | <code ini> |
+ | [ToggleNationalityObject] | ||
+ | Graphic | ||
+ | Scale = 2 | ||
+ | Position = (0, 120) | ||
+ | |||
+ | [ToggleNationalityGraphic] | ||
+ | Text = ToggleNationalityText | ||
+ | Pivot = center | ||
+ | |||
+ | [ToggleNationalityText] | ||
+ | String = "PRESS SPACE TO CHANGE NATIONALITY" | ||
+ | |||
+ | [CurrentNationalityObject] | ||
+ | Graphic | ||
+ | Scale = 2 | ||
+ | Position = (0, 160) | ||
+ | Color = (0, 128, 255) | ||
+ | |||
+ | [CurrentNationalityGraphic] | ||
+ | Text = CurrentNationalityText | ||
+ | Pivot = center | ||
+ | |||
+ | [CurrentNationalityText] | ||
+ | String = FRENCH | ||
+ | |||
+ | [SpeechObject] | ||
+ | Graphic | ||
+ | Scale = 2 | ||
+ | Position = (-70, -100) | ||
+ | Color = (0, 128, 255) | ||
+ | |||
+ | [SpeechGraphic] | ||
+ | Text = SpeechText | ||
+ | Pivot = center | ||
+ | |||
+ | [SpeechText] | ||
+ | String = Bonjour | ||
+ | </ | ||
And now place them into the scene by adding them to the Childlist: | And now place them into the scene by adding them to the Childlist: | ||
+ | |||
+ | <code ini> | ||
+ | [Scene] | ||
+ | ChildList = Person1 # Person2 # ToggleNationalityObject # CurrentNationalityObject # SpeechObject | ||
+ | </ | ||
Next is the music. Define it with: | Next is the music. Define it with: | ||
- | [] | + | <code ini> |
+ | [BackgroundThemeMusic] | ||
+ | Music = je-te-veux.ogg | ||
+ | Volume | ||
+ | Loop = true | ||
+ | KeepInCache = true | ||
+ | </ | ||
And add it to the scene with: | And add it to the scene with: | ||
- | [] | + | <code ini> |
+ | [Scene] | ||
+ | ChildList = Person1 # Person2 # ToggleNationalityObject # CurrentNationalityObject # SpeechObject | ||
+ | SoundList = BackgroundThemeMusic | ||
+ | </ | ||
Next is the actual conversation. Define the speech with: | Next is the actual conversation. Define the speech with: | ||
- | [] | + | <code ini> |
+ | [Hello1] | ||
+ | Sound = bonjour1.ogg | ||
+ | KeepInCache = true | ||
- | Them using a timeline track switch on and off the alpha of the speech text object to make it appear/ | + | [Hello2] |
+ | Sound = bonjour2.ogg | ||
+ | KeepInCache = true | ||
+ | </ | ||
- | Compile and run. Our two French gentlemen will start having | + | Then, using a timeline track switch on and off the alpha of the speech text object to make it appear/ |
+ | <code ini> | ||
+ | [ConversationTimeLine] | ||
+ | 0 = Object.SetPosition ^ (-70,-100) # Object.SetAlpha ^ 1.0 # Object.AddSound ^ Hello1 | ||
+ | 1 = Object.SetPosition ^ (70,-100) # Object.AddSound ^ Hello2 | ||
+ | 2 = Object.SetAlpha ^ 0.0 | ||
+ | 4 = | ||
+ | Loop = true | ||
+ | KeepInCache = true | ||
+ | </ | ||
- | That is the basic game. | + | Add the Timeline to the '' |
+ | <code ini> | ||
+ | [SpeechObject] | ||
+ | Graphic | ||
+ | Scale = 2 | ||
+ | Position | ||
+ | Color = (0, 128, 255) | ||
+ | TrackList = ConversationTimeLine | ||
+ | </ | ||
+ | |||
+ | Compile and run. Our two French gentlemen will start having a lovely conversation. | ||
+ | |||
+ | That is the basic game. | ||
Now to make the game switchable to Australia mode. This is the easy part. | Now to make the game switchable to Australia mode. This is the easy part. | ||
+ | |||
+ | |||
+ | ===== Australian Assets ===== | ||
+ | |||
+ | We'll get the Australian version of the assets in now. These will replace the French ones. | ||
+ | |||
+ | Australian sprite: | ||
+ | |||
+ | {{ tutorials: | ||
+ | |||
+ | Speech samples: | ||
+ | |||
+ | {{ tutorials: | ||
+ | {{ tutorials: | ||
+ | |||
+ | Music: | ||
+ | |||
+ | {{ tutorials: | ||
Begin by defining the two languages for the game: French and Australian. | Begin by defining the two languages for the game: French and Australian. | ||
- | [] | + | <code ini> |
+ | [Locale] | ||
+ | LanguageList = French # Australian | ||
+ | </ | ||
Next, define those languages as sections containing your keys for the various assets or text: | Next, define those languages as sections containing your keys for the various assets or text: | ||
- | [] | + | <code ini> |
+ | [French] | ||
+ | Hello = Bonjour | ||
+ | Image = typical-frenchman.png | ||
+ | HelloSound1 | ||
+ | HelloSound2 | ||
+ | BackgroundMusic = je-te-veux.ogg | ||
+ | LanguageText | ||
+ | |||
+ | [Australian] | ||
+ | Hello = Gidday | ||
+ | Image = typical-aussie.png | ||
+ | HelloSound1 | ||
+ | HelloSound2 | ||
+ | BackgroundMusic = binda_polka.ogg | ||
+ | LanguageText | ||
+ | </ | ||
+ | |||
+ | Finally, go to each config and replace the absolute asset paths and text with the named keys from language sections. These keys are called using the special $ symbol: | ||
+ | |||
+ | <code ini> | ||
+ | |||
+ | [Hello1] | ||
+ | Sound = $HelloSound1 | ||
+ | KeepInCache = true | ||
+ | |||
+ | [Hello2] | ||
+ | Sound = $HelloSound2 | ||
+ | KeepInCache = true | ||
+ | |||
+ | [BackgroundThemeMusic] | ||
+ | Music = $BackgroundMusic | ||
+ | Volume | ||
+ | Loop = true | ||
+ | KeepInCache = true | ||
+ | |||
+ | [Person1] | ||
+ | Graphic | ||
+ | Texture | ||
+ | Pivot = center | ||
+ | Scale = 5.0 | ||
+ | Position | ||
+ | KeepInCache = true | ||
+ | |||
+ | [CurrentNationalityText] | ||
+ | String = $LanguageText | ||
+ | |||
+ | [SpeechText] | ||
+ | String = $Hello | ||
+ | |||
+ | </ | ||
+ | |||
+ | Excellent, the localization is now added to all our parts of the config. But there is no way to switch locales. The final step is the define the '' | ||
+ | |||
+ | <code ini> | ||
+ | [MainInput] | ||
+ | KEY_ESCAPE | ||
+ | KEY_SPACE = SwitchLanguage | ||
+ | </ | ||
+ | |||
+ | Define a variable at the top of the code to keep track of the current language: | ||
+ | |||
+ | <code c> | ||
+ | int currentLanguageIndex = 0; | ||
+ | </ | ||
- | Finally go to each config and replace | + | Then in code, in the '' |
- | [] | + | <code c> |
+ | if (orxInput_HasBeenActivated(" | ||
+ | { | ||
+ | currentLanguageIndex++; | ||
+ | if (currentLanguageIndex > 1){ | ||
+ | currentLanguageIndex = 0; | ||
+ | } | ||
+ | |||
+ | orxLocale_SelectLanguage(orxLocale_GetLanguage(currentLanguageIndex)); | ||
+ | } | ||
+ | </ | ||
Compile and run. Now you can switch between the two languages with the Space Bar. Everything in the game switches over in an instant. Pretty impressive stuff. | Compile and run. Now you can switch between the two languages with the Space Bar. Everything in the game switches over in an instant. Pretty impressive stuff. | ||
+ | {{ tutorials: | ||
- | Acknowledgements, | + | Acknowledgements, |
- | Accordion | + | * Thank you to Norimichi Nagasaka for allowing me to use his accordion |
- | Graphics by Trevor Brennan: http:// | + | * Thanks to Trevor Brennan: http:// |
- | Thanks to FullyBugged, | + | |