Open Garito opened 9 years ago
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
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!
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'
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
:+1: for this.
:+1:
:+1:
:+1:
:+1:
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.
@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?
@IvanRF you mean like this? https://github.com/moment/moment/pull/4183
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
@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
thanks for the fast answer 👍 👍
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
}
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!!!