Skip to main content

Crate laratext

Crate laratext 

Source
Expand description

Laratext for Laravel Rust: translation keys with their source text, and auto-translation with OpenAI, Claude, Google Translate or Translatorio.

In Laravel, __() takes either the key, and the file becomes unreadable, or the text, and the translation breaks when you change a character. Laratext takes both:

use laratext::{replace, text};

text("key_name", "default_value");

// A key alone makes its text: "Hello Mate".
assert_eq!(text!("hello_mate"), "Hello Mate");

assert_eq!(
    text!("items.count", "One item|You have :count items", replace! { count => 5 }),
    "You have 5 items"
);

laratext:scan reads the calls in your project and translates what is missing, and {{ text('key', 'Default') }} does the same in a MiniJinja template.

It is the port of the PHP package edulazaro/laratext to Laravel Rust 0.1 (beta), and its API follows the framework’s changes until 1.0. The current locale comes from laralocale, which has to be registered as well.

Re-exports§

pub use catalog::Catalog;
pub use catalog::Lines;
pub use config::ClaudeConfig;
pub use config::GoogleConfig;
pub use config::ModelOverride;
pub use config::OpenAiConfig;
pub use config::ScanSettings;
pub use config::ScriptScanSettings;
pub use config::TextsConfig;
pub use config::TranslatorioConfig;
pub use helpers::text;
pub use limits::Json;
pub use limits::ModelLimits;
pub use locks::TranslationLocks;
pub use provider::LaratextServiceProvider;
pub use replace::Replace;
pub use replace::ReplaceValue;
pub use replace::make_replacements;
pub use scripts::Extracted;
pub use scripts::ScriptTexts;
pub use scripts::Unreadable;
pub use selector::choose;
pub use text::Frontend;
pub use text::Prefixes;
pub use text::Text;
pub use translator::RealSleeper;
pub use translator::Sleeper;
pub use translator::Texts;
pub use translator::TranslateError;
pub use translator::Translated;
pub use translator::Translations;
pub use translator::Translator;
pub use translator::log_to_console;
pub use translator::with_messages;
pub use translators::ClaudeTranslator;
pub use translators::GoogleTranslator;
pub use translators::OpenAiTranslator;
pub use translators::TranslatorioTranslator;
pub use translators::Translators;

Modules§

catalog
config
console
The commands: laratext:scan, laratext:lock, laratext:unlock and make:translator, with the names, arguments and options of the PHP package, and laratext:publish, which Laravel Rust needs for the JavaScript module.
helpers
js
The JavaScript module, which laratext:publish copies into an application and which the provider serves under /vendor/laratext/.
json
limits
locks
plural
Plural rules, generated from Illuminate\Translation\MessageSelector::getPluralIndex() of Laravel 13.44.1.
provider
replace
scripts
selector
Laravel’s MessageSelector: which form of One item|You have :count items a number takes.
sources
The scanner of text() calls in Rust and template files.
support
text
translator
translators
The translators that ship with the package, and the registry laratext:scan picks from.
views
The MiniJinja functions text() and texts(), the equivalents of the @text and @texts Blade directives.

Macros§

replace
Build the Replace of a text.
text
PHP’s text() helper, with the arguments it takes: text!("key"), text!("key", "default"), text!("key", "default", replace) and text!("key", "default", replace, "locale").