sibiraj-s / ngx-editor

🖋️ Rich Text Editor for angular using ProseMirror
https://sibiraj-s.github.io/ngx-editor/
MIT License
457 stars 191 forks source link

Feature: Support observables for label translations #466

Closed ludoviccarretti closed 1 year ago

ludoviccarretti commented 1 year ago

Facilitate the integration of label translations by allowing the use of Observable. This feature allows integration with other asynchronous services like ngx-translate or other asynchronous APIs.

This PR contains:

Breaking Changes?

Checklist

Describe Your Changes

Add the ability to provide label translation using string or Observable to avoid overwriting NgxEditorConfig when language update is needed. By supporting Observable, labels can be translated more easily with modules like ngx-translate. Example of implementation with ngx-translate:

export function ngxEditorConfigFactory(translateService: TranslateService): NgxEditorConfig {
  return {
    locals: {
      // Use stream instead of instant to refresh automatically label when language change
      italic: translateService.stream('styles.italic'),
      bold: translateService.stream('styles.bold'),
    },
  };
}

@NgModule({
  imports: [CommonModule, ReactiveFormsModule, NgxEditorModule.forRoot()],
  providers: [
    {
      useFactory: ngxEditorConfigFactory,
      provide: NGX_EDITOR_CONFIG_TOKEN,
      deps: [TranslateService],
    },
  ],
})
export class MyModule {}

Does this PR affects any existing issues?

This feature can solve this issue #451 which allows you to manage different languages and update labels without the need to refresh the page or overwrite the editor's configuration manually when display language is updated.

sibiraj-s commented 1 year ago

Thanks @ludoviccarretti . Sorry for the delay. Will check this weekend. Just asking upfront, will this break anythings for existing users? I might have to do a major release then.

ludoviccarretti commented 1 year ago

Thanks @sibiraj-s, no there is no breaking change. This update doesn't require any change for existing user configuration !

github-actions[bot] commented 1 year ago

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in the thread.