{"id":16489950,"url":"https://github.com/crowdagger/crowbook-intl","last_synced_at":"2025-12-12T10:52:30.740Z","repository":{"id":11642074,"uuid":"70211221","full_name":"crowdagger/crowbook-intl","owner":"crowdagger","description":"A dirty and ugly library to do localization in Rust","archived":false,"fork":false,"pushed_at":"2022-12-31T12:15:36.000Z","size":64,"stargazers_count":15,"open_issues_count":4,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-05-02T06:13:02.362Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/crowdagger.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-07T03:03:33.000Z","updated_at":"2021-07-27T06:41:05.000Z","dependencies_parsed_at":"2023-01-13T16:36:17.234Z","dependency_job_id":null,"html_url":"https://github.com/crowdagger/crowbook-intl","commit_stats":null,"previous_names":["crowdagger/crowbook-intl","lise-henry/crowbook-intl"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crowdagger%2Fcrowbook-intl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crowdagger%2Fcrowbook-intl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crowdagger%2Fcrowbook-intl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crowdagger%2Fcrowbook-intl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/crowdagger","download_url":"https://codeload.github.com/crowdagger/crowbook-intl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245104460,"owners_count":20561377,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T13:45:58.168Z","updated_at":"2025-12-12T10:52:25.696Z","avatar_url":"https://github.com/crowdagger.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# crowbook-intl\n\nA library to localize strings, translating them according to runtime options.\n\nBasically, this library allows your project to generate a `lformat!` macro, that behaves\nsimilarly to `format!`, except the message string (the first argument) might get translated\n(if you can find the appropriate string for the language).\n\n## Usage\n\nFirst, you'll need to add the following to your `Cargo.toml` file:\n\n```toml\nbuild = \"build.rs\"\n\n[build-dependencies]\ncrowbook-intl = \"0.1.0\"\n\n[dependencies]\ncrowbook-intl-runtime = \"0.1.0\"\n```\n\nYou'll then need to create the `build.rs` file, which can look like this:\n\n```rust,ignore\nextern crate crowbook_intl;\nuse crowbook_intl::{Localizer, Extractor};\n\nfn main() {\n    // Generate a `lang/default.pot` containing strings used to call `lformat!`\n    let mut extractor = Extractor::new();\n    extractor.add_messages_from_dir(concat!(env!(\"CARGO_MANIFEST_DIR\"), \"/src\")).unwrap();\n    extractor.write_pot_file(concat!(env!(\"CARGO_MANIFEST_DIR\"), \"/lang/default.pot\")).unwrap();\n\n    // Generate the `localize_macros.rs` file\n    let mut localizer = Localizer::new(\u0026extractor);\n    // Use env::var instead of env! to avoid problems when cross-compiling\n    let dest_path = Path::new(\u0026env::var(\"OUT_DIR\").unwrap())\n       .join(\"localize_macros.rs\");\n    localizer.write_macro_file(dest_path).unwrap();\n}\n```\n\nThis will create a `localize_macros.rs` at build time somewhere in `OUT_DIR`, containing the `lformat!` macro.\nTo actually use this macro, you have to create a `src/localize_macros.rs` file that includes it:\n\n```rust,ignore\ninclude!(concat!(env!(\"OUT_DIR\"), \"/localize_macros.rs\"));\n```\n\nTo use it, the last step is to modify your `src/lib/lib.rs` file:\n\n```rust,ignore\nextern crate crowbook_intl_runtime;\n#[macro_use] mod localize_macros;\n```\n\nOnce this is done, you can start replacing your calls to `format!` with calls to `lformat!`.\n\nIn order to get translation, you'll need to actually translate the strings in separate\nfiles, and set your `build.rs` to load them.\n\nE.g., if you have the following code:\n\n```rust,ignore\nprintln!(\"{}\", lformat!(\"Hello, world!\"));\n```\n\nand you want it translated in french, you'll have to create a `lang/fr.po` file\nfrom the `lang/default.pot` file containing:\n\n```text\nmsgid \"Hello, world!\";\nmsgstr \"Bonjour le monde !\";\n```\n\nAnd load it in your `build.rs` file:\n\n```rust,ignore\nlet mut localizer = Localizer::new();\nlocalizer.add_lang(\"fr\", include_str!(concat!(env!(\"CARGO_MANIFEST_DIR\"), \"/lang/fr.mp\"))).unwrap();\n(...)\n```\n\nOnce *this* is done, you can use the `localize_macros::set_lang` function\nto switch the language at runtime:\n\n```rust,ignore\nuse crowbook_intl_runtime::set_lang;\nset_lang(\"en\");\nprintln!(\"{}\", lformat!(\"Hello, world!\")); // prints \"Hello, world!\"\nset_lang(\"fr\");\nprintln!(\"{}\", lformat!(\"Hello, world!\")); // prints \"Bonjour le monde !\"\n```\n\n## Updating your translation\n\nWhen you add new strings that need to be translated (by more calls to `lformat!`),\nor when you change the content of existing strings, you can use [Gettext's `msgmerge` and `msgcmp`](https://www.gnu.org/software/gettext/manual/html_node/msgmerge-Invocation.html)\ncommands to update your translation. While it is not guaranteed that the formats are\nstrictly identical, it should work. (That is, it is a bug if it doesn't; but at this\nstage, this library is absolutely not guaranteed to be bug-free.)\n\n## Known limitations and bugs\n\n* Currently, `crowbook-intl` doesn't handle correctly raw string literals in `lformat!`\n  (they won't be translated correctly).\n* Multiple calls to the same string, but formatted differently (e.g. using a backslash\n  before a newline to separate a string on multiple lines) will also cause problems.\n\n## Warning\n\nIn case the complexity of the operation didn't discourage you, I should warn you\nthat this library is highly experimental at this time.\n\n## License\n\nThis is free software, published under the [Mozilla Public License,\nversion 2.0](https://www.mozilla.org/en-US/MPL/2.0/).\n\n## Documentation ##\n\nSee the\n[documentation on docs.rs](https://docs.rs/crowbook-intl).\n\n## ChangeLog ##\n\nSee [the ChangeLog file](ChangeLog.md).\n\n## Author ##\n\n[Élisabeth Henry](http://lise-henry.github.io/) \u003cliz.henry@ouvaton.org\u003e. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrowdagger%2Fcrowbook-intl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrowdagger%2Fcrowbook-intl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrowdagger%2Fcrowbook-intl/lists"}