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: translations in packagings READ API v3 #7749

Merged
merged 7 commits into from
Nov 23, 2022
Merged

Conversation

stephanegigandet
Copy link
Contributor

This PR changes the structure of the returned "packagings" structure so that it can include translated name in the language specified by tags_lc (if sent), as described in #7564 and the OpenAPI specification.

Note that this new structure is only returned for v3 requests, in order not to break apps (not sure if there are some that use this field already) that expect the old structure.

Also added tests.

@stephanegigandet stephanegigandet requested a review from a team as a code owner November 22, 2022 13:07
@github-actions github-actions bot added API Issues related to the Open Food Facts API. More specific labels exist & should be used (API WRITE…) 📚 Documentation Documentation issues improve the project for everyone. 🧪 integration tests 📖 Knowledge Panels https://wiki.openfoodfacts.org/Knowledge_panels 📦 Packaging https://wiki.openfoodfacts.org/Category:Recycling 🧬 Taxonomies https://wiki.openfoodfacts.org/Global_taxonomies 🧪 tests labels Nov 22, 2022
@@ -1478,23 +1478,23 @@
"entry_dates_tags" : "--ignore--",
"food_groups_tags" : [],
"forest_footprint_data" : {
"footprint_per_kg" : 0.0132222222222222,
"footprint_per_kg" : "0.0132222222222222",
Copy link
Contributor

Choose a reason for hiding this comment

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

Integer to string (Perl issue apparently), can live with it :)

Copy link
Contributor

@monsieurtanuki monsieurtanuki left a comment

Choose a reason for hiding this comment

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

Hi @stephanegigandet!
I'm not an expert in .pm (I don't even know what language it is) but I located your adding of the localized label and that looked appropriate.

Other remarks:

  • it's really a pity to have some ints (not even all ints) becoming Strings in json - I hope you can roll that back
  • what happens if we put several comma-delimited languages in tags_lc?

Copy link
Contributor

@olivier5741 olivier5741 left a comment

Choose a reason for hiding this comment

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

@stephanegigandet
Copy link
Contributor Author

  • it's really a pity to have some ints (not even all ints) becoming Strings in json - I hope you can roll that back

I think that's an issue in the test framework, I still have numbers when I access the API.

@stephanegigandet
Copy link
Contributor Author

  • what happens if we put several comma-delimited languages in tags_lc?

It's not supported. Adding something like that could cause errors down the line. e.g. if you ask for "fr", you can get "Plastique", and then write it again, by specifying the same tags_lc=fr. If we try to support something like tags_lc=fr,nl,en , then it becomes very messy: we have to specify in the response which it is, and then in an edit interface, we can have a mix of languages, which the user could change. I don't think it's worth it.

Copy link
Member

@alexgarel alexgarel left a comment

Choose a reason for hiding this comment

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

LGTM

https://world.openfoodfacts.org/data/taxonomies/packaging_materials.json
https://world.openfoodfacts.org/data/taxonomies/packaging_recycling.json

If the tags_lc field is set, the properties will include a lc_name field with the translation in the requested language.
Copy link
Member

Choose a reason for hiding this comment

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

Don't you want to add it as a patternProperty in the files ?

tests/integration/api_v2_product_read.t Show resolved Hide resolved
@github-actions github-actions bot added the Translations We use a non-standard version of GetText, lack language variants support translate.openfoodfacts.org label Nov 22, 2022
stephanegigandet and others added 2 commits November 23, 2022 11:53
Co-authored-by: Alex Garel <alex@garel.org>
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@stephanegigandet stephanegigandet merged commit 72cf120 into main Nov 23, 2022
@stephanegigandet stephanegigandet deleted the packaging-api-read branch November 23, 2022 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Issues related to the Open Food Facts API. More specific labels exist & should be used (API WRITE…) 📚 Documentation Documentation issues improve the project for everyone. 🧪 integration tests 📖 Knowledge Panels https://wiki.openfoodfacts.org/Knowledge_panels 📦 Packaging https://wiki.openfoodfacts.org/Category:Recycling 🧬 Taxonomies https://wiki.openfoodfacts.org/Global_taxonomies 🧪 tests Translations We use a non-standard version of GetText, lack language variants support translate.openfoodfacts.org
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants