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

Fix maketext interpolation in PG. #2213

Closed

Conversation

drgrice1
Copy link
Member

@drgrice1 drgrice1 commented Sep 16, 2023

The key to making this work is to override the _compile method of Locale::Maketext and remove the use strict usage inside of its code eval call. That is the only essential difference between the override method added here and the orignal method in Locale::Maketext.

With this you can now use maketext interpolation in PG. For example, you can call maketext('[quant,_1,dog] ate my homework', $num_dogs).

This is an important part of removing the attempts table, and moving the code the provides feedback to PG.

The WeBWorK::Localize module is also cleaned up considerably.

@drgrice1 drgrice1 force-pushed the proper-localization-for-pg branch from dcb2f47 to 61af630 Compare September 16, 2023 16:34
@taniwallach taniwallach self-requested a review September 18, 2023 19:59
@drgrice1 drgrice1 force-pushed the proper-localization-for-pg branch from 61af630 to 8cf57d3 Compare September 19, 2023 16:55
@pstaabp
Copy link
Member

pstaabp commented Sep 19, 2023

This seems to perform the translation fine, but not sure how to test the interpolation, since we don't have any of that in PG. Perhaps this just will pave the way for removing the attempts table, or @drgrice1, do you have a good way to test?

Would we now have the ability to do maketext in a macro perhaps?

@drgrice1
Copy link
Member Author

There is an easy way to test. Add maketext('[quant,_1,dog] ate my homework', $num_dogs) to a problem, and then run /opt/webwork/webwork2/bin/dev_scripts/update-localization-files -p. Then modify that string in your chosen language .po file. Then switch the course to that language, and see that the translation comes through. Test it with various values of $num_dogs.

Note you can also test this for English without running the script testing for various values of $num_dogs. It should say "1 dog ate my homework" if $num_dogs = 1, and "2 dogs ate my homework" if $num_dogs = 2. If you then test the problem with the develop branch, you will get an error.

The key to making this work is to override the `_compile` method of
`Locale::Maketext` and remove the `use strict` usage inside of its code
eval call. That is the only essential difference between the override
method added here and the orignal method in `Locale::Maketext`.

With this you can now use maketext interpolation in PG. For example, you
can call `maketext('[quant,_1,dog] ate my homework', $num_dogs)`.

This is an important part of removing the attempts table, and moving the
code the provides feedback to PG.

The WeBWorK::Localize module is also cleaned up considerably.
@drgrice1 drgrice1 force-pushed the proper-localization-for-pg branch from 674625f to 94960dd Compare October 6, 2023 10:25
@drgrice1
Copy link
Member Author

drgrice1 commented Oct 7, 2023

I am closing this in favor of #2225 and openwebwork/pg#936.

@drgrice1 drgrice1 closed this Oct 7, 2023
@drgrice1 drgrice1 deleted the proper-localization-for-pg branch October 7, 2023 18:44
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