Closed LeRatierBretonnien closed 2 years ago
I like that idea, maybe extend the existing API to include the functions getFolder(folderId)
and renameFolder(folder)
. The folder ID wont change if youre translating a compendium. Ill have a think of a way to reliably searching for folder ids (because just searching by name may not be enough)
Yes, this can be great !
Hi, so turns out you can actually do this with the existing implementation. Here's an example of how:
const packCode = 'world.pack1';
let folders = await game.CF.FICFolderAPI.loadFolders(packCode);
//here you can get using the folder IDs that CF generates:
let folderToChange = folders.get('temp_abcd....');
//or filter for the exact name or other criteria
let folderToChange = folders.contents.find(f => f.name === 'Animals');
folderToChange.data.name = 'Translated Name';
await folderToChange.save();
I would strongly recommend only sticking to cosmetic folder changes (so name, color, icon). I need to add some checks in here to prevent you from accessing the folder paths or children
If you need any help give us a shout, i'll close this for the time being but can reopen if there are issues
Edit: Not as simple as i thought, its been a while since i checked out the code. Will get back to you on this one
Thanks !!
Any news/idea on this ?
Sorry I've been busy with other stuff recently. I've been going through the code I wrote previously and am having to rework some of the bits, so its taking longer than normal.
Thanks sure !
Ok, i've got a version ready for testing. If you uninstall your current version of CF and install the testing one using the manifest here: https://raw.githubusercontent.com/earlSt1/vtt-compendium-folders/082-update/test/module.json , you will be able to use the folder API to move folders in a compendium.
Here's an example of how to use the renaming functionality:
const packCode = 'world.sceness';
let folders = await game.CF.FICFolderAPI.loadFolders(packCode);
//here you can get using the folder IDs that CF generates:
//let folderToChange = folders.get('temp_abcd....');
//or filter for the exact name or other criteria
let folderToChange = folders.contents.find(f => f.name === 'Original Name');
await game.CF.FICFolderAPI.renameFolder(folderToChange,'New Name');
I strongly recommend backing up your compendiums/worlds just in case
Thanks! I am running some games today and tomorrow, so no time to test it right now. I will do it next week.
Implemented in v2.3.60
This is working perfectly, but in fact it modifies the compendium itself. One better option might be to allow dynamic change of the words by registering a translation callback for example. Then the 'translation callback' (if present) is called on each term, and return the translated term (like in Babele in fact).
Ahh i see, so call the hook translateCompendiumFolders when the compendium is rendered, provide all the folders, and then in the translation module youd just update the folder names?
On Mon, 29 Nov 2021, 17:26 sladecraven, @.***> wrote:
This is working perfectly, but in fact it modifies the compendium itself. One better option might be to allow dynamic change of the words by registering a translation callback for example. Then the 'translation callback' (if present) is called on each term, and return the translated term (like in Babele in fact).
— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/earlSt1/vtt-compendium-folders/issues/112#issuecomment-981851434, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADI2CKBW7CTOYLOURRHY4IDUOOZT7ANCNFSM5EWPUKMQ .
Yes, we only need to change folder names (as far as I know :) )
Any progress on this?
Hi ! Any progress on this?
Good news! Sorry for the wait, but I think i've found a way to do the dynamic translations.
Can you both try installing this test version of CF and giving it a test run? Basically if you provide a translation key as a folder name (I've been using the CF translations like CF.moveFolder
), then it should dynamically translate the folder name if a valid translation exists. If no translation exists it will fall back to the default functionality.
The test manifest is here: https://raw.githubusercontent.com/earlSt1/vtt-compendium-folders/09x-update/test/module.json
Thanks ! Quick try, and I got :
Uncaught (in promise) LibWrapperPackageError: Error detected in module Compendium Folders.
This is *not* a libWrapper bug.
Find information about this module here: https://github.com/earlSt1/vtt-compendium-folders
Ask the community for support:
- FoundryVTT Discord's #modules-troubleshooting channel: https://discord.gg/foundryvtt
- FoundryVTT Reddit: https://www.reddit.com/r/FoundryVTT
== Technical Details:
Detected by libWrapper.
Package ID= compendium-folders
Error= Could not find target 'MacroSidebarDirectory.prototype._getFolderContextOptions': Could not find root scope 'MacroSidebarDirectory'.
[Detected 1 package: compendium-folders]
at ae (libWrapper-api.js:135:10)
at se (libWrapper-api.js:152:19)
at Function.🎁register [as register] (libWrapper-api.js:522:14)
at Function.setup (fic-folders.js:574:20)
at compendium-folders.js:1863:24
at Function._call (foundry.js:294:14)
at Function.callAll (foundry.js:253:12)
at Game.initialize (foundry.js:5418:11)
at Wrapper.🎁call_wrapped [as call_wrapped] (libWrapper-wrapper.js:511:22)
at Game.🎁libWrapperInit (libWrapper-api.js:793:11)
Gah, sorry about that, forgot to test that pull request. Can you try installing using the manifest again?
OK, so what I understand is that the source module must provide a key as a name (ie like "MYMODULE.ActorName" = "Actor"), and then in the translation modules, we provide "MYMODULE.ActorName" = "Acteur". Am I right ?
Correct! I've got some examples in Compendium Folders that people have contributed (in the lang/*.json
files). In my module manifest you can see they are mapped there too.
OK... Bu many modules does not use translation keys (unfortunatly...). Could you try to always call game.i18n.localize( word)
, event if the "word" is not a translation key in the initial system/module ?
It works !!!! Great !!! You can release :)
I can try to look into reverse-translating the words (e.g not using the key), but i can tell it will be a bit difficult as foundry mainly uses the translation keys to handle translations. I'll release the module so it uses keys for now and maybe revisit it at another date.
It works in all cases anyway, forget my message above ^^
Great. Will release later today. You can stick with that test version then when i release it officially you can update to the main branch version :smile:
Implemented in v2.4.2
Not quite understand how to use this new feature, would you explain?
Sure. So any module in Foundry (as well as core foundry) use translation keys to represent words to be translated. For example in my module Compendium Folders, the CF.moveFolder
key represents the English text of Move Folder
. You can see this in the translation file here: https://github.com/earlSt1/vtt-compendium-folders/blob/de965ce4cf337bb107311eb402acd6b217c5428e/lang/en.json#L19
I've also got a French translation mapping in the module (stored in lang/fr.json
) which adds the French translation of this word - Déplacer le dossier
. You can see this in the translation file here: https://github.com/earlSt1/vtt-compendium-folders/blob/de965ce4cf337bb107311eb402acd6b217c5428e/lang/fr.json#L19
I can define the languages that this module supports by modifying the module.json
manifest - seen here: https://github.com/earlSt1/vtt-compendium-folders/blob/de965ce4cf337bb107311eb402acd6b217c5428e/module.json#L12-L48
With these new changes, if I create a folder in the compendium called CF.moveFolder
, if my system language was set to English it would render as Move Folder
, whereas if my language was set to French the same folder in the same compendium would render as Déplacer le dossier
But how do I get these keys for folders in compendiums?
I tried export translation files with Babele, but all I get is:
I'm not familiar with Babele, so I'm not sure how it does the translations. I'll need to look into it later.
But how do I get these keys for folders in compendiums?
I tried export translation files with Babele, but all I get is:
Your are misunderstanding the stuff :
但是我如何获得纲要中文件夹的这些密钥? 我尝试使用 Babele 导出翻译文件,但得到的只是:
你误解了这些东西:
- 要翻译纲要内容(即项目、演员等,-> 您必须使用 Babele,它与 CompendiumFolders 没有任何关系。
- 要翻译 CompendiuumFolders 标题 -> 您只需在语言文件中添加一个键(参见我上面的帖子中所述)。
So, if I want to translate this Tables
folder, I need to write "CF.Tables": "Tables"
in lang/language.json
like "CF.Tables": "translated_Tables"
?
When a module or a system (for example SWADE) makes use of Compendium Folders, the title of folders are in the original language (English, usually). When the systems or modules are translated (interface and compendiums), there is no way up to now to change the name of the folders. An API or something like that to help localization could great - to be discusses of course