{"id":19219799,"url":"https://github.com/plume-org/gettext-macros","last_synced_at":"2025-05-13T01:07:20.607Z","repository":{"id":34041143,"uuid":"166654404","full_name":"Plume-org/gettext-macros","owner":"Plume-org","description":"A few proc-macros to help internationalizing Rust applications","archived":false,"fork":false,"pushed_at":"2022-02-26T15:22:24.000Z","size":56,"stargazers_count":11,"open_issues_count":3,"forks_count":3,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-05-13T01:07:02.278Z","etag":null,"topics":["gettext","i18n","internationalization","proc-macro","rust"],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Plume-org.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-01-20T11:40:01.000Z","updated_at":"2022-02-09T18:17:48.000Z","dependencies_parsed_at":"2022-08-07T23:31:35.921Z","dependency_job_id":null,"html_url":"https://github.com/Plume-org/gettext-macros","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Plume-org%2Fgettext-macros","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Plume-org%2Fgettext-macros/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Plume-org%2Fgettext-macros/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Plume-org%2Fgettext-macros/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Plume-org","download_url":"https://codeload.github.com/Plume-org/gettext-macros/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253851060,"owners_count":21973673,"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":["gettext","i18n","internationalization","proc-macro","rust"],"created_at":"2024-11-09T14:32:53.243Z","updated_at":"2025-05-13T01:07:20.579Z","avatar_url":"https://github.com/Plume-org.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Gettext macros [![Crates.io](https://img.shields.io/crates/v/gettext-macros.svg)](https://crates.io/crates/gettext-macros) [![Docs.rs](https://docs.rs/gettext-macros/badge.svg)](https://docs.rs/gettext-macros)\n\nA few proc-macros to help you internationalize your Rust apps.\n\nIt uses gettext under the hood. The idea is that just by wrapping strings in macros, they are added to\na template for translation files (`.pot` file). Then, the actual translation files (`.po`) are generated\nfor each language, and you can upload them to Weblate/Crowdin/POedit/whatever to have them translated.\nAnd finally, they get transformed into binary translation files (`.mo`) that you can embed in your app.\n\n## How does it works?\n\nThere are five main macros:\n\n- `init_i18n`, that should be called first. It tells the domain to use for the current\ncrate, and the supported locales.\n- `compile_i18n`, that should be called at the end of your `main.rs`. It updates translation files and compile them.\n- `include_i18n`, that will embed translations in your binary, making it easier to distribute. It should be called after `compile_i18n` to work correctly.\n- `i18n`, that translates a given message.\n- `t`, that works like `i18n`, but doesn't actually translate the message, just adds it to the list of strings to translate.\n\nThe advantage of these macros is that they allow you to work with multiple translation\ndomains (for instance, one for each of your workspace's crate), and that they automatically\ngenerate a .pot file for these domains.\n\n## Example\n\n*main.rs*\n\n```rust,ignore\nuse gettext_macros::*;\n\n// The translations for this crate are stored in the \"my_app\" domain.\n// Translations for all the listed languages will be available.\ninit_i18n!(\"my_app\", ar, de, en, fr, it, ja, ru);\n\nfn main() {\n    let catalog = cat();\n\n    println!(\"{}\", i18n!(catalog, \"Hello, world!\"));\n    let name = \"Jane\";\n    println!(\"{}\", i18n!(catalog, \"Hello, {}!\"; name));\n    let message_count = 42;\n    println!(\"{}\", i18n!(catalog, \"You have one new message\", \"You have {0} new messages\"; message_count));\n}\n\nfn cat() -\u003e gettext::Catalog {\n    // include_i18n! embeds translations in your binary.\n    // It gives a Vec\u003c(\u0026'static str, Catalog)\u003e (list of catalogs with their associated language).\n    let catalog = include_i18n!()[0]\n}\n\n// Generate or update .po from .pot, and compile them to .mo\ncompile_i18n!();\n```\n\n## Order of the macros\n\nThe macros should be called in a certain order to work properly. This order\ndoesn't depend on the program flow, but of the Rust parser flow. Rust will execute\nmacros in the same order they are written in your code. For instance:\n\n```rust,ignore\ni_am_expanded_first!();\nthen_i_am_expanded!()\n```\n\nOr, for projects with modules:\n\n```rust,ignore\n// In main.rs\n\nfirst_macro!();\n\nmod a;\n\nthird_macro!();\n```\n\n```rust,ignore\n// In a.rs\n\nsecond_macro!();\n```\n\nSo, for the macros provided by this crate, the order to follow is:\n\n1. `init_i18n!`\n2. `i18n!` and `t!`, as many times as you want\n3. `compile_i18n!`\n4. `include_i18n!`\n\nBecause some of these macros depends on files written by the previous ones to work properly.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplume-org%2Fgettext-macros","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fplume-org%2Fgettext-macros","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplume-org%2Fgettext-macros/lists"}