#3935 closed enhancement (fixed)
Language specific screenshots
Reported by: | f.staude | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Component: | Plugin Directory | Keywords: | has-patch |
Cc: |
Description (last modified by )
The captions of the screenshots can be translated.
It would be nice if I could also upload language-specific screenshots.
So screenshot-1.png
as default screenshot and screenshot-1-de_DE.png
or screenshot-1-es_ES.png
for language specific screenshots in the selected language (In this example for German and Spanish)
Attachments (3)
Change History (14)
#3
@
6 years ago
- Keywords has-patch added
Attached a patch attachment:3935.diff to implement support screenshots for multiple locales.
- Extended the import plugin process to support locale in the file name as suggested.
- Plugin page fallback to display screenshots without locale if user locale is not matched with any screenshots with locale.
#4
@
6 years ago
Updated with patch attachment:3935.2.diff
- Extended regex to support locales with variants (eg:
de_DE
,de_DE_informal
).
#5
@
5 years ago
Hey @ck3lee,
Just looking at 3935.2.diff
- The regex looks correct to me, although I haven't tested it yet
- Even with the above, it looks like we're only using the first two digits of the locale?
substr( $image['locale'], 0, 2 )
Consider this line up of files:
screenshot-1.png
screenshot-1-de_DE.png
screenshot-1-de_CH.png
If the array of results was ordered exactly like that, you'd only had screenshot-1.png
being used, if it was ordered 2,3,1 then for de_CH
it'd only use the de_DE
file.
I think the list of images needs to be reduced before the loop:
Do any images have a locale?
If so, Is our locale there? Or is a nearish locale there? (ie. look for de_CH, then de)
You should also consider this set of files, which is potentially likely:
screenshot-1.png
screenshot-1-de_DE.png
screenshot-2.png
screenshot-2-de_CH.png
screenshot-3.png
#6
@
5 years ago
Thanks, @dd32.
I've added a reduced function to better match the locale of the image with user's locale, attachment:3935.3.diff with the intent to have:
- Image with fully matched locale (language, country and variance) has the highest priority.
- Image with language matched only has second priority.
- Then, fallback to default image without locale if no image is matched.
#8
@
5 years ago
@ck3lee nice work!
In [8729] I've rearranged a bit of the code, and generalised it more to allow it to work with the API components.
Some things I noticed while working with the patch
- In
reduce_screenshots_with_locale()
it was expecting that the new$image['locale']
field was always set, where it won't be for any older screenshot meta, In the above commit i simply flipped the first two if conditionals to account for that - Images with locales such as
de_DE
andde_CH
work as intended, butde_DE_informal
will fall back tode_CH
if it exists as it's lower in the alphabet. I left it as-is there as it's pretty minor and no plugins yet have these anyway :)
Updating it to support the API was required as otherwise the images were duplicated within WordPress installs, you can see the API responses here and here (Note: Using those APIs directly isn't encouraged, but it's good for testing. All API clients should be using api.wordpress.org instead which is heavily cached).
Testing was performed with one of my test plugins, for those who would like to see it in action compare English to German to Moroccan Arabic.
Of course it must be called screenshot-1-de_DE.png