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

getLocalizedData in ModelWithSettings does not fallback when a translation is missing #10690

Open
kaitlinnewson opened this issue Dec 11, 2024 · 1 comment
Assignees
Labels
Bug:1:Low A bug that does not have a severe consequence or affects a small number of users.
Milestone

Comments

@kaitlinnewson
Copy link
Member

kaitlinnewson commented Dec 11, 2024

Describe the bug
In ModelWithSettings.php, getLocalizedData() does not fallback to the first available piece of data when a translation is missing, so a null value may be used when a fallback is available. This is different from the behaviour in the DataObject implementation.

To Reproduce
Steps to reproduce the behavior:

  1. Have a journal with multiple languages enabled
  2. Enable announcements in the journal
  3. Create the announcement in one language only and publish it
  4. In the front-end, view the announcement and toggle between languages, noting that the title appears empty in languages where it was not translated

What application are you using?
OJS, OMP or OPS version main

Additional information

  • DataObject implementation of getLocalizedData() for comparison:
    public function getLocalizedData(string $key, ?string $preferredLocale = null, ?string &$selectedLocale = null): mixed
    {
    $value = $this->getData($key);
    if (!is_array($value)) {
    return $value;
    }
    return $this->getBestLocalizedData((array) $this->getData($key), $preferredLocale, $selectedLocale);
    }
  • getBestLocalizedData():
    protected function getBestLocalizedData(array $data, ?string $preferredLocale = null, ?string &$selectedLocale = null): mixed
    {
    foreach ($this->getLocalePrecedence($preferredLocale) as $locale) {
    if (!empty($data[$locale])) {
    $selectedLocale = $locale;
    return $data[$locale];
    }
    }
    // Fallback: Get the first available piece of data.
    foreach ($data as $locale => $dataValue) {
    if (!empty($dataValue)) {
    $selectedLocale = $locale;
    return $dataValue;
    }
    }
    return null;
    }

PRs
pkp-lib --> #10785
ojs --> pkp/ojs#4585 [TEST ONLY]

@kaitlinnewson kaitlinnewson added the Bug:1:Low A bug that does not have a severe consequence or affects a small number of users. label Dec 11, 2024
@kaitlinnewson kaitlinnewson added this to the 3.5 Internal milestone Dec 11, 2024
@touhidurabir touhidurabir self-assigned this Jan 8, 2025
touhidurabir added a commit to touhidurabir/pkp-lib that referenced this issue Jan 8, 2025
touhidurabir added a commit to touhidurabir/ojs that referenced this issue Jan 8, 2025
@touhidurabir
Copy link
Member

@Vitaliy-1 can you please review the PRs at #10690 (comment) .

touhidurabir added a commit to touhidurabir/pkp-lib that referenced this issue Jan 8, 2025
touhidurabir added a commit to touhidurabir/ojs that referenced this issue Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug:1:Low A bug that does not have a severe consequence or affects a small number of users.
Projects
None yet
Development

No branches or pull requests

2 participants