question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Localization : feature?

See original GitHub issue

Description of the Issue and Steps to Reproduce:

Did you search for duplicate issue? [Yes / No]

Please describe the issue and steps to reproduce, preferably with a code sample / plunker: I guess this is more of a question than an issue, but I haven’t found any info on this anywhere. Terribly sorry if this is the wrong place to post. But here goes:

Is there any way to localize the output of moment using this module? I know moment has the .locale() function, but I haven’t gotten that to work, and I can’t see any functions in this library where I could set the locale either. My goal is to allow for swedish translations as well as english, but I’ve had no luck. Any help would be very much appreciated.

Thank you

Ensure your issue is isolated to angular2-moment. Issues involving third party tools will be closed unless submitted by the tool’s author/maintainer.

Environment:

Please answer the following questions:

  • Angular version? final ^2.0.0
  • TypeScript version? ^2.0.3
  • moment version? ^2.15.2
  • Are you using moment-timezone? no
  • Are you using the angular-cli? Not sure? Probably
  • Using Rollup/Webpack/System.js/Ionic/similar? Ionic 2, with rollup.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:11

github_iconTop GitHub Comments

12reactions
davorpeiccommented, Jan 5, 2017

For someone trying to use locales in ionic 2 app, I just included lang module as instructed by @Alx101 in app.module.ts after including angular2-moment like this and that automatically pulled spanish language

import { MomentModule, DateFormatPipe } from 'angular2-moment';
import 'moment/locale/es';

dp

5reactions
Alx101commented, Oct 28, 2016

I solved this now by using the moment package directly and setting locale there. I will post a snippet in case anyone else needs it. But it would still be nice to have locales included in this module and functions for switching them. All credit goes to the user reedrichards over at the ionic forums (github is @peterpeterparker, again thank you) , who posted this excellent solution:

  1. Install momentis sudo npm install moment --save
  2. Install typescript definition for moments sudo npm install --save-dev @types/moment
  3. Import moment in one of your typescript class like following import moment from 'moment';
  4. If you want to define swedish to use as locales for moment (not 100% sure it’s ‘se’ but most probably) <-- it was sv, but close enough 😉 moment().locale('sv');

4.a Remember to import the locale as described in the P.S import 'moment/src/locale/sv';

  1. If you want to display a date like ‘26 oktober 2016 kl. 21:39’, do following (you find all pattern at the end of following page http://momentjs.com) moment(new Date()).format('LLL');
  2. If you want to add 5 days to today moment(new Date()).add(5, 'd').toDate()

P.S.: If the locales doesn’t work, you may need to include explicitly the locales you want to use. For me it’s the case. It works when I debug but when I test on my real phone it doesn’t work (just tested right now). Therefore import it like following (I’m not sure if its needed or not…):

import 'moment/src/locale/sv';

Read more comments on GitHub >

github_iconTop Results From Across the Web

What Is Localization? - Localize
Localize is a translation management system that simplifies your workflow and localization process with powerful features like glossaries, style guides, ...
Read more >
Localization | Apple Developer Documentation
Localization is the process of translating and adapting your app into multiple languages and regions. Localize your app to provide access for users...
Read more >
Feature localization and identification - ScienceDirect.com
To localize a feature in the visual field the involvement of the second attentional stage is required. The attentional stage allows features that...
Read more >
Localization Features of the Core Components
Localization Features of the Core Components. Many websites require content to be delivered in a localized format across multiple languages ...
Read more >
Classification of localization features - Dynamics 365
Localization features must be classified as either regulatory or competitive in the Business process modeler (BPM) library in Microsoft Dynamics ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found