react-native-datepicker icon indicating copy to clipboard operation
react-native-datepicker copied to clipboard

[help] how to change locale ?

Open ddpdev opened this issue 8 years ago • 24 comments

DatePicker~ i Love it ^^;

but, i don't know how to change moment locale()

help me please ~

ddpdev avatar Dec 20 '16 13:12 ddpdev

I have this question too ..

rocwong-cn avatar Dec 21 '16 03:12 rocwong-cn

Same problem, any idea?

dcolin avatar Dec 21 '16 08:12 dcolin

Hi guys ! @dcolin @ddpdev It depends on what your device locale setting ,when I run on my iPhone ,everything works well for now ...

rocwong-cn avatar Dec 22 '16 09:12 rocwong-cn

@rocwangv You're right! It works well on my simulator and my device.

dcolin avatar Dec 22 '16 09:12 dcolin

So... But I have another problem. The format in my app is defined by user profile. His device is English but his config is Portuguese. So... the correctly format is Protuguese

marquinhoalm avatar Jan 09 '17 16:01 marquinhoalm

Hey guys, maybe this still help someone:

import moment from 'moment'
import 'moment/locale/pt-br'
moment.locale('pt-BR')

You can set this at any point of the app and to set it globally you can put in app.js for example.

cesarcosta99 avatar Sep 09 '17 00:09 cesarcosta99

Valeu, César!

NickBefore avatar Oct 31 '17 17:10 NickBefore

If you only consider IOS, another way to work around is that, we can config global locale for UIDatePicker in - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions.

E.g.

[[UIDatePicker appearance] setLocale:[[NSLocale alloc]initWithLocaleIdentifier:@"zh-Hans"]];

wxy325 avatar Nov 08 '17 08:11 wxy325

Hello guys, I want to have the month's names inside the picker use Vietnamese. I've tried @cesarcosta99 solution but it doesn't work. Do anyone has the solution for this? thanks.

import Moment from "moment";
require("moment/locale/vi");
Moment.locale("vi");

DanteEvil avatar Jan 05 '18 04:01 DanteEvil

Well @DanteEvil that's weird, did you check if vi.js file is in the moment/locale folder inside node_modules? Either way you can update an existing locale and even create a custom locale to achieve what you want, check this out: Moment Customization.

cesarcosta99 avatar Jan 05 '18 13:01 cesarcosta99

My fork include this feature: https://github.com/pablo-albaladejo/react-native-datepicker

<DatePicker locale={'es'} date={this.state.date} mode='date'/>

pablo-albaladejo avatar Feb 23 '18 19:02 pablo-albaladejo

Hello guys, I want to have the month's names inside the picker use Vietnamese. I have to try many solutions but it can't work. Please help me.

ngocnguyen09910060 avatar Feb 26 '18 12:02 ngocnguyen09910060

@ngocnguyen09910060 my fork works:

<DatePicker locale={'vi'} date={this.state.date} mode='date'/>

provides: simulator screen shot - iphone 6 plus - 2018-02-26 at 16 11 17

pablo-albaladejo avatar Feb 26 '18 15:02 pablo-albaladejo

Hi Mr @pablo-albaladejo, Thanks you for your help. I'm a newbie in React Native. Can you explain steps to integrate your fork to an exist project? This is my package information: "react": "16.0.0", "react-native": "0.50.0", "react-native-datepicker": "^1.6.0", I added locale={'vi'} to <DatePicker> but it isn't work. Please help me.

ngocnguyen09910060 avatar Feb 27 '18 02:02 ngocnguyen09910060

Hi @ngocnguyen09910060

Update you package.json as follows:

"react": "16.2.0",
"react-native": "0.52.0",
"react-native-datepicker": "git+https://github.com/pablo-albaladejo/react-native-datepicker.git",

and run

rm -rf node_modules && npm install

pablo-albaladejo avatar Feb 27 '18 06:02 pablo-albaladejo

@wxy325 thanks, solved one of my pain points.

bobzhen avatar Feb 28 '18 15:02 bobzhen

FYI: This has been fixed in version 1.7.0

jenskuhrjorgensen avatar Apr 18 '18 10:04 jenskuhrjorgensen

Locale seems to be still ignored, at least for Android. Tried things like <DatePicker locale='en' or <DatePicker locale={I18n.locale} (after manually changing I18n.locale and seeing it taking effect on other things). No effect, datepicker still in default phone language. Or am I doing it wrong?

andreyboytsov avatar May 29 '18 23:05 andreyboytsov

@andreyboytsov Can you confirm, that you are using "react-native-datepicker": "1.7.0" (or newer)? According to the release notes t was fixed in 1.7.0 - and it works like a charm here using <DatePicker locale={i18n.language}/>.

jenskuhrjorgensen avatar May 30 '18 05:05 jenskuhrjorgensen

@jenskuhrjorgensen Thanks for getting back! "react-native": "0.55.4", "react-native-datepicker": "^1.7.2",

I'll try to come up with some small reproduction example.

andreyboytsov avatar May 30 '18 18:05 andreyboytsov

Hi there,

React-native does not expose a locale param for Android: DatePickerAndroid So it always will be localized as the OS is.

On the other hand, iOS provides this feature: DatePickerIOS

So in Android it is not possible to overwrite the OS locale at native datepicker.

Hope it helps.

pablo-albaladejo avatar May 30 '18 18:05 pablo-albaladejo

Wow, I didn't realize until now that you were talking about Android only! Sry for giving you false hope @andreyboytsov, but @pablo-albaladejo is absolutely right. Hopefully in another release someday soon 😄

jenskuhrjorgensen avatar May 30 '18 18:05 jenskuhrjorgensen

OK.

@pablo-albaladejo @jenskuhrjorgensen Thanks for your assistance!

andreyboytsov avatar May 30 '18 19:05 andreyboytsov

So, can someone tell when will we able to see locale support for Android? Thanks

valeriik avatar Nov 02 '20 19:11 valeriik