How to use DEFAULT_LOCALE method in storybook-root

Best JavaScript code snippet using storybook-root

world_languages.js

Source:world_languages.js Github

copy

Full Screen

1/**2 * Created by Ali on 3/23/2015.3 */4"use strict";5module.exports = {6 "fr": "FR",7 "en": "US",8 "es": "ES",9 "de": "DE",10 "pt": "PT",11 "ar": "EG",12 "da": "DK",13 "nl": "NL",14 "sv": "SE",15 "zh": "CN",16 "hi": "IN",17 "fa": "IR",18 "it": "IT",19 "ja": "JP",20 "AF": {21 "country_name": "Afghanistan",22 "default_locale": "ps-AF",23 "other_locales": ["fa-AF", "ps-AF", "ug-AF", "uz-AF"]24 },25 "AL": {26 "country_name": "Albania",27 "default_locale": "sq-AL",28 "other_locales": []29 },30 "AM": {31 "country_name": "Armenia",32 "default_locale": "hy-AM",33 "other_locales": []34 },35 "AO": {36 "country_name": "Angola",37 "default_locale": "kg-AO",38 "other_locales": ["pt-AO"]39 },40 "AZ": {41 "country_name": "Azerbaijan",42 "default_locale": "az-AZ ",43 "other_locales": ["av-AZ", "az-Arab-AZ", "az-Cyrl-AZ", "az-Latn-AZ", "os-AZ"]44 },45 "BA": {46 "country_name": "Bosnia And Herzegovina",47 "default_locale": "bs-BA",48 "other_locales": ["hr-BA", "sr-BA"]49 },50 "BD": {51 "country_name": "Bangladesh",52 "default_locale": "bn-BD",53 "other_locales": []54 },55 "BG": {56 "country_name": "Bulgaria",57 "default_locale": "bg-BG ",58 "other_locales": ["cu-BG", "tr-BG"]59 },60 "BT": {61 "country_name": "Bhutan",62 "default_locale": "dz-BT",63 "other_locales": ["ne-BT"]64 },65 "BY": {66 "country_name": "Belarus",67 "default_locale": "be-BY ",68 "other_locales": ["cu-BY", "yi-BY"]69 },70 "CC": {71 "country_name": "Cocos Islands",72 "default_locale": "ms-CC",73 "other_locales": []74 },75 "CD": {76 "country_name": "The Democratic Republic Of Congo",77 "default_locale": "kg-CD ",78 "other_locales": ["fr-CD", "ln-CD", "lu-CD"]79 },80 "CG": {81 "country_name": "Congo",82 "default_locale": "kg-CG",83 "other_locales": ["fr-CG", "ln-CG"]84 },85 "CS": {86 "country_name": "Serbia And Montenegro",87 "default_locale": "sr-CS",88 "other_locales": [89 "cu-CS",90 "hu-CS",91 "sq-CS",92 "sr-CS",93 "sr-Cyrl-CS",94 "sr-Latn-CS"95 ]96 },97 "CX": {98 "country_name": "Christmas Island",99 "default_locale": "ms-CC",100 "other_locales": []101 },102 "CY": {103 "country_name": "Cyprus",104 "default_locale": "el-CY",105 "other_locales": ["tr-CY"]106 },107 "CZ": {108 "country_name": "Czech Republic",109 "default_locale": "cs-CZ",110 "other_locales": []111 },112 "DJ": {113 "country_name": "Djibouti",114 "default_locale": "aa-DJ",115 "other_locales": ["fr-DJ", "so-DJ"]116 },117 "DK": {118 "country_name": "Denmark",119 "default_locale": "da-DK",120 "other_locales": ["de-DK"]121 },122 "EE": {123 "country_name": "Estonia",124 "default_locale": "et-EE",125 "other_locales": ["yi-EE"]126 },127 "ER": {128 "country_name": "Eritrea",129 "default_locale": "aa-ER",130 "other_locales": ["byn-ER", "en-ER", "gez-ER", "ti-ER", "tig-ER"]131 },132 "ET": {133 "country_name": "Ethiopia",134 "default_locale": "aa-ET",135 "other_locales": [136 "am-ET",137 "en-ET",138 "gez-ET",139 "om-ET",140 "sid-ET",141 "so-ET",142 "ti-ET",143 "wal-ET"144 ]145 },146 "FI": {147 "country_name": "Finland",148 "default_locale": "fi-FI",149 "other_locales": ["smn-FI", "sv-FI"]150 },151 "FJ": {152 "country_name": "Fiji",153 "default_locale": "fj-FJ",154 "other_locales": ["en-FJ"]155 },156 "FO": {157 "country_name": "Faroe Islands",158 "default_locale": "da-FO",159 "other_locales": ["fo-FO"]160 },161 "GE": {162 "country_name": "Georgia",163 "default_locale": "ka-GE",164 "other_locales": ["ab-GE", "os-GE"]165 },166 "GH": {167 "country_name": "Ghana",168 "default_locale": "ak-GH",169 "other_locales": ["ee-GH", "en-GH", "tw-GH"]170 },171 "GL": {172 "country_name": "Greenland",173 "default_locale": "da-GL",174 "other_locales": ["kl-GL"]175 },176 "GR": {177 "country_name": "Greece",178 "default_locale": "el-GR",179 "other_locales": []180 },181 "HR": {182 "country_name": "Croatia",183 "default_locale": "hr-HR",184 "other_locales": ["it-HR"]185 },186 "HT": {187 "country_name": "Haiti",188 "default_locale": "ht-HT",189 "other_locales": ["fr-HT"]190 },191 "HU": {192 "country_name": "Hungary",193 "default_locale": " hu-HU",194 "other_locales": ["de-HU", "sk-HU", "sr-HU"]195 },196 "ID": {197 "country_name": "Indonesia",198 "default_locale": "id-ID",199 "other_locales": ["jv-ID", "su-ID"]200 },201 "IL": {202 "country_name": "Israel",203 "default_locale": "he-IL",204 "other_locales": ["ar-IL", "en-IL", "yi-IL"]205 },206 "IS": {207 "country_name": "Iceland",208 "default_locale": "is-IS",209 "other_locales": []210 },211 "KG": {212 "country_name": "Kyrgyzstan",213 "default_locale": "ky-KG",214 "other_locales": ["ug-KG"]215 },216 "KH": {217 "country_name": "Cambodia",218 "default_locale": "km-KH",219 "other_locales": []220 },221 "KP": {222 "country_name": "Democratic People 's Republic Of Korea",223 "default_locale": "ko-KP",224 "other_locales": []225 },226 "KR": {227 "country_name": "Republic Of Korea",228 "default_locale": "ko-KR",229 "other_locales": []230 },231 "KZ": {232 "country_name": "Kazakhstan",233 "default_locale": "kk-KZ",234 "other_locales": ["av-KZ", "os-KZ", "ug-KZ"]235 },236 "LA": {237 "country_name": "Lao People's Democratic Republic",238 "default_locale": "lo-LA",239 "other_locales": []240 },241 "LK": {242 "country_name": "Sri Lanka",243 "default_locale": "si-LK",244 "other_locales": []245 },246 "LT": {247 "country_name": "Lithuania",248 "default_locale": "lt-LT",249 "other_locales": ["yi-LT"]250 },251 "LV": {252 "country_name": "Latvia",253 "default_locale": "lv-LV",254 "other_locales": ["yi-LV"]255 },256 "MD": {257 "country_name": "Republic Of Moldova,",258 "default_locale": "mo-MD",259 "other_locales": ["ro-MD", "tr-MD", "uk-MD", "yi-MD"]260 },261 "MK": {262 "country_name": "Macedonia",263 "default_locale": "mk-MK",264 "other_locales": ["cu-MK"]265 },266 "ML": {267 "country_name": "Mali",268 "default_locale": " fr-ML",269 "other_locales": ["bm-ML"]270 },271 "MM": {272 "country_name": "Myanmar",273 "default_locale": "my-MM",274 "other_locales": []275 },276 "MN": {277 "country_name": "Mongolia",278 "default_locale": "mn-MN",279 "other_locales": []280 },281 "MT": {282 "country_name": "Malta",283 "default_locale": "mt-MT",284 "other_locales": ["en-MT"]285 },286 "MV": {287 "country_name": "Maldives",288 "default_locale": "dv-MV",289 "other_locales": []290 },291 "MY": {292 "country_name": "Malaysia",293 "default_locale": "ms-MY",294 "other_locales": ["jv-MY"]295 },296 "NO": {297 "country_name": "Norway",298 "default_locale": "no-NO",299 "other_locales": ["nb-NO", "nn-NO", "no-bok-NO", "no-nyn-NO"]300 },301 "NP": {302 "country_name": "Nepal",303 "default_locale": "ne-NP",304 "other_locales": []305 },306 "NR": {307 "country_name": "Nauru",308 "default_locale": "na-NR",309 "other_locales": ["en-NR"]310 },311 "PK": {312 "country_name": "Pakistan",313 "default_locale": "ur-PK",314 "other_locales": ["en-PK", "sd-PK"]315 },316 "PL": {317 "country_name": "Poland",318 "default_locale": "pl-PL",319 "other_locales": ["de-PL", "yi-PL"]320 },321 "RO": {322 "country_name": "Romania",323 "default_locale": "ro-RO",324 "other_locales": ["cu-RO", "hu-RO", "yi-RO"]325 },326 "RU": {327 "country_name": "Russian Federation",328 "default_locale": "ru-RU",329 "other_locales": [330 "av-RU",331 "ba-RU",332 "ce-RU",333 "cu-RU",334 "cv-RU",335 "kv-RU",336 "os-RU",337 "tt-RU",338 "yi-RU"339 ]340 },341 "RW": {342 "country_name": "Rwanda",343 "default_locale": "rw-RW",344 "other_locales": ["en-RW", "fr-RW"]345 },346 "SI": {347 "country_name": "Slovenia",348 "default_locale": "hu-SI",349 "other_locales": ["it-SI"]350 },351 "SK": {352 "country_name": "Slovakia",353 "default_locale": "sk-SK",354 "other_locales": ["hu-SK"]355 },356 "SN": {357 "country_name": "Senegal",358 "default_locale": "ff-SN",359 "other_locales": ["wo-SN"]360 },361 "SZ": {362 "country_name": "Swaziland",363 "default_locale": "ss-SZ",364 "other_locales": ["en-SZ"]365 },366 "TG": {367 "country_name": "Togo",368 "default_locale": "ee-TG",369 "other_locales": ["fr-TG", "ha-TG"]370 },371 "TH": {372 "country_name": "Thailand",373 "default_locale": "th-TH",374 "other_locales": ["si-TH"]375 },376 "TJ": {377 "country_name": "Tajikistan",378 "default_locale": "tg-TJ",379 "other_locales": ["os-TJ", "ug-TJ"]380 },381 "TM": {382 "country_name": "Turkmenistan",383 "default_locale": "tk-TM",384 "other_locales": ["os-TM"]385 },386 "TO": {387 "country_name": "Tonga",388 "default_locale": "to-TO",389 "other_locales": ["en-TO"]390 },391 "TR": {392 "country_name": "Turkey",393 "default_locale": "tr-TR",394 "other_locales": ["ab-TR", "av-TR", "ku-TR", "ug-TR"]395 },396 "TV": {397 "country_name": "Tuvalu",398 "default_locale": "tvl-TV",399 "other_locales": ["gil-TV"]400 },401 "TZ": {402 "country_name": "United Republic Of Tanzania",403 "default_locale": "sw-TZ",404 "other_locales": []405 },406 "UA": {407 "country_name": "Ukraine",408 "default_locale": "uk-UA",409 "other_locales": [410 "ab-UA",411 "cu-UA",412 "hu-UA",413 "os-UA",414 "pl-UA",415 "ro-UA",416 "ru-UA",417 "yi-UA"418 ]419 },420 "UZ": {421 "country_name": "Uzbekistan",422 "default_locale": "uz-UZ",423 "other_locales": ["os-UZ", "ug-UZ", "uz-Cyrl-UZ", "uz-Latn-UZ"]424 },425 "VA": {426 "country_name": "Vatican City State",427 "default_locale": "la-VA",428 "other_locales": ["fr-VA", "it-VA"]429 },430 "VN": {431 "country_name": "Viet Nam",432 "default_locale": "vi-VN",433 "other_locales": []434 },435 "WS": {436 "country_name": "Samoa",437 "default_locale": "sm-WS",438 "other_locales": ["en-WS"]439 },440 "YU": {441 "country_name": "Yugoslavia",442 "default_locale": "sr-YU",443 "other_locales": []444 }...

Full Screen

Full Screen

constantTranslations.ts

Source:constantTranslations.ts Github

copy

Full Screen

1import {2 ATTRIBUTE_POSITION_IN_TITLE_AFTER_KEYWORD,3 ATTRIBUTE_POSITION_IN_TITLE_BEFORE_KEYWORD,4 ATTRIBUTE_POSITION_IN_TITLE_BEGIN,5 ATTRIBUTE_POSITION_IN_TITLE_END,6 ATTRIBUTE_POSITION_IN_TITLE_REPLACE_KEYWORD,7 ATTRIBUTE_VARIANT_MULTIPLE_SELECT,8 ATTRIBUTE_VARIANT_NUMBER,9 ATTRIBUTE_VARIANT_SELECT,10 ATTRIBUTE_VARIANT_STRING,11 ATTRIBUTE_VIEW_VARIANT_ICON,12 ATTRIBUTE_VIEW_VARIANT_LIST,13 ATTRIBUTE_VIEW_VARIANT_OUTER_RATING,14 ATTRIBUTE_VIEW_VARIANT_TAG,15 ATTRIBUTE_VIEW_VARIANT_TEXT,16 DEFAULT_LOCALE,17 GENDER_HE,18 GENDER_IT,19 GENDER_PLURAL,20 GENDER_SHE,21 GENDER_SINGULAR,22 NAV_GROUP_CMS,23 NAV_GROUP_CONSOLE,24 OPTIONS_GROUP_VARIANT_COLOR,25 OPTIONS_GROUP_VARIANT_ICON,26 OPTIONS_GROUP_VARIANT_TEXT,27 SECONDARY_LOCALE,28 SUPPLIER_PRICE_VARIANT_CHARGE,29 SUPPLIER_PRICE_VARIANT_DISCOUNT,30} from 'lib/config/common';31import { get } from 'lodash';32export const constantTranslations = {33 nav: {34 blog: {35 [DEFAULT_LOCALE]: 'Блог',36 [SECONDARY_LOCALE]: 'Blog',37 },38 contacts: {39 [DEFAULT_LOCALE]: 'Контакты',40 [SECONDARY_LOCALE]: 'Contacts',41 },42 },43 shops: {44 single: {45 [DEFAULT_LOCALE]: 'магазин',46 [SECONDARY_LOCALE]: 'shop',47 },48 plural: {49 [DEFAULT_LOCALE]: 'магазинах',50 [SECONDARY_LOCALE]: 'shops',51 },52 },53 boolean: {54 true: {55 [DEFAULT_LOCALE]: 'Да',56 [SECONDARY_LOCALE]: 'Yes',57 },58 false: {59 [DEFAULT_LOCALE]: 'Нет',60 [SECONDARY_LOCALE]: 'No',61 },62 },63 messages: {64 error: {65 [DEFAULT_LOCALE]: 'Что-то пошло не так. Попробуйте ещё раз.',66 [SECONDARY_LOCALE]: 'Something went wrong. Please try again.',67 },68 dataError: {69 [DEFAULT_LOCALE]: 'Ошибка загрузки данных.',70 [SECONDARY_LOCALE]: 'Data loading error.',71 },72 permissionError: {73 [DEFAULT_LOCALE]: 'У вас нет прав доступа к данной операции.',74 [SECONDARY_LOCALE]: `You don't have permission to access this operation.`,75 },76 },77 breadcrumbs: {78 main: {79 [DEFAULT_LOCALE]: 'Главная',80 [SECONDARY_LOCALE]: 'Main',81 },82 },83 catalogueTitleSeparator: {84 [DEFAULT_LOCALE]: 'и',85 [SECONDARY_LOCALE]: 'and',86 },87 catalogueFilter: {88 brands: {89 [DEFAULT_LOCALE]: 'Бренды',90 [SECONDARY_LOCALE]: 'Brands',91 },92 brandCollections: {93 [DEFAULT_LOCALE]: 'Линейки бренда',94 [SECONDARY_LOCALE]: 'Brand collections',95 },96 manufacturers: {97 [DEFAULT_LOCALE]: 'Производители',98 [SECONDARY_LOCALE]: 'Manufacturers',99 },100 },101 navGroups: {102 [NAV_GROUP_CMS]: {103 [DEFAULT_LOCALE]: 'CMS',104 [SECONDARY_LOCALE]: 'CMS',105 },106 [NAV_GROUP_CONSOLE]: {107 [DEFAULT_LOCALE]: 'Панель управления компании',108 [SECONDARY_LOCALE]: 'Company console',109 },110 },111 suppliers: {112 priceVariant: {113 [SUPPLIER_PRICE_VARIANT_DISCOUNT]: {114 [DEFAULT_LOCALE]: 'Дилерская скидка',115 [SECONDARY_LOCALE]: 'Dealer discount',116 },117 [SUPPLIER_PRICE_VARIANT_CHARGE]: {118 [DEFAULT_LOCALE]: 'Дилерская наценка',119 [SECONDARY_LOCALE]: 'Dealer charge',120 },121 },122 },123 selectsOptions: {124 gender: {125 [GENDER_SHE]: {126 [DEFAULT_LOCALE]: 'Женский род',127 [SECONDARY_LOCALE]: 'She',128 },129 [GENDER_HE]: {130 [DEFAULT_LOCALE]: 'Мужской род',131 [SECONDARY_LOCALE]: 'He',132 },133 [GENDER_IT]: {134 [DEFAULT_LOCALE]: 'Средний род',135 [SECONDARY_LOCALE]: 'It',136 },137 [GENDER_PLURAL]: {138 [DEFAULT_LOCALE]: 'Множественное число',139 [SECONDARY_LOCALE]: 'Plural',140 },141 [GENDER_SINGULAR]: {142 [DEFAULT_LOCALE]: 'Единственное число',143 [SECONDARY_LOCALE]: 'Singular',144 },145 },146 attributeVariants: {147 [ATTRIBUTE_VARIANT_SELECT]: {148 [DEFAULT_LOCALE]: 'Селект',149 [SECONDARY_LOCALE]: 'Select',150 },151 [ATTRIBUTE_VARIANT_MULTIPLE_SELECT]: {152 [DEFAULT_LOCALE]: 'Мульти-селект',153 [SECONDARY_LOCALE]: 'Multi-select',154 },155 [ATTRIBUTE_VARIANT_STRING]: {156 [DEFAULT_LOCALE]: 'Строка',157 [SECONDARY_LOCALE]: 'String',158 },159 [ATTRIBUTE_VARIANT_NUMBER]: {160 [DEFAULT_LOCALE]: 'Число',161 [SECONDARY_LOCALE]: 'Number',162 },163 },164 attributeVariantsPlural: {165 [ATTRIBUTE_VARIANT_SELECT]: {166 [DEFAULT_LOCALE]: 'Селекты',167 [SECONDARY_LOCALE]: 'Selects',168 },169 [ATTRIBUTE_VARIANT_MULTIPLE_SELECT]: {170 [DEFAULT_LOCALE]: 'Мульти-селекты',171 [SECONDARY_LOCALE]: 'Multi-selects',172 },173 [ATTRIBUTE_VARIANT_STRING]: {174 [DEFAULT_LOCALE]: 'Текстовые',175 [SECONDARY_LOCALE]: 'Strings',176 },177 [ATTRIBUTE_VARIANT_NUMBER]: {178 [DEFAULT_LOCALE]: 'Числовые',179 [SECONDARY_LOCALE]: 'Numbers',180 },181 },182 attributePositioning: {183 [ATTRIBUTE_POSITION_IN_TITLE_BEGIN]: {184 [DEFAULT_LOCALE]: 'Начало заголовка',185 [SECONDARY_LOCALE]: 'In the beginning of title',186 },187 [ATTRIBUTE_POSITION_IN_TITLE_BEFORE_KEYWORD]: {188 [DEFAULT_LOCALE]: 'Перед ключевым словом',189 [SECONDARY_LOCALE]: 'Before keyword',190 },191 [ATTRIBUTE_POSITION_IN_TITLE_REPLACE_KEYWORD]: {192 [DEFAULT_LOCALE]: 'Замена ключевого слова',193 [SECONDARY_LOCALE]: 'Replace keyword',194 },195 [ATTRIBUTE_POSITION_IN_TITLE_AFTER_KEYWORD]: {196 [DEFAULT_LOCALE]: 'После ключевого слова',197 [SECONDARY_LOCALE]: 'After keyword',198 },199 [ATTRIBUTE_POSITION_IN_TITLE_END]: {200 [DEFAULT_LOCALE]: 'Конец заголовка',201 [SECONDARY_LOCALE]: 'In the end of title',202 },203 },204 attributeView: {205 [ATTRIBUTE_VIEW_VARIANT_LIST]: {206 [DEFAULT_LOCALE]: 'Список',207 [SECONDARY_LOCALE]: 'In list',208 },209 [ATTRIBUTE_VIEW_VARIANT_TEXT]: {210 [DEFAULT_LOCALE]: 'Текст',211 [SECONDARY_LOCALE]: 'As text',212 },213 [ATTRIBUTE_VIEW_VARIANT_TAG]: {214 [DEFAULT_LOCALE]: 'Тег',215 [SECONDARY_LOCALE]: 'As tag',216 },217 [ATTRIBUTE_VIEW_VARIANT_ICON]: {218 [DEFAULT_LOCALE]: 'С иконкой',219 [SECONDARY_LOCALE]: 'With icon',220 },221 [ATTRIBUTE_VIEW_VARIANT_OUTER_RATING]: {222 [DEFAULT_LOCALE]: 'Внешний рейтинг',223 [SECONDARY_LOCALE]: 'As outer rating',224 },225 },226 optionsGroupVariant: {227 [OPTIONS_GROUP_VARIANT_TEXT]: {228 [DEFAULT_LOCALE]: 'Текст',229 [SECONDARY_LOCALE]: 'Text',230 },231 [OPTIONS_GROUP_VARIANT_ICON]: {232 [DEFAULT_LOCALE]: 'С иконкой',233 [SECONDARY_LOCALE]: 'With icon',234 },235 [OPTIONS_GROUP_VARIANT_COLOR]: {236 [DEFAULT_LOCALE]: 'С цветом',237 [SECONDARY_LOCALE]: 'With color',238 },239 },240 },241 pagination: {242 page: {243 [DEFAULT_LOCALE]: 'страница',244 [SECONDARY_LOCALE]: 'page',245 },246 },247 validation: {248 email: {249 [DEFAULT_LOCALE]: 'Email обязателен к заполнению.',250 [SECONDARY_LOCALE]: 'Email is required.',251 },252 name: {253 [DEFAULT_LOCALE]: 'Имя обязательно к заполнению.',254 [SECONDARY_LOCALE]: ' is required.',255 },256 phone: {257 [DEFAULT_LOCALE]: 'Телефон обязателен к заполнению.',258 [SECONDARY_LOCALE]: 'Phone is required.',259 },260 privacy: {261 [DEFAULT_LOCALE]: 'Подтвердите согласие на обработку личных данных.',262 [SECONDARY_LOCALE]: 'Confirm privacy agreement.',263 },264 },265};266interface GetBooleanTranslationInterface {267 value?: boolean | string | null;268 locale: string;269}270export const getConstantTranslation = (path: string): string => {271 return `${get(constantTranslations, path)}`;272};273export const getBooleanTranslation = ({274 value,275 locale,276}: GetBooleanTranslationInterface): string => {277 let finalValue = value ? 'true' : 'false';278 if (typeof value === 'string') {279 finalValue = value;280 }281 if (typeof value === 'number') {282 finalValue = value > 0 ? 'true' : 'false';283 }284 return getConstantTranslation(`boolean.${finalValue}.${locale}`);...

Full Screen

Full Screen

index.ts

Source:index.ts Github

copy

Full Screen

1/**2 * @module @eartharoid/i18n3 * @author eartharoid <contact@eartharoid.me>4 * @copyright 2021 Isaac Saunders (eartharoid)5 * @license MIT6 */7'use strict';8interface NamedArgs {9 [name: string]: string | number10}11type MessageArgs = (string | number | NamedArgs)[]12type Message = string[] | string;13interface Messages {14 [message: string]: Messages | Message15}16interface Locales {17 [locale: string]: Messages18}19module.exports = class I18n {20 public default_locale: string;21 public readonly locales: string[];22 private readonly messages: Locales;23 /**24 * Create a new I18n instance25 * @param {string} default_locale - The name of the default locale26 * @param {Locales} locales - An object of your locales27 */28 constructor(29 default_locale: string,30 locales: Locales31 ) {32 if (typeof default_locale !== 'string')33 throw new TypeError(`Expected "default_locale" to be a string, got ${typeof default_locale}`);34 if (typeof locales !== 'object')35 throw new TypeError(`Expected "locales" to be an object, got ${typeof locales}`);36 /**37 * The name of the default locale38 * @type {string}39 */40 this.default_locale = default_locale;41 /**42 * An array of locales43 * @type {string[]}44 */45 this.locales = Object.keys(locales);46 /**47 * Messages from all locales48 * @type {any}49 */50 this.messages = locales;51 if (!this.locales.includes(this.default_locale))52 throw new Error(`The default locale "${default_locale}" does not exist`);53 }54 /**55 * Get a locale56 * @param {string} [locale] - The locale to get57 * @returns {(message: string, ...args: MessageArgs) => string | undefined}58 */59 public getLocale(60 locale: string | undefined = this.default_locale61 ): (message: string, ...args: MessageArgs) => string | undefined {62 return (message: string, ...args: MessageArgs) => this.getMessage(locale, message, ...args);63 }64 /**65 * Get a message from a locale66 * @param {string} [locale] - The locale to get the message from67 * @param {string} message - The message to get68 * @param {MessageArgs} args - Placeholder values69 * @returns {string|undefined}70 */71 public getMessage(72 locale: string | undefined = this.default_locale,73 message: string,74 ...args: MessageArgs75 ): string | undefined {76 // fallback to default locale if provided one is an empty string77 locale ||= this.default_locale;78 if (!this.locales.includes(locale)) throw new Error(`A locale with the name of "${locale}" does not exist`);79 // || instead of ?? as empty strings should fallback80 let text = this.resolve(this.messages[locale], message) || this.resolve(this.messages[this.default_locale], message);81 if (!text) return undefined;82 if (!args && typeof text === 'string') return text;83 else if (!args) throw new Error(`"${message}" is an array and a number was not provided.`);84 if (text instanceof Array) {85 const number = args.shift();86 switch (number) {87 case 0:88 text = text[text.length === 3 ? 0 : 1];89 break;90 case 1:91 text = text[text.length === 3 ? 1 : 0];92 break;93 default:94 text = text[text.length === 3 ? 2 : 1];95 }96 } else if (typeof text === 'object') {97 throw new Error(`"${message}" in the "${locale}" locale is not an array or string`);98 }99 if (typeof args[0] === 'object') {100 const regex = /(?<!\\){{1,2}\s?([A-Za-z0-9\-._:]+)\s?(?<!\\)}{1,2}/gi;101 const data: NamedArgs = args[0];102 return text.replace(regex, ($: string, $1: string): string | undefined => {103 const value = <string>this.resolve(data, $1);104 return value === undefined ? $ : value;105 });106 } else {107 const regex = /(?<!\\)%(d|s)/gi;108 let i = 0;109 return text110 .replace(regex, () => <string>args[i++]);111 }112 }113 /**114 * Resolve a value from an object using a dot notation string115 * @param {Messages|MessageArgs} obj - The object containing the value116 * @param {string} key - The dot notation string117 * @returns {string|string[]|undefined}118 */119 private resolve(120 obj: Messages | MessageArgs | NamedArgs,121 key: string122 ): string | string[] | undefined {123 const item: string | string[] | undefined = key124 .split(/\./g)125 .reduce((acc, part) => acc && acc[part], obj);126 return item;127 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { DEFAULT_LOCALE } from 'storybook-root';2import { DEFAULT_LOCALE } from 'storybook-root';3import { DEFAULT_LOCALE } from 'storybook-root';4import { DEFAULT_LOCALE } from 'storybook-root';5import { DEFAULT_LOCALE } from 'storybook-root';6import { DEFAULT_LOCALE } from 'storybook-root';7import { DEFAULT_LOCALE } from 'storybook-root';8import { DEFAULT_LOCALE } from 'storybook-root';9import { DEFAULT_LOCALE } from 'storybook-root';10import { DEFAULT_LOCALE } from 'storybook-root';11import { DEFAULT_LOCALE } from 'storybook-root';12import { DEFAULT_LOCALE } from 'storybook-root';13import { DEFAULT_LOCALE } from 'storybook-root';14import { DEFAULT_LOCALE } from 'storybook-root';15import { DEFAULT_LOCALE } from 'storybook-root';16import { DEFAULT_LOCALE } from 'storybook-root';17import { DEFAULT_LOCALE } from 'storybook-root';18import { DEFAULT_LOCALE } from 'storybook-root';19import { DEFAULT_LOCALE } from 'storybook-root';20import { DEFAULT_LOCALE } from

Full Screen

Using AI Code Generation

copy

Full Screen

1import { DEFAULT_LOCALE } from 'storybook-root';2console.log(DEFAULT_LOCALE);3import { DEFAULT_LOCALE } from 'storybook-root';4console.log(DEFAULT_LOCALE);5import { setDefaultLocale } from 'storybook-root';6setDefaultLocale('en');

Full Screen

Using AI Code Generation

copy

Full Screen

1import { DEFAULT_LOCALE } from 'storybook-root';2import { DEFAULT_LOCALE } from 'storybook-root';3import { DEFAULT_LOCALE } from 'storybook-root';4import { DEFAULT_LOCALE } from 'storybook-root';5As you can see, I am importing the same method from the same package in 3 different files. But when I run npm run storybook , I am getting the following error:6 @ multi ./node_modules/@storybook/core/dist/server/common/polyfills.js ./node_modules/@storybook/core/dist/server/preview/globals.js ./.storybook/config.js (webpack)-hot-middleware/client.js?reload=true7 @ multi ./node_modules/@storybook/core/dist/server/common/polyfills.js ./node_modules/@storybook/core/dist/server/preview/globals.js ./.storybook/config.js (webpack)-hot-middleware/client.js?reload=true8 @ multi ./node_modules/@storybook/core/dist/server/common/polyfills.js ./node_modules/@storybook/core/dist/server/preview/globals.js ./.storybook/config.js (webpack)-hot-middleware/client.js?reload=true

Full Screen

Using AI Code Generation

copy

Full Screen

1import { DEFAULT_LOCALE } from 'storybook-addon-root';2import { getRootDecorator } from 'storybook-addon-root';3import { withRoot } from 'storybook-addon-root';4import { getRootDecorator } from 'storybook-addon-root';5import { withRoot } from 'storybook-addon-root';6import { getRootDecorator } from 'storybook-addon-root';7import { withRoot } from 'storybook-addon-root';8import { getRootDecorator } from 'storybook-addon-root';9import { withRoot } from 'storybook-addon-root';10import { getRootDecorator } from 'storybook-addon-root';11import { withRoot } from 'storybook-addon-root';12import { getRootDecorator } from 'storybook-addon-root';13import { withRoot } from 'storybook-addon-root';14import { getRootDecorator } from 'storybook-addon-root';15import { withRoot } from 'storybook-addon-root';16import { getRootDecorator } from 'storybook-addon-root';17import { withRoot } from 'storybook-addon-root';18import { getRootDecorator } from 'storybook-addon-root';19import { withRoot } from 'storybook-addon-root';20import { getRootDecorator } from 'storybook-addon-root';

Full Screen

Using AI Code Generation

copy

Full Screen

1import { DEFAULT_LOCALE } from 'storybook-root';2import { configure } from '@storybook/react';3import { addDecorator, addParameters } from '@storybook/react';4import { withInfo } from '@storybook/addon-info';5import { withKnobs } from '@storybook/addon-knobs';6addParameters({7 options: {8 },9});10addDecorator(withInfo);11addDecorator(withKnobs);12configure(require.context('../src', true, /\.stories\.js$/), module);13import { DEFAULT_LOCALE } from 'storybook-root';14import { configure } from '@storybook/react';15import { addDecorator, addParameters } from '@storybook/react';16import { withInfo } from '@storybook/addon-info';17import { withKnobs } from '@storybook/addon-knobs';18addParameters({19 options: {20 },21});22addDecorator(withInfo);23addDecorator(withKnobs);24configure(require.context('../src', true, /\.stories\.js$/), module);

Full Screen

Using AI Code Generation

copy

Full Screen

1import { DEFAULT_LOCALE } from 'storybook-root-addon';2import { DEFAULT_LOCALE } from 'storybook-root-addon';3import { DEFAULT_LOCALE } from 'storybook-root-addon';4import { DEFAULT_LOCALE } from 'storybook-root-addon';5import { DEFAULT_LOCALE } from 'storybook-root-addon';6import { DEFAULT_LOCALE } from 'storybook-root-addon';7import { DEFAULT_LOCALE } from 'storybook-root-addon';8import { DEFAULT_LOCALE } from 'storybook-root-addon';9import { DEFAULT_LOCALE } from 'storybook-root-addon';10import { DEFAULT_LOCALE } from 'storybook-root-addon';11import { DEFAULT_LOCALE } from 'storybook-root-addon';12import { DEFAULT_LOCALE } from 'storybook-root-addon';13import { DEFAULT_LOCALE } from 'storybook-root-addon';14import { DEFAULT_LOCALE } from 'storybook-root-addon';15import { DEFAULT_LOCALE } from 'storybook-root-addon';16import { DEFAULT_LOCALE } from 'storybook-root-addon';17import { DEFAULT_LOCALE } from 'storybook-root-addon';18import { DEFAULT_LOCALE } from '

Full Screen

Using AI Code Generation

copy

Full Screen

1import {DEFAULT_LOCALE} from 'storybook-root';2export const test = () => {3 return DEFAULT_LOCALE;4}5import {test} from './test';6import {DEFAULT_LOCALE} from 'storybook-root';7describe('test', () => {8 it('should return DEFAULT_LOCALE', () => {9 expect(test()).toEqual(DEFAULT_LOCALE);10 });11});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run storybook-root automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful