-
Notifications
You must be signed in to change notification settings - Fork 4
feat: clear translation cache #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
5533c44
d2b3bf2
ab129a1
7c55766
2e3ffaf
0fb09e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1130,6 +1130,7 @@ declare global { | |
onError?: (error: Error) => void | ||
) => void; | ||
translate: (langCode: string, onComplete?: (result: TranslationResult) => void, onError?: (error: Error) => void) => Promise<TranslationResult>; | ||
clearCache: (lang_code:string[], onComplete?: () => void, onError?: (error: Error) => void) => void; | ||
} | ||
} | ||
|
||
|
@@ -1139,7 +1140,7 @@ if (typeof window !== "undefined") { | |
* @param defaultLang The default language to reset to | ||
* @param onComplete Callback function that will be called when the translation is complete | ||
* @param onError Callback function that will be called if the translation fails | ||
* @returns A promise that resolves to the translation result | ||
* @returns void | ||
*/ | ||
window.resetTranslation = ( | ||
defaultLang: string, | ||
|
@@ -1199,4 +1200,24 @@ if (typeof window !== "undefined") { | |
}; | ||
} | ||
}; | ||
|
||
/** | ||
* @param langArr Array of language codes to clear cache for. Empty array clears all languages. | ||
* @param onComplete Callback function that will be called when the translation is complete | ||
* @param onError Callback function that will be called if the translation fails | ||
* @returns void | ||
*/ | ||
window.clearCache = ( | ||
lang_code: string[] = [], | ||
onComplete?: () => void, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently, the clear() function removes all cached translations from localStorage. I’d like to add an optional lang_code parameter—if provided, it should only clear the cache for that specific language. If not provided, it should continue to clear everything as before. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. alright will add this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added this as well. just one thing, when clearing cache for specific language it doesn't clear |
||
onError?: (error: Error) => void | ||
) => { | ||
const localStorageWrapper = new LocalStorageWrapper(CACHE_PREFIX); | ||
try { | ||
localStorageWrapper.clear(lang_code); | ||
onComplete?.(); | ||
} catch (error) { | ||
onError?.(error as Error); | ||
} | ||
}; | ||
} |
Uh oh!
There was an error while loading. Please reload this page.