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

Add language selector on site (fixes #64) #76

Merged
merged 2 commits into from
Feb 17, 2022
Merged

Conversation

Nutomic
Copy link
Member

@Nutomic Nutomic commented Feb 14, 2022

There are probably better ways to implement some things, but its not easy to find good docs for js/ts.

vi: "Tiếng Việt",
pt: "Português",
};

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried some libraries for this, but none of them worked well, partly because our language identifiers are in different formats. And mnc (Manchu) is essentially a dead language with 20 native speakers, so we can easily remove it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the library I'm using in lemmy-ui: https://github.com/LemmyNet/lemmy-ui/blob/main/src/shared/utils.ts#L431

Then all you need are the codes:

export const languages = [
  { code: "ca" },
  { code: "en" },
...

Copy link
Member

@dessalines dessalines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good... does the rustdoc pages work with cookies, or with a url param?

vi: "Tiếng Việt",
pt: "Português",
};

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the library I'm using in lemmy-ui: https://github.com/LemmyNet/lemmy-ui/blob/main/src/shared/utils.ts#L431

Then all you need are the codes:

export const languages = [
  { code: "ca" },
  { code: "en" },
...

src/client/index.tsx Outdated Show resolved Hide resolved
src/server/index.tsx Outdated Show resolved Hide resolved

export class Navbar extends Component<any, any> {
constructor(props: any, context: any) {
super(props, context);
}

handleLanguageChange(event: ChangeEvent<HTMLSelectElement>) {
location.href = `/?lang=${event.target.value}`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we have any params-based things here, might just require setting the language cookie then reloading.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That will also work, but sometimes its useful to link people to a specific language version of the site, and thats much easier if you can just use the selection and then copy the url.

src/shared/components/navbar.tsx Outdated Show resolved Hide resolved
<option
key={i}
value={language}
selected={i18n.language.startsWith(language)}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pry don't need the startsWith here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using equality instead, it didnt work because i18n.language was en-GB, and language only contained en, so it wouldnt match.

@Nutomic
Copy link
Member Author

Nutomic commented Feb 15, 2022

I didnt check with rustdoc, you would probably have to change the languge separately.

About the iso-639-1 library, its missing some language names, and also in Lemmy itself its broken. Like 中文_Hant is nonsense, it should be 文言. Same for Norsk bokmål_NO, should just be Norsk bokmål. And some language names are in lower case for some reason, like suomi or euskara. mnc isnt translated at all (again, we can remove that lang). Defining it like this in our code works much better, and i would do it the same way in Lemmy.

@dessalines dessalines merged commit ba5015d into main Feb 17, 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

Successfully merging this pull request may close these issues.

2 participants