synacor / preact-i18n

Simple localization for Preact.
BSD 3-Clause "New" or "Revised" License
206 stars 18 forks source link

Is there feature to translate text out of component #17

Closed lamemmv closed 6 years ago

lamemmv commented 6 years ago

I'm using preact-redux which use Epic pattern. In the Epic file I have the section like this: const uploadFileSuccessEpic = action$ => action$.ofType(UPLOAD_FILE_SUCCESS) .flatMap(action => Observable.concat( Observable.of(getFiles(1)), Observable.of(addNotification('Uploaded', 'success', 'Upload files')) ) );

I want to translate the text 'Uploaded' and 'Upload files' here. How can I do that? Is there the way to do like this: let uploadedText = (<Text id='common.uploaded'></Text>); and we will use uploadedText in Observable.of(addNotification(uploadedText, 'success', 'Upload files'))

Thank in advance.

pl12133 commented 6 years ago

Hey @lamemmv, in order to translate you must have the dictionary available somewhere; that is set as this.context.intl.dictionary inside components. You can pass the dictionary from a Component to your action payload if you want to translate something outside a Component.

let uploadedText = action.payload.dictionary.common.uploaded;

Let me know if that solution works for you. I think this is a common use case so it would be good to have a written solution in the docs for it.

billneff79 commented 6 years ago

Closing for now. Let us know if you still have a question