Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

User language is ignored when viewing translations in a table #11546

Closed
3 tasks done
iksent opened this issue Feb 9, 2022 · 12 comments
Closed
3 tasks done

User language is ignored when viewing translations in a table #11546

iksent opened this issue Feb 9, 2022 · 12 comments

Comments

@iksent
Copy link
Contributor

iksent commented Feb 9, 2022

Preflight Checklist

Describe the Bug

See steps to reproduce

To Reproduce

  1. Create a model with auto-configured translations
  2. Set "Use Current User Language" to "Enable" at "Translations" at "Display" tab:
    image
  3. Create 2 translations:
    image
  4. Change profile language to something else from English (I choose Russian):
    image
  5. Go to model items table and see, that there is an "English" default item displayed instead of Russian:
    image

Errors Shown

No response

What version of Directus are you using?

9.5.1

What version of Node.js are you using?

14.17.5

What database are you using?

MariaDB

What browser are you using?

Chrome

What operating system are you using?

macOS

How are you deploying Directus?

running locally

@azrikahar
Copy link
Contributor

I can't seem to reproduce this neither on v9.5.0 nor the latest version v9.5.1 (I'd still recommend actually confirming this on the latest version in accordance to the Preflight Checklist in this and future issues 👍):

9nnJdJIbaz.mp4

Not sure what could be happening here, but I'd also recommend trying to replicate this on a fresh Directus instance + fresh DB on your end and see whether it happens or not.

@iksent
Copy link
Contributor Author

iksent commented Feb 10, 2022

Sorry, we are on the latest 9.5.1, will change it in the description now.

Weird! I just moved my DB to the remote server and the issue is still persists...

Should I send you my database?

@iksent
Copy link
Contributor Author

iksent commented Feb 10, 2022

Oh! I just found that it displays chaotically:

image

Can you please try to create more items?

@azrikahar
Copy link
Contributor

Sorry, we are on the latest 9.5.1, will change it in the description now.

Weird! I just moved my DB to the remote server and the issue is still persists...

No worries! Would it be possible for you to test on a fresh instance as a sanity check? But feel free to hold off on this first as I think we should approach this from the following steps first.

Should I send you my database?

That is definitely a great plan, but I do wish to try the following checks first since honestly the possibilities of things outside of user or userStore in Pinia affecting this is pretty unlikely.

Currently the language display grabs the user's language, so it'll be helpful if you can verify the /users/me endpoint upon refresh shows the correct language before/after language switches:

qqiZ2SknUJ.mp4

Oh! I just found that it displays chaotically:

Can you please try to create more items?

Tried to create more items as shown above 👍 Still wondering if this is something purely app side or relates to the returned API result. Perhaps you can try with another browser as well just to rule out any chance of browser-related issues.

@iksent
Copy link
Contributor Author

iksent commented Feb 10, 2022

  1. Yes, /me endpoint returns correct language:

  1. Tried Safari (instead of Chrome), same problem:

@iksent
Copy link
Contributor Author

iksent commented Feb 10, 2022

I've just figured it out, that sort param is set to ID:
image

And this probably leads to incorrect display:

image

So try to create RU/DE items firstly (start to filling them first)?

@azrikahar
Copy link
Contributor

I can confirm the returned API does indicate that they are in order of creation, but the Translations display seems to still be working as intended in my case:

7Dlw3hc73X.mp4

Took a second look and it seems like your languages table uses languages_code rather than languages_id (auto generated):

image

My current running theory would be somehow there's something funky with your translation/language relation thus it is failing the logic here:

props.value.find((val) => val?.[relation.value.field]?.[langPkField] === user.currentUser?.language) ?? item;

and since the Left Hand Side with the langPkField fails, your current display now defaults to the RHS which is the first translation item.

Would you mind taking a schema snapshot and share it here? Feel free to use the following template since GH doesn't allow .yaml file uploads (and I personally feel although zip file works, it's also nice to be able to see the schema at a glance without needing to download + unzip it 😁)

<details>
<summary>Schema Snapshot</summary>

```yaml
# paste your yaml here
```

</details>

@iksent
Copy link
Contributor Author

iksent commented Feb 10, 2022

@azrikahar sorry i think my db is private. Can I email you personally?

@azrikahar
Copy link
Contributor

No worries! I think we may not need to anymore as I just realized something... I believe what's happening here is because your language codes are en & ru, but your userStore (as we verified before) are returning en-US & ru-RU. Would you be able to verify this, with backup of course, and change your language codes according to the xx-XX format?

@iksent
Copy link
Contributor Author

iksent commented Feb 10, 2022

Yes, we changed it specially to "en" and "ru" to match our client's locales at Next.js, which is "en" & "ru" by default (and also we don't need to separate en-us from en-gb)

I will try to do it asap and back with a news ;)

@iksent
Copy link
Contributor Author

iksent commented Feb 12, 2022

@azrikahar, you were right!
This was the problem: changing languages codes to en-US & ru-RU solves the problem.

How can we fix this problem? Is it will be correct to try match languages based on lang prefix "en-" & "ru-"? It will solve my problem, but this is not a 100% universal solution (if such a solution exists).


Another interesting issue is that "Code" field editing is allowed in my configs:

image

But I can't edit it in the UI:

image

@azrikahar
Copy link
Contributor

Thanks for confirming!

Is it will be correct to try match languages based on lang prefix "en-" & "ru-"?

This does sound like a plausible solution. There is sort of a similar logic applied when we're matching locales from date-fns and fullcalendar:

const localesToTry = [lang, lang.split('-')[0], 'en-US'];

const localesToTry = [lang, lang.split('-')[0], 'en-US'];

It will solve my problem, but this is not a 100% universal solution (if such a solution exists).

Technically ya it might be truly universal if we can allow "mappings", such as "abc" equals "en-US", "def" equals "ru-RU", but I think that'd end up being (potentially) confusing & likely doesn't conform to the 80/20 rule.

But I can't edit it in the UI:

It's currently it is not possible to edit primary keys (although IIRC it was briefly discussed before on making it possible).


Alternatively, we can make the display item based on "language indicator field OR primary key" by modifying the logic here:

const langPkField = relationPrimaryKeyField.value?.field;

so that for your use case, users can add an additional field to indicate en is mapped to en-US, and you'll use the en-US field as the displayed field.

@directus directus locked and limited conversation to collaborators Apr 15, 2022
@rijkvanzanten rijkvanzanten converted this issue into discussion #12792 Apr 15, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

2 participants