mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2026-02-03 20:51:07 -05:00
fix(i18n): remove unneeded special cases for relative time (#10691)
Followup to https://codeberg.org/forgejo/forgejo/pulls/6154 en-US: two days ago -> 2 days ago two weeks ago -> 2 weeks ago two months ago -> 2 months ago two years ago -> 2 years ago Other locales still require changes to ensure that the relative time numbering is consistent. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/10691 Reviewed-by: 0ko <0ko@noreply.codeberg.org> Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: lily <lesson085@gmail.com> Co-committed-by: lily <lesson085@gmail.com>
This commit is contained in:
parent
01fbb1499f
commit
66d83702a3
4 changed files with 5 additions and 25 deletions
|
|
@ -49,13 +49,9 @@
|
|||
"other": "%d years ago"
|
||||
},
|
||||
"relativetime.1day": "yesterday",
|
||||
"relativetime.2days": "two days ago",
|
||||
"relativetime.1week": "last week",
|
||||
"relativetime.2weeks": "two weeks ago",
|
||||
"relativetime.1month": "last month",
|
||||
"relativetime.2months": "two months ago",
|
||||
"relativetime.1year": "last year",
|
||||
"relativetime.2years": "two years ago",
|
||||
"repo.issues.filter_poster.hint": "Filter by the author",
|
||||
"repo.issues.filter_assignee.hint": "Filter by assigned user",
|
||||
"repo.issues.filter_reviewers.hint": "Filter by user who reviewed",
|
||||
|
|
|
|||
|
|
@ -204,7 +204,7 @@ func Contexter() func(next http.Handler) http.Handler {
|
|||
"FUTURE": ctx.Locale.TrString("relativetime.future"),
|
||||
"NOW": ctx.Locale.TrString("relativetime.now"),
|
||||
}
|
||||
for _, key := range []string{"relativetime.1day", "relativetime.1week", "relativetime.1month", "relativetime.1year", "relativetime.2days", "relativetime.2weeks", "relativetime.2months", "relativetime.2years"} {
|
||||
for _, key := range []string{"relativetime.1day", "relativetime.1week", "relativetime.1month", "relativetime.1year"} {
|
||||
// These keys are used for special-casing some time words. We only add keys that are actually translated, so that we
|
||||
// can fall back to the generic pluralized time word in the correct language if the special case is untranslated.
|
||||
if ctx.Locale.HasKey(key) {
|
||||
|
|
|
|||
|
|
@ -123,9 +123,6 @@ export function DoUpdateRelativeTime(object, now) {
|
|||
if (years === 1 && pageData.DATETIMESTRINGS['relativetime.1year']) {
|
||||
// Datetime is one year ago.
|
||||
object.textContent = pageData.DATETIMESTRINGS['relativetime.1year'];
|
||||
} else if (years === 2 && pageData.DATETIMESTRINGS['relativetime.2years']) {
|
||||
// Datetime is two year ago.
|
||||
object.textContent = pageData.DATETIMESTRINGS['relativetime.2years'];
|
||||
} else {
|
||||
// Datetime is more than a year ago.
|
||||
object.textContent = GetPluralizedStringOrFallback('relativetime.years', years, 'year');
|
||||
|
|
@ -139,9 +136,6 @@ export function DoUpdateRelativeTime(object, now) {
|
|||
if (months === 1 && pageData.DATETIMESTRINGS['relativetime.1month']) {
|
||||
// Datetime is one month ago.
|
||||
object.textContent = pageData.DATETIMESTRINGS['relativetime.1month'];
|
||||
} else if (months === 2 && pageData.DATETIMESTRINGS['relativetime.2months']) {
|
||||
// Datetime is two months ago.
|
||||
object.textContent = pageData.DATETIMESTRINGS['relativetime.2months'];
|
||||
} else {
|
||||
// Datetime is several months ago (but less than a year).
|
||||
object.textContent = GetPluralizedStringOrFallback('relativetime.months', months, 'month');
|
||||
|
|
@ -155,9 +149,6 @@ export function DoUpdateRelativeTime(object, now) {
|
|||
if (weeks === 1 && pageData.DATETIMESTRINGS['relativetime.1week']) {
|
||||
// Datetime is one week ago.
|
||||
object.textContent = pageData.DATETIMESTRINGS['relativetime.1week'];
|
||||
} else if (weeks === 2 && pageData.DATETIMESTRINGS['relativetime.2weeks']) {
|
||||
// Datetime is two week ago.
|
||||
object.textContent = pageData.DATETIMESTRINGS['relativetime.2weeks'];
|
||||
} else {
|
||||
// Datetime is several weeks ago (but less than a month).
|
||||
object.textContent = GetPluralizedStringOrFallback('relativetime.weeks', weeks, 'week');
|
||||
|
|
@ -170,9 +161,6 @@ export function DoUpdateRelativeTime(object, now) {
|
|||
if (days === 1 && pageData.DATETIMESTRINGS['relativetime.1day']) {
|
||||
// Datetime is one day ago.
|
||||
object.textContent = pageData.DATETIMESTRINGS['relativetime.1day'];
|
||||
} else if (days === 2 && pageData.DATETIMESTRINGS['relativetime.2days']) {
|
||||
// Datetime is two days ago.
|
||||
object.textContent = pageData.DATETIMESTRINGS['relativetime.2days'];
|
||||
} else {
|
||||
// Datetime is several days but less than a week ago.
|
||||
object.textContent = GetPluralizedStringOrFallback('relativetime.days', days, 'day');
|
||||
|
|
|
|||
|
|
@ -9,10 +9,6 @@ test('CalculateRelativeTimes', () => {
|
|||
'relativetime.1week': 'last week',
|
||||
'relativetime.1month': 'last month',
|
||||
'relativetime.1year': 'last year',
|
||||
'relativetime.2days': 'two days ago',
|
||||
'relativetime.2weeks': 'two weeks ago',
|
||||
'relativetime.2months': 'two months ago',
|
||||
'relativetime.2years': 'two years ago',
|
||||
};
|
||||
window.config.pageData.PLURALSTRINGS_LANG = {
|
||||
'relativetime.mins': ['%d minute ago', '%d minutes ago'],
|
||||
|
|
@ -84,7 +80,7 @@ test('CalculateRelativeTimes', () => {
|
|||
|
||||
mock.setAttribute('datetime', '2024-10-25T01:00:00+02:00');
|
||||
expect(DoUpdateRelativeTime(mock, now)).toEqual(ONE_DAY);
|
||||
expect(mock.textContent).toEqual('two days ago');
|
||||
expect(mock.textContent).toEqual('2 days ago');
|
||||
|
||||
mock.setAttribute('datetime', '2024-10-21T01:00:00+02:00');
|
||||
expect(DoUpdateRelativeTime(mock, now)).toEqual(ONE_DAY);
|
||||
|
|
@ -100,7 +96,7 @@ test('CalculateRelativeTimes', () => {
|
|||
|
||||
mock.setAttribute('datetime', '2024-10-13T01:00:00+02:00');
|
||||
expect(DoUpdateRelativeTime(mock, now)).toEqual(ONE_DAY);
|
||||
expect(mock.textContent).toEqual('two weeks ago');
|
||||
expect(mock.textContent).toEqual('2 weeks ago');
|
||||
|
||||
mock.setAttribute('datetime', '2024-10-06T01:00:00+02:00');
|
||||
expect(DoUpdateRelativeTime(mock, now)).toEqual(ONE_DAY);
|
||||
|
|
@ -116,7 +112,7 @@ test('CalculateRelativeTimes', () => {
|
|||
|
||||
mock.setAttribute('datetime', '2024-07-30T01:00:00+02:00');
|
||||
expect(DoUpdateRelativeTime(mock, now)).toEqual(ONE_DAY);
|
||||
expect(mock.textContent).toEqual('two months ago');
|
||||
expect(mock.textContent).toEqual('2 months ago');
|
||||
|
||||
mock.setAttribute('datetime', '2024-05-30T01:00:00+02:00');
|
||||
expect(DoUpdateRelativeTime(mock, now)).toEqual(ONE_DAY);
|
||||
|
|
@ -152,7 +148,7 @@ test('CalculateRelativeTimes', () => {
|
|||
|
||||
mock.setAttribute('datetime', '2022-10-20T01:00:00+10:00');
|
||||
expect(DoUpdateRelativeTime(mock, now)).toEqual(ONE_DAY);
|
||||
expect(mock.textContent).toEqual('two years ago');
|
||||
expect(mock.textContent).toEqual('2 years ago');
|
||||
|
||||
mock.setAttribute('datetime', '2021-10-20T01:00:00+02:00');
|
||||
expect(DoUpdateRelativeTime(mock, now)).toEqual(ONE_DAY);
|
||||
|
|
|
|||
Loading…
Reference in a new issue