μ΄κ²μ λ΄κ° κ°μ§κ³ μμ§λ§ μλνμ§ μμ΅λλ€.
import moment from 'moment'
import 'moment/min/moment-with-locales'
import 'moment-duration-format' // used by moment
componentDidMount () {
console.log(moment.locale())
console.log(moment.locale('zh-cn'))
console.log(moment.locale())
}
μ½μ λ‘κ·Έ μΆλ ₯: en, en, en
μμ μ½μ λ‘κ·Έ μΆλ ₯: en, zh-cn, zh-cn
'moment'μμ 'moment/min/moment-with-locales'λ‘ μκ° κ°μ Έμ€κΈ°λ₯Ό λ³κ²½νλ €κ³ μλνμ§λ§ μ΄ μ€μμ μ€λ₯κ° λ°μν©λλ€.
const total = moment.duration(this.props.stoveUsage.total, 'seconds').format('H:mm', { trim: false })
μ€λ₯: momentWithLocales2.default.duration(...).formatμ ν¨μκ° μλλλ€.
moment.locale('es')
λ React Nativeμμ λμκ² μλ¬΄λ° μν₯μ λ―ΈμΉμ§ μλλ€λ κ²μ νμΈν©λλ€.
import 'moment/min/moment-with-locales'
νΈλ¦μ μνν©λλ€!
moment.locale('fr'); moment().format("ll");
κ²°κ³Όλ μμλλ‘ "1 fΓ©vr. 2018"
μ
λλ€.
λͺ¨λ λ‘μΌμΌ λ°μ΄ν°λ₯Ό λ‘λνλ moment-with-locales
λ₯Ό μ¬μ©νμ§ μμΌλ €λ©΄ v2.18 μμ μΌλ‘ λ‘€λ°±νμ¬ μ΄ λ¬Έμ λ₯Ό ν΄κ²°νμ΅λλ€. μκ° v2.20κ³Ό λ°μ λ€μ΄ν°λΈμμ λ‘μΌμΌμ μ€μ νλ λ²κ·Έκ° λΆλͺ
ν μμ΅λλ€.
@Leeds-eBooks λͺ¨λ©νΈλ₯Ό κ°μ Έμ€λ λ°©λ²μ μ€λͺ ν΄ μ£Όμκ² μ΅λκΉ? 2.18λ‘ λ‘€λ°±νμ§λ§ λ‘μ»¬μ΄ λ°μ λ€μ΄ν°λΈμμ μ λλ‘ μλνλλ‘ νλ €λ©΄ λ‘μΊμ΄ μλ μκ°μμ μκ°μ κ°μ ΈμμΌ ν©λλ€.
κ°μ¬ ν΄μ
@msevestre λ€, λ¬Όλ‘ , μ μ루μ μ΄ μ§κΈμ ꡬμμΌ μ μλ€κ³ μκ°νμ§λ§, μ μ½λμμ μλνλλ‘ λ§λ€κ³ κ³μ μ§ννμ΅λλ€. λͺ¨λ©νΈμ μ΄ν λ²μ μμ μμ νμ μλ μμ΅λλ€. κ·ΈλΌμλ λΆκ΅¬νκ³ λ΄ μμ μ¬νμ λ€μκ³Ό κ°μ΅λλ€.
moment
λμ gitμμ https://github.com/tqc/moment.git#no-dynamic-import
μ€μΉimport moment from 'moment'
import 'moment/src/locale/en-gb'
import 'moment/src/locale/es'
import 'moment/src/locale/fr'
import 'moment/src/locale/pl'
import 'moment/src/locale/pt'
// ...etc
// bonus trick!
import DeviceInfo from 'react-native-device-info'
const deviceLocale = DeviceInfo.getDeviceLocale()
moment.locale([deviceLocale, 'en'])
μ΄κ²μ΄ μ κ° νκ³ μλ μΌμ΄κ³ μ μκ² ν¨κ³Όμ μ΄μ§λ§ μ κ° λ§νλ―μ΄ λ μ΄μ νμνμ§ μμ μλ μμ΅λλ€.
@Leeds-eBook κ΅μ₯ν©λλ€. λΉ λ₯Έ νΌλλ°±μ κ°μ¬λ립λλ€. μ λ§ λμμ΄ λμμ΅λλ€
μ΄κ²μ λμκ² ν¨κ³Όκ° μμκ³ ,
https://momentjs.com/docs/#/i18n/instance -locale/
App.jsμμ μνλ κ²λ³΄λ€ λͺ¨λ λ¨μ΄λ₯Ό μΈμ΄λ‘ μΈμ€ν΄μ€νν΄μΌ ν©λλ€. μ΄κ²μ λͺ¨λ μ ν리μΌμ΄μ
μμ μλν©λλ€.
@VanessaChu - μ¬μ ν λ¬Έμ κ° μμ΅λκΉ?
μ΄ μ루μ μ μ μκ² ν¨κ³Όμ μ λλ€.
μλ
νμΈμ μ¬λ¬λΆ, import 'moment/locale/fr';
μ΄ μ μκ² ν¨κ³Όμ μ΄μ§λ§ κΈ°μ‘΄μ λͺ¨λ μΈμ΄λ₯Ό κ°μ Έμ¬ νμκ° μλ κ²κ³Ό κ°μ΄ λμ μΈμ΄λ₯Ό μννλ €λ κ²½μ° import 'moment/locale/[variable]'
where variable νμν μΈμ΄μ
λκΉ?
λͺ¨λ κ΅κ°μμ μλνλλ‘... :/
λλΆλΆμ ν λ‘ μ°Έκ°μκ° λ¬Έμ λ₯Ό ν΄κ²°νμΌλ©΄ μ’κ² μ΅λλ€. :) κ°μ¬ν©λλ€. @Leeds-eBook
3.xμ κ²½μ° λμ κ°μ Έμ€κΈ°/es6μ΄ μκ±°λ μλ λ λ§μ λ²μ μ μκ°μ΄ μμ μ μμΌλ―λ‘ μ΄λ λ¬Έμ κ° λμ§ μμ΅λλ€.
μλ
νμΈμ @MayeuldP ,
Reactjs/ReactNativeμμ μκ°μ λ€μν μΈμ΄λ₯Ό μ¬μ©νμ¬ μμ νκΈ° μν΄ λμ°©νλμ§ λͺ¨λ₯΄κ² μ§λ§ λκ΅°κ°μκ² λμμ΄ λ μ μλ μ루μ
μ 곡μ νκ³ μΆμ΅λλ€.
λ¬Ένλ³λ‘ λ¬Ένλ₯Ό κ°μ Έμ¬ νμκ° μμ΅λλ€. import 'moment/min/locales'
λ§ μΆκ°νλ©΄ λμ€μ μ’μνλ λ¬Ένλ‘ moment.local('')μ μ€μ ν μ μμ΅λλ€.
μ λ v2.18μ μ¬μ©νκ³ μμΌλ©° μ΄ λ°©λ²μ΄ μλν©λλ€.
import moment from 'moment';
import momentFR from 'moment/src/locale/fr'
moment.locale('fr',momentFR );
μλ νμΈμ, @KashifAhmed v.2.22.2 μμλ moment.updateLocale('fr',momentFR)μ μ¬μ©ν΄μΌ ν©λλ€.
μ¬μ© μ€λ¨ κ²½κ³ : moment.updateLocale(localeName, config)μ μ¬μ©νμ¬ κΈ°μ‘΄ λ‘μΌμΌμ λ³κ²½νμμμ€. moment.defineLocale(localeName, config)μ μ λ‘μΌμΌ μμ±μλ§ μ¬μ©ν΄μΌ ν©λλ€. μμΈν λ΄μ©μ http://momentjs.com/guides/#/warnings/define -locale/μ μ°Έμ‘°νμμμ€.
μ΄κ²μ νμΈνμμμ€:
import moment from "moment";
import 'moment/min/locales'
μ¬κΈ°μλ μκ°μ λͺ¨λ languaje ꡬμ±μ΄ ν¬ν¨λλ©° jsμ΄λ―λ‘ ν¬κΈ°μ λ¬Έμ κ° μμ΅λλ€.
λλ μ΄λ€ μ¬λμ΄ λ€λ₯Έ μΈμ΄λ‘ λͺ¨λ°μΌλ‘ μ±μ μ€μΉν λ λ¬Έμ κ° μμμ΅λλ€.
μ΄κ²μμ λΉμ μ λ¬Έμ μμ΄ μκ° μ μ λ λͺ¨λ λ‘μΌμΌμ μ€μ ν μ μμ΅λλ€.
moment.locale('es');
λλ @benadamstylesμ μμ κ°μ΄ μ₯μΉ λ‘μΌμΌμ κ±±μ νμ§ μκ³ μ¬μ©νλ κ²μ languajes μ¬μμ λ²μ΄λ©λλ€.
μ κ²½μ°μλ import λ‘μΌμΌλ§μΌλ‘λ μΆ©λΆνμ§ μμμ κ°μ Έμ¨ μ¬μ μ μ¬μ©νκ³ λ°μ€ _
μΈ μ²« λ²μ§Έ λ¬Έμλ₯Ό μ κ±°νμ΅λλ€.
import moment from 'moment';
import momentPTBR from 'moment/src/locale/pt-br';
function prepareLocale(locale) {
for (const key in locale) {
if (locale.hasOwnProperty(key)) {
// remove first character underscore fom key, i.e. '_calendar' => 'calendar'
locale[key.substring(1)] = locale[key];
}
}
return locale;
}
moment.defineLocale('pt-br', prepareLocale(momentPTBR));
import 'moment/src/locale/en-gb'
λ μλνμ§ μμμ§λ§ import 'moment/locale/en-gb'
λ μλνμ΅λλ€.
"dependencies": {
"expo": "32.0.0",
"moment": "2.24.0",
"react": "16.5.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz"
},
νΈλ¦¬μ μ΅μμ νμΌμμ λ΄ μ½λλ λ€μκ³Ό κ°μ΅λλ€.
import moment from 'moment'
import 'moment/locale/en-gb'
const momentLocale = moment.locale('en-gb')
if (momentLocale !== 'en-gb') {
throw new Error(`Moment fell back to locale ${momentLocale}`)
}
export default () => null
μ λ v2.18μ μ¬μ©νκ³ μμΌλ©° μ΄ λ°©λ²μ΄ μλν©λλ€.
`
import moment from 'moment'; import momentFR from 'moment/src/locale/fr' moment.locale('fr',momentFR );
λͺ κ°μ§ μλ₯Ό λ€μ΄ μ£Όμκ² μ΅λκΉ?
μ λ§ κ°μ¬ν©λλ€!
λ΄ λ²μ μ 2.24μμ 2.18λ‘ λ³κ²½νλλ° μ΄μ μλν©λλ€. 2.20 μ΄ν μ΄λκ°μ λ²κ·Έκ° μμ΅λλ€.
λλ₯Ό μν μΌ
import moment from 'moment'
import 'moment/locale/pt-br'
moment.locale('pt-br')
λλ₯Ό μν μΌ
import moment from 'moment' import 'moment/locale/pt-br' moment.locale('pt-br')
.locale()
μμ λλ €λ°λ κΈμ‘μ΄ μ€μ ν κ²μΈμ§ νμΈνμμμ€. μ‘°μ©ν λ€λ‘ λμ΄μ§λλ€.
κ°μ₯ μ μ©ν λκΈ
import 'moment/min/moment-with-locales'
νΈλ¦μ μνν©λλ€!
moment.locale('fr'); moment().format("ll");
κ²°κ³Όλ μμλλ‘
"1 fΓ©vr. 2018"
μ λλ€.