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

Any way to change locale at the moment? #2

Closed
ctrinh98 opened this issue Jun 22, 2018 · 5 comments
Closed

Any way to change locale at the moment? #2

ctrinh98 opened this issue Jun 22, 2018 · 5 comments

Comments

@ctrinh98
Copy link

In vanilla moment.js you can change the locale to say “3m” instead of “3 minutes”, “8s” instead of “8 seconds”, etc. by manually redefining the locale function in your JavaScript code. Is there a way to do that here or perhaps in the future?

@rinukkusu
Copy link
Owner

rinukkusu commented Jun 22, 2018

Will look into it! 👍

@rinukkusu rinukkusu reopened this Jun 22, 2018
@rinukkusu
Copy link
Owner

Hi @ctrinh98,

I've implemented that feature - you can now add your own locale or extend the existing english locale if you want to:

class ShortLocaleEn extends LocaleEn {
  String get seconds => '%is';

  String get aMinute => '%im';
  String get minutes => '%im';

  String get anHour => '%ih';
  String get hours => '%ih';

  String get aDay => '%id';
  String get days => '%id';
}

To set the locale for all usages of Moment:

Moment.setLocaleGlobally(new ShortLocaleEn());

To set the locale only for the current instance of Moment:

var moment = new Moment.now().locale(new ShortLocaleEn());

Hope, this works for you! :)

@ctrinh98
Copy link
Author

Thank you so much!! I can't express how incredible that was -- thank you for responding and implementing my request so quickly! This is perfect for what I want to do!

One question -- if I wanted to stop the IdentifierPosition from displaying, how would I set that? I tried writing the following but I keep getting this as an error.

Invalid override. The type of 'ShortLocaleEn.future position' ('() -> IdentifierPosition') isn't a subtype of 'LocaleEn.future position' ('() -> IdentifierPosition').

class ShortLocaleEn extends LocaleEn {
  String get seconds => '%is';

  String get aMinute => '%im';
  String get minutes => '%im';

  String get anHour => '%ih';
  String get hours => '%ih';

  String get aDay => '%id';
  String get days => '%id';
  
  IdentifierPosition get futurePosition => IdentifierPosition.dontDisplay;
}

Again, thank you so much! This is really driving forward my enthusiasm with this Flutter project, hahaha! :)

@rinukkusu
Copy link
Owner

Whoops, I may have forgotten to export IdentifierPosition - please remove your 'package:simple_moment/src/identifier_position.dart' import - this type should come now from the main Import as well! :)

It's corrected in version 0.1.1 I just published.

Also thanks for using and improving this package!! :)

@ctrinh98
Copy link
Author

Works perfectly!! Thank you so much for responding to all my requests so quickly and for making such a useful and great package! You're the best! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants