Skip to content
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

Feature: Support observables for label translations #466

Merged

Conversation

ludoviccarretti
Copy link
Contributor

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:

  • bugfix
  • feature
  • refactor
  • tests
  • documentation
  • others

Breaking Changes?

  • yes
  • no

Checklist

  • commit messages follow the Conventional Commits pattern
    • A feature commit message is prefixed "feat:"
    • A bugfix commit message is prefixed "fix:"
    • A document related commit is prefixed "docs:"
  • docs have been added / updated (for bug fixes / features)

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?

  • yes
  • no

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
Copy link
Owner

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
Copy link
Contributor Author

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

@sibiraj-s sibiraj-s enabled auto-merge (squash) July 15, 2023 06:18
@sibiraj-s sibiraj-s disabled auto-merge July 15, 2023 06:18
@sibiraj-s sibiraj-s enabled auto-merge (squash) July 15, 2023 06:19
@sibiraj-s sibiraj-s merged commit e2fb7d8 into sibiraj-s:master Jul 15, 2023
1 check passed
@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants