Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Locale doesn't set from ShadApp in ShadDatePicker #263

Closed
patricknicolosi opened this issue Jan 22, 2025 · 1 comment · Fixed by #264
Closed

Locale doesn't set from ShadApp in ShadDatePicker #263

patricknicolosi opened this issue Jan 22, 2025 · 1 comment · Fixed by #264
Assignees
Labels
accepted A valid and reproducible issue bug Something isn't working

Comments

@patricknicolosi
Copy link

patricknicolosi commented Jan 22, 2025

Steps to reproduce

Following this guide the Locale passed in ShadApp does not set the Locale in ShadDatePicker.

Expected results

Actual results

shadcn_ui version

0.18.0

Platform

Windows

Code sample

ShadApp(
      locale: Locale("it"),
      navigatorKey: navigatorKey,
      localizationsDelegates: [
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      supportedLocales: [Locale('it')],
)

Screenshots or Video

No response

Logs

No response

Flutter Doctor output

@patricknicolosi patricknicolosi added bug Something isn't working triage Issues that need assessment and prioritization labels Jan 22, 2025
@nank1ro nank1ro added accepted A valid and reproducible issue and removed triage Issues that need assessment and prioritization labels Jan 23, 2025
@nank1ro nank1ro self-assigned this Jan 23, 2025
@nank1ro
Copy link
Owner

nank1ro commented Jan 23, 2025

Thanks for filling the issue.

I'm merging a PR to take the locale in consideration.
For the selected date, the ordinal day is only supported in English, this is the default used by ShadDatePicker

  String defaultDateFormat(DateTime date, Locale locale) {
    final ordinalDay = date.getOrdinalDay();
    final month =
        intl.DateFormat('MMMM', locale.toLanguageTag()).format(date); // October
    final year =
        intl.DateFormat('y', locale.toLanguageTag()).format(date); // 2024
    return '$month $ordinalDay, $year'; // October 1st, 2024
  }

I suggest creating a custom date format for italian, like:

  String dateFormat(DateTime date, Locale locale) {
    final month =
        DateFormat('MMMM', locale.toLanguageTag()).format(date); // gennaio
    final year = DateFormat('y', locale.toLanguageTag()).format(date); // 2025
    return '${date.day} $month $year'; // 1 gennaio 2024
  }

  final locale = Localizations.localeOf(context);

  ShadDatePicker(
            formatDate: (date) => dateFormat(date, locale),
          )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted A valid and reproducible issue bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants