-
Notifications
You must be signed in to change notification settings - Fork 60
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
Conversation
vi: "Tiếng Việt", | ||
pt: "Português", | ||
}; | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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" },
...
1ea8a67
to
91706b4
Compare
There was a problem hiding this 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", | ||
}; | ||
|
There was a problem hiding this comment.
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" },
...
|
||
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}`; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
<option | ||
key={i} | ||
value={language} | ||
selected={i18n.language.startsWith(language)} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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 |
There are probably better ways to implement some things, but its not easy to find good docs for js/ts.