UNPKG

react-i18nify

Version:

Simple i18n translation and localization components and helpers for React.

23 lines (22 loc) 1.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _utils = require("./utils"); var _settings = require("./settings"); var _default = exports.default = function _default(key) { let replacements = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; const locale = options.locale || (0, _settings.getLocale)(); let translation = ''; try { const translationLocale = (0, _settings.getTranslations)()[locale] ? locale : locale.split('-')[0]; translation = (0, _utils.fetchTranslation)((0, _settings.getTranslations)(), `${translationLocale}.${key}`, replacements.count); } catch (err) { if (options.returnNullOnError) return null; if (options.returnKeyOnError) return key; return (0, _settings.handleMissingTranslation)(key, replacements, options, err); } return (0, _utils.replace)(translation, replacements); };