ios & android: detect current language [SOLVED]
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
ios & android: detect current language [SOLVED]
Is there a way to detect the current language on mobile device ?
My aim is to adapt the language of the visual novel according to the language of the device
My aim is to adapt the language of the visual novel according to the language of the device
Last edited by Jibus on Wed Jul 22, 2015 6:17 pm, edited 1 time in total.
- PyTom
- Ren'Py Creator
- Posts: 16096
- Joined: Mon Feb 02, 2004 10:58 am
- Completed: Moonlight Walks
- Projects: Ren'Py
- IRC Nick: renpytom
- Github: renpytom
- itch: renpytom
- Location: Kings Park, NY
- Contact:
Re: Mobile devlopment : detect current language
I don't know of any. If you can find an android or iOS API that can do this, it's something I can add to Ren'Py.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom(When was the last time you backed up your game?)
Software > Drama • https://www.patreon.com/renpytom
Re: Mobile devlopment : detect current language
In Python, I suppose ?
Re: Mobile devlopment : detect current language
ios :
NSString * language = [[NSLocale preferredLanguages] objectAtIndex:0];
Can we mimic this with Pyobjus ?
android :
Locale.getDefault().getDisplayLanguage()
NSString * language = [[NSLocale preferredLanguages] objectAtIndex:0];
Can we mimic this with Pyobjus ?
android :
Locale.getDefault().getDisplayLanguage()
Re: Mobile devlopment : detect current language
I am trying to detect the current local with Pyobjus, but i am bit stuck.
preferredLanguages should return the user's language preference order as an array of strings.
But current_language seems to be empty
Code: Select all
init python:
if renpy.ios:
import pyobjus
NSLocale = pyobjus.autoclass("NSLocale")
languages = NSLocale.preferredLanguages()
current_language = languages[0]
But current_language seems to be empty
- PyTom
- Ren'Py Creator
- Posts: 16096
- Joined: Mon Feb 02, 2004 10:58 am
- Completed: Moonlight Walks
- Projects: Ren'Py
- IRC Nick: renpytom
- Github: renpytom
- itch: renpytom
- Location: Kings Park, NY
- Contact:
Re: Mobile devlopment : detect current language
Have you tried languages.objectAtIndex_(0) ?
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom(When was the last time you backed up your game?)
Software > Drama • https://www.patreon.com/renpytom
Re: Mobile devlopment : detect current language
Code: Select all
if renpy.ios:
import pyobjus
NSLocale = pyobjus.autoclass("NSLocale")
languages = NSLocale.preferredLanguages()
current_language = str(languages.objectAtIndex_(0))
Code: Select all
___main___-____NSCFString object at 0x121ac4f50
- PyTom
- Ren'Py Creator
- Posts: 16096
- Joined: Mon Feb 02, 2004 10:58 am
- Completed: Moonlight Walks
- Projects: Ren'Py
- IRC Nick: renpytom
- Github: renpytom
- itch: renpytom
- Location: Kings Park, NY
- Contact:
Re: Mobile devlopment : detect current language
Maybe,
current_language = languages.objectAtIndex_(0).UTF8String().decode("utf-8")
will turn it into a unicode string properly.
current_language = languages.objectAtIndex_(0).UTF8String().decode("utf-8")
will turn it into a unicode string properly.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom(When was the last time you backed up your game?)
Software > Drama • https://www.patreon.com/renpytom
Re: Mobile devlopment : detect current language
Yes ! It's working ! Thanks you PyTom
Here is the full code to get the current language in ios
I will now look for android and post the result in this thread
Here is the full code to get the current language in ios
Code: Select all
if renpy.ios:
import pyobjus
NSLocale = pyobjus.autoclass("NSLocale")
languages = NSLocale.preferredLanguages()
current_language = languages.objectAtIndex_(0).UTF8String().decode("utf-8")
Re: Mobile devlopment : detect current language
And here is the working code for android device :
Code: Select all
if renpy.android:
from jnius import autoclass
Locale = autoclass('java.util.Locale')
current_language = str(Locale.getDefault().getLanguage())
- PyTom
- Ren'Py Creator
- Posts: 16096
- Joined: Mon Feb 02, 2004 10:58 am
- Completed: Moonlight Walks
- Projects: Ren'Py
- IRC Nick: renpytom
- Github: renpytom
- itch: renpytom
- Location: Kings Park, NY
- Contact:
Re: ios & android: detect current language [SOLVED]
Can I include this code in a future version of Ren'Py?
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom(When was the last time you backed up your game?)
Software > Drama • https://www.patreon.com/renpytom
Re: ios & android: detect current language [SOLVED]
No need to ask Of course !
Re: ios & android: detect current language [SOLVED]
Bump this thread. I notice that the code for ios doesn't work anymore in the latest release.
I was wondering if you have change something that may have impacted this ?
Thanks in advance !
I was wondering if you have change something that may have impacted this ?
Thanks in advance !
- PyTom
- Ren'Py Creator
- Posts: 16096
- Joined: Mon Feb 02, 2004 10:58 am
- Completed: Moonlight Walks
- Projects: Ren'Py
- IRC Nick: renpytom
- Github: renpytom
- itch: renpytom
- Location: Kings Park, NY
- Contact:
Re: ios & android: detect current language [SOLVED]
What's broken about it?
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom(When was the last time you backed up your game?)
Software > Drama • https://www.patreon.com/renpytom
Re: ios & android: detect current language [SOLVED]
Found it!
It seems that iOS returns now the language and the region, ie: en-US.
Updated code:
current_language[0] contains the language code and current_language[1] the region code.
It seems that iOS returns now the language and the region, ie: en-US.
Updated code:
Code: Select all
init python:
if renpy.ios:
import pyobjus
NSLocale = pyobjus.autoclass("NSLocale")
languages = NSLocale.preferredLanguages()
current_language_region = languages.objectAtIndex_(0).UTF8String().decode("utf-8")
current_language = current_language_region.split("-")
Who is online
Users browsing this forum: Bing [Bot], jeffster