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

pkp/pkp-lib#9910 Use UI Language in Web Feeds #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bozana
Copy link

@bozana bozana commented Jul 16, 2024

templates/rss.tpl Outdated Show resolved Hide resolved
Copy link
Contributor

@jonasraoni jonasraoni left a comment

Choose a reason for hiding this comment

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

@bozana I just think it's better to keep the country information of the locale (if available).

@bozana
Copy link
Author

bozana commented Jul 17, 2024

Hi @jonasraoni, I considered the comments, could you please take another look?
Thanks a lot!

@@ -126,7 +128,8 @@ public function fetch($args, $request): bool
'latestDate' => $latestDate,
'feedUrl' => $request->getRequestUrl(),
'userGroups' => $userGroups,
'includeIdentifiers' => $includeIdentifiers
'includeIdentifiers' => $includeIdentifiers,
'language' => str_replace('_', '-', str_replace(['@cyrillic', '@latin', '_Latn', '_Cyrl'], '', Locale::getLocale())),
Copy link
Contributor

@jonasraoni jonasraoni Jul 17, 2024

Choose a reason for hiding this comment

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

Looks like the BCP 47 format is roughly <language>-<script>-<region> (there are other optional sub-components, but not important for us), so this will work for our current locales, but other variants might break this in the future, because our locale has a different order <language>_<region>@<script>.

Also, the str_replace() seems to be too limited (I guess you've extracted this from the Locale class, because I saw someone added it there), as there are extra scripts that we're not covering.

I think it's enough just to fix the "order".

About the limited scripts on the replace, that's something for another issue.

Copy link
Author

@bozana bozana Jul 18, 2024

Choose a reason for hiding this comment

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

Hmmm... I was only looking at our currently existing UI locales and the fact that we will move to Weblate locales soon (s. pkp/pkp-lib#9707).
But, maybe I should consider all Weblate locales:
I see now that Weblate has different scripts (than Latn and Cyrl) but also something with @ (e.g. hi@hinglish, pt_BR@formal, sr@ijekavian_Latn).
Regarding the order: it seems Weblate locales have the order language_script_region (e.g. en_Shaw_US, zh_Hant_HK).
Thus, currently I am not sure what pattern would work to get it correctly. Maybe I can use PHP intl functions locale_get_primary_language and locale_get_region to get it right? 🤔

@@ -126,7 +128,8 @@ public function fetch($args, $request): bool
'latestDate' => $latestDate,
'feedUrl' => $request->getRequestUrl(),
'userGroups' => $userGroups,
'includeIdentifiers' => $includeIdentifiers
'includeIdentifiers' => $includeIdentifiers,
'language' => locale_get_region(Locale::getLocale()) ? locale_get_primary_language(Locale::getLocale()) . '-' . locale_get_region(Locale::getLocale()) : locale_get_primary_language(Locale::getLocale()),
Copy link
Author

Choose a reason for hiding this comment

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

@jonasraoni, what about this solution?

Copy link
Contributor

Choose a reason for hiding this comment

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

The PKP Locale class doesn't provide such things, so I agree with the fix. Another option is to make the Locale::_parse() method public.


About the code, I'd just store the locale_get_region(Locale::getLocale()) and locale_get_primary_language(Locale::getLocale()) in variables, to make the code shorter and perhaps use the class-based version of \Locale::getRegion() and \Locale::getPrimaryLanguage().

Copy link
Contributor

Choose a reason for hiding this comment

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

Another possible problem, that makes me think that it's better to make that method public is that perhaps some PHP locales are not very compatible with our ones.

I mean, we have be@cyrillic, but a call to Locale::getScript('be@cyrillic') won't bring what we would expect, while be-Cyrl will.

@bozana
Copy link
Author

bozana commented Jul 19, 2024

@jonasraoni, what about this solution?

Copy link
Contributor

@jonasraoni jonasraoni left a comment

Choose a reason for hiding this comment

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

I just left some notes, nothing important =]

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