blob: 9232ac18a693f5d62cdda76cb7d7e3bc87b3b8c1 [file] [log] [blame]
Michael Landof5f13c42017-02-19 12:35:04 +02001/*-
2 * ============LICENSE_START=======================================================
3 * SDC
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
19 */
20
21'use strict';
22
23/**
24 * Translator for documentation pages.
25 *
26 * To enable translation you should include one of language-files in your index.html
27 * after <script src='lang/translator.js' type='text/javascript'></script>.
28 * For example - <script src='lang/ru.js' type='text/javascript'></script>
29 *
30 * If you wish to translate some new texsts you should do two things:
31 * 1. Add a new phrase pair ("New Phrase": "New Translation") into your language file (for example lang/ru.js). It will be great if you add it in other language files too.
32 * 2. Mark that text it templates this way <anyHtmlTag data-sw-translate>New Phrase</anyHtmlTag> or <anyHtmlTag data-sw-translate value='New Phrase'/>.
33 * The main thing here is attribute data-sw-translate. Only inner html, title-attribute and value-attribute are going to translate.
34 *
35 */
36window.SwaggerTranslator = {
37
38 _words:[],
39
40 translate: function(sel) {
41 var $this = this;
42 sel = sel || '[data-sw-translate]';
43
44 $(sel).each(function() {
45 $(this).html($this._tryTranslate($(this).html()));
46
47 $(this).val($this._tryTranslate($(this).val()));
48 $(this).attr('title', $this._tryTranslate($(this).attr('title')));
49 });
50 },
51
52 _tryTranslate: function(word) {
53 return this._words[$.trim(word)] !== undefined ? this._words[$.trim(word)] : word;
54 },
55
56 learn: function(wordsMap) {
57 this._words = wordsMap;
58 }
59};