-
-
Notifications
You must be signed in to change notification settings - Fork 2
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 request: Keeping spaces #62
Comments
Hey @stevengunneweg, This change breaks all the test and However, there is nothing stopping it from being done as an option that may come in handy for someone ;) Try this new unreleased version:
Set this option: import { NgxTranslateCutModule } from 'ngx-translate-cut';
@NgModule({
// ...
imports: [
// ...
NgxTranslateCutModule.forRoot({
trim: false
}),
]
}) ...and let me know ;) |
@bartholomej thanks for your quick response and work on this request! I'm using Angular standalone components which somehow doesn't seem to work well with the app.config.ts NgxTranslateCutModule.forRoot({
separator: '*',
trim: false,
}), app.component.ts @Component({
standalone: true,
imports: [CommonModule, RouterModule, TranslateModule, NgxTranslateCutModule],
providers: [NgxTranslateCutPipe],
})
export class AppComponent {
constructor(
@Optional() @Inject(FOR_ROOT_OPTIONS_TOKEN) options: any,
optionspipe: NgxTranslateCutPipe,
) {
console.log('!!!', options);
console.log('!!!', optionspipe['options']);
console.log(
'!!! before:',
JSON.stringify(optionspipe.transform('asdfas | other * label', 0)),
);
optionspipe['options']['trim'] = false;
console.log(
'!!! after:',
JSON.stringify(optionspipe.transform('asdfas | other * label', 0)),
);
}
} results in the following > !!! {separator: '*', trim: false}
> !!! NgxTranslateCutOptionsService {separator: '|', trim: true} // <-- should be same settings as above
> !!! before: "asdfas"
> !!! after: "asdfas " I thought that adding the I also suspect that the trim option check needs a small adjustment since a - if (options.trim) {
+ if (options.trim !== undefined) {
ngxTranslateCutOptionsService.trim = options.trim;
} |
UpdateI made several changes to my fork and everything seems to work now! I've opened a pull request #71 where I implemented below changes and added some tests. Service injectable optionsI added Standalone pipeI made the
Undefined check for boolean optionI added the earlier suggestion to add an undefined check to |
Great job Steven! And thank you! Just try |
I use this library for a while already and it works great but I need one additional feature. For this reason I created a fork but it feels ridiculous to maintain a fork for 1 tiny change.
The issue:
When I have a text that I want to cut to apply some additional HTML for example, the spaces are trimmed even though this is not desired.
E.g.
for the following HTML
"translation": "This is a |cut| sentence.",
will work fine since my HTML is responsible for placing the correct spaces.
However when my cut is at the end of a sentence like this
"translation": "This is a sentence that is |cut|.",
the HTML does not know whether a space is needed between the cuts so there will be either spaces on both sides of
cut
or none at all, neither is correct.My fix
To fix this I made the following change to
/projects/ngx-translate-cut/src/lib/ngx-translate-cut.pipe.ts
(which could be optimised further)This will keep the existing spaces from the original translation and just needs small adjustment to my html to work without any issues
If this is too much of a risk to just apply without it breaking for other users of this library it could become a configuration option in the
forRoot
implementation.Personally I doubt that this change will break anything for other users since they are already responsible for the correct spaces in their HTML but it would help me a lot. Please consider my request.
The text was updated successfully, but these errors were encountered: