{"id":17108309,"url":"https://github.com/plume-org/rocket_i18n","last_synced_at":"2025-04-13T02:42:50.080Z","repository":{"id":44884833,"uuid":"137658361","full_name":"Plume-org/rocket_i18n","owner":"Plume-org","description":"A crate to help you internationalize your Rocket applications.","archived":false,"fork":false,"pushed_at":"2023-12-28T12:28:23.000Z","size":57,"stargazers_count":17,"open_issues_count":4,"forks_count":6,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-13T02:42:42.379Z","etag":null,"topics":["gettext","i18n","internationalization","l10n","localization","rocket","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":"gpl-3.0","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":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-06-17T13:49:02.000Z","updated_at":"2025-01-06T23:31:20.000Z","dependencies_parsed_at":"2022-07-22T19:53:02.934Z","dependency_job_id":null,"html_url":"https://github.com/Plume-org/rocket_i18n","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%2Frocket_i18n","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Plume-org%2Frocket_i18n/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Plume-org%2Frocket_i18n/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Plume-org%2Frocket_i18n/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Plume-org","download_url":"https://codeload.github.com/Plume-org/rocket_i18n/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248657858,"owners_count":21140843,"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","l10n","localization","rocket","rust"],"created_at":"2024-10-14T16:05:00.723Z","updated_at":"2025-04-13T02:42:50.061Z","avatar_url":"https://github.com/Plume-org.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rocket I18N [![Build Status](https://travis-ci.org/Plume-org/rocket_i18n.svg?branch=master)](https://travis-ci.org/Plume-Org/rocket_i18n)\n\nA crate to help you internationalize your Rocket or Actix Web applications.\n\nIt just selects the correct locale for each request, and return the corresponding `gettext::Catalog`.\n\n## Usage\n\nFirst add it to your `Cargo.toml`:\n\n```toml\n[dependencies]\nrocket_i18n = \"0.4\"\ngettext-macros = \"0.1\" # Provides proc-macros to manage translations\n```\n\nThen, in your `main.rs`:\n\n```rust,ignore\n# use rocket;\nuse gettext_macros::{compile_i18n, include_i18n, init_i18n};\n\ninit_i18n!(\"my_web_app\", en, eo, it, pl);\n\nfn main() {\n    rocket::ignite()\n        // Make Rocket manage your translations.\n        .manage(include_i18n!());\n        // Register routes, etc\n}\n\ncompile_i18n!();\n```\n\nThen in all your requests you'll be able to use the `i18n` macro to translate anything.\nIt takes a `gettext::Catalog` and a string to translate as argument.\n\n```rust,ignore\nuse gettext_macros::i18n;\nuse rocket_i18n::I18n;\n\n#[get(\"/\")]\nfn route(i18n: I18n) -\u003e \u0026str {\n    i18n!(i18n.catalog, \"Hello, world!\")\n}\n```\n\nFor strings that may have a plural form, just add the plural and the number of element to the\narguments\n\n```rust,ignore\ni18n!(i18n.catalog, \"One new message\", \"{0} new messages\", 42);\n```\n\nAny extra argument, after a `;`, will be used for formatting.\n\n```rust,ignore\nlet user_name = \"Alex\";\ni18n!(i18n.catalog, \"Hello {0}!\"; user_name);\n```\n\nWhen using it with plural, `{0}` will be the number of elements, and other arguments will start\nat `{1}`.\n\nBecause of its design, rocket_i18n is only compatible with askama, ructe or compiled templates\nin general.\nYou can use the `t` macro in your templates, as long as they have a field called `catalog` to\nstore your catalog.\n\n### Using with Actix Web\n\nFirst, disable the default features so it doesn't pull in all of Rocket.\n\n```toml\n[dependencies.rocket_i18n]\nversion = \"0.4\"\ndefault-features = false\nfeatures = [\"actix-web\"]\n```\n\nThen add it to your application.\n\n```rust\nuse gettext_macros::*;\nuse rocket_i18n::{I18n, Internationalized, Translations};\n\nfn route_handler(i18n: I18n) -\u003e \u0026str {\n    i18n!(i18n.catalog, \"Hello, world!\")\n}\n\n#[derive(Clone)]\nstruct MyState {\n    translations: Translations,\n}\n\nimpl Internationalized for MyState {\n    fn get(\u0026self) -\u003e Translations {\n        self.translations.clone()\n    }\n}\n\nfn main() {\n    let state = MyState {\n        translations: rocket_i18n::i18n(\"your-domain\", vec![ \"en\", \"fr\", \"de\", \"ja\" ]);\n    };\n\n    App::with_state(state)\n        .resource(\"\", |r| r.with(route_handler))\n        .finish();\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplume-org%2Frocket_i18n","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fplume-org%2Frocket_i18n","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplume-org%2Frocket_i18n/lists"}