Skip to content

Commit cc441e2

Browse files
committed
minor #2108 [Autocomplete] Translate "Add ..." text (jmsche)
This PR was squashed before being merged into the 2.x branch. Discussion ---------- [Autocomplete] Translate "Add ..." text | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | Issues | Fix #745 | License | MIT Hi, this PR fixes #745, allowing to translate the "Add Abc..." text when the create option is set to true :) Added the translated text as comment in most translation files. ![image](https://github.com/user-attachments/assets/594c4b50-46cb-4bdb-b0b5-81168f83d53e) Commits ------- f4c647f [Autocomplete] Translate "Add ..." text
2 parents 7af61a7 + f4c647f commit cc441e2

38 files changed

+64
-1
lines changed

src/Autocomplete/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## 2.20.0
4+
5+
- Translate the `option_create` option from TomSelect #2108
6+
37
## 2.17.0
48

59
- Allow `choice_value` option in entity autocomplete fields #1723

src/Autocomplete/assets/dist/controller.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export default class extends Controller {
1515
loadingMoreText: StringConstructor;
1616
noResultsFoundText: StringConstructor;
1717
noMoreResultsText: StringConstructor;
18+
createOptionText: StringConstructor;
1819
minCharacters: NumberConstructor;
1920
tomSelectOptions: ObjectConstructor;
2021
preload: StringConstructor;
@@ -24,6 +25,7 @@ export default class extends Controller {
2425
readonly loadingMoreTextValue: string;
2526
readonly noMoreResultsTextValue: string;
2627
readonly noResultsFoundTextValue: string;
28+
readonly createOptionTextValue: string;
2729
readonly minCharactersValue: number;
2830
readonly hasMinCharactersValue: boolean;
2931
readonly tomSelectOptionsValue: object;

src/Autocomplete/assets/dist/controller.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ _default_1_instances = new WeakSet(), _default_1_getCommonConfig = function _def
239239
no_results: () => {
240240
return `<div class="no-results">${this.noResultsFoundTextValue}</div>`;
241241
},
242+
option_create: (data, escapeData) => {
243+
return `<div class="create">${this.createOptionTextValue.replace('%placeholder%', `<strong>${escapeData(data.input)}</strong>`)}</div>`;
244+
},
242245
};
243246
const config = {
244247
render,
@@ -314,6 +317,9 @@ _default_1_instances = new WeakSet(), _default_1_getCommonConfig = function _def
314317
no_results: () => {
315318
return `<div class="no-results">${this.noResultsFoundTextValue}</div>`;
316319
},
320+
option_create: (data, escapeData) => {
321+
return `<div class="create">${this.createOptionTextValue} <strong>${escapeData(data.input)}</strong>&hellip;</div>`;
322+
},
317323
},
318324
preload: this.preload,
319325
});
@@ -336,6 +342,7 @@ default_1.values = {
336342
loadingMoreText: String,
337343
noResultsFoundText: String,
338344
noMoreResultsText: String,
345+
createOptionText: String,
339346
minCharacters: Number,
340347
tomSelectOptions: Object,
341348
preload: String,

src/Autocomplete/assets/src/controller.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import { Controller } from '@hotwired/stimulus';
22
import TomSelect from 'tom-select';
33
import type { TPluginHash } from 'tom-select/dist/types/contrib/microplugin';
4-
import type { RecursivePartial, TomSettings, TomTemplates, TomLoadCallback } from 'tom-select/dist/types/types';
4+
import type {
5+
RecursivePartial,
6+
TomSettings,
7+
TomTemplates,
8+
TomLoadCallback,
9+
TomOption,
10+
} from 'tom-select/dist/types/types';
11+
import type { escape_html } from 'tom-select/dist/types/utils';
512

613
export interface AutocompletePreConnectOptions {
714
options: any;
@@ -18,6 +25,7 @@ export default class extends Controller {
1825
loadingMoreText: String,
1926
noResultsFoundText: String,
2027
noMoreResultsText: String,
28+
createOptionText: String,
2129
minCharacters: Number,
2230
tomSelectOptions: Object,
2331
preload: String,
@@ -28,6 +36,7 @@ export default class extends Controller {
2836
declare readonly loadingMoreTextValue: string;
2937
declare readonly noMoreResultsTextValue: string;
3038
declare readonly noResultsFoundTextValue: string;
39+
declare readonly createOptionTextValue: string;
3140
declare readonly minCharactersValue: number;
3241
declare readonly hasMinCharactersValue: boolean;
3342
declare readonly tomSelectOptionsValue: object;
@@ -136,6 +145,9 @@ export default class extends Controller {
136145
no_results: () => {
137146
return `<div class="no-results">${this.noResultsFoundTextValue}</div>`;
138147
},
148+
option_create: (data: TomOption, escapeData: typeof escape_html): string => {
149+
return `<div class="create">${this.createOptionTextValue.replace('%placeholder%', `<strong>${escapeData(data.input)}</strong>`)}</div>`;
150+
},
139151
};
140152

141153
const config: RecursivePartial<TomSettings> = {
@@ -240,6 +252,9 @@ export default class extends Controller {
240252
no_results: (): string => {
241253
return `<div class="no-results">${this.noResultsFoundTextValue}</div>`;
242254
},
255+
option_create: (data: TomOption, escapeData: typeof escape_html): string => {
256+
return `<div class="create">${this.createOptionTextValue} <strong>${escapeData(data.input)}</strong>&hellip;</div>`;
257+
},
243258
},
244259
preload: this.preload,
245260
});

src/Autocomplete/src/Form/AutocompleteChoiceTypeExtension.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public function finishView(FormView $view, FormInterface $form, array $options):
9191
$values['loading-more-text'] = $this->trans($options['loading_more_text']);
9292
$values['no-results-found-text'] = $this->trans($options['no_results_found_text']);
9393
$values['no-more-results-text'] = $this->trans($options['no_more_results_text']);
94+
$values['create-option-text'] = $this->trans($options['create_option_text']);
9495
$values['preload'] = $options['preload'];
9596

9697
foreach ($values as $name => $value) {
@@ -147,6 +148,7 @@ public function configureOptions(OptionsResolver $resolver): void
147148
'loading_more_text' => 'Loading more results...',
148149
'no_results_found_text' => 'No results found',
149150
'no_more_results_text' => 'No more results',
151+
'create_option_text' => 'Add %placeholder%...',
150152
'min_characters' => null,
151153
'max_results' => 10,
152154
'preload' => 'focus',

src/Autocomplete/translations/AutocompleteBundle.ar.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@
1313
'Loading more results...' => 'تحميل المزيد من النتائج...',
1414
'No results found' => 'لم يتم العثور على أي نتائج',
1515
'No more results' => 'لا توجد نتائج أٌخرى',
16+
// 'Add %placeholder%...' => 'Add %placeholder%...',
1617
];

src/Autocomplete/translations/AutocompleteBundle.bg.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@
1313
'Loading more results...' => 'Зареждане на още резултати...',
1414
'No results found' => 'Няма намерени съвпадения',
1515
'No more results' => 'Няма повече резултати',
16+
// 'Add %placeholder%...' => 'Add %placeholder%...',
1617
];

src/Autocomplete/translations/AutocompleteBundle.ca.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@
1313
'Loading more results...' => 'S\'estan carregant més resultats...',
1414
'No results found' => 'No s\'han trobat resultats',
1515
'No more results' => 'No hi ha més resultats',
16+
// 'Add %placeholder%...' => 'Add %placeholder%...',
1617
];

src/Autocomplete/translations/AutocompleteBundle.cs.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@
1313
'Loading more results...' => 'Načítání dalších výsledků...',
1414
'No results found' => 'Nenalezeny žádné položky',
1515
'No more results' => 'Žádné další výsledky',
16+
// 'Add %placeholder%...' => 'Add %placeholder%...',
1617
];

src/Autocomplete/translations/AutocompleteBundle.da.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@
1313
'Loading more results...' => 'Indlæser flere resultater...',
1414
'No results found' => 'Ingen resultater fundet',
1515
'No more results' => 'Ingen flere resultater',
16+
// 'Add %placeholder%...' => 'Add %placeholder%...',
1617
];

0 commit comments

Comments
 (0)