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

[web] Fix hardcode 'You' with i18 translation (also add locale for moment js) #1214

Closed
wants to merge 1 commit into from

Conversation

Musicminion
Copy link

@Musicminion Musicminion commented Apr 25, 2024

Description

Hello, I am Musicminion, Overleaf’s volunteer translator for Chinese. When I was using and translating Overleaf I found that the project owner in your Project page was not translated. So I checked related code, it seems that phrase You is hard coded, as shown in the pic.

image

I am not sure if this is by design, so I make a pr. And I have signed contributor Agreement with name Musicminion.

In the meantime, it seems that you use moment.js to show time, however, you didn't set locale for moment.js, so, as shown above, the relative modify time is also untranslated in English.

I try to add locale setting for moment.js with the following code, but this commit is not contained in this pr, if you are interested, I can add this commit too!

// services/web/frontend/js/utils/dates.js
import moment from 'moment'
import { useTranslation } from 'react-i18next'
import 'moment/min/locales';

export function formatDate(date, format) {
  if (!date) return 'N/A'
  if (format == null) {
    format = 'Do MMM YYYY, h:mm a'
  }
  const { i18n } = useTranslation();
  moment.locale(i18n.language);
  return moment(date).format(format)
}

export function fromNowDate(date) {
  const { i18n } = useTranslation();
  moment.locale(i18n.language);
  return moment(date).fromNow()
}

After fix, the effect is shown below, it can show the relative time correctly.
5daed5959d129883e09ab653be9d78e6

I have run image build for this pr with my own server, it works well too.

Thanks for your time of this pr!

Related issues / Pull Requests

Contributor Agreement

@aeaton-overleaf
Copy link
Contributor

Thank you for this contribution! React only allows the useTranslation hook to be used inside a React component or hook, so this needed a slightly different approach, but this has now been implemented in 08c784f

We'll look into adding the Moment locales separately.

@Musicminion
Copy link
Author

Thanks, already see effect in overkeaf.com!

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

Successfully merging this pull request may close these issues.

None yet

2 participants