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

Change the language #177

Closed
bimoware opened this issue Jan 30, 2022 · 2 comments
Closed

Change the language #177

bimoware opened this issue Jan 30, 2022 · 2 comments

Comments

@bimoware
Copy link

bimoware commented Jan 30, 2022

I already have a function for this :

function ms(value,long,fr){
  if(!value) return 0;
  try {
    let res = require('ms')(value,{ long });
    if(typeof res === "string" && fr) res = res
      .replace('years','années')
      .replace('weeks','semaines')
      .replace('days','jours')
      .replace('hours','heures')
      .replace('seconds','secondes')
      .replace('milliseconds','millisecondes');
    return res;
  } catch(err){
    console.error(err);
    return;
  }

But still would be cool to be able to change the language returned

ms('2d').locale('fr') // 2 jours
ms('3y').locale('fr') // 3 années

Here, it's 'fr' for french but it could be 'en' for English (which would be by default) or whatever language people could help to support in the pull requests.

@italodeandra
Copy link

As a future reference: ms only has days, hours, minutes and seconds implemented when formatting instead of parsing.

@leerob
Copy link
Member

leerob commented Jul 11, 2022

As @italodeandra mentioned, this library is focused specifically for time parsing.

@leerob leerob closed this as completed Jul 11, 2022
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

3 participants