0

I'm localazing my app.

//localization.js
export const dateFormat = {
  US: 'M/d/yyyy',
  AL: 'yyyy-MM-dd',
  TR: 'dd.MM.yyyy'
}

//page.js
import { dateFormat } from "../../Config/localization";
import * as RNLocalize from "react-native-localize";

class page extends React.Component {
    constructor(props) {
        super(props);
        const getLocales = RNLocalize.getLocales();

        this.state = {
            countryCode: getLocales[0].countryCode,
            dateFormat: dateFormat
        }
    }

    componentDidMount() {
        console.log(this.state.countryCode); //TR
        console.log(this.state.dateFormat.US); //M/d/yyyy
    }
}

In the second console.log, US statically defined.

I want to get Date Format according to Country Code.

Something like:

console.log("User Date Format:: " + this.state.dateFormat.countryCode) // dd.MM.yyyy

How can I achieve this?

ilvthsgm
  • 586
  • 1
  • 8
  • 26

0 Answers0