index.rst 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795
  1. .. Converse.js documentation master file, created by
  2. sphinx-quickstart on Fri Apr 26 20:48:03 2013.
  3. You can adapt this file completely to your liking, but it should at least
  4. contain the root `toctree` directive.
  5. .. toctree::
  6. :maxdepth: 2
  7. .. contents:: Table of Contents
  8. :depth: 3
  9. :local:
  10. =========================================
  11. Quickstart (to get a demo up and running)
  12. =========================================
  13. When you download a specific release of *Converse.js* there will be two minified files inside the zip file.
  14. * converse.min.js
  15. * converse.min.css
  16. You can include these two files inside the *<head>* element of your website via the *script* and *link*
  17. tags:
  18. ::
  19. <link rel="stylesheet" type="text/css" media="screen" href="converse.min.css">
  20. <script src="converse.min.js"></script>
  21. You need to initialize Converse.js with configuration settings particular to
  22. your requirements.
  23. Please refer to the `Configuration variables`_ section further below for info on
  24. all the available configuration settings.
  25. To do this, put the following inline Javascript code at the
  26. bottom of your page (after the closing *</body>* element).
  27. ::
  28. require(['converse'], function (converse) {
  29. converse.initialize({
  30. auto_list_rooms: false,
  31. auto_subscribe: false,
  32. bosh_service_url: 'https://bind.opkode.im', // Please use this connection manager only for testing purposes
  33. hide_muc_server: false,
  34. i18n: locales.en, // Refer to ./locale/locales.js to see which locales are supported
  35. prebind: false,
  36. show_controlbox_by_default: true,
  37. xhr_user_search: false
  38. });
  39. });
  40. Finally, Converse.js requires a special snippet of HTML markup to be included in your page:
  41. ::
  42. <div id="chatpanel">
  43. <div id="collective-xmpp-chat-data"></div>
  44. <div id="toggle-controlbox">
  45. <a href="#" class="chat toggle-online-users">
  46. <strong class="conn-feedback">Toggle chat</strong> <strong style="display: none" id="online-count">(0)</strong>
  47. </a>
  48. </div>
  49. </div>
  50. The `index.html <https://github.com/jcbrand/converse.js/blob/master/index.html>`_ file inside the
  51. Converse.js repository serves as a nice usable example of this.
  52. These minified files provide the same demo-like functionality as is available
  53. on the `conversejs.org <http://conversejs.org>`_ website. Useful for testing or demoing, but not very
  54. practical.
  55. You'll most likely want to implement some kind of single-signon solution for
  56. your website, where users authenticate once in your website and then stay
  57. logged into their XMPP session upon page reload.
  58. For more info on this, read: `Pre-binding and Single Session Support`_.
  59. You might also want to have more fine-grained control of what gets included in
  60. the minified Javascript file. Read `Configuration`_ and `Minification`_ for more info on how to do
  61. that.
  62. ============
  63. Introduction
  64. ============
  65. Even though you can connect to public XMPP servers on the `conversejs.org`_
  66. website, *Converse.js* is not really meant to be a "Software-as-a-service" (SaaS)
  67. webchat.
  68. Instead, its goal is to provide the means for website owners to add a tightly
  69. integrated instant messaging service to their own sites.
  70. As a website owner, you are expected to host *Converse.js* yourself, and to do some legwork to
  71. properly configure and integrate it into your site.
  72. The benefit in doing this, is that your users have a much more streamlined and integrated
  73. webchat experience and that you have control over the data. The latter being a
  74. requirement for many sites dealing with sensitive information.
  75. You'll need to set up your own XMPP server and in order to have
  76. `Session Support`_ (i.e. single-signon functionality whereby users are authenticated once and stay
  77. logged in to XMPP upon page reload) you will also have to add some server-side
  78. code.
  79. The `What you will need`_ section has more information on all these
  80. requirements.
  81. ==================
  82. What you will need
  83. ==================
  84. An XMPP/Jabber server
  85. =====================
  86. *Converse.js* implements `XMPP`_ as its messaging protocol, and therefore needs
  87. to connect to an XMPP/Jabber server (Jabber is really just a synonym for XMPP).
  88. You can connect to public XMPP servers like ``jabber.org`` but if you want to
  89. have `Session Support`_ you'll have to set up your own XMPP server.
  90. You can find a list of public XMPP servers/providers on `xmpp.net`_ and a list of
  91. servers that you can set up yourself on `xmpp.org`_.
  92. Connection Manager
  93. ==================
  94. Your website and *Converse.js* use `HTTP`_ as protocol to communicate with
  95. the webserver. HTTP connections are stateless and usually shortlived.
  96. `XMPP`_ on the other hand, is the protocol that enables instant messaging, and
  97. its connections are stateful and usually longer.
  98. To enable a web application like *Converse.js* to communicate with an XMPP
  99. server, we need a proxy in the middle that can act as a bridge between the two
  100. protocols.
  101. This is the job of a connection manager. A connection manager can be either a
  102. standalone application or part of an XMPP server. `ejabberd`_ for example,
  103. includes a connection manager (but you have to enable it).
  104. The demo on the `Converse.js homepage`_ uses a a connection manager located at https://bind.opkode.im.
  105. This connection manager is for testing purposes only, please don't use it in
  106. production.
  107. Overcoming cross-domain request restrictions
  108. --------------------------------------------
  109. The domain of the *Converse.js* demo is *conversejs.org*, but the domain of the connection manager is *opkode.im*.
  110. HTTP requests are made by *Converse.js* to the connection manager via XmlHttpRequests (XHR).
  111. Until recently, it was not possible to make such requests to a different domain
  112. than the one currently being served (to prevent XSS attacks).
  113. Luckily there is now a standard called `CORS`_ (Cross-origin resource sharing), which enables exactly that.
  114. Modern browsers support CORS, but there are problems with Internet Explorer <
  115. 10.
  116. IE 8 and 9 partially support CORS via a proprietary implementation called
  117. XDomainRequest. There is a `Strophe.js plugin`_ which you can use to enable
  118. support for XDomainRequest when it is present.
  119. In IE < 8, there is no support for CORS.
  120. Instead of using CORS, you can add a reverse proxy in
  121. Apache/Nginx which serves the connection manager under the same domain as your
  122. website. This will remove the need for any cross-domain XHR support.
  123. For example:
  124. ~~~~~~~~~~~~
  125. Assuming your site is accessible on port ``80`` for the domain ``mysite.com``
  126. and your connection manager manager is running at ``someothersite.com/http-bind``.
  127. The *bosh_service_url* value you want to give Converse.js to overcome
  128. the cross-domain restriction is ``mysite.com/http-bind`` and not
  129. ``someothersite.com/http-bind``.
  130. Your ``nginx`` or ``apache`` configuration will look as follows:
  131. Nginx
  132. ~~~~~
  133. ::
  134. http {
  135. server {
  136. listen 80
  137. server_name mysite.com;
  138. location ~ ^/http-bind/ {
  139. proxy_pass http://someothersite.com;
  140. }
  141. }
  142. }
  143. Apache
  144. ~~~~~~
  145. ::
  146. <VirtualHost *:80>
  147. ServerName mysite.com
  148. RewriteEngine On
  149. RewriteRule ^/http-bind(.*) http://someothersite.com/http-bind$1 [P,L]
  150. </VirtualHost>
  151. Server-side authentication
  152. ==========================
  153. .. _`Session Support`:
  154. Pre-binding and Single Session Support
  155. --------------------------------------
  156. It's possible to enable single-site login, whereby users already
  157. authenticated in your website will also automatically be logged in on the chat server,
  158. but this will require custom code on your server.
  159. Jack Moffitt has a great `blogpost`_ about this and even provides an `example Django application`_ to demonstrate it.
  160. .. Note::
  161. If you want to enable single session support, make sure to pass **prebind: true**
  162. when you call **converse.initialize** (see ./index.html).
  163. Additionally you need to pass in valid **jid**, **sid**, **rid** and
  164. **bosh_service_url** values.
  165. When you authenticate to the XMPP server on your backend, you'll receive two
  166. tokens, RID (request ID) and SID (session ID).
  167. These tokens then need to be passed back to the javascript running in your
  168. browser, where you will need them to attach to the existing session.
  169. You can embed the RID and SID tokens in your HTML markup or you can do an
  170. XMLHttpRequest call to your server and ask it to return them for you.
  171. Below is one example of how this could work. An Ajax call is made to the
  172. relative URL **/prebind** and it expects to receive JSON data back.
  173. ::
  174. $.getJSON('/prebind', function (data) {
  175. converse.initialize({
  176. prebind: true,
  177. bosh_service_url: data.bosh_service_url,
  178. jid: data.jid,
  179. sid: data.sid,
  180. rid: data.rid
  181. });
  182. );
  183. **Here's what's happening:**
  184. The JSON data contains the user's JID (jabber ID), RID, SID and the URL to the
  185. BOSH connection manager.
  186. Facebook integration
  187. ====================
  188. .. Note ::
  189. It should be possible to integrate Converse.js with Facebook chat, and
  190. below I'll provide some tips and documentation on how to achieve this. That
  191. said, I don't have a Facebook account and therefore haven't tried to do
  192. this myself. Feedback and patches from people who have succesfully done this
  193. will be appreciated.
  194. Converse.js uses `Strophe.js <http://strophe.im/strophejs>`_ to connect and
  195. communicate with the XMPP server. One nice thing about Strophe.js is that it
  196. can be extended via `plugins <http://github.com/strophe/strophejs-plugins>`_.
  197. Here is a `plugin for authenticating with facebook
  198. <https://github.com/kissrobber/turedsocial/blob/master/strophe-plugins/src/facebook.js>`_.
  199. You will need your own BOSH connection manager to act as a proxy between
  200. Converse.js/Strophe.js and Facebook's XMPP server. That is because Facebook's
  201. XMPP server doesn't support BOSH natively.
  202. The BOSH connection manager that I make available for
  203. testing purposes (at https://bind.opkode.im) uses `Punjab <https://github.com/twonds/punjab>`_,
  204. although there are quite a few other options available as well.
  205. When you configure Converse.js, via its ``initialize`` method, you must specify the
  206. `bosh_service_url`_ value, which is to be your BOSH connection manager.
  207. Please note, to enable Facebook integration, you'll have to
  208. get your hands dirty and modify Converse.js's code, so that it calls the
  209. ``facebookConnect`` method of the plugin above.
  210. The plugin above gives the following code example for you to meditate upon:
  211. ::
  212. connection = new Strophe.Connection("http://localhost:5280/bosh");
  213. connection.facebookConnect(
  214. "12345@chat.facebook.com",
  215. onConnectFacebook,
  216. 300,
  217. 1,
  218. '5e64a30272af065bd72258c565a03f2f',
  219. '8147a27e4a7f9b55ffc85c2683f9529a',
  220. FB.getSession().session_key
  221. );
  222. The connection is already created inside Converse.js, so the
  223. ``facebookConnect`` method needs to also be called from there.
  224. If someone submits a sane patch that does the above, I'll be happy to merge it.
  225. Until then, people will have to do this themselves.
  226. ===========
  227. Development
  228. ===========
  229. If you want to work with the non-minified Javascript and CSS files you'll soon
  230. notice that there are references to a missing *components* folder. Please
  231. follow the instructions below to create this folder and fetch Converse's
  232. 3rd-party dependencies.
  233. Install Node.js and development dependencies
  234. ============================================
  235. We use development tools (`Grunt <http://gruntjs.com>`_ and `Bower <http://bower.io>`_)
  236. which depend on Node.js and npm (the Node package manager).
  237. If you don't have Node.js installed, you can download and install the latest
  238. version `here <https://nodejs.org/download>`_.
  239. Once you have Node.js installed, run the following command inside the Converse.js
  240. directory:
  241. ::
  242. npm install
  243. This will install all the development dependencies for Converse.js. If you are
  244. curious to know what these are, take a look at whats under the *devDependencies* key in
  245. `package.json <https://github.com/jcbrand/converse.js/blob/master/package.json>`.
  246. Install 3rd party dependencies
  247. ==============================
  248. After running ``npm install``, you will now have Grunt and Bower installed.
  249. We use Bower to manage Converse's front-end dependencies (e.g. Javascript that
  250. should get loaded in the browser).
  251. To fetch these dependencies, run:
  252. ::
  253. grunt fetch
  254. If you don't have grunt installed globally, you need to specify the relative
  255. path:
  256. ::
  257. ./node_modules/.bin/grunt fetch
  258. This will call Bower in the background to fetch all the front-end
  259. dependencies (like backbone.js, strophe.js etc.) and then put them in the
  260. *components* folder.
  261. With AMD and require.js (recommended)
  262. =====================================
  263. Converse.js uses `require.js <http://requirejs.org>`_ to asynchronously load dependencies.
  264. If you want to develop or customize converse.js, you'll want to load the
  265. non-minified javascript files.
  266. Add the following two lines to the *<head>* section of your webpage:
  267. ::
  268. <link rel="stylesheet" type="text/css" media="screen" href="converse.css">
  269. <script data-main="main" src="components/requirejs/require.js"></script>
  270. require.js will then let the main.js file be parsed (because of the *data-main*
  271. attribute on the *script* tag), which will in turn cause converse.js to be
  272. parsed.
  273. Without AMD and require.js
  274. ==========================
  275. Converse.js can also be used without require.js. If you for some reason prefer
  276. to use it this way, please refer to
  277. `non_amd.html <https://github.com/jcbrand/converse.js/blob/master/non_amd.html>`_
  278. for an example of how and in what order all the Javascript files that converse.js
  279. depends on need to be loaded.
  280. Before submitting a pull request
  281. ================================
  282. Add tests for your bugfix or feature
  283. ------------------------------------
  284. Add a test for any bug fixed or feature added. We use Jasmine
  285. for testing.
  286. Take a look at ``tests.html`` and ``spec/MainSpec.js`` to see how
  287. the tests are implemented.
  288. If you are unsure how to write tests, please
  289. `contact me <http://opkode.com/contact>`_ and I'll be happy to help.
  290. Check that the tests pass
  291. -------------------------
  292. Check that the Jasmine tests complete sucessfully. Open
  293. `tests.html <https://github.com/jcbrand/converse.js/blob/master/tests.html>`_
  294. in your browser, and the tests will run automatically.
  295. On the command line you can run:
  296. ::
  297. grunt test
  298. Check your code for errors or bad habits by running JSHint
  299. ----------------------------------------------------------
  300. `JSHint <http://jshint.com>`_ will do a static analysis of your code and hightlight potential errors
  301. and/or bad habits.
  302. ::
  303. grunt jshint
  304. You can run both the tests and jshint in one go by calling:
  305. ::
  306. grunt check
  307. =============
  308. Configuration
  309. =============
  310. The included minified JS and CSS files can be used for demoing or testing, but
  311. you'll want to configure *Converse.js* to suit your needs before you deploy it
  312. on your website.
  313. *Converse.js* is passed its configuration settings when you call its
  314. *initialize* method.
  315. You'll most likely want to call the *initialize* method in your HTML page. For
  316. an example of how this is done, please see the bottom of the *./index.html* page.
  317. Please refer to the `Configuration variables`_ section below for info on
  318. all the available configuration settings.
  319. After you have configured *Converse.js*, you'll have to regenerate the minified
  320. JS file so that it will include the new settings. Please refer to the
  321. `Minification`_ section for more info on how to do this.
  322. Configuration variables
  323. =======================
  324. allow_contact_requests
  325. ----------------------
  326. Default = ``true``
  327. Allow users to add one another as contacts. If this is set to false, the
  328. **Add a contact** widget, **Contact Requests** and **Pending Contacts** roster
  329. sections will all not appear. Additionally, all incoming contact requests will be
  330. ignored.
  331. allow_muc
  332. ---------
  333. Default = ``true``
  334. Allow multi-user chat (muc) in chatrooms. Setting this to ``false`` will remove
  335. the ``Chatrooms`` tab from the control box.
  336. animate
  337. -------
  338. Default = ``true``
  339. Show animations, for example when opening and closing chat boxes.
  340. auto_list_rooms
  341. ---------------
  342. Default = ``false``
  343. If true, and the XMPP server on which the current user is logged in supports
  344. multi-user chat, then a list of rooms on that server will be fetched.
  345. Not recommended for servers with lots of chat rooms.
  346. For each room on the server a query is made to fetch further details (e.g.
  347. features, number of occupants etc.), so on servers with many rooms this
  348. option will create lots of extra connection traffic.
  349. auto_subscribe
  350. --------------
  351. Default = ``false``
  352. If true, the user will automatically subscribe back to any contact requests.
  353. bosh_service_url
  354. ----------------
  355. Connections to an XMPP server depend on a BOSH connection manager which acts as
  356. a middle man between HTTP and XMPP.
  357. See `here <http://metajack.im/2008/09/08/which-bosh-server-do-you-need>`_ for more information.
  358. debug
  359. -----
  360. Default = ``false``
  361. If set to true, debugging output will be logged to the browser console.
  362. fullname
  363. --------
  364. If you are using prebinding, can specify the fullname of the currently
  365. logged in user, otherwise the user's vCard will be fetched.
  366. hide_muc_server
  367. ---------------
  368. Default = ``false``
  369. Hide the ``server`` input field of the form inside the ``Room`` panel of the
  370. controlbox. Useful if you want to restrict users to a specific XMPP server of
  371. your choosing.
  372. i18n
  373. ----
  374. Specify the locale/language. The language must be in the ``locales`` object. Refer to
  375. ``./locale/locales.js`` to see which locales are supported.
  376. prebind
  377. --------
  378. Default = ``false``
  379. Use this option when you want to attach to an existing XMPP connection that was
  380. already authenticated (usually on the backend before page load).
  381. This is useful when you don't want to render the login form on the chat control
  382. box with each page load.
  383. For prebinding to work, your backend server must authenticate for you, and
  384. then return a JID (jabber ID), SID (session ID) and RID (Request ID).
  385. If you set ``prebind`` to ``true``, you have to make sure to also pass in these
  386. values as ``jid``, ``sid``, ``rid``.
  387. Additionally, you have to specify ``bosh_service_url``.
  388. show_controlbox_by_default
  389. --------------------------
  390. Default = ``false``
  391. The "controlbox" refers to the special chatbox containing your contacts roster,
  392. status widget, chatrooms and other controls.
  393. By default this box is hidden and can be toggled by clicking on any element in
  394. the page with class *toggle-online-users*.
  395. If this options is set to true, the controlbox will by default be shown upon
  396. page load.
  397. show_only_online_users
  398. ----------------------
  399. Default = ``false``
  400. If set to ``true``, only online users will be shown in the contacts roster.
  401. Users with any other status (e.g. away, busy etc.) will not be shown.
  402. xhr_custom_status
  403. -----------------
  404. Default = ``false``
  405. Note::
  406. XHR stands for XMLHTTPRequest, and is meant here in the AJAX sense (Asynchronous Javascript and XML).
  407. This option will let converse.js make an AJAX POST with your changed custom chat status to a
  408. remote server.
  409. xhr_custom_status_url
  410. ---------------------
  411. Note::
  412. XHR stands for XMLHTTPRequest, and is meant here in the AJAX sense (Asynchronous Javascript and XML).
  413. Default = Empty string
  414. Used only in conjunction with ``xhr_custom_status``.
  415. This is the URL to which the AJAX POST request to set the user's custom status
  416. message will be made.
  417. The message itself is sent in the request under the key ``msg``.
  418. xhr_user_search
  419. ---------------
  420. Default = ``false``
  421. Note::
  422. XHR stands for XMLHTTPRequest, and is meant here in the AJAX sense (Asynchronous Javascript and XML).
  423. There are two ways to add users.
  424. * The user inputs a valid JID (Jabber ID), and the user is added as a pending contact.
  425. * The user inputs some text (for example part of a firstname or lastname), an XHR (Ajax Request) will be made to a remote server, and a list of matches are returned. The user can then choose one of the matches to add as a contact.
  426. This setting enables the second mechanism, otherwise by default the first will be used.
  427. *What is expected from the remote server?*
  428. A default JSON encoded list of objects must be returned. Each object
  429. corresponds to a matched user and needs the keys ``id`` and ``fullname``.
  430. xhr_user_search_url
  431. -------------------
  432. Note::
  433. XHR stands for XMLHTTPRequest, and is meant here in the AJAX sense (Asynchronous Javascript and XML).
  434. Default = Empty string
  435. Used only in conjunction with ``xhr_user_search``.
  436. This is the URL to which an AJAX GET request will be made to fetch user data from your remote server.
  437. The query string will be included in the request with ``q`` as its key.
  438. ============
  439. Minification
  440. ============
  441. Minifying Javascript and CSS
  442. ============================
  443. Please make sure to read the section `Development`_ and that you have installed
  444. all development dependencies (long story short, you can run ``npm install``
  445. and then ``grunt fetch``).
  446. We use `require.js`_ to keep track of *Converse.js* and its dependencies and to
  447. to bundle them together in a single minified file fit for deployment to a
  448. production site.
  449. To minify the Javascript and CSS, run the following command:
  450. ::
  451. grunt minify
  452. Javascript will be bundled and minified with `require.js`_'s optimization tool,
  453. using `almond <https://github.com/jrburke/almond>`_.
  454. You can `read more about require.js's optimizer here`_.
  455. CSS is minified via `cssmin <https://github.com/gruntjs/grunt-contrib-cssmin>`_.
  456. ============
  457. Translations
  458. ============
  459. .. Note ::
  460. Translations take up a lot of space and will bloat your minified file.
  461. At the time of writing, all the translations add about 50KB of extra data to
  462. the minified javascript file. Therefore, make sure to only
  463. include those languages that you intend to support and remove from
  464. ./locale/locales.js those which you don't need. Remember to rebuild the
  465. minified file afterwards.
  466. The gettext POT file located in ./locale/converse.pot is the template
  467. containing all translations and from which for each language an individual PO
  468. file is generated.
  469. The POT file contains all translateable strings extracted from converse.js.
  470. To make a user facing string translateable, wrap it in the double underscore helper
  471. function like so:
  472. ::
  473. __('This string will be translated at runtime');
  474. After adding the string, you'll need to regenerate the POT file, like so:
  475. ::
  476. make pot
  477. You can then create or update the PO file for a specific language by doing the following:
  478. ::
  479. msgmerge ./locale/de/LC_MESSAGES/converse.po ./locale/converse.pot -U
  480. To do this for ALL languages, run:
  481. ::
  482. make merge
  483. The resulting PO file is then what gets translated.
  484. If you've created a new PO file, please make sure to add the following
  485. attributes at the top of the file (under *Content-Transfer-Encoding*). They are
  486. required as configuration settings for Jed, the Javascript translations library
  487. that we're using.
  488. ::
  489. "domain: converse\n"
  490. "lang: de\n"
  491. "plural_forms: nplurals=2; plural=(n != 1);\n"
  492. Unfortunately `Jed <http://slexaxton.github.io/Jed>`_ cannot use the PO files directly. We have to generate from it
  493. a file in JSON format and then put that in a .js file for the specific
  494. language.
  495. To generate JSON from a PO file, you'll need po2json for node.js. Run the
  496. following command to install it (npm being the node.js package manager):
  497. ::
  498. npm install po2json
  499. You can then convert the translations into JSON format:
  500. ::
  501. po2json locale/de/LC_MESSAGES/converse.po locale/de/LC_MESSAGES/converse.json
  502. Now from converse.json paste the data as a value for the "locale_data" key in the
  503. object in the language's .js file.
  504. So, if you are for example translating into German (language code 'de'), you'll
  505. create or update the file ./locale/LC_MESSAGES/de.js with the following code:
  506. ::
  507. (function (root, factory) {
  508. define("de", ['jed'], function () {
  509. return factory(new Jed({
  510. "domain": "converse",
  511. "locale_data": {
  512. // Paste the JSON data from converse.json here
  513. }
  514. })
  515. }
  516. }(this, function (i18n) {
  517. return i18n;
  518. }));
  519. making sure to also paste the JSON data as value to the "locale_data" key.
  520. .. Note ::
  521. If you are adding translations for a new language that is not already supported,
  522. you'll have to make one more edit in ./locale/locales.js to make sure the
  523. language is loaded by require.js.
  524. Congratulations, you've now succesfully added your translations. Sorry for all
  525. those hoops you had to jump through.
  526. .. _`read more about require.js's optimizer here`: http://requirejs.org/docs/optimization.html
  527. .. _`HTTP`: https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol
  528. .. _`XMPP`: https://en.wikipedia.org/wiki/Xmpp
  529. .. _`Converse.js homepage`: http://conversejs.org
  530. .. _`CORS`: https://en.wikipedia.org/wiki/Cross-origin_resource_sharing
  531. .. _`Strophe.js plugin`: https://gist.github.com/1095825/6b4517276f26b66b01fa97b0a78c01275fdc6ff2
  532. .. _`xmpp.net`: http://xmpp.net
  533. .. _`xmpp.org`: http://xmpp.org/xmpp-software/servers/
  534. .. _`ejabberd`: http://www.ejabberd.im
  535. .. _`blogpost`: http://metajack.im/2008/10/03/getting-attached-to-strophe
  536. .. _`example Django application`: https://github.com/metajack/strophejs/tree/master/examples/attach