UNPKG

3.27 kBJavaScriptView Raw
1/*
2 * Copyright 2017-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 * the License. A copy of the License is located at
6 *
7 * http://aws.amazon.com/apache2.0/
8 *
9 * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 * and limitations under the License.
12 */
13import { I18n as I18nClass } from './I18n';
14import { ConsoleLogger as Logger } from '../Logger';
15import { Amplify } from '../Amplify';
16var logger = new Logger('I18n');
17var _config = null;
18var _i18n = null;
19/**
20 * Export I18n APIs
21 */
22var I18n = /** @class */ (function () {
23 function I18n() {
24 }
25 /**
26 * @static
27 * @method
28 * Configure I18n part
29 * @param {Object} config - Configuration of the I18n
30 */
31 I18n.configure = function (config) {
32 logger.debug('configure I18n');
33 if (!config) {
34 return _config;
35 }
36 _config = Object.assign({}, _config, config.I18n || config);
37 I18n.createInstance();
38 return _config;
39 };
40 I18n.getModuleName = function () {
41 return 'I18n';
42 };
43 /**
44 * @static
45 * @method
46 * Create an instance of I18n for the library
47 */
48 I18n.createInstance = function () {
49 logger.debug('create I18n instance');
50 if (_i18n) {
51 return;
52 }
53 _i18n = new I18nClass(_config);
54 };
55 /**
56 * @static @method
57 * Explicitly setting language
58 * @param {String} lang
59 */
60 I18n.setLanguage = function (lang) {
61 I18n.checkConfig();
62 return _i18n.setLanguage(lang);
63 };
64 /**
65 * @static @method
66 * Get value
67 * @param {String} key
68 * @param {String} defVal - Default value
69 */
70 I18n.get = function (key, defVal) {
71 if (!I18n.checkConfig()) {
72 return typeof defVal === 'undefined' ? key : defVal;
73 }
74 return _i18n.get(key, defVal);
75 };
76 /**
77 * @static
78 * @method
79 * Add vocabularies for one language
80 * @param {String} langurage - Language of the dictionary
81 * @param {Object} vocabularies - Object that has key-value as dictionary entry
82 */
83 I18n.putVocabulariesForLanguage = function (language, vocabularies) {
84 I18n.checkConfig();
85 return _i18n.putVocabulariesForLanguage(language, vocabularies);
86 };
87 /**
88 * @static
89 * @method
90 * Add vocabularies for one language
91 * @param {Object} vocabularies - Object that has language as key,
92 * vocabularies of each language as value
93 */
94 I18n.putVocabularies = function (vocabularies) {
95 I18n.checkConfig();
96 return _i18n.putVocabularies(vocabularies);
97 };
98 I18n.checkConfig = function () {
99 if (!_i18n) {
100 _i18n = new I18nClass(_config);
101 }
102 return true;
103 };
104 return I18n;
105}());
106export { I18n };
107Amplify.register(I18n);
108/**
109 * @deprecated use named import
110 */
111export default I18n;
112//# sourceMappingURL=index.js.map
\No newline at end of file