svelte-i18n icon indicating copy to clipboard operation
svelte-i18n copied to clipboard

Disable automatic "lang" attribute setting

Open jonaswascheroh opened this issue 1 year ago • 2 comments

Is your feature request related to a problem? Please describe. I am using this library for an embedded widget that is integrated into other companies websites. I only just realized now that this library is automatically setting the "lang" attribute on the html tag, whenever the internalLocale is changed. This is mixing up our customers websites.

Describe the solution you'd like I would like to have the option in the init method to disable the automatic attribute setting.

How important is this feature to you? Very important as there is currently no other way to do it.

jonaswascheroh avatar May 29 '24 15:05 jonaswascheroh

@kaisermann First I thought I could avoid this problem in my application but now it seems that even with no rendering of my application this library is being executed when the JavaScript ran. That means, that it sets the HTML "lang" attribute to null or empty string even though there is never a call of the "init" method. Do you have any ideas how to fix this?

jonaswascheroh avatar Sep 04 '24 14:09 jonaswascheroh

I encountered the same problem and temporarily covered the relevant code with pnpm patch, specifically this line below.

https://github.com/kaisermann/svelte-i18n/blob/5afd1f8677c8371dcbec5b5b9a7175500f17591b/src/runtime/stores/locale.ts#L39

If I submit a PR to add an option to disable it, would @kaisermann be willing to merge it?

rxliuli avatar Mar 20 '25 15:03 rxliuli

Can you share more about why it's a problem to automatically update the lang attribute? I'd expect it'd generally be desirable to do so and we try to avoid adding options unless it's really needed

benmccann avatar Aug 08 '25 16:08 benmccann

Can you share more about why it's a problem to automatically update the lang attribute? I'd expect it'd generally be desirable to do so and we try to avoid adding options unless it's really needed

Simply put, the script I inject into the webpage through a Chrome extension pops up a panel, and the panel itself supports multiple languages. Unfortunately, automatically modifying the document attribute causes the website's own language to change as well, which is not the intended behavior.

rxliuli avatar Aug 08 '25 17:08 rxliuli