-
-
Notifications
You must be signed in to change notification settings - Fork 10
Open
Description
I have a special use case where I, for some customers, need to override a few text strings. I want to have the application localized using wuchale, but be able to, based on the signed in user, override some strings. My plan is to, for each locale, define a mapping from source text to override text on the customer, stored in the database. When loading the catalog, I plan to do something like this:
- Load the catalogs using wuchale like normally
- Load the text override map for the current locale from the database based on the signed-in user
- For each override-text, find the corresponding index in the wuchale catalogs
- Update the index in the catalog with the override-text
I understand that this will result in the loader having to do async work, and hence placeholders will be shown. I don't think that will be an issue.
The problem I have is how to solve step 3. What do you think about one of these ideas:
- Implement an option for emitting a map from extracted text to catalog index that can be enabled per adapter in the wuchale config.
- Expose
adaptersin the Vite plugin:
export class Wuchale {
// ...
get adapters(): ReadonlyMap<string, AdapterHandler> {
return this.#adapters
}
}Then I think I would be able to use a plugin like this:
import { wuchale } from '@wuchale/vite-plugin'
const wuchalePlugin = wuchale()
function wuchaleSourceMapPlugin() {
return {
name: 'wuchale-source-map',
generateBundle() {
// With the proposed getter, this would work:
for (const [key, handler] of wuchalePlugin.adapters) {
const sourceMap = {}
for (const [sourceStr, id] of handler.sharedState.indexTracker.indices) {
sourceMap[id] = sourceStr
}
this.emitFile({
type: 'asset',
fileName: `wuchale-source-map-${key}.json`,
source: JSON.stringify(sourceMap),
})
}
},
}
}
export default {
plugins: [wuchalePlugin, wuchaleSourceMapPlugin()],
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels