https://github.com/creative-workflow/jquery.language
This plugin helps managing browser languages.
https://github.com/creative-workflow/jquery.language
Last synced: 9 months ago
JSON representation
This plugin helps managing browser languages.
- Host: GitHub
- URL: https://github.com/creative-workflow/jquery.language
- Owner: creative-workflow
- License: mit
- Created: 2015-05-28T15:34:26.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2015-08-05T18:54:17.000Z (almost 11 years ago)
- Last Synced: 2025-02-08T19:59:35.724Z (over 1 year ago)
- Language: CoffeeScript
- Homepage:
- Size: 176 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# jquery.language [](https://travis-ci.org/creative-workflow/jquery.language) [](https://codeclimate.com/github/creative-workflow/jquery.language)
This plugin helps managing browser languages. It looks for an url param or the navigator language and stores the language in a cookie.
## Usage
### javascript
$.language({
active: 'auto',
fallback: 'de',
available: ['en', 'de']
});
console.log($.language()); //prints de or en
$.language('de') //sets the language
It also exposes the class `JQueryLanguage` for manual instantiating.
### coffee script
$.language
active: 'auto'
fallback: 'de'
available: [
'en'
'de'
]
console.log $.language() #prints de or en
$.language 'de' #sets the language
It also exposes the class `JQueryLanguage` for manual instantiating and extending.
### Parameter
#### active
auto - default, means try to detect from url param, cookie, navigator or use fallback
or a available language
#### fallback
language that is used if no language could be detected
#### available
array of allowed languages, default is ['en']
#### urlParam
name of the url param to watch for, default is 'language'
#### cookieName
name of the cookie for language storing, default is 'language'
### Functions
#### $.language(configuration|language|null)
Initialize the plugin.
* with a configuration object.
* or with a language string
* If no parameter is given it returns the actual language.
#### $.language.config(configuration|null)
Updates the configuration.
* calls `$.language.autodetectLanguage()` and writes result to cookie.
* if no parameter is given returns the actual configuration
#### $.language.setLanguage(possibleLanguage)
Normalizes, validates and stores the `possibleLanguage` if it is different from the actual language.
* triggers event `language.invalid` with parameter `{invalid: possibleLanguage, active: activeLanguage}` if the possibleLang is invalid
* triggers event `language.changed' with parameter `{active: activeLanguage, old: oldLanguage}` if language was successfully changed
#### $.language.autodetectLanguage()
Returns the auto detected language by looking first
* at the url param with the name given by config.urlParam
* then look for a cookie with the name config.cookieName
* then try to get the first language from navigator.language and navigator.userLanguage
* or finally returns config.fallback
#### $.language.isValid(language)
* checks if a language is defined in `config.available`
#### $.language.normalize(language)
Normalizes a language string.
* trim string
* only use the first to chars
* return the lower case equivalent
### Dependencies
* [jquery](https://jquery.com)
* [js-cookie](https://github.com/js-cookie/js-cookie)
* [js-url](https://github.com/websanova/js-url)
### Resources
* https://github.com/creative-workflow/jquery.language
* https://travis-ci.org/creative-workflow/jquery.language
* https://codeclimate.com/github/creative-workflow/jquery.language
* https://www.npmjs.com/package/jquery.language
* http://bower.io/search/?q=jquery.language
### Authors
[Tom Hanoldt](https://github.com/monotom)
# Contributing
Check out the [Contributing Guidelines](CONTRIBUTING.md)