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

Languages #14

Closed
medokin opened this issue Nov 13, 2014 · 20 comments
Closed

Languages #14

medokin opened this issue Nov 13, 2014 · 20 comments

Comments

@medokin
Copy link

medokin commented Nov 13, 2014

Is there an easy way to change the language?

@stefanpenner
Copy link
Collaborator

not yet, but seems like a good enhancement.

The questions are:

  • global language option
  • bindable language option?
  • per transform option?
  • what makes the most sense for those using i18n with moment already? (@lukemelia I know we do this, but i don't remember the details, can you provide some feedback here?)

@jasonmit
Copy link
Collaborator

@stefanpenner we should sync up on this. I have made some progress around this area by building an ember-addon for formatjs and would let to vet it.

Bindable languages work
{{format-time today 'hhmmss' locale=locale}}

Per transform option:

{{#x-intl locales='fr-FR'}}
    <p>
        <b>{{format-date today day='numeric' month='long'}}</b>
        <i>('fr-FR' locale)</i>
    </p>
{{/x-intl}}

The one I need to think through is how to globally store a language option.

@stefanpenner
Copy link
Collaborator

maybe 'locale:main' that is configured to be one of the existing locals that could be resolved from

app/locales/en
app/locales/de

@jasonmit
Copy link
Collaborator

👍 great idea

@felipeleusin
Copy link

Hi,
Do you guys need help with this? Began using ember-moment but now need to add support for localization and got kinda stuck... https://github.com/edgycircle/ember-pikaday suggests using the brocfile and a initializer which sounds good for a global setting (my use case). Maybe something along this lines?

@jasonmit
Copy link
Collaborator

I am days away from releasing ember-intl which has relative time and date support using the native Intl API. Moment is not a dependency either. It will likely be released tomorrow or Thursday as the latest.

The syntax will be nearly identical to handlebars-intl

@jasonmit
Copy link
Collaborator

https://github.com/yahoo/ember-intl the helper you are looking for is like format time date and relative


Sent from Mailbox

On Tue, Jan 27, 2015 at 5:52 PM, Felipe Leusin notifications@github.com
wrote:

Hi,

Do you guys need help with this? Began using ember-moment but now need to add support for localization and got kinda stuck... https://github.com/edgycircle/ember-pikaday suggests using the brocfile and a initializer which sounds good for a global setting (my use case). Maybe something along this lines?

Reply to this email directly or view it on GitHub:
#14 (comment)

@stefanpenner
Copy link
Collaborator

@jasonmit nice!

@larryisthere
Copy link

This feature is needed strongly. I'd prefer a global configuration.

Maybe this is helpful:
https://www.npmjs.com/package/handlebars-helper-moment

@jasonmit
Copy link
Collaborator

jasonmit commented Feb 1, 2015

I'd prefer a global configuration

moment.locale('fr');  // Set the default/global locale

Of course that wouldn't result in bound helpers, but perhaps something you can use until it's implemented.

@jelhan
Copy link

jelhan commented Apr 9, 2015

I'm using ember-cli-i18n which stores current locale as locale property of application. I use an initializer to set locale for moment on init and register an observer for locale changes which updates moment locale. I'm currently not using ember-moment but a helper to format dates with moment. But this solution doesn't update already formatted dates. I'm also using ember-cli-bootstrap-datepicker which uses a bindable locale option.

Since there isn't a common way to store locale setting in application yet I would prefer using a bindable locale option in ember-moment. If you decide to support a global locale option following ember-cli-i18n and use locale property of application would probably the best way to go.

@jelhan
Copy link

jelhan commented Apr 9, 2015

I was able to update my little moment helper to observe locale changes and rerender view. Perhaps it's a starting point. I'm not sure if rerender helper view is the right way to go.

import Ember from "ember";
/* global moment */

export default function(date, options) {
  var format = options.hash.format ? options.hash.format : 'LLLL',
      application = this.get('container').lookup('application:main'),
      self = this;

  Ember.addObserver(application, 'locale', self, self.rerender);

  return moment(date).format( format );
}

@jasonmit
Copy link
Collaborator

@jelhan usually the locale does not change throughout the lifetime of app. Are you sure you need to observe locale versus forcing an app reload in the event the user does change their locale.

I say this because I'm in the process of ripping this functionality out of ember-intl and would like to hear your use case.

Also, are you removing the observer when the view is destroyed?

@jelhan
Copy link

jelhan commented Apr 11, 2015

@jasonmit I have to support on-the-fly switching of locales without a reload of page in my app and therefore moved from ember-i18n to ember-cli-i18n. Of course it depends on your project if on-the-fly update of locales is needed or if observing locales should be avoided due to performance issues.

@jasonmit
Copy link
Collaborator

I have to support on-the-fly switching of locales without a reload of page in my app

I should have been more clear, you get this behavior if you force an app reset on locale change. You now don't take the perf hit and you aren't re-fetching your assets.

var app = this.container.lookup('application:main');
app.reset();

@seven7seven
Copy link

Changing locales doesn't seem to work for me right now. I added a default locale, as specified in the README, but moment's locale seems to be set in tone to 'en'. Any luck with this?

@jelhan
Copy link

jelhan commented Jul 31, 2015

@jasonmit app.reset(); does reset model and therefore does not meet all my requirements. Had discussed the issue without real solution sometime ago on stackoverflow. ember-i18n observes locale changes since 4.0.0 which was released two month ago. At least since that change other addons dealing with locales should also observe locale changes.

@seven7seven Do you include the locale you specified as default locale? Also have a check if your default locale is supported by moment.js.

@jasonmit
Copy link
Collaborator

@seven7seven are you able to reproduce this and show me so I can look into it.

@jelhan

At least since that change other addons dealing with locales should also observe locale changes.

I'd be happy to review a pull request but I don't feel this functionality of changing your locale to trigger a rerender covers the 80% usecase. And as I said above, ember-intl does support the functionality you are after and supports date, time and relative time formatting.

@jasonmit
Copy link
Collaborator

jasonmit commented Aug 7, 2015

#75 will allow for inlining locales, global is supported and documented

@jasonmit
Copy link
Collaborator

jasonmit commented Aug 7, 2015

Closing as there is now documentation on setting global and local locales

@jasonmit jasonmit closed this as completed Aug 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants