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

i18n_selector map a wrong i18n value #22

Open
nonumpa opened this issue May 27, 2024 · 1 comment
Open

i18n_selector map a wrong i18n value #22

nonumpa opened this issue May 27, 2024 · 1 comment
Labels
缺陷 bug Something isn't working

Comments

@nonumpa
Copy link
Contributor

nonumpa commented May 27, 2024

Issue snapshot

i18n_selector

Root cause

目前是用 select.getAttribute(selectors) 讓所有 selector 一起 query,但是回傳的元素順序是按照 dom 順序排列,跟 selector 順序無關,所以 i18n 的值沒有照著 dom 上的 selector 順序排就會對應到錯的元素。

References

html
https://github.com/nics-tw/guide/blob/main/_components/form/index.md
https://github.com/nics-tw/guide/blob/main/_includes/form/form-elements.html

js

const selector = select.getAttribute('data-i18n-selector')

Possible solutions

  1. 可以把 i18n 順序調整得跟回傳的 nodelist 一樣
  2. 或是分開 query selector、更新 value
const selectors = ["[for=city]", "[for=id]"];
const i18n = {
    "[for=city]": "City of residence",
    "[for=id]": "ID type",
};

selectors.forEach(selector => {
    const elements = document.querySelectorAll(selector);
    elements.forEach(element => {
        // Update the inner text with the i18n value
        element.textContent = i18n[selector];
    });
});
@nonumpa nonumpa added the 缺陷 bug Something isn't working label May 27, 2024
@IK-Ngoo
Copy link
Contributor

IK-Ngoo commented Aug 18, 2024

PR #39 嘗試暫時解決表單元件範例中,輸入欄位與多語言標籤排序不一致問題。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
缺陷 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants