-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
116 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,26 @@ | ||
import { RouteLocation } from '@builder.io/qwik-city'; | ||
|
||
import type { SpeakLocale, SpeakState } from './types'; | ||
import { loadTranslation } from './core'; | ||
|
||
/** | ||
* Change locale at runtime: loads translation data and rerenders components that uses translations | ||
* @param newLocale The new locale to set | ||
* @param ctx Speak context | ||
* @param location Optional Qwik City location context | ||
* @param url Optional URL object | ||
*/ | ||
export const changeLocale = async ( | ||
newLocale: SpeakLocale, | ||
ctx: SpeakState, | ||
location?: RouteLocation | ||
url?: URL | ||
): Promise<void> => { | ||
const { locale, translation, translateFn } = ctx; | ||
|
||
// Load translation data | ||
const loadedTranslation = await loadTranslation(newLocale.lang, ctx, location); | ||
const loadedTranslation = await loadTranslation(newLocale.lang, ctx, url); | ||
|
||
// Update state | ||
Object.assign(translation, loadedTranslation); | ||
Object.assign(locale, newLocale); | ||
|
||
// Store the locale | ||
await translateFn.storeLocale$(newLocale); | ||
await translateFn.storeLocale$(newLocale, url); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.