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

block_formats options not translated if using documented approach #9598

Open
andrewnicols opened this issue Apr 29, 2024 · 0 comments · May be fixed by #9599
Open

block_formats options not translated if using documented approach #9598

andrewnicols opened this issue Apr 29, 2024 · 0 comments · May be fixed by #9599

Comments

@andrewnicols
Copy link

📝 Provide detailed reproduction steps (if any)

https://fiddle.tiny.cloud/Fug3lEC28d/0

  1. Set a block_formats option of (exact copy from docs):
Paragraph=p; Heading 1=h1; Heading 2=h2; Heading 3=h3; Heading 4=h4; Heading 5=h5; Heading 6=h6;
  1. Set language to German
  2. Ensure that the format menubar is present
  3. Open the Format menu -> Blocks

✔️ Expected result

All headings translated

❌ Actual result

Only paragraph is translated. Others are not

❓ Possible solution

I believe the following patch will solve the issue:

diff --git a/modules/tinymce/src/themes/silver/main/ts/ui/core/complex/SelectDatasets.ts b/modules/tinymce/src/themes/silver/main/ts/ui/core/complex/SelectDatasets.ts
index 01de005aa2..39a7892112 100644
--- a/modules/tinymce/src/themes/silver/main/ts/ui/core/complex/SelectDatasets.ts
+++ b/modules/tinymce/src/themes/silver/main/ts/ui/core/complex/SelectDatasets.ts
@@ -26,7 +26,7 @@ const process = (rawFormats: string[]): BasicSelectItem[] => Arr.map(rawFormats,
   // Allow text=value block formats
   const values = item.split('=');
   if (values.length > 1) {
-    title = values[0];
+    title = values[0].trim();
     format = values[1];
   }
 

I haven't worked out where to write a unit test for this but happy to provide one.

📃 Other details

  • Browser: Any
  • OS: Any.
  • First affected version: Unsure
  • Worked in version: Unsure

andrewnicols added a commit to andrewnicols/tinymce that referenced this issue Apr 29, 2024
The `buildBasicSettingsDataset` call is used for:
- `block_formats`
- `font_family_formats`
- `font_size_formats`

The documented values for both `block_formats` and
`font_family_formats` include a space between the `;` and the title, for
example the default value in `block_formats` is:

```
Paragraph=p; Heading 1=h1; Heading 2=h2; Heading 3=h3; Heading 4=h4; Heading 5=h5; Heading 6=h6;
```

However the `split()` method in `SelectDatasets.ts` splits on the
delimter, leading to values such as ` Heading 1=h1` which are then
passed into the `process()` method which just split them on `=` leading
to a title of ` Heading 1` (with leading whitespace) which does not
match any valid translation.

This patch modifies the `split()` method to trim the title component.
@andrewnicols andrewnicols linked a pull request Apr 29, 2024 that will close this issue
5 tasks
andrewnicols added a commit to andrewnicols/tinymce that referenced this issue Apr 30, 2024
The `buildBasicSettingsDataset` call is used for:
- `block_formats`
- `font_family_formats`
- `font_size_formats`

The documented values for both `block_formats` and
`font_family_formats` include a space between the `;` and the title, for
example the default value in `block_formats` is:

```
Paragraph=p; Heading 1=h1; Heading 2=h2; Heading 3=h3; Heading 4=h4; Heading 5=h5; Heading 6=h6;
```

However the `split()` method in `SelectDatasets.ts` splits on the
delimiter, leading to values such as ` Heading 1=h1` which are then
passed into the `process()` method which just split them on `=` leading
to a title of ` Heading 1` (with leading whitespace) which does not
match any valid translation.

This patch modifies the `split()` method to trim the title component.

It also refactors the SelectDatasets module to move the configuration
processing into a utility method, and allows it to be unit tested.

Additionally any white-spare around the `=` or `;` leads to erroneous
values, for example a value of:

```
Paragraph = p ;
```

Leads to:
title: `Paragraph `
value: ` p `

And multiple contiguous spaces leads to additional values, for example:
```
12pt  14pt 16pt  18pt
```

Leads to a set of values:
- `12pt`
- `` (empty value)
- `14pt`
- `16pt`
- `18pt`
andrewnicols added a commit to andrewnicols/tinymce that referenced this issue Apr 30, 2024
The `buildBasicSettingsDataset` call is used for:
- `block_formats`
- `font_family_formats`
- `font_size_formats`

The documented values for both `block_formats` and
`font_family_formats` include a space between the `;` and the title, for
example the default value in `block_formats` is:

```
Paragraph=p; Heading 1=h1; Heading 2=h2; Heading 3=h3; Heading 4=h4; Heading 5=h5; Heading 6=h6;
```

However the `split()` method in `SelectDatasets.ts` splits on the
delimiter, leading to values such as ` Heading 1=h1` which are then
passed into the `process()` method which just split them on `=` leading
to a title of ` Heading 1` (with leading whitespace) which does not
match any valid translation.

This patch modifies the `split()` method to trim the title component.

It also refactors the SelectDatasets module to move the configuration
processing into a utility method, and allows it to be unit tested.

Additionally any white-spare around the `=` or `;` leads to erroneous
values, for example a value of:

```
Paragraph = p ;
```

Leads to:
title: `Paragraph `
value: ` p `

And multiple contiguous spaces leads to additional values, for example:
```
12pt  14pt 16pt  18pt
```

Leads to a set of values:
- `12pt`
- `` (empty value)
- `14pt`
- `16pt`
- `18pt`
andrewnicols added a commit to andrewnicols/tinymce that referenced this issue Apr 30, 2024
The `buildBasicSettingsDataset` call is used for:
- `block_formats`
- `font_family_formats`
- `font_size_formats`

The documented values for both `block_formats` and
`font_family_formats` include a space between the `;` and the title, for
example the default value in `block_formats` is:

```
Paragraph=p; Heading 1=h1; Heading 2=h2; Heading 3=h3; Heading 4=h4; Heading 5=h5; Heading 6=h6;
```

However the `split()` method in `SelectDatasets.ts` splits on the
delimiter, leading to values such as ` Heading 1=h1` which are then
passed into the `process()` method which just split them on `=` leading
to a title of ` Heading 1` (with leading whitespace) which does not
match any valid translation.

This patch modifies the `split()` method to trim the title component.

It also refactors the SelectDatasets module to move the configuration
processing into a utility method, and allows it to be unit tested.

Additionally any white-spare around the `=` or `;` leads to erroneous
values, for example a value of:

```
Paragraph = p ;
```

Leads to:
title: `Paragraph `
value: ` p `

And multiple contiguous spaces leads to additional values, for example:
```
12pt  14pt 16pt  18pt
```

Leads to a set of values:
- `12pt`
- `` (empty value)
- `14pt`
- `16pt`
- `18pt`
@TheSpyder TheSpyder linked a pull request May 3, 2024 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant