Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Localization #649

Merged
merged 68 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
a58d689
add auto-width tester
rpatters1 Jan 12, 2024
4f82981
auto resize width sample
rpatters1 Jan 13, 2024
e04897a
refinements
rpatters1 Jan 14, 2024
34a00ef
add ComboBox to mixin, plus sample
rpatters1 Jan 14, 2024
8d366dc
lint fix and sample update
rpatters1 Jan 15, 2024
7525a9f
add other auto-layout features
rpatters1 Jan 16, 2024
bf6cdb3
sample auto_layout updates
rpatters1 Jan 17, 2024
2ff3ea6
auto-layout sample for 0.71
rpatters1 Jan 17, 2024
aeb97b4
revise auto-layout demo script
rpatters1 Jan 18, 2024
a2fce80
fix issue with FCMCtrlCheckBox not storing state
rpatters1 Jan 18, 2024
c21a6f6
add 3-state checkbox for testing
rpatters1 Jan 18, 2024
fca08c9
fix text
rpatters1 Jan 18, 2024
78172fd
add localization demo
rpatters1 Jan 18, 2024
25af53c
refactor localization to add the localization tables to the library i…
rpatters1 Jan 19, 2024
c77f535
localize menu options of Transpose By Steps
rpatters1 Jan 19, 2024
5051a36
docs, tranposition localization
rpatters1 Jan 19, 2024
ae478e3
localization of transpose
rpatters1 Jan 19, 2024
77faaa6
fix a few typos
rpatters1 Jan 20, 2024
478fe45
make compatible with JW Lua
rpatters1 Jan 20, 2024
ea5b041
fix typo
rpatters1 Jan 20, 2024
9ee3264
Fix typos in Spanish text.
rpatters1 Jan 20, 2024
1788e8c
localized enharmonic transposition scripts
rpatters1 Jan 20, 2024
f2a8a92
refinements to localization
rpatters1 Jan 21, 2024
779811d
add localization for chromatic transpose
rpatters1 Jan 21, 2024
3e11d5c
refinements to localizing transposition
rpatters1 Jan 21, 2024
1e60872
auto_layout changes for latest RGP Lua dev branch
rpatters1 Jan 22, 2024
a0f6c21
Add mixin version of `__FCUserWindow::CreateChildUI` for backwards co…
rpatters1 Jan 23, 2024
f568680
update finenv with latest info
rpatters1 Jan 29, 2024
f0c0383
one more lint warning
rpatters1 Jan 31, 2024
5a78f36
transpose_by_step is working
rpatters1 Feb 1, 2024
2cf8a3d
transpose_chromatic
rpatters1 Feb 1, 2024
4249224
enharmonic transposing
rpatters1 Feb 1, 2024
324f9cc
Merge branch 'RGP-automatic-localization' into RGP-localization
rpatters1 Feb 1, 2024
e13bf80
lint errors
rpatters1 Feb 1, 2024
b1d8df1
refactor folder layout for localization
rpatters1 Feb 2, 2024
d7a89c3
Merge branch 'master' into RGP-localization
rpatters1 Feb 2, 2024
a936359
clarify comments
rpatters1 Feb 2, 2024
0f9c83e
checkpoint localization tool
rpatters1 Feb 3, 2024
64d59a8
checkpoint localization tool
rpatters1 Feb 3, 2024
f8ef97b
localization tool semi-working. main things missing are plugindef sup…
rpatters1 Feb 3, 2024
12f0a65
refactor sync openai calls to async
rpatters1 Feb 3, 2024
8c85429
line ending
rpatters1 Feb 3, 2024
88953d9
plugindef localization kind of working
rpatters1 Feb 4, 2024
4704eb2
plugindef localization is working
rpatters1 Feb 4, 2024
2efafc1
localize an example with a lot of additional menu items
rpatters1 Feb 4, 2024
9311b4a
Add script group name and description
rpatters1 Feb 4, 2024
983a675
minor updates
rpatters1 Feb 5, 2024
3a92c8c
Merge branch 'master' into RGP-localization
rpatters1 Feb 5, 2024
9a46284
Added table to list of types recognized by AddStrings method. Other m…
rpatters1 Feb 5, 2024
89423a0
refactor mixins per suggestions from ThistleSifter
rpatters1 Feb 6, 2024
48d4f32
Merge branch 'master' into RGP-localization
rpatters1 Feb 6, 2024
a2e17a0
a word
rpatters1 Feb 6, 2024
0a3f419
update sample localized script with latest approaches
rpatters1 Feb 6, 2024
7a3759e
Bundle localizations
asherber Feb 6, 2024
1abb39f
Merge pull request #6 from asherber/bundle-localization
rpatters1 Feb 6, 2024
8ff3c8c
address code review issues.
rpatters1 Feb 7, 2024
3bae150
in-progress checkpoint for Base localization.
rpatters1 Feb 7, 2024
5118dcc
Base localization added to all src scripts and utilities. Still need …
rpatters1 Feb 7, 2024
b38d2eb
auto_layout.lua code complete
rpatters1 Feb 7, 2024
d12bf4f
Merge branch 'master' into RGP-localization
rpatters1 Feb 8, 2024
c4c495d
update with latest agreed changes
rpatters1 Feb 8, 2024
5a3054d
fix lint error
rpatters1 Feb 8, 2024
48d7a85
Merge branch 'master' into RGP-localization
rpatters1 Feb 9, 2024
942fa21
add table support for multi-string arguments methods.
rpatters1 Feb 9, 2024
67be045
changed `process_string_arguments` to `create_multi_string_proxy` so …
rpatters1 Feb 9, 2024
c77beac
remove mobdebug
rpatters1 Feb 9, 2024
8a87b51
fix small issues discovered
rpatters1 Feb 9, 2024
44e53dc
Changes for `*AutoLocalized` mixin functions.
rpatters1 Feb 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions .github/actions/bundle/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6791,12 +6791,13 @@ const importFileBase = (name, importedFiles, fetcher) => {
}
};
exports.importFileBase = importFileBase;
const bundleFileBase = (name, importedFiles, mixins, fetcher) => {
const bundleFileBase = (name, importedFiles, mixins, localizations, fetcher) => {
var _a;
const fileContents = (0, inject_extras_1.injectExtras)(name, fetcher(name));
const fileStack = [fileContents];
const importStack = (0, helpers_1.getAllImports)(fileContents);
const importedFileNames = new Set();
importStack.push(...localizations);
while (importStack.length > 0) {
const nextImport = (_a = importStack.pop()) !== null && _a !== void 0 ? _a : '';
if (importedFileNames.has(nextImport))
Expand All @@ -6821,7 +6822,16 @@ const bundleFileBase = (name, importedFiles, mixins, fetcher) => {
};
exports.bundleFileBase = bundleFileBase;
const bundleFile = (name, sourcePath, mixins) => {
const bundled = (0, exports.bundleFileBase)(name, exports.files, mixins, (fileName) => fs_1.default.readFileSync(path_1.default.join(sourcePath, fileName)).toString());
const localizations = [];
const baseName = path_1.default.basename(name, '.lua');
const locPath = path_1.default.join(sourcePath, 'localization', baseName);
if (fs_1.default.existsSync(locPath)) {
localizations.push(...fs_1.default
.readdirSync(locPath)
.filter(fileName => fileName.endsWith('.lua'))
.map(file => `localization.${baseName}.${path_1.default.basename(file, '.lua')}`));
}
const bundled = (0, exports.bundleFileBase)(name, exports.files, mixins, localizations, (fileName) => fs_1.default.readFileSync(path_1.default.join(sourcePath, fileName)).toString());
const parts = (0, helpers_1.getFileParts)(bundled);
return (0, remove_comments_1.removeComments)(parts.prolog, true)
+ (0, remove_comments_1.removeComments)(parts.plugindef, false)
Expand Down
8 changes: 4 additions & 4 deletions .github/actions/bundle/src/bundle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('bundle', () => {
}

it('bundleFile', () => {
const bundle = bundleFileBase('a.lua', {}, [], fetcher)
const bundle = bundleFileBase('a.lua', {}, [], [], fetcher)
expect(bundle).toBe(
[
'package.preload["b"] = package.preload["b"] or function()',
Expand All @@ -58,17 +58,17 @@ describe('bundle', () => {
})

it('bundleFile with no imports', () => {
const bundle = bundleFileBase('c.lua', {}, [], fetcher)
const bundle = bundleFileBase('c.lua', {}, [], [], fetcher)
expect(bundle).toBe('return {}')
})

it('ignore unresolvable imports', () => {
const bundle = bundleFileBase('invalid.lua', {}, [], fetcher)
const bundle = bundleFileBase('invalid.lua', {}, [], [], fetcher)
expect(bundle).toBe(["local invalid = require('invalid.import')"].join('\n'))
})

it('imports all mixins', () => {
const bundle = bundleFileBase('mixin.lua', {}, ['mixin.FCMControl', 'mixin.FCMString'], fetcher)
const bundle = bundleFileBase('mixin.lua', {}, ['mixin.FCMControl', 'mixin.FCMString'], [], fetcher)
expect(bundle).toBe(
[
'package.preload["mixin.FCMControl"] = package.preload["mixin.FCMControl"] or function()',
Expand Down
16 changes: 15 additions & 1 deletion .github/actions/bundle/src/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@ export const bundleFileBase = (
name: string,
importedFiles: ImportedFiles,
mixins: string[],
localizations: string[],
fetcher: (name: string) => string
) => {
const fileContents = injectExtras(name, fetcher(name))
const fileStack: string[] = [fileContents]
const importStack: string[] = getAllImports(fileContents)
const importedFileNames = new Set<string>()

importStack.push(...localizations)

while (importStack.length > 0) {
const nextImport = importStack.pop() ?? ''
if (importedFileNames.has(nextImport)) continue
Expand All @@ -63,7 +66,18 @@ export const bundleFileBase = (
}

export const bundleFile = (name: string, sourcePath: string, mixins: string[]): string => {
const bundled: string = bundleFileBase(name, files, mixins, (fileName: string) =>
const localizations: string[] = []
const baseName = path.basename(name, '.lua')
const locPath = path.join(sourcePath, 'localization', baseName)
if (fs.existsSync(locPath)) {
localizations.push(...fs
.readdirSync(locPath)
.filter(fileName => fileName.endsWith('.lua'))
.map(file => `localization.${baseName}.${path.basename(file, '.lua')}`)
)
}

const bundled: string = bundleFileBase(name, files, mixins, localizations, (fileName: string) =>
fs.readFileSync(path.join(sourcePath, fileName)).toString()
);
const parts = getFileParts(bundled);
Expand Down
4 changes: 3 additions & 1 deletion .github/actions/bundle/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
"module": "commonjs",
"moduleResolution": "node",
"resolveJsonModule": true,
"declaration": false
"declaration": false,
"outDir": "dist",
"sourceMap": true
},
"include": [
"**/*.ts",
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ dist/**/personal*
# (finale_lua_menus.txt is the menu layout file used by finale_lua_menu_organizer.lua)
finale_lua_menus.txt

.github/**/dist/*.js
!.github/**/dist/index.js
.github/**/dist/*.map
2 changes: 1 addition & 1 deletion .luacheckrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- luacheck: ignore 131
include_files = { "src/**/*.lua", "samples/**/*.lua"}
include_files = { "src/**/*.lua", "samples/**/*.lua", "utilities/**/*.lua"}
exclude_files = {
"mobdebug.lua",
}
Expand Down
5 changes: 3 additions & 2 deletions .vscode/recommended_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@
"loadall",
"loadallforregion",
"pairsbykeys",
"prettyformatjson",
"bit32",
"utf8",
"socket",
"tinyxml2",
"xmlelements",
"xmlattributes",
"prettyformatjson"
"xmlattributes"
],
"files.exclude": {
"mobdebug.lua": true,
"dist/**": true
},
"editor.formatOnSave": true,
"Lua.diagnostics.enable": false,
Expand Down
34 changes: 31 additions & 3 deletions docs/rgp-lua.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ print ("Hello, world!")
If you want a “Hello, world!” example that shows up as a menu option in Finale's Plug-in menu, here is a slightly more complex version:

```lua
function plugindef()
function plugindef(locale)
return "Hello World", "Hello World", 'Displays a message box saying, "Hello, world!"'
end

Expand Down Expand Up @@ -285,7 +285,6 @@ The `plugindef()` function is an optional function that **only** should do a _ma
* Return the _plug-in name_, _undo string_ and _brief description_ to be used in the _Finale_ plug-in menu and for automatic undo blocks.
* Define the `finaleplugin` namespace environment to further describe the plug-in (see below).


A simple `plugindef()` implementation might look like this:

```lua
Expand All @@ -296,7 +295,36 @@ function plugindef()
end
```

`plugindef()` is considered to be a reserved name in the global namespace. If the script has a function named `plugindef()`, the Lua plugin may call it at any time (not only during script execution) to gather information about the plug-in. The `plugindef()` function can **NOT** have dependencies outside the function itself.
Starting with version 0.71, _RGP Lua_ passes the user's locale code as an argument to the `plugindef` function. You can use this to localize any strings returned by the function or assigned to variables. The user's locale code is a 2-character lowercase language code followed by "_" or "-" and then a 2-digit uppercase region code. This is the same value that is returned by `finenv.UI():GetUserLocaleName()`. (See the note below detailing why the `plugindef` function cannot call `GetUserLocaleName` directly.)

A localized version of the same function might look like this:

```lua
function plugindef(locale)
finaleplugin.RequireSelection = true
finaleplugin.CategoryTags = "Rest, Region"
local localization = {}
localization.en = {
menu = "Hide Rests",
desc = "Hides all rests in the selected region."
}
localization.es = {
menu = "Ocultar Silencios",
desc = "Oculta todos los silencios en la región seleccionada."
}
localization.jp = {
menu = "休符を隠す",
desc = "選択した領域内のすべての休符を隠します。",
}
-- add more localizations as desired
local t = locale and localization[locale:sub(1,2)] or localization.en
return t.menu, t.menu, t.desc
end
```

Note that the `plugindef()` function must be *entirely* self-contained. It may not have access to any of the global namespaces that the rest of the script uses, such as `finenv` or `finale`. It *does* have access to all the standard Lua libraries. If the script has a function named `plugindef()`, the Lua plugin may call it at any time (not only during script execution) to gather information about the plug-in.

`plugindef` is a reserved name in the global namespace.

All aspects of the `plugindef()` are optional, but for a plug-in script that is going to be used repeatedly, the minimum should be to return a plug-in name, undo string, and short description.

Expand Down
5 changes: 3 additions & 2 deletions docs/rgp-lua/finenv-properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,22 +245,23 @@ end

A list of constants that define the type of message returned by `finenv.ExecuteLuaScriptItem` (if any).

- `SCRIPT_RESULT` : The message was returned by Lua. It could be either an error or a value returned by the script. If it is an error, the first value returned by `ExecuteLuaScriptItem` is false.|
- `SCRIPT_RESULT` : The message was returned by the Lua script. This is not an error message.
- `DOCUMENT_REQUIRED` : The script was not executed because it specified `finaleplugin.RequireDocument = true` but no document was open.
- `SELECTION_REQUIRED` : The script was not executed because it specified `finaleplugin.RequireSelection = true` but there was no selection.
- `SCORE_REQUIRED` : The script was not executed because it specified `finaleplugin.RequireScore = true` but the document was viewing a part.
- `FINALE_VERSION_MISMATCH` : The script was not executed because it specified a minimum or maximum Finale version and the current running version of Finale does not meet the requirement.
- `LUA_PLUGIN_VERSION_MISMATCH` : The script was not executed because it specified a minimum or maximum Lua plugin version and the current running version of _RGP Lua_ does not meet the requirement.
- `MISCELLANEOUS` : Other types of error messages that do not fit any of the other categories.
- `EXTERNAL_TERMINATION` : The script was externally terminated by the user or a controlling script.
- `LUA_ERROR` : The message is an error message returned by Lua.

Example:

```lua
local scripts = finenv.CreateLuaScriptItems()
local success, error_msg, msg_type = finenv.ExecuteLuaScriptItem(scripts:GetItemAt(0))
if not success then
if msg_type == finenv.MessageResultType.SCRIPT_RESULT then
if msg_type == finenv.MessageResultType.LUA_ERROR then
-- take some action
end
end
Expand Down
Loading