{"id":13992067,"url":"https://github.com/recurser/jquery-i18n","last_synced_at":"2025-04-07T18:14:59.671Z","repository":{"id":1511910,"uuid":"1769315","full_name":"recurser/jquery-i18n","owner":"recurser","description":"A jQuery plugin for doing client-side translations in javascript.","archived":false,"fork":false,"pushed_at":"2020-08-29T11:45:40.000Z","size":137,"stargazers_count":198,"open_issues_count":2,"forks_count":60,"subscribers_count":15,"default_branch":"develop","last_synced_at":"2025-03-31T16:15:07.076Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://www.daveperrett.com/articles/2008/02/21/jquery-i18n-translation-plugin/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"jshint/jshint","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/recurser.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-05-19T02:12:30.000Z","updated_at":"2025-03-15T20:58:03.000Z","dependencies_parsed_at":"2022-08-16T13:31:21.622Z","dependency_job_id":null,"html_url":"https://github.com/recurser/jquery-i18n","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/recurser%2Fjquery-i18n","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/recurser%2Fjquery-i18n/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/recurser%2Fjquery-i18n/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/recurser%2Fjquery-i18n/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/recurser","download_url":"https://codeload.github.com/recurser/jquery-i18n/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247704571,"owners_count":20982298,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-09T14:01:46.320Z","updated_at":"2025-04-07T18:14:59.647Z","avatar_url":"https://github.com/recurser.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","34. 国际化(i18n) ##","34. 国际化(i18n)"],"sub_categories":["13.20 视差滚动(Parallax Scrolling) ###","24.3 Web Sockets"],"readme":"\nAbout\n-----\n\n_jQuery-i18n_ is a jQuery plugin for doing client-side translations in javascript. It is based heavily on [javascript i18n that almost doesn't suck](http://markos.gaivo.net/blog/?p=100) by Marko Samastur, and is licensed under the [MIT license](http://www.opensource.org/licenses/mit-license.php).\n\nInstallation\n------------\n\nYou'll need to download the [jQuery library](http://docs.jquery.com/Downloading_jQuery#Current_Release), and include it before _jquery.i18n.js_ in your HTML source. See the _examples_ folder for examples.\n\nThis library is also available as a [bower](http://bower.io/) component under the name *jquery-i18n*.\n\nUsage\n-----\n\nBefore you can do any translation you have to initialise the plugin with a 'dictionary' (basically a property list mapping keys to their translations).\n\n```javascript\nvar myDictionary = {\n  \"some text\":      \"a translation\",\n  \"some more text\": \"another translation\"\n}\n$.i18n.load(myDictionary);\n```\n\nOnce you've initialised it with a dictionary, you can translate strings using the $.i18n._() function, for example:\n\n```javascript\n$('div#example').text($.i18n._('some text'));\n```\n\nor using $('selector')._t() function\n\n```javascript\n$('div#example')._t('some text');\n```\n\nIf you'd like to switch languages, you can unload the current dictionary and load a new one:\n\n```javascript\n$.i18n.load('en');\n$.i18n.unload();\n$.i18n.load('ja');\n```\n\nWildcards\n---------\n\nIt's straightforward to pass dynamic data into your translations. First, add _%s_ in the translation for each variable you want to swap in :\n\n```javascript\nvar myDictionary = {\n  \"wildcard example\": \"We have been passed two values : %s and %s.\"\n}\n$.i18n.load(myDictionary);\n```\n\nNext, pass values in sequence after the dictionary key when you perform the translation :\n\n```javascript\n$('div#example').text($.i18n._('wildcard example', 100, 200));\n```\n\nor\n\n```javascript\n$('div#example')._t('wildcard example', 100, 200);\n```\n\nThis will output _We have been passed two values : 100 and 200._\n\nBecause some languages will need to order arguments differently to english, you can also specify the order in which the variables appear :\n\n```javascript\nvar myDictionary = {\n  \"wildcard example\": \"We have been passed two values : %2$s and %1$s.\"\n}\n$.i18n.load(myDictionary);\n\n$('div#example').text($.i18n._('wildcard example', 100, 200));\n```\n\nThis will output: _We have been passed two values: 200 and 100._\n\nIf you need to explicitly output the string _%s_ in your translation, use _%%s_ :\n\n```javascript\nvar myDictionary = {\n  \"wildcard example\": \"I have %s literal %%s character.\"\n}\n$.i18n.load(myDictionary);\n\n$('div#example').text($.i18n._('wildcard example', 1));\n```\n\nThis will output: _I have 1 literal %%s character._\n\n\nIdentifying missing translations\n---------\n\nWhen loading the dictionary, you can pass a second `missingPattern` parameter, which will be used to format any missing translations.\n\n```javascript\n$.i18n.load({ a_key: 'translated string' }, \"{{ %s }}\");\n// The following line will output '{{ another_key }}'\n$.i18n._('another_key')\n```\n\nThis allows you scan for the given pattern to identify missing translations.\n\n\nBuilding From Scratch\n---------------------\n\nUse `npm install` to install the dependencies, and `grunt` to run the build.\n\n\nChange history\n-----------\n\n* **Version 1.1.2 (2017-08-11)** : Add an `unload()` method to clear the dictionary, support passing a `missingPattern` when loading the dictionary (thanks to [briantani](https://github.com/briantani)).\n* **Version 1.1.1 (2014-01-05)** : Use `html()` instead of `text()` when rendering translations.\n* **Version 1.1.0 (2013-12-31)** : Use grunt, update `printf` implementation, `setDictionary` is now `load` (thanks to [ktmud](https://github.com/ktmud)).\n* **Version 1.0.1 (2013-10-11)** : Add bower support.\n* **Version 1.0.0 (2012-10-14)** : 1.0 release - addition of a test suite (huge thanks to [alexaitken](https://github.com/alexaitken)), plus a major cleanup.\n\nBug Reports\n-----------\n\nIf you come across any problems, please [create a ticket](https://github.com/recurser/jquery-i18n/issues) and we'll try to get it fixed as soon as possible.\n\n\nContributing\n------------\n\nOnce you've made your commits:\n\n1. [Fork](http://help.github.com/fork-a-repo/) jquery-i18n\n2. Create a topic branch - `git checkout -b my_branch`\n3. Push to your branch - `git push origin my_branch`\n4. Create a [Pull Request](https://help.github.com/en/articles/about-pull-requests) from your branch\n5. That's it!\n\n\nAuthor\n------\n\nDave Perrett :: hello@daveperrett.com :: [@daveperrett](http://twitter.com/daveperrett)\n\n\nCopyright\n---------\n\nCopyright (c) 2010 Dave Perrett. See [License](https://github.com/recurser/jquery-i18n/blob/master/LICENSE) for details.\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frecurser%2Fjquery-i18n","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frecurser%2Fjquery-i18n","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frecurser%2Fjquery-i18n/lists"}