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

i18n #6

Open
Garito opened this issue Nov 21, 2014 · 16 comments
Open

i18n #6

Garito opened this issue Nov 21, 2014 · 16 comments

Comments

@Garito
Copy link

Garito commented Nov 21, 2014

Hi!
I would like to use your library with internationalization so I was digging the code

Did you notice that moment by itself has the strings your code needs to make the precise range?

Would be nice to make a deeper integration with the dependency and it will gain automatic translation

Are you interested on this issue?

Thanks!!!

@codebox
Copy link
Owner

codebox commented Nov 22, 2014

Hi,
When I was writing the plugin I looked through the moment.js code to see if it had all the strings I needed, I could find some but not all of them. It would be a much better solution if I could use the built-in strings, for i18n as you describe. Are you sure they are all there (including plurals ie hour/hours etc), if so can you point me to them?
many thanks
Rob

@Garito
Copy link
Author

Garito commented Nov 22, 2014

Sure!
You could use _relativeTime. The internationalization mechanism use it to do so

The actual line: https://github.com/moment/moment/blob/develop/moment.js#L947

Cheers!

@codebox
Copy link
Owner

codebox commented Nov 22, 2014

Yes, I think I saw that when I was looking over the moment.js code - it's close to what I would need, but doesn't quite cover everything. There is no string for '1 second' (the closest is 'a few seconds') and also the singular phrases for minutes, hours etc all use 'a' or 'an' rather than '1' - I think it would look odd if the plugin produced output that was a mixture, like '2 hours a minute 3 seconds' rather than '2 hours 1 minute 3 seconds'

@Garito
Copy link
Author

Garito commented Nov 22, 2014

Would be nice to make it very configurable for this kind of things
I think that the correct way to act it to ask to the monents creators to add the few options you miss
I found you by their website, I think they will be ok with your needs

@nlaplante
Copy link

👍 for this.

@miguelcobain
Copy link

👍

3 similar comments
@dellheng
Copy link

👍

@dbrgn
Copy link

dbrgn commented Dec 14, 2015

👍

@ZalemCitizen
Copy link

👍

@codebox
Copy link
Owner

codebox commented Apr 7, 2016

I have added a returnValueObject parameter to the preciseDiff methods, setting this value to true will cause the methods to return a value object containing the numeric results of the diff calculation. Hopefully this should help people who require internationalisation - they can let the library do the maths and use their own language files to turn the result into words.

@IvanRF
Copy link

IvanRF commented Jun 5, 2016

@codebox it's a pity you can't reuse relativeTime, you almost have all translations there:

relativeTime : {
            future : 'in %s',
            past : '%s ago',
            s : 'a few seconds',
            m : 'a minute',
            mm : '%d minutes',
            h : 'an hour',
            hh : '%d hours',
            d : 'a day',
            dd : '%d days',
            M : 'a month',
            MM : '%d months',
            y : 'a year',
            yy : '%d years'
},

What if you suggest to add ss : '%d seconds', to moment.js?

@TWiStErRob
Copy link

@IvanRF you mean like this? moment/moment#4183

@borisBelloc
Copy link

borisBelloc commented Apr 3, 2020

can someone tell me if there is a solution about this issue ?

I'm trying to translate the result of
moment("2020-03-17 12:00:00").preciseDiff(moment());

17 days 2 hours 20 minutes 36 seconds

to french but I don't find how to do it...

Every thread refer to #6 but I don't see any tips about it :(

I "found' those lines in the moment-precise-range.js :

    var STRINGS = {
        nodiff: '',
        year: 'year',
        years: 'years',
        month: 'month',
        months: 'months',
        day: 'day',
        days: 'days',
        hour: 'hour',
        hours: 'hours',
        minute: 'minute',
        minutes: 'minutes',
        second: 'second',
        seconds: 'seconds',
        delimiter: ' '
    };

helas, I have no idea how to overide it

@codebox
Copy link
Owner

codebox commented Apr 3, 2020

@borisBelloc probably best you can do is to call preciseDiff(moment(), true) which will give you an object back with the numeric values for seconds, minutes, hours etc and then build up the string yourself

@borisBelloc
Copy link

thanks for the fast answer 👍 👍

@ugurcanalyuz
Copy link

ugurcanalyuz commented Jan 29, 2023

I wrote in Turkish, but this code will work.

const append = () => {
   const times = moment.preciseDiff(text, new moment(), true)
   let returnText = ''
   if (times.days > 0) {
      returnText = `${times.days} Gün, ${times.hours} Saat, ${times.minutes} Dakika`
   } else if (times.hours > 0) {
      returnText = `${times.hours} Saat, ${times.minutes} Dakika`
   } else if (times.minutes > 0) {
      returnText = `${times.minutes} Dakika, ${times.seconds} Saniye`
   } else {
      returnText = `Son Dakika Teklif Verilemez`
   }
   return returnText
}

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