themoeway / yomitan

Pop-up dictionary browser extension. Successor to Yomichan.
https://yomitan.wiki
GNU General Public License v3.0
1.13k stars 88 forks source link

Dynamic profile switching condition based on language #626

Open Casheeew opened 7 months ago

Casheeew commented 7 months ago

Resurfacing #56 , since switching profiles based on site language is more relevant now with the multiple languages support.

Casheeew commented 6 months ago

@toasted-nutbread is it possible to lift the lang information from #730 to the profile context level for profile switching?

toasted-nutbread commented 6 months ago

It seems kinda unrelated to #730, but you could pass the HTML/body element's lang attribute value (if present) into the OptionsContext types and then handle that later on for profile conditions. Not sure if that is robust or efficient depending on how often you read that value though.

Casheeew commented 6 months ago

It seems kinda unrelated to https://github.com/themoeway/yomitan/pull/730

I was thinking of something like switching profiles based on what value you get when scanning text, using https://github.com/themoeway/yomitan/blob/2e9ea19207a7410f929bb908759d48cb2340f29c/ext/js/language/text-utilities.js#L26 kinda like language auto-detection when using something like Google Translate.

toasted-nutbread commented 6 months ago

Oh I see. It will likely not be a robust test, since that function is really only going to be doing some character code range tests, and many languages have overlapping character sets, particularly European languages. I didn't mention this anywhere, but in its current form, it really doesn't even need to do detection of European languages; the main reason this function is used is to assign the lang tag to try to improve character rendering, since sometimes that is dependent on the lang attribute.

I suppose you could try it out, although again I'm not sure what performance considerations that may have.