compile_i18n as a build function #9

Closed
ghost wants to merge 1 commit from process into master
ghost commented 2019-03-24 20:04:25 +00:00 (Migrated from github.com)
  • Add pub fn compile_i18n in gettext_utils
  • Change i18n!, i18n_domain! and include_i18n! so that they use the new paths
  • Make i18n! report new strings
  • Remove init_i18n! and compile_i18n!
  • Update doc
  • Test with workspaces
  • rerun build.rs when i18n! adds new strings
  • remove unused msgids from the pot file
  • do not rerun twice after pot is initialized

The way this works now is:

po
├── domain1
│   ├── ar.po
│   ├── de.po
│   └── domain1.pot
└── domain2
    ├── en.po
    ├── pt.po
    └── domain2.pot
target
└── translations
    └── .domains
        ├── domain1
        └── domain2

compile_i18n is called from build.rs. It

  • creates po/{domain} and the `.po inside
  • creates target/translations/.domains/{domain} (previously target/debug/gettext_macros/{domain})
    It doesn't contain the domain on the first line anymore.
  • Set the environment variable GETTEXT_MACROS_DOMAIN to {domain}, it's then used by i18n! and include_i18n!

i18n! now

  • rewrites the .pot file if GETTEXT_POT_INIT is not set, then set GETTEXT_POT_INIT
  • adds the msgid to the .pot like before

include_i18n! now

  • merges the .pot with each .po file for the domain (it fetches the list of locales from target/translations/.domains/{domain}
  • compiles each .po file and put the output into the tokenstream directly (without writing to a .mo file, see note)

Removed feature uniform_paths (since it's in stable now), and added proc_macro_diagnostic to allow i18n! to print warnings when new strings are added (don't need it anymore since a second cargo build is not needed).

About the include_i18n not writing to a mo file, this is because otherwise include_bytes! would add an implicit cargo:rerun-if-changed=file.mo, and cargo build would rebuild the whole project every time even if nothing changed.

- [x] Add `pub fn compile_i18n` in `gettext_utils` - [x] Change i18n!, i18n_domain! and include_i18n! so that they use the new paths - [x] Make i18n! report new strings - [x] Remove init_i18n! and compile_i18n! - [x] Update doc - [x] Test with workspaces - [x] rerun build.rs when i18n! adds new strings - [x] remove unused msgids from the pot file - [x] do not rerun twice after pot is initialized The way this works now is: ``` po ├── domain1 │ ├── ar.po │ ├── de.po │ └── domain1.pot └── domain2 ├── en.po ├── pt.po └── domain2.pot target └── translations └── .domains    ├── domain1    └── domain2 ``` `compile_i18n` is called from `build.rs`. It - creates `po/{domain}` and the `.po inside - creates `target/translations/.domains/{domain}` (previously `target/debug/gettext_macros/{domain}`) It doesn't contain the domain on the first line anymore. - Set the environment variable `GETTEXT_MACROS_DOMAIN` to {domain}, it's then used by `i18n!` and `include_i18n!` `i18n!` now - rewrites the `.pot` file if `GETTEXT_POT_INIT` is not set, then set `GETTEXT_POT_INIT` - adds the msgid to the `.pot` like before `include_i18n!` now - merges the `.pot` with each `.po` file for the domain (it fetches the list of locales from `target/translations/.domains/{domain}` - compiles each `.po` file and put the output into the tokenstream directly (without writing to a `.mo` file, see note) Removed feature `uniform_paths` (since it's in stable now), ~~and added `proc_macro_diagnostic` to allow `i18n!` to print warnings when new strings are added~~ (don't need it anymore since a second `cargo build` is not needed). About the include_i18n not writing to a mo file, this is because otherwise `include_bytes!` would add an implicit `cargo:rerun-if-changed=file.mo`, and `cargo build` would rebuild the whole project every time even if nothing changed.
ghost commented 2019-03-25 11:56:11 +00:00 (Migrated from github.com)

Still testing the "rerun" mechanism that makes the translations recompile when there's new strings

Still testing the "rerun" mechanism that makes the translations recompile when there's new strings
ghost commented 2019-03-25 20:28:46 +00:00 (Migrated from github.com)

Looks like it works now

Looks like it works now
ghost commented 2019-03-27 09:00:45 +00:00 (Migrated from github.com)

... or not? unused msgids are not removed from the pot.

... or not? unused msgids are not removed from the pot.
ghost commented 2019-03-29 21:14:09 +00:00 (Migrated from github.com)

I moved the pot -> po -> mo compilation logic into include_i18n!, and only one cargo build is needed to have everything at once now...

... BUT it reruns the compiler even if nothing in the project has changed!
:) definitely not a bug

I moved the pot -> po -> mo compilation logic into include_i18n!, and only one cargo build is needed to have everything at once now... ... BUT it reruns the compiler even if nothing in the project has changed! :) definitely not a bug

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: plume/gettext-macros#9
No description provided.