Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Being able to pass argument for a given translation #5

Closed
morphonet opened this issue Apr 16, 2021 · 1 comment
Closed

Being able to pass argument for a given translation #5

morphonet opened this issue Apr 16, 2021 · 1 comment

Comments

@morphonet
Copy link

morphonet commented Apr 16, 2021

As a user, i'd like to be able to give an argument when using useTranslation that will be injected into the translated string.

For exemple :
useTranslation("myTranslate1", player.name)

And in my json:
Fr > myTranslate1: "Bienvenue #### !",
En > myTranslate1: "Welcome #### !"

Even better, give a struct as an argument, and fill the translated strings with named properties, such as :
useTranslation("myTranslate1", {playerName: "Morphonet", level: 10});

And in my json:
Fr > myTranslate1: "Bienvenue {{playerName}} ! Oh, vous êtes déjà au niveau {{level}} ? Bien joué !"
En > myTranslate1: "Welcome {{playerName}} ! Oh, i see you're already level {{level}} ? Well done !"

@rbarbosa95 rbarbosa95 pinned this issue Apr 17, 2021
@rbarbosa95
Copy link
Contributor

rbarbosa95 commented Feb 4, 2023

Almost two years later 😅

To be quite honest I haven't found a way to do this, but with the new Game Maker updates, you can do this again natively.

You can use your own string or string_ext functions.

For example:

In the translation files
Fr > myTranslate1: "Bienvenue {0} ! Oh, vous êtes déjà au niveau {1} ? Bien joué !"
En > myTranslate1: "Welcome {0} ! Oh, i see you're already level {1} ? Well done !"

// Create
t = method(self, useTranslation);
nameVar =  t("welcome", "nameVar");

// Draw
draw_text(32, room_height / 2, string_ext(nameVar, ["Creative", "Hand"]));

This will cause it, before rendering the text, to take the information between keys to exchange with the array step as the second parameter of string_ext

I know it sounds like a bit of work, but using the native way I believe is the best way now.
And of course if I have any unmapped cases, I'll try to answer them or help out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants