Skip to content

Commit 4c98411

Browse files
committed
Added translations. + Removed redundant logic.
1 parent 0d2aaf1 commit 4c98411

5 files changed

Lines changed: 77 additions & 75 deletions

File tree

dmenu/Main.qml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ Item {
152152
|| manifest.resultFile
153153
|| "/tmp/noctalia-dmenu-result";
154154
cfg.resultFormat = overrides.resultFormat || "plain";
155-
cfg.allowCustomInput = overrides.allowCustomInput === true ? true : false;
156-
cfg.closeOnSelect = overrides.closeOnSelect === false ? false : true;
155+
cfg.allowCustomInput = overrides.allowCustomInput;
156+
cfg.closeOnSelect = overrides.closeOnSelect;
157157
cfg.maxResults = overrides.maxResults
158158
|| defaults.maxResults
159159
|| manifest.maxResults
@@ -231,8 +231,7 @@ Item {
231231
var resultStr = formatResult(value, index);
232232
var resultFile = state.resultFile;
233233
var callbackCmd = state.callbackCmd;
234-
var showToast = pluginApi
235-
? (pluginApi.pluginSettings.showToastOnSelect || false) : false;
234+
var showToast = pluginApi?.pluginSettings?.showToastOnSelect ?? false;
236235
var shouldClose = state.closeOnSelect;
237236

238237
// Capture item name BEFORE endSession clears items

dmenu/Panel.qml

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ FocusScope {
238238
fontSize: Style.fontSizeM
239239
placeholderText: {
240240
var st = root.dmenuState;
241-
return (st && st.prompt) ? st.prompt : "Type to filter...";
241+
return (st && st.prompt) ? st.prompt : root.pluginApi?.tr("provider.typeToFilterPlaceholder");
242242
}
243243
text: root.filterText
244244
onTextChanged: root.filterText = text
@@ -388,9 +388,9 @@ FocusScope {
388388
visible: root.filteredItems.length === 0
389389
text: {
390390
var st = root.dmenuState;
391-
if (!st || !st.active) return "Loading...";
392-
if (root.filterText !== "") return "No matches";
393-
return "No items";
391+
if (!st || !st.active) return root.pluginApi?.tr("provider.loading");
392+
if (root.filterText !== "") return root.pluginApi?.tr("provider.noMatches");
393+
return root.pluginApi?.tr("provider.noItems");
394394
}
395395
pointSize: Style.fontSizeM
396396
color: Color.mOnSurfaceVariant
@@ -407,13 +407,27 @@ FocusScope {
407407
Layout.fillWidth: true
408408
text: {
409409
if (root.filteredItems.length === 0) {
410-
if (root.filterText) return "No results";
410+
if (root.filterText) return root.pluginApi?.tr("provider.noResults");
411411
return "";
412412
}
413-
var prefix = "";
414-
if (root.filterText && root.showMatchCount)
415-
prefix = root.filteredItems.length + " of " + (root.dmenuState ? root.dmenuState.items.length : 0) + " · ";
416-
return prefix + root.filteredItems.length + " result" + (root.filteredItems.length !== 1 ? "s" : "");
413+
if (root.filterText && root.showMatchCount) {
414+
return root.pluginApi?.trp(
415+
"provider.filteredResultsCount",
416+
root.filteredItems.length,
417+
"{filtered} of {total} · {count} result",
418+
"{filtered} of {total} · {count} results",
419+
{
420+
filtered: root.filteredItems.length,
421+
total: root.dmenuState ? root.dmenuState.items.length : 0
422+
}
423+
);
424+
}
425+
return root.pluginApi?.trp(
426+
"provider.resultsCount",
427+
root.filteredItems.length,
428+
"{count} result",
429+
"{count} results"
430+
);
417431
}
418432
pointSize: Style.fontSizeXS
419433
color: Color.mOnSurfaceVariant

dmenu/README.md

Lines changed: 40 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,6 @@ A dmenu replacement plugin for [Noctalia Shell](https://github.com/noctalia-dev/
66

77
Everything is driven by Noctalia's IPC system. A script calls `showItems` or `showJson` to open the panel with a list of choices. When the user selects one, the plugin writes the result to a file and optionally runs a callback command. The included `noctalia-dmenu` helper script wraps this into a familiar pipe interface — under the hood it sends the IPC call, waits for the result file, and prints the selection to stdout.
88

9-
## Install
10-
11-
```bash
12-
cd ~/.config/noctalia/plugins/
13-
git clone https://github.com/DaBenjle/noctalia-plugin-dmenu dmenu
14-
```
15-
16-
Add to `~/.config/noctalia/plugins.json`:
17-
18-
```json
19-
{ "states": { "dmenu": { "enabled": true } } }
20-
```
21-
22-
Restart Noctalia, enable in Settings → Plugins.
23-
24-
For pipe-style usage:
25-
26-
```bash
27-
ln -s ~/.config/noctalia/plugins/dmenu/noctalia-dmenu ~/.local/bin/noctalia-dmenu
28-
```
29-
309
## API
3110

3211
All commands go through `noctalia-shell ipc call plugin:dmenu <method> [args]`.
@@ -74,36 +53,36 @@ noctalia-shell ipc call plugin:dmenu showFromFile /tmp/items.txt '{"separator":"
7453

7554
### Item fields
7655

77-
| Field | Type | Description |
78-
|-------|------|-------------|
79-
| `name` | string | Display text |
80-
| `value` | string | Return value (defaults to `name`) |
81-
| `description` | string | Subtitle |
82-
| `icon` | string | [Tabler icon](https://tabler.io/icons) name |
83-
| `image` | string | Absolute path to image (overrides `icon`) |
56+
| Field | Type | Description |
57+
| ------------- | ------ | ------------------------------------------- |
58+
| `name` | string | Display text |
59+
| `value` | string | Return value (defaults to `name`) |
60+
| `description` | string | Subtitle |
61+
| `icon` | string | [Tabler icon](https://tabler.io/icons) name |
62+
| `image` | string | Absolute path to image (overrides `icon`) |
8463

8564
### Options
8665

8766
For `showItems` / `showFromFile`, pass as second arg. For `showJson`, include in the same object.
8867

89-
| Field | Type | Default | Description |
90-
|-------|------|---------|-------------|
91-
| `separator` | string | `"\n"` | Item delimiter (`showItems` / `showFromFile` text mode) |
92-
| `prompt` | string | `""` | Search bar placeholder |
93-
| `callbackCmd` | string | `""` | Run on selection. `{}` = value, `{index}` = index, `{name}` = name |
94-
| `resultFile` | string | `/tmp/noctalia-dmenu-result` | Where to write the result |
95-
| `resultFormat` | string | `"plain"` | `"plain"`, `"json"`, or `"index"` |
96-
| `allowCustomInput` | bool | `false` | Allow typing values not in the list |
97-
| `closeOnSelect` | bool | `true` | Close after selection |
98-
| `maxResults` | int | `200` | Max displayed items |
68+
| Field | Type | Default | Description |
69+
| ------------------ | ------ | ---------------------------- | ------------------------------------------------------------------ |
70+
| `separator` | string | `"\n"` | Item delimiter (`showItems` / `showFromFile` text mode) |
71+
| `prompt` | string | `""` | Search bar placeholder |
72+
| `callbackCmd` | string | `""` | Run on selection. `{}` = value, `{index}` = index, `{name}` = name |
73+
| `resultFile` | string | `/tmp/noctalia-dmenu-result` | Where to write the result |
74+
| `resultFormat` | string | `"plain"` | `"plain"`, `"json"`, or `"index"` |
75+
| `allowCustomInput` | bool | `false` | Allow typing values not in the list |
76+
| `closeOnSelect` | bool | `true` | Close after selection |
77+
| `maxResults` | int | `200` | Max displayed items |
9978

10079
### Other commands
10180

102-
| Command | Description |
103-
|---------|-------------|
81+
| Command | Description |
82+
| -------- | ------------------------ |
10483
| `toggle` | Toggle panel open/closed |
105-
| `close` | Cancel and close |
106-
| `clear` | Reset state |
84+
| `close` | Cancel and close |
85+
| `clear` | Reset state |
10786

10887
## Helper script
10988

@@ -121,17 +100,17 @@ noctalia-dmenu -f /tmp/items.txt -p "Select:"
121100
echo -e "Firefox\nChromium" | noctalia-dmenu -cb "gtk-launch {}"
122101
```
123102

124-
| Flag | Description |
125-
|------|-------------|
126-
| `-p`, `--prompt` | Search bar placeholder |
127-
| `-cb`, `--callback` | Command on selection |
128-
| `-c`, `--custom` | Allow custom input |
129-
| `-s`, `--separator` | Delimiter (default: newline) |
130-
| `-t`, `--timeout` | Wait timeout (default: 30s) |
131-
| `-r`, `--result-file` | Override result path |
132-
| `-f`, `--file` | Read from file |
133-
| `-F`, `--format` | Output: plain, json, index |
134-
| `-no-close` | Keep panel open |
103+
| Flag | Description |
104+
| --------------------- | ---------------------------- |
105+
| `-p`, `--prompt` | Search bar placeholder |
106+
| `-cb`, `--callback` | Command on selection |
107+
| `-c`, `--custom` | Allow custom input |
108+
| `-s`, `--separator` | Delimiter (default: newline) |
109+
| `-t`, `--timeout` | Wait timeout (default: 30s) |
110+
| `-r`, `--result-file` | Override result path |
111+
| `-f`, `--file` | Read from file |
112+
| `-F`, `--format` | Output: plain, json, index |
113+
| `-no-close` | Keep panel open |
135114

136115
Exit: `0` selected, `1` timeout/cancelled, `2` error.
137116

@@ -157,14 +136,14 @@ esac
157136

158137
Settings → Plugins → Dmenu Provider → Configure.
159138

160-
| Setting | Default | Description |
161-
|---------|---------|-------------|
162-
| Panel position | Follow launcher | Where the panel appears |
163-
| Show match count | On | Filtered/total in footer |
164-
| Show footer | On | Result count bar |
165-
| Show toast | Off | Notification on selection |
166-
| Result file | `/tmp/noctalia-dmenu-result` | Default path |
167-
| Max results | 200 | Display cap |
139+
| Setting | Default | Description |
140+
| ---------------- | ---------------------------- | ------------------------- |
141+
| Panel position | Follow launcher | Where the panel appears |
142+
| Show match count | On | Filtered/total in footer |
143+
| Show footer | On | Result count bar |
144+
| Show toast | Off | Notification on selection |
145+
| Result file | `/tmp/noctalia-dmenu-result` | Default path |
146+
| Max results | 200 | Display cap |
168147

169148
## Testing
170149

dmenu/Settings.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ ColumnLayout {
136136
spacing: Style.marginS
137137

138138
NLabel {
139-
label: root.pluginApi?.tr("settings.maxResults") + ": " + root.editMaxResults
139+
label: root.pluginApi?.tr("settings.maxResultsLabel", { count: root.editMaxResults })
140140
description: root.pluginApi?.tr("settings.maxResultsDesc", { count: root.editMaxResults })
141141
}
142142

dmenu/i18n/en.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,17 @@
22
"provider": {
33
"name": "Dmenu",
44
"command": "External menu (dmenu mode)",
5+
"loading": "Loading...",
6+
"noMatches": "No matches",
7+
"noItems": "No items",
58
"noSession": "No active dmenu session",
69
"noSessionDesc": "Use IPC or noctalia-dmenu script to send items",
10+
"noResults": "No results",
11+
"filteredResultsCount": "{filtered} of {total} · {count} result",
12+
"filteredResultsCount_plural": "{filtered} of {total} · {count} results",
13+
"resultsCount": "{count} result",
14+
"resultsCount_plural": "{count} results",
15+
"typeToFilterPlaceholder": "Type to filter...",
716
"customInput": "Use as custom input",
817
"customInputHint": "✎ Custom input allowed — type anything and press Enter",
918
"selected": "Selected: {value}"
@@ -40,6 +49,7 @@
4049
"showToast": "Show toast on select",
4150
"showToastDesc": "Display a notification when an item is selected",
4251
"maxResults": "Max results",
52+
"maxResultsLabel": "Max results: {count}",
4353
"maxResultsDesc": "Maximum number of items to display: {count}"
4454
}
4555
}

0 commit comments

Comments
 (0)