From 3beb6c28ae1aa4818d6923ba3652900cdd2233a1 Mon Sep 17 00:00:00 2001 From: jcorporation Date: Sun, 6 Oct 2024 20:37:59 +0200 Subject: [PATCH] Feat: Add mympd.read_file() Lua function --- CHANGELOG.md | 2 +- contrib/lualibs/mympd/50-util.lua | 12 ++++++++++++ docs/050-scripting/functions/index.md | 1 + docs/050-scripting/functions/util.md | 12 ++++++++++++ docs/_includes/translating_status.md | 28 +++++++++++++-------------- htdocs/js/globales.js | 5 +++++ src/i18n/json/de-DE.json | 3 ++- src/i18n/json/i18n.json | 18 ++++++++--------- src/i18n/json/phrases.json | 1 + 9 files changed, 57 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d2d1802d..dcd8983b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/contrib/lualibs/mympd/50-util.lua b/contrib/lualibs/mympd/50-util.lua index db4bde1c5..d23785bec 100644 --- a/contrib/lualibs/mympd/50-util.lua +++ b/contrib/lualibs/mympd/50-util.lua @@ -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 diff --git a/docs/050-scripting/functions/index.md b/docs/050-scripting/functions/index.md index d93b5c334..2942277ce 100644 --- a/docs/050-scripting/functions/index.md +++ b/docs/050-scripting/functions/index.md @@ -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. | diff --git a/docs/050-scripting/functions/util.md b/docs/050-scripting/functions/util.md index e54a305b2..8834cd507 100644 --- a/docs/050-scripting/functions/util.md +++ b/docs/050-scripting/functions/util.md @@ -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 diff --git a/docs/_includes/translating_status.md b/docs/_includes/translating_status.md index 3d54c77bd..6b439b22c 100644 --- a/docs/_includes/translating_status.md +++ b/docs/_includes/translating_status.md @@ -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 diff --git a/htdocs/js/globales.js b/htdocs/js/globales.js index b55d1d07d..7d0925506 100644 --- a/htdocs/js/globales.js +++ b/htdocs/js/globales.js @@ -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": "" } }; diff --git a/src/i18n/json/de-DE.json b/src/i18n/json/de-DE.json index 6eb6d6706..0faf7c93d 100644 --- a/src/i18n/json/de-DE.json +++ b/src/i18n/json/de-DE.json @@ -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." } \ No newline at end of file diff --git a/src/i18n/json/i18n.json b/src/i18n/json/i18n.json index 3011e288f..54c66cbb8 100644 --- a/src/i18n/json/i18n.json +++ b/src/i18n/json/i18n.json @@ -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} } diff --git a/src/i18n/json/phrases.json b/src/i18n/json/phrases.json index ab33a2254..f3e81bef4 100644 --- a/src/i18n/json/phrases.json +++ b/src/i18n/json/phrases.json @@ -714,6 +714,7 @@ {"term":"Quick remove button"}, {"term":"Random"}, {"term":"Rating"}, +{"term":"Read an ascii file."}, {"term":"Reconnect"}, {"term":"Refresh interval"}, {"term":"Region"},