Freecam icon indicating copy to clipboard operation
Freecam copied to clipboard

Generate lang files at build time

Open MattSturgeon opened this issue 5 months ago • 4 comments

  • [x] Refactor :metadata into a more general :data project
  • [x] Introduce a custom gradle task that can "build" lang files
  • [x] Move most VariantTooltip logic to the gradle task
  • [x] Move mod description to lang files
  • [x] Use the built description in mod metadata
  • [ ] Reformat lang files as .properties (not planned)
  • [ ] Split lang files into main & config (low priority?)
  • [ ] Allow defining per-file key prefix/suffix or json "flattening" (not planned)
  • [x] Fabric support (using ModMenu's documented API)
  • [ ] Forge support (depends on https://github.com/neoforged/NeoForge/issues/639)
  • [ ] Unit tests for LangTask
  • [x] Unit tests for the LangProcessor implementations

Fixes #172

MattSturgeon avatar Feb 07 '24 14:02 MattSturgeon

This is feature complete and ready for review.

General notes

  • First time using Kotlin; seems nice so far. A very expressive language, and excellent null safety.
    • Kotlin was used to experiment with what it's like, with a view to potentially porting other parts of the build script in future.
  • I would have liked to implement functional tests using Gradle's TestKit, however I was running into issues getting buildSrc into the runner's classpath...
    • I may still add some unit tests though.
  • buildSrc is an entirely separate "build", with it's own gradle "projects".
    • Gradle automatically compiles buildSrc before running the main build, and makes the result available to the build script.
    • It is a simple way to have freecam-specific build logic, plugins, & tasks without having to clutter up the actual build script.
  • I've verified that :data builds everything correctly.

Tooltips

  • VariantTooltip is now mostly a build step, the only thing handled at runtime is line count.
  • Mod name and description are now handled by :data's langTask.
    • If there is a freecam.name.<variant> translation, it is appended to the end of freecam.name.
    • Same for description.
    • These are also used for the name/description in the mod metadata file.
    • These are also assigned to the various modmenu-specific translation keys.

Forge

  • Forge's Mod Menu doesn't support translating mod info
  • I patched in support via two mixins.
    • My gut feeling says this is a bad idea, and we should instead open a NeoForge issue/PR.
    • I've opened https://github.com/neoforged/NeoForge/issues/639, let's see if there's any interest.
    • The forge commit can be dropped from this PR if we'd rather stick to native behavior.

MattSturgeon avatar Feb 08 '24 12:02 MattSturgeon

Added some basic unit tests for the LangProcessor implementations & cleaned up LangTask a little.

MattSturgeon avatar Feb 14 '24 19:02 MattSturgeon

Dropped the forge mixin for now, hopefully we'll get a proper upstream solution.

MattSturgeon avatar Feb 15 '24 13:02 MattSturgeon

Neoforge has added support in v2.4.179, using the following keys:

  • fml.menu.mods.info.displayname.freecam
  • fml.menu.mods.info.description.freecam

I've also been thinking about better ways to approach the transformer funcs and "variant" translations, at risk of making this even more over-engineered.

MattSturgeon avatar Feb 25 '24 18:02 MattSturgeon