astro-static-dict
Advanced tools
+13
-5
@@ -91,19 +91,27 @@ /****************************************************************************** | ||
| }); | ||
| const handler = (event) => __awaiter(void 0, void 0, void 0, function* () { | ||
| const handler = (newLanguage) => __awaiter(void 0, void 0, void 0, function* () { | ||
| try { | ||
| changeLanguageOnPage({ | ||
| newDict: yield getDictionary(event.detail), | ||
| newDict: yield getDictionary(newLanguage), | ||
| keySeparator, | ||
| keySuffix | ||
| }); | ||
| window.selectedLanguage = event.detail; | ||
| window.selectedLanguage = newLanguage; | ||
| } | ||
| catch (error) { | ||
| console.error(`Dictionary for language ${event.detail} not found`); | ||
| console.error(`Dictionary for language ${newLanguage} not found`); | ||
| } | ||
| }); | ||
| window.changeLanguage = (newLanguage) => window.dispatchEvent(new CustomEvent('changeLanguage', { detail: newLanguage })); | ||
| window.addEventListener('changeLanguage', handler); | ||
| window.addEventListener('changeLanguage', event => handler(event.detail)); | ||
| document.addEventListener('astro:after-swap', () => { | ||
| if (defaultLanguage === window.selectedLanguage) { | ||
| return; | ||
| } | ||
| const selectedLanguage = window.selectedLanguage; | ||
| window.selectedLanguage = defaultLanguage; | ||
| handler(selectedLanguage); | ||
| }); | ||
| }; | ||
| export { watchLanguageChange }; |
+1
-1
| { | ||
| "author": "brentlok", | ||
| "name": "astro-static-dict", | ||
| "version": "1.1.0", | ||
| "version": "1.1.1", | ||
| "main": "index.js", | ||
@@ -6,0 +6,0 @@ "repository": "https://github.com/Brentlok/astro-static-dict", |
+26
-10
@@ -88,8 +88,12 @@ # Astro static dict | ||
| ```astro | ||
| <script> | ||
| import { watchLanguageChange } from 'astro-static-dict/client' | ||
| ```ts | ||
| import { watchLanguageChange } from 'astro-static-dict/client' | ||
| import { enUs } from 'lib/locale' | ||
| watchLanguageChange() | ||
| </script> | ||
| watchLanguageChange({ | ||
| cachedDictionaries: { | ||
| enUs | ||
| }, | ||
| defaultLanguage: 'enUs' | ||
| }) | ||
| ``` | ||
@@ -99,8 +103,10 @@ | ||
| #### watchLanguageChange config (optional) | ||
| #### watchLanguageChange config | ||
| | Property | Type | Description | | ||
| |-----------------|----------------------------|-------------------------------------------------------------------------------------------------------------------------------------------| | ||
| | keySeparator | string | Default: `@@@` <br> Must be the same as initDictionary's keySeparator | | ||
| | keySuffix | string | Default: `!!!` <br> Must be the same as initDictionary's keySuffix | | ||
| | Property | Type | Description | | ||
| |--------------------|------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------| | ||
| | cachedDictionaries | Record<string, DictionaryBranch> | Dictionaries that will be injected into window.cachedDictionaries, you must include dictionary used in build process but more is up to you | | ||
| | defaultLanguage | string | <br> Name of default language used on a page. Must be the same as dictionary used in build process | | ||
| | keySeparator | string | Default: `@@@` <br> Must be the same as initDictionary's keySeparator | | ||
| | keySuffix | string | Default: `!!!` <br> Must be the same as initDictionary's keySuffix | | ||
@@ -116,1 +122,11 @@ #### Trigger language change | ||
| ``` | ||
| ### Window modified properties | ||
| ```ts | ||
| interface Window { | ||
| changeLanguage(newLanguage: string): void, | ||
| selectedLanguage: string, | ||
| cachedDictionaries: Partial<Record<string, DictionaryBranch>> | ||
| } | ||
| ``` |
Sorry, the diff of this file is too big to display
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
451263
0.26%8064
0.14%130
14.04%