-
-
Notifications
You must be signed in to change notification settings - Fork 424
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
[Feat]: Placeholders in language json #637
Comments
There are no placeholder replacement functions built it, and unfortunately I don't plan on implementing one. With that said, I can allow the use of callback functions, so that you won't have to load all the json files at once: language: {
default: sk,
autoDetect: 'document',
translations: {
en: () => readLangJson('/libs/js/cookieconsent/en.json', PLACEHOLDER.en),
sk: () => readLangJson('/libs/js/cookieconsent/sk.json', PLACEHOLDER.sk),
},
} This way only the required translation would be loaded. You could also use an async callback: language: {
default: 'sk',
autoDetect: 'document',
translations: {
en: async () => {
const resp = await fetch('path-to-json');
return await resp.json();
}
},
} |
I used xhr sync instead of fetch async because using async ends with console error.
this ends with
|
Yes, it's expected to throw error because callbacks are not supported currently, but we can change that. The main benefit of using callback functions is that only the required translation would be loaded, unlike your current implementation where both translations are loaded at once. |
The discussed support for callback functions will be tracked in #638, closing this. |
Description
Lets say you have implement cookie consent to multiple sites and dont want to edit each language json individually. In that case placeholders would be great and will be replaced dynamically. Maybe it is implemented or there's some solution but I havent found that.. or I am just blind.
In v2 I used to use variables inside the 'inline' json, but now I find it better to use standalone lang files en.json whatever.json
Proposed solution
I have cc-init.js where I grab all necessary values like sitename, gdpr link, email for infos about cookies etc. These values are populated dynamically by site language. Inside cc-init.js is also cc.run
Then would be great in en.json or whatever.json to use for example
So some find/replace method.
Additional details
edit: This is what I tried a while ago and was working:
and a synchronous fetch function
I'm not a pro so I bet it could be written much better.
No response
The text was updated successfully, but these errors were encountered: