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

feat: localize keyboard shortcut #325

Merged
merged 6 commits into from
Nov 19, 2022
Merged

feat: localize keyboard shortcut #325

merged 6 commits into from
Nov 19, 2022

Conversation

benbenben2
Copy link
Contributor

What

Replaced the shortcut to answer questions in Hunger Games to "y"

Why

The actual shortcut to reply "yes" to questions in Hunger Games is "o".
Assuming that it is a typo (French abbreviation maybe?), I changed it to "y" (for yes).

Remark: it is my first PR to hunger games project. I tested the changes locally.

@benbenben2 benbenben2 requested a review from a team as a code owner October 25, 2022 18:53
@alexfauquette
Copy link
Member

Thanks for the contribution :)

The code looks good, @teolemon I'm wondering if we should adapt with the locale, such that at least for french, it's still an O for yes (Oui in french)

Ans also because N, K, O has a better alignment on AZERTY keyboards

@teolemon
Copy link
Member

Ideally, yes it should be localizable, and we should carefully choose patterns.
I wonder whether libraries exist for such a common issue ( yes no maybe)

@alexfauquette
Copy link
Member

Don't need a library.

A file shortcut-l10n.js

const SHORTCUT_LOCALISATION = {
	en: {
		yes: "y",
		no: "n",
		skip: "k",
	},
	fr: {
		yes: "y",
		no: "n",
		skip: "k",
	}
}

const getShortcuts = (lang) => {
	return {...SHORTCUT_LOCALISATION.en, ...SHORTCUT_LOCALISATION[lang ?? getLang()]}
}

That in the main file you can do

const shortcuts = getShortcuts()

// ...

{t("questions.yes")} ({shortcuts.yes})

probably need to replace the switch(event.keyCode) by switch(event.code)

@benbenben2
Copy link
Contributor Author

Hi guys,
Sorry for late reply.
I will not be able to do that by myself :-(
Should I close this PR and let you do this by yourself?

@alexfauquette
Copy link
Member

@benbenben2 No problem, I will finish the PR

@VaiTon
Copy link
Member

VaiTon commented Nov 8, 2022

Hey! Nice idea about the localized shortcuts!

Something I would like to add is the fact that a lot of localized cli commands always take y as yes and n as no, so that if somebody is used to the english version it would work too.

@alexfauquette
Copy link
Member

The main reason I want to keep N, K, O is that on AZERTY keyboard those letters are aligned :)

image

@alexfauquette
Copy link
Member

@benbenben2 If you want to have a look, I added a commit to modify shortcuts depending on localization

@alexfauquette alexfauquette changed the title switch_shortcut_letter_for_questions_from_o_to_y feat: localize keyboard shortcut Nov 19, 2022
@alexfauquette alexfauquette merged commit e2a49e7 into openfoodfacts:master Nov 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants