Skip to content

Commit

Permalink
Feat: Add mympd.read_file() Lua function
Browse files Browse the repository at this point in the history
  • Loading branch information
jcorporation committed Oct 6, 2024
1 parent c73b38a commit 3beb6c2
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 25 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This is a small maintenance release.

### Changelog

- Feat: New custom Lua function: mympd.splitlines(), mympd.trim()
- Feat: New custom Lua function: mympd.splitlines(), mympd.trim(), mympd.read_file()
- Upd: Translations
- Upd: Mongoose to current master

Expand Down
12 changes: 12 additions & 0 deletions contrib/lualibs/mympd/50-util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,15 @@ end
function mympd.sleep(ms)
mympd_util_sleep(ms)
end

--- Read an ascii file
-- @param path Filename
function mympd.read_file(path)
local file = io.open(path, "r")
if not file then
return nil
end
local content = file:read "*a"
file:close()
return content
end
1 change: 1 addition & 0 deletions docs/050-scripting/functions/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ List of myMPD specific Lua functions.
| [mympd.notify_client](util.md) | Sends a notification to the client. |
| [mympd.notify_partition](util.md) | Sends a notification to all clients in a partition. |
| [mympd.os_capture](system_command.md) | Executes a system command and capture its output. |
| [mympd.read_file](util.md) | Read an ascii file. |
| [mympd.sleep](util.md) | Sleep ms. |
| [mympd.splitlines](string.md) | Split string by newline characters and trims the lines. |
| [mympd.tmp_file](diskcache.md) | Generates a random tmp filename for the misc cache. |
Expand Down
12 changes: 12 additions & 0 deletions docs/050-scripting/functions/util.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ mympd.notify_partition(severity, message)
| SEVERITY_WARNING | 1 | Warning |
| SEVERITY_ERR | 2 | Error |

## Read an ascii file

```lua
local content = mympd.read_file(path)
```

**Parameters:**

| PARAMETER | TYPE | DESCRIPTION |
| --------- | ---- | ----------- |
| path | string | Filepath to open and read. |

## Sleep

```lua
Expand Down
28 changes: 14 additions & 14 deletions docs/_includes/translating_status.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
- bg-BG: 1086 missing phrases
- es-AR: 3 missing phrases
- es-ES: 953 missing phrases
- es-VE: 941 missing phrases
- fi-FI: 938 missing phrases
- fr-FR: 3 missing phrases
- it-IT: 3 missing phrases
- ja-JP: 3 missing phrases
- ko-KR: 3 missing phrases
- nl-NL: 3 missing phrases
- pl-PL: 86 missing phrases
- ru-RU: 34 missing phrases
- zh-Hans: 3 missing phrases
- zh-Hant: 120 missing phrases
- bg-BG: 1087 missing phrases
- es-AR: 4 missing phrases
- es-ES: 954 missing phrases
- es-VE: 942 missing phrases
- fi-FI: 939 missing phrases
- fr-FR: 4 missing phrases
- it-IT: 4 missing phrases
- ja-JP: 4 missing phrases
- ko-KR: 4 missing phrases
- nl-NL: 4 missing phrases
- pl-PL: 87 missing phrases
- ru-RU: 35 missing phrases
- zh-Hans: 4 missing phrases
- zh-Hant: 121 missing phrases
5 changes: 5 additions & 0 deletions htdocs/js/globales.js
Original file line number Diff line number Diff line change
Expand Up @@ -1718,6 +1718,11 @@ const LUAfunctions = {
"desc": "Sleeps number of milliseconds.",
"func": "sleep(ms)",
"feat": ""
},
"mympd.read_file": {
"desc": "Read an ascii file.",
"func": "local content = mympd.read_file(path)",
"feat": ""
}
};

Expand Down
3 changes: 2 additions & 1 deletion src/i18n/json/de-DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -1232,5 +1232,6 @@
"wasapi": "Windows Audio Session API",
"Split a multiline string in lines.": "Teilt einen mehrzeiligen String in einzelne Zeilen.",
"Trims a string.": "Trimt einen String.",
"Sleeps number of milliseconds.": "Wartet die Spanne von Millisekunden."
"Sleeps number of milliseconds.": "Wartet die Spanne von Millisekunden.",
"Read an ascii file.": "Liest eine Textdatei ein."
}
18 changes: 9 additions & 9 deletions src/i18n/json/i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"default": {"desc":"Browser default", "missingPhrases": 0},
"de-DE": {"desc":"Deutsch (de-DE)", "missingPhrases": 0},
"en-US": {"desc":"English (en-US)", "missingPhrases": 0},
"es-AR": {"desc":"Español (es-AR)", "missingPhrases": 3},
"fr-FR": {"desc":"Français (fr-FR)", "missingPhrases": 3},
"it-IT": {"desc":"Italiano (it-IT)", "missingPhrases": 3},
"ja-JP": {"desc":"日本語 (ja-JP)", "missingPhrases": 3},
"ko-KR": {"desc":"한국어 (ko-KR)", "missingPhrases": 3},
"nl-NL": {"desc":"Nederlands (nl-NL)", "missingPhrases": 3},
"pl-PL": {"desc":"Polish (pl-PL)", "missingPhrases": 86},
"ru-RU": {"desc":"Russian (ru-RU)", "missingPhrases": 34},
"zh-Hans": {"desc":"简体中文 (zh-Hans)", "missingPhrases": 3}
"es-AR": {"desc":"Español (es-AR)", "missingPhrases": 4},
"fr-FR": {"desc":"Français (fr-FR)", "missingPhrases": 4},
"it-IT": {"desc":"Italiano (it-IT)", "missingPhrases": 4},
"ja-JP": {"desc":"日本語 (ja-JP)", "missingPhrases": 4},
"ko-KR": {"desc":"한국어 (ko-KR)", "missingPhrases": 4},
"nl-NL": {"desc":"Nederlands (nl-NL)", "missingPhrases": 4},
"pl-PL": {"desc":"Polish (pl-PL)", "missingPhrases": 87},
"ru-RU": {"desc":"Russian (ru-RU)", "missingPhrases": 35},
"zh-Hans": {"desc":"简体中文 (zh-Hans)", "missingPhrases": 4}
}
1 change: 1 addition & 0 deletions src/i18n/json/phrases.json
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,7 @@
{"term":"Quick remove button"},
{"term":"Random"},
{"term":"Rating"},
{"term":"Read an ascii file."},
{"term":"Reconnect"},
{"term":"Refresh interval"},
{"term":"Region"},
Expand Down

0 comments on commit 3beb6c2

Please sign in to comment.