jQuery Plugin: Find text within selector element(s) that matches specified language and wrap it in a span[lang=langauge]

Sometimes character encoding detection in the back-end of software can be difficult. Here is a quick solution to do it in JavaScript! I’ve implemented a jQuery plugin that accepts selectors and a language, iterates through the .text() of the selectors, and wraps the text in a <span lang=””> where the lang attribute matches the language passed in. With this code, you can change fonts, apply specific actions to text (right to left or left to right), etc…

Here is an example CSS:

Currently, only hebrew and english are defined in the plugin by default, but you can pass in additional languages in the options object when you call the function. The function parameter expects an object that contains these keys

Here’s an example on how you’d call the function:

Download the code from GitHub