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

Use gettext for plugin translation #34

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

rimas-kudelis
Copy link
Contributor

@rimas-kudelis rimas-kudelis commented Dec 14, 2024

This translates the widget using gettext, however, the language setting doesn't seem to work, needs some more digging or to be removed entirely.

I changed language codes because WP doesn't seem to be smart enough to fallback to lt when it can't find lt_LT.

Fixes #33.

@rimas-kudelis rimas-kudelis force-pushed the feat/use-gettext branch 2 times, most recently from 49bb5f8 to c4ba485 Compare December 15, 2024 09:25
@rimas-kudelis
Copy link
Contributor Author

Okay, so the switcher works, but there's a gotcha: the switch_to_locale() WordPress function will only switch locale if it deems that that target locale is installed/enabled.

For example, I can only switch between lt_LT and en_US on my installation.

@ovx, how much do you want to keep that setting? I'm thinking maybe it's not that useful when the language is properly selected automatically?

Also, WP requires .mo files for the translation to work. I committed them to the repo, but I'm sure it's also possible to generate them before pushing the plugin to WordPress SVN instead.

@ovx
Copy link
Contributor

ovx commented Dec 21, 2024

@rimas-kudelis Hi, thank you a lot for this PR, gettext was definitely planned. I think the language settings can be dropped since it works automatically now. Will review this a bit later.

@rimas-kudelis rimas-kudelis changed the title WIP: Use gettext for plugin translation Use gettext for plugin translation Dec 21, 2024
@rimas-kudelis
Copy link
Contributor Author

Cool, in that case I've updated the plugin to remove that setting.

I kept some code, which should still make it possible to switch to a specific language when using the shortcode, but I didn't test that scenario.

By the way, do you even ensure that altcha is correctly submitted if it was inserted via the shortcode?

@rimas-kudelis rimas-kudelis marked this pull request as ready for review December 21, 2024 08:10
includes/core.php Outdated Show resolved Hide resolved
@rimas-kudelis rimas-kudelis force-pushed the feat/use-gettext branch 3 times, most recently from 9eac807 to 64cedaa Compare December 21, 2024 08:49
@rimas-kudelis
Copy link
Contributor Author

By the way, originally, the array of 'en' translations contained the following extra string:

"cannot_submit" => "Cannot submit."

I coudn't find this identifier in JS, meaning the seems to have been unused, so I have removed it.

@rimas-kudelis
Copy link
Contributor Author

Marked more strings for localization.

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.

Convert translations to gettext
2 participants