Hi,
We’re developing a12 add-ons which depend on the a12 client. We are facing the problem that we cannot use the overridden resources in the sagas of the add-ons.
The flow is:
- Add-ons package provides the default resources
- The A12 client import the resources and optionally override the resources
- From the redux sagas of the add-on, get the localizer that contains the overridden resources
Could anyone guide me on how to make it work? Thank you very much
Hi,
from a conceptional point of view this sounds odd. Localization should happen in the view that will show the text an never in the backend of the client.
Can you illustrate your case in more detail?
Another point that I am worried about is that your addon provides resources instead of localizables. Your code should handle default texts in the localizables and a user can override it by using the keys of the localizables.
Hi, there are some different cases we’re currently having in our chat addon:
- If there is some errors happen, map the errors to the messages which are displayed on the user view
- Emit the notification to the user view from redux
- If some messages are not from real user but from the system, set the display name of the message to the default sender name
export function* sendNotification(
ts: IMessagePayload["createdAt"],
notificationType: NotificationType,
sender?: string
): SagaGenerator<void> {
const localizer: ChatLocalizer = yield* call(getChatLocalizer);
const name = sender ? sender : localizer("default.agent");
const message = localizer(NotificationDict[notificationType], { agent: name });
const notification: IMessagePayload = {
text: message,
type: MessageType.NOTIFICATION,
createdAt: ts
};
yield* put(ChatActions.addMessage(notification));
}
example code here.
Another point that I am worried about is that your addon provides resources instead of localizable.
I don’t really get you at this point since we have no problem with providing and overriding the resources. But we have a problem when getting the overridden resources by key from the addon.
From my point of view you should never localize data in the redux store, because this will cause issues in case the user switches the language. You should always localize in the view that will show the text.
Therefore, you should store Localizables in the redux store for simplicity reasons. If you need a localized placeholder, then is is alreday supported by the localization API (See here).
I don’t really get you at this point since we have no problem with providing and overriding the resources. But we have a problem when getting the overridden resources by key from the addon.
With the current A12 API for localization you should never bother with the resources from someone else. These are handled by the API.
Thank you @stefan-cold-haze We decided to decouple the logic from the localization