Find and Replace in Translations

87 vues Markdown

Search the texts of every enabled language pack, and rewrite a word across many translation keys in one pass.

Reaching the Screen

Menu: Languages then Find and Replace. The same screen sits behind the Find and Replace button above the language list: {admin}/languages/find-and-replace

The address accepts a search term, so a link can open the screen with its results already on it: {admin}/languages/find-and-replace?word=Invoice. Both the menu entry and the button are drawn only for staff who may edit languages.

What Is on the Screen

One search bar across the top, the results on the left, the selected key on the right, and a bar at the foot that appears only while a replacement is being prepared.

Search bar The search box with its two switches, and the button that opens the replacement box under it.
Counters and filters How many keys matched and how many files they sit in, then a chip for every language pack and one for every area, each with its own count, plus an All Languages and an All chip that clear the filter.
Result list The matching keys, grouped by the file they live in, with the match highlighted in the key name and in the text.
Translation pane The selected key with every enabled language side by side, editable and saved from here.
Apply bar Appears once a replacement is typed: it counts what will change and carries the apply button.

The search runs shortly after you stop typing. Three characters is the minimum; anything shorter leaves the screen on its opening state. The word is matched against the text of every key and against the key name itself, across every enabled language pack at once. Two switches sit inside the box: Match case makes the search case sensitive (it is not by default), and Whole word matches the word only where it stands on its own instead of inside a longer one. The arrows button beside the box opens the replacement field.

Routing files and a few configuration files are outside the search: URL slugs, the home page blocks and the shared constants are not reached from here, and the string count on the opening screen does not include them.

Before the first search the list offers two example searches as chips, one for a key name and one for a variable.

The result list

Results are grouped by the language file they belong to. A group header names the file, the area it serves and how many of its keys matched; clicking it folds the group away. Each row is one translation key: its short name, then the text with the match highlighted. When several packs carry the word and no language chip is active, the row also shows the flag of the pack whose text is on display.

Results arrive 150 keys at a time. When more are waiting, a button at the end of the list loads the next batch.

The chips above the list narrow the search. The language chips keep only the keys that matched in that pack. The area chips split them into Client Interface (what the client reads), Admin Interface (the panel) and System Interface (shared texts such as dates and general messages). Each chip carries its own count, and a pack with no match is shown dimmed. The first chip of each strip clears that filter: All Languages, which appears once more than one pack is enabled, and All.

A row can be listed because its key name matched rather than its text. That row is a real result, but a replacement will not change it: replacing works on the text only.

When nothing matches, the list says so and offers the way out it can see: if the word exists in another pack, a button switches the list to it, and if Match case is on, a button turns it off.

The translation pane

Selecting a row opens the key on the right with one field per enabled language, the pack the match came from first. Above the fields sit the area, the file the key lives in and the key itself, next to a button that copies the key to the clipboard.

A language that does not carry this key yet says so under its field, and writing there creates it. The braces listed below a field are the variables that text may use; the system fills them in when the message goes out. Save stays closed until something changes and then writes only the languages you edited. Revert throws away the unsaved edits of that key.

Replace mode

The arrows button opens a second box under the search box. As soon as it carries text the screen turns into a review: every row shows its current text struck through with the new text beside it, each row gets a checkbox (all ticked to begin with), the group header gets one that toggles its own rows, and the right pane becomes Pending Changes, listing up to forty of the selected rows.

A locked chip at the end of the replacement box names the pack that will be written, and that is the only pack the replacement touches. An active language chip decides it. Otherwise the chip stays on the pack it is already aimed at for as long as that pack still has matches, which on the first search is the panel's own language. It moves to the pack with the most matches only when the current one has none left. Rows with no match in that pack stay out of the selection.

The bar at the foot counts the selected rows and the changes inside them, and says which pack is being written and how many rows were left out. Clear selection unticks everything. Apply changes asks to confirm, writes the file, then closes the replacement box and runs the search again so the list shows the new state.

Developer mode

While the installation runs in developer mode, an Add Translation Key button appears beside the link back to the language list and opens a window that writes a brand new key into one pack. The screen otherwise edits only keys it can find, so this is the one way to seed one. Outside developer mode neither the button nor the window exists.

Fields

Search a word, sentence or key At least three characters. Matched against the translation text and against the key name, in every enabled pack, apart from the routing and configuration files.
Replacement text Hidden until the arrows button opens it. What is written here replaces every highlighted match in the selected rows; leaving it empty keeps the screen in plain search mode.
Language pack Only in developer mode. The pack the new key is written into; the panel's own language is preselected.
Key Only in developer mode. A slash makes the key nested, for example admin/settings/item-name. Both this and Value have to be filled in: the window accepts an empty one and reports success, but nothing is written.
Value Only in developer mode. Plain text, or JSON when the text has to carry variables. It has to be filled in as well: an empty one is reported as saved and written nowhere.

Tasks

Find a string

  1. Type at least three characters into the search box.
  2. Narrow the results with the language and area chips when the list is long.
  3. Turn on Match case or Whole word when a short word matches too much.
  4. Select a row; the key opens on the right with every enabled language next to each other.

Edit one key

  1. Select the row you found.
  2. Edit the languages you mean to change. A pack that does not have the key yet gets it as you write.
  3. Save. Only the edited languages are written, and the row in the list picks up the new text.

Replace a word across many keys

  1. Search the word, then click the chip of the pack you mean to change so the replacement cannot land on another one.
  2. Open the replacement box with the arrows button and type the new text. Read the chip at the end of the box: it names the pack that will be written.
  3. Untick the rows or whole groups you want left alone. The bar at the foot keeps count of what is left in.
  4. Use Apply changes and confirm. The file is written, the replacement box closes and the search runs again showing the new wording.

Things to Watch

A replacement cannot be undone from here

Applying writes the language files straight away and this screen keeps no copy of the previous wording. The panel only takes a backup when a language is imported, so the restore offered on the language screen is not a way back from here. Export the language first when the word is a common one.

Only one language pack is changed

The search spans every enabled pack, the replacement does not: it writes the single pack named on the locked chip. If that is not the pack you meant, click its language chip before applying. The others keep their wording even though they matched, and disabled packs are outside the search altogether.

Variables have to survive the replacement

A text in braces is a value the system fills in later, such as a name or an amount. A replacement that swallows one is not refused here: the message keeps working but loses that piece of information. Read the preview on the right before applying, and keep the braces in the new wording.

Required Privileges

Searching, saving a translation and applying a replacement all run under LANGUAGES_OPERATION. Without it the menu entry and the button on the language list are not drawn, and the address still opens the screen with nothing on it: every search comes back refused. LANGUAGES_LOOK alone opens the language list.

Cet article vous a-t-il été utile ?

Merci pour votre retour !

Besoin d'aide supplémentaire ?

Notre équipe d'assistance est disponible 24h/24 pour tout ce que vous ne trouvez pas ci-dessus.