Getting language from JS?

Game development with Board Game Arena Studio
User avatar
__wiz__
Posts: 14
Joined: 22 September 2020, 18:15

Getting language from JS?

Post by __wiz__ »

Hi!

Is there a variable I can check on the client side to find out the user's requested language?

Thanks,
Thomas
User avatar
Tisaac
Posts: 2736
Joined: 26 August 2014, 21:28

Re: Getting language from JS?

Post by Tisaac »

__wiz__ wrote: 05 June 2021, 11:46 Hi!

Is there a variable I can check on the client side to find out the user's requested language?

Thanks,
Thomas
Why would you want to do that ?
User avatar
__wiz__
Posts: 14
Joined: 22 September 2020, 18:15

Re: Getting language from JS?

Post by __wiz__ »

It seems I'll be getting images for different language versions of a game (the graphics differ, so it's not just text replacement), so I want to display the correct images for the language.
Not sure how else to do that than to turn preloading off and then load the proper images for the language based on the client's language. But if you have better ideas?
User avatar
robinzig
Posts: 459
Joined: 11 February 2021, 18:23

Re: Getting language from JS?

Post by robinzig »

__wiz__ wrote: 06 June 2021, 11:31 It seems I'll be getting images for different language versions of a game (the graphics differ, so it's not just text replacement), so I want to display the correct images for the language.
Not sure how else to do that than to turn preloading off and then load the proper images for the language based on the client's language. But if you have better ideas?
Thanks for asking - if I'm allowed to "hijack", I've got an identical question about the game I'm developing (Deus). The image files I was given included two versions of the cards - one with names/text in English and the other in French. So far I'm only using the English ones but since the publisher included the French ones, and I believe they're a French-speaking publisher, it would be good to be able to use the French ones instead where appropriate. I'm not even going to think about implementing anything until the game logic is complete, but this was definitely on my mind to ask as part of the review process so I'm glad someone else has asked the question in advance :)

[One thought that crossed my mind was to use the game options and allow users to manually select English or French cards - but it would be good to be able to have it chosen automatically instead.]
User avatar
thoun
Posts: 1619
Joined: 10 December 2020, 22:25

Re: Getting language from JS?

Post by thoun »

For another game, editor sent cards with English text. We asked him for files without text and they send us layered files, so I could remove text and rebuild text with translated words. It's easier like this, having image file for each language will be hell to handle.
For original question, you say that it's not only the text that are different, can you put an example of 2 cards in different languages so we can see the difference and make the best suggestion?
User avatar
Tisaac
Posts: 2736
Joined: 26 August 2014, 21:28

Re: Getting language from JS?

Post by Tisaac »

The "cleanest" way to handle that is to recreate the cards yourself with the content as a real, translatable, text. This ensure that everyone can have it displayed in its own langage. That's a bit more work though.
An intermediate solution is to always display cards in english and have the card text/explanation in a translatable tooltip.
For your problem, I am not sure to understand what could be the advantages to have different assets for different languages
User avatar
XCID
Posts: 78
Joined: 26 March 2020, 01:45

Re: Getting language from JS?

Post by XCID »

Regarding translatable card texts, does anyone have a good solution for dynamic text size to fit in the availabe space on the card?

What I do is setting a default fontsize, get the height of the div and keep reduceing the font size 1 by 1 until the div height is smaller than the maximum height. Bit I wonder if there is a more elegant and performant solution.
User avatar
User Already Exists
Posts: 30
Joined: 30 January 2020, 05:13

Re: Getting language from JS?

Post by User Already Exists »

It was my understanding that the original poster had different images for different languages (maybe different editions of the game), rather than just different text in the images.

Perhaps one method to get the language would be something like the following, which is clunky but might work:

Code: Select all

switch (_("en")) {
case "en": 
default:
  // use English cards
  break;
case "fr":
  // use French cards
  break;
}
One would then have to ask the translators to translate the string "en" into the ISO 639-1 code of their respective languages. Of course, this is a bit indirect and error prone, since it requires cooperation from translators. If the language information is already available in the framework somehow, that would be more reliable.
User avatar
apollo1001
Posts: 191
Joined: 21 July 2015, 10:41

Re: Getting language from JS?

Post by apollo1001 »

If it is only 2 languages, then rather than trying to do things automatically, you could potentially use english as your default and add a gamepreference where the user can change it to the french cards if they wish to. I wouldn't recommend this if you're going to have more than 2 languages though...
User avatar
Quinarbre
Posts: 140
Joined: 15 December 2013, 23:26

Re: Getting language from JS?

Post by Quinarbre »

Res Arcana does precisely that (default is english, but french cards are displayed for French players).
Take a look at how they did, or ask the devs directly.
Post Reply

Return to “Developers”