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

compile_i18n as a build function #9

Closed
wants to merge 1 commit into from
Closed

compile_i18n as a build function #9

wants to merge 1 commit into from

Conversation

ghost
Copy link

@ghost ghost commented Mar 24, 2019

  • 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.

@ghost ghost marked this pull request as ready for review March 24, 2019 22:35
@ghost ghost changed the title WIP: compile_i18n as a build function compile_i18n as a build function Mar 24, 2019
@ghost
Copy link
Author

ghost commented Mar 25, 2019

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

@ghost
Copy link
Author

ghost commented Mar 25, 2019

Looks like it works now

@ghost
Copy link
Author

ghost commented Mar 27, 2019

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

@ghost ghost changed the title compile_i18n as a build function WIP: compile_i18n as a build function Mar 27, 2019
@ghost
Copy link
Author

ghost commented Mar 29, 2019

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

@ghost ghost changed the title WIP: compile_i18n as a build function compile_i18n as a build function Mar 30, 2019
@ghost ghost mentioned this pull request Mar 30, 2019
@elegaanz elegaanz self-requested a review March 30, 2019 11:19
@elegaanz elegaanz closed this May 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant