Skip to content

Android: Date formatting issue in React Native for Chinese locales #2123

@auroursa

Description

@auroursa

Describe the bug

In a React Native application, when formatting dates for Chinese locales (both Simplified and Traditional Chinese), the date output is incorrect on Android devices, but works correctly on iOS.

On Android, the date is output in an incorrect or default format, while on iOS, the expected localized format for Chinese is output correctly.

To Reproduce

I take Simplified Chinese (zh-CN) as an example.

import React from "react";
import { StyleSheet, Text, View } from "react-native";
import { I18nProvider } from "@lingui/react";
import { setupI18n, I18n} from "@lingui/core";

const i18n = setupI18n({
  locales: ["zh-CN"],
});

function localizedDate(i18n: I18n, date: number | string | Date) {
  const d = new Date(date);
  return i18n.date(d, {
    dateStyle: "long",
    timeStyle: "short",
  });
}

const App = () => {
  const date = "2024-12-14T12:00:00Z";
  const formattedDate = localizedDate(i18n, date);

  return (
    <I18nProvider i18n={i18n}>
      <View style={styles.container}>
        <Text>{`Formatted date: ${formattedDate}`}</Text>
      </View>
    </I18nProvider>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: "center",
    alignItems: "center",
  },
});

export default App;

Android: December 14 2024 at 12:00 PM

iOS: 2024年12月14日 12:00

Expected behavior

The date should be correctly localized on Android, just like it does on iOS.

  • jsLingui version 5.1.0
  • Babel version 7.26.0
  • Macro support:
  • I'm using SWC with @lingui/swc-plugin
  • I'm using Babel with babel-macro-plugin
  • I'm not using macro
  • Your Babel config (e.g. .babelrc) or framework you use (Create React App, NextJs, Vite)
    Framework: React Native 0.76.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions