use crate::args::{Arg, Args, Count, Hit, Small, escape_html};
use crate::catalog::{Entry, Msg, hole_ranges, is_js_space};
use crate::i18n::{I18n, View};
use crate::scope::{self, Code};
use std::borrow::Cow;
use std::fmt;
use std::sync::Arc;
type Rule = Arc<dyn Fn(&PluralCtx<'_>) -> Option<String> + Send + Sync>;
#[derive(Clone)]
pub struct Text {
key: Cow<'static, str>,
i18n: Option<I18n>,
locale: Option<Code>,
page: Option<Code>,
args: Args<'static>,
count: Option<Count>,
#[cfg(feature = "format")]
number: Option<Shown>,
default: Option<Cow<'static, str>>,
rule: Option<Rule>,
html: bool,
hide: bool,
pub(crate) depth: u8,
shown: fn(&Text, &mut dyn fmt::Write) -> fmt::Result,
}
#[cfg(feature = "format")]
#[derive(Debug, Clone, PartialEq)]
enum Shown {
Number(crate::Number, Option<Cow<'static, str>>),
When(crate::DateArg<'static>),
}
#[cfg(feature = "format")]
impl Shown {
fn rank(&self) -> u8 {
match self {
Shown::Number(..) => 0,
Shown::When(d) => 1 + u8::from(d.is_relative()),
}
}
}
#[derive(Debug)]
#[non_exhaustive]
pub struct PluralCtx<'a> {
pub key: &'a str,
pub count: f64,
pub locale: &'a str,
text: &'a Text,
i18n: &'a I18n,
view: Option<&'a str>,
page: Option<&'a str>,
quiet: bool,
}
impl PluralCtx<'_> {
#[must_use]
pub fn get(&self, key: &str) -> String {
if key.is_empty() {
return String::new();
}
let found = self
.i18n
.inner
.read(|s| match s.lookup(self.view, self.page, key) {
Some(e) => Ok(e.text().map(String::from)),
None => Err(s.locale.clone()),
});
match found {
Ok(Some(t)) => t,
Ok(None) => key_text(key, self.text.html),
Err(active) => {
if !self.quiet && !scope::quiet() {
self.i18n
.report(Some(self.view.unwrap_or(&active)), self.page, key);
}
match self.text.default_text() {
Some(d) => d.to_owned(),
None => key_text(key, self.text.html),
}
}
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Part<'a> {
Text(Cow<'a, str>),
Slot(Cow<'a, str>),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Key(&'static str);
impl Key {
#[must_use]
pub const fn new(key: &'static str) -> Key {
Key(key)
}
#[must_use]
pub fn args(self) -> Text {
Text::new(Cow::Borrowed(self.0), None)
}
}
impl fmt::Display for Key {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.args().fmt(f)
}
}
pub(crate) const MAX_NESTING: u8 = 64;
#[derive(Clone, Copy)]
enum Tpl<'s> {
Holes {
raw: &'s str,
start: usize,
end: usize,
holes: &'s [(u32, u32)],
},
Scan(&'s str),
Literal(&'s str),
}
enum Piece<'s> {
Lit(&'s str),
Hole(&'s str),
}
impl<'s> Tpl<'s> {
fn pieces(self, f: &mut dyn FnMut(Piece<'_>) -> fmt::Result) -> fmt::Result {
match self {
Tpl::Literal(s) => f(Piece::Lit(s)),
Tpl::Scan(raw) => walk(raw, 0, raw.len(), hole_ranges(raw), f),
Tpl::Holes {
raw,
start,
end,
holes,
} => walk(
raw,
start,
end,
holes.iter().map(|&(s, e)| (s as usize, e as usize)),
f,
),
}
}
fn write(self, out: &mut dyn fmt::Write, p: Params<'_>) -> fmt::Result {
self.pieces(&mut |piece| match piece {
Piece::Lit(s) => out.write_str(s),
Piece::Hole(name) => {
if !p.put(name, out)? {
out.write_char('{')?;
out.write_str(name)?;
out.write_char('}')?;
}
Ok(())
}
})
}
fn blank(self, p: Params<'_>) -> Result<bool, fmt::Error> {
let mut probe = NonBlank(false);
let p = Params { quiet: true, ..p };
match self.write(&mut probe, p) {
Err(_) if probe.0 => Ok(false),
Err(e) => Err(e),
Ok(()) => Ok(true),
}
}
fn measure(self, p: Params<'_>) -> usize {
let mut len = Len(0);
let p = Params { measure: true, ..p };
let _ = self.write(&mut len, p);
len.0
}
}
fn walk(
raw: &str,
start: usize,
end: usize,
holes: impl Iterator<Item = (usize, usize)>,
f: &mut dyn FnMut(Piece<'_>) -> fmt::Result,
) -> fmt::Result {
let mut at = start;
for (s, e) in holes {
if s <= start || e >= end {
continue;
}
let Some(name) = raw.get(s..e) else {
continue;
};
f(Piece::Lit(raw.get(at..s - 1).unwrap_or("")))?;
f(Piece::Hole(name))?;
at = e + 1;
}
f(Piece::Lit(raw.get(at..end).unwrap_or("")))
}
#[derive(Clone, Copy)]
struct Params<'x> {
args: &'x Args<'static>,
count: Option<Count>,
spread: bool,
html: bool,
measure: bool,
#[cfg(feature = "format")]
number: Option<Fill<'x>>,
quiet: bool,
outer: &'x Outer<'x>,
}
#[cfg(feature = "format")]
#[derive(Clone, Copy)]
enum Fill<'x> {
Number {
value: crate::Number,
options: &'x crate::format::NumberOptions,
loc: &'static crate::format::Loc,
},
When(&'x crate::DateArg<'static>),
}
#[cfg(feature = "format")]
impl Fill<'_> {
fn name(&self) -> &'static str {
match self {
Fill::Number { .. } => "number",
Fill::When(d) if d.is_relative() => "relativeDate",
Fill::When(_) => "date",
}
}
fn write(&self, outer: &Outer<'_>, out: &mut dyn fmt::Write) -> fmt::Result {
match *self {
Fill::Number {
value,
options,
loc,
} => crate::format::write(value, options, loc, out),
Fill::When(d) => d.write_in(outer.i18n, outer.locale.map(Code::as_str), out),
}
}
}
struct Outer<'x> {
i18n: Option<&'x I18n>,
locale: Option<&'x Code>,
page: Option<&'x Code>,
}
impl Params<'_> {
fn put(&self, name: &str, out: &mut dyn fmt::Write) -> Result<bool, fmt::Error> {
#[cfg(feature = "format")]
if let Some(n) = &self.number
&& name == n.name()
{
n.write(self.outer, out)?;
return Ok(true);
}
if let Some(c) = self.count
&& name == "count"
{
let mut b = Small::new();
c.write(&mut b);
out.write_str(b.as_str())?;
return Ok(true);
}
let value = if self.spread {
self.args.spread(name)
} else {
self.args.find(name)
};
let v = match value {
Some(Hit::Arg(v)) => v,
Some(Hit::Len(n)) => return Arg::Int(n).emit(out, false).map(|()| true),
None => return Ok(false),
};
match v {
Arg::Text(_) if self.measure => Ok(true),
Arg::Text(_) => self.nested(v, out).map(|()| true),
#[cfg(feature = "format")]
Arg::Number { value, format } => {
let o = self.outer;
crate::format::api::write_in(
o.i18n,
o.locale.map(Code::as_str),
*value,
format.as_deref(),
out,
)
.map(|()| true)
}
#[cfg(feature = "format")]
Arg::Date(d) => {
let o = self.outer;
d.write_in(o.i18n, o.locale.map(Code::as_str), out)
.map(|()| true)
}
v => v.emit(out, self.html).map(|()| true),
}
}
}
impl Params<'_> {
#[inline(never)]
fn nested(&self, v: &Arg<'_>, out: &mut dyn fmt::Write) -> fmt::Result {
let o = self.outer;
scope::nest(o.i18n, o.locale, o.page, self.quiet, || {
v.emit(out, self.html)
})
}
}
struct NonBlank(bool);
impl fmt::Write for NonBlank {
fn write_str(&mut self, s: &str) -> fmt::Result {
if s.chars().all(is_js_space) {
Ok(())
} else {
self.0 = true;
Err(fmt::Error)
}
}
}
struct Len(usize);
impl fmt::Write for Len {
fn write_str(&mut self, s: &str) -> fmt::Result {
self.0 += s.len();
Ok(())
}
}
struct Same<'a> {
rest: &'a str,
ok: bool,
}
impl fmt::Write for Same<'_> {
fn write_str(&mut self, s: &str) -> fmt::Result {
match self.rest.strip_prefix(s) {
Some(rest) => self.rest = rest,
None => self.ok = false,
}
if self.ok { Ok(()) } else { Err(fmt::Error) }
}
}
#[cfg(feature = "format")]
fn fill<'x>(s: &'x crate::i18n::Snapshot, locale: Option<&str>, shown: &'x Shown) -> Fill<'x> {
let loc = locale.map_or(s.number, |c| s.number_of(c));
let code = locale.unwrap_or(&s.locale);
match shown {
Shown::Number(value, name) => {
let options = name.as_deref().and_then(|n| s.meta.named_number(code, n));
if options.is_none()
&& let Some(n) = name
{
crate::trace::missing_format("number", n, code);
}
Fill::Number {
value: *value,
options: options.unwrap_or(&crate::format::NumberOptions::DEFAULT),
loc,
}
}
Shown::When(d) => Fill::When(d),
}
}
fn key_text(key: &str, html: bool) -> String {
let mut out = String::new();
if html {
let _ = escape_html(&mut out, key);
} else {
out.push_str(key);
}
out
}
fn needs_escape(s: &str) -> bool {
s.bytes()
.any(|b| matches!(b, b'&' | b'<' | b'>' | b'"' | b'\''))
}
impl Text {
pub(crate) fn new(key: Cow<'static, str>, i18n: Option<I18n>) -> Text {
Text {
key,
i18n,
locale: None,
page: None,
args: Args::new(),
count: None,
#[cfg(feature = "format")]
number: None,
default: None,
rule: None,
html: false,
hide: false,
depth: 0,
shown: Text::emit,
}
}
pub(crate) fn show(&self, out: &mut dyn fmt::Write) -> fmt::Result {
(self.shown)(self, out)
}
#[must_use]
pub fn arg(
mut self,
name: impl Into<Cow<'static, str>>,
value: impl Into<Arg<'static>>,
) -> Self {
let value = value.into();
if let Arg::Text(t) = &value {
if t.depth >= MAX_NESTING {
return self;
}
self.depth = self.depth.max(t.depth + 1);
}
self.args.push_named(name.into(), value);
self
}
#[must_use]
pub fn args<I>(mut self, items: I) -> Self
where
I: IntoIterator,
I::Item: Into<Arg<'static>>,
{
let mut depth = self.depth;
self.args
.extend_list(items.into_iter().map(Into::into).inspect(|a| {
if let Arg::Text(t) = a
&& t.depth < MAX_NESTING
{
depth = depth.max(t.depth + 1);
}
}));
self.depth = depth;
self
}
#[must_use]
pub fn count(mut self, n: impl Into<Count>) -> Self {
self.count = Some(n.into());
self
}
#[cfg(feature = "format")]
#[must_use]
pub fn number(self, n: impl Into<crate::Number>) -> Self {
self.set_shown(Shown::Number(n.into(), None))
}
#[cfg(feature = "format")]
fn set_shown(mut self, s: Shown) -> Self {
if self
.number
.as_ref()
.is_none_or(|old| old.rank() >= s.rank())
{
self.number = Some(s);
}
self
}
#[cfg(feature = "format")]
#[must_use]
pub fn number_as(
self,
n: impl Into<crate::Number>,
name: impl Into<Cow<'static, str>>,
) -> Self {
self.set_shown(Shown::Number(n.into(), Some(name.into())))
}
#[cfg(feature = "format")]
#[must_use]
pub fn date(self, t: impl Into<crate::Timestamp>) -> Self {
self.set_shown(Shown::When(crate::DateArg::date(t.into(), None)))
}
#[cfg(feature = "format")]
#[must_use]
pub fn date_as(
self,
t: impl Into<crate::Timestamp>,
name: impl Into<Cow<'static, str>>,
) -> Self {
self.set_shown(Shown::When(crate::DateArg::date(
t.into(),
Some(name.into()),
)))
}
#[cfg(feature = "format")]
#[must_use]
pub fn relative(self, t: impl Into<crate::Timestamp>) -> Self {
self.set_shown(Shown::When(crate::DateArg::relative(t.into())))
}
#[must_use]
pub fn or(mut self, default: impl Into<Cow<'static, str>>) -> Self {
self.default = Some(default.into());
self
}
#[must_use]
pub fn hide_if_empty(mut self) -> Self {
self.hide = true;
self
}
#[must_use]
pub fn plural_rule(
mut self,
rule: impl Fn(&PluralCtx<'_>) -> Option<String> + Send + Sync + 'static,
) -> Self {
self.rule = Some(Arc::new(rule));
self
}
#[must_use]
pub fn page(mut self, name: impl Into<Cow<'static, str>>) -> Self {
self.page = Some(Code::from(name.into()));
self
}
#[must_use]
pub fn locale(mut self, code: impl Into<Cow<'static, str>>) -> Self {
self.locale = Some(Code::from(code.into()));
self
}
#[must_use]
pub fn html(mut self) -> Self {
self.html = true;
self
}
#[must_use]
pub fn resolve(&self) -> Option<String> {
let (out, keyed, hidden) = self.sized();
(!keyed && !hidden).then_some(out)
}
#[allow(clippy::inherent_to_string_shadow_display)] #[must_use]
pub fn to_string(&self) -> String {
let (out, _, hidden) = self.sized();
if hidden {
return self.default_text().map(str::to_owned).unwrap_or_default();
}
out
}
pub fn write_to(&self, out: &mut impl fmt::Write) -> fmt::Result {
self.emit(out)
}
fn hidden(&self, tpl: Tpl<'_>, p: Params<'_>) -> Result<bool, fmt::Error> {
if !tpl.blank(p)? {
return Ok(false);
}
if self.depth > 0 {
let _ = tpl.write(&mut Len(0), p);
}
Ok(true)
}
pub fn parts(&self) -> impl Iterator<Item = Part<'static>> + use<> {
self.split(None).into_iter()
}
pub fn fold<T>(
&self,
mut text: impl FnMut(&str) -> T,
slots: &[(&str, &dyn Fn() -> T)],
) -> Vec<T> {
let names: Vec<&str> = slots.iter().map(|(n, _)| *n).collect();
self.split(Some(&names))
.into_iter()
.filter_map(|part| match part {
Part::Text(s) => Some(text(&s)),
Part::Slot(name) => slots.iter().find(|(n, _)| *n == name).map(|(_, f)| f()),
})
.collect()
}
fn split(&self, slots: Option<&[&str]>) -> Vec<Part<'static>> {
let mut parts = Vec::new();
let mut buf = String::new();
let mut hidden = false;
let _ = self.with_tpl(false, &mut |tpl, p| {
if self.hide && self.hidden(tpl, p)? {
hidden = true;
return Ok(());
}
tpl.pieces(&mut |piece| {
match piece {
Piece::Lit(s) => buf.push_str(s),
Piece::Hole(name) => {
let slot = if let Some(slots) = slots
&& slots.contains(&name)
{
true
} else if slots.is_none() {
!p.put(name, &mut buf)?
} else {
if !p.put(name, &mut buf)? {
buf.push('{');
buf.push_str(name);
buf.push('}');
}
false
};
if slot {
if !buf.is_empty() {
parts.push(Part::Text(Cow::Owned(std::mem::take(&mut buf))));
}
parts.push(Part::Slot(Cow::Owned(name.to_owned())));
}
}
}
Ok(())
})
});
if hidden {
parts.clear();
buf = self.default_text().map(str::to_owned).unwrap_or_default();
}
if !buf.is_empty() {
parts.push(Part::Text(Cow::Owned(buf)));
}
parts
}
fn default_text(&self) -> Option<&str> {
self.default.as_deref().filter(|d| !d.is_empty())
}
pub(crate) fn emit(&self, out: &mut dyn fmt::Write) -> fmt::Result {
self.emit_as(out, false)
}
fn emit_as(&self, out: &mut dyn fmt::Write, quiet: bool) -> fmt::Result {
let mut hidden = false;
self.with_tpl(quiet, &mut |tpl, p| {
if self.hide && self.hidden(tpl, p)? {
hidden = true;
return Ok(());
}
tpl.write(out, p)
})?;
match self.default_text() {
Some(d) if hidden => out.write_str(d),
_ => Ok(()),
}
}
fn sized(&self) -> (String, bool, bool) {
let mut out = String::new();
let mut hidden = false;
let keyed = self.with_tpl(false, &mut |tpl, p| {
if self.hide && self.hidden(tpl, p)? {
hidden = true;
return Ok(());
}
out.reserve_exact(tpl.measure(p));
tpl.write(&mut out, p)
});
(out, keyed.unwrap_or(false), hidden)
}
pub(crate) fn same(&self, other: &Text) -> bool {
let rule = match (&self.rule, &other.rule) {
(Some(a), Some(b)) => Arc::ptr_eq(a, b),
(a, b) => a.is_none() && b.is_none(),
};
let i18n = match (&self.i18n, &other.i18n) {
(Some(a), Some(b)) => Arc::ptr_eq(&a.inner, &b.inner),
(a, b) => a.is_none() && b.is_none(),
};
self.key == other.key
&& i18n
&& rule
&& self.locale == other.locale
&& self.page == other.page
&& self.args.same(&other.args)
&& self.count == other.count
&& self.same_number(other)
&& self.default == other.default
&& self.html == other.html
&& self.hide == other.hide
}
#[cfg(feature = "format")]
fn same_number(&self, other: &Text) -> bool {
self.number == other.number
}
#[cfg(not(feature = "format"))]
fn same_number(&self, _: &Text) -> bool {
true
}
fn plural_count(&self) -> Option<Count> {
#[cfg(feature = "format")]
if self.number.is_some() {
return None;
}
self.count
}
pub(crate) fn is_html(&self) -> bool {
self.html
}
fn with_tpl(
&self,
quiet: bool,
f: &mut dyn FnMut(Tpl<'_>, Params<'_>) -> fmt::Result,
) -> Result<bool, fmt::Error> {
let (scoped, scope_locale, scope_page, quiet_frame) = scope::current(
self.i18n.is_none(),
self.locale.is_none(),
self.page.is_none(),
);
let locale_code = self.locale.as_ref().or(scope_locale.as_ref());
let page_code = self.page.as_ref().or(scope_page.as_ref());
let locale = locale_code.map(Code::as_str);
let page = page_code.map(Code::as_str);
let key = &*self.key;
let global: Option<&I18n> = scope::global_instance();
let instance = self.i18n.as_ref().or(scoped.as_ref()).or(global);
let outer = Outer {
i18n: instance,
locale: locale_code,
page: page_code,
};
let plain = Params {
args: &self.args,
count: None,
spread: self.html || self.plural_count() != self.count,
html: self.html,
measure: false,
#[cfg(feature = "format")]
number: None,
quiet,
outer: &outer,
};
let count = self.plural_count();
let params = match count {
Some(c) => Params {
count: Some(c),
spread: true,
..plain
},
None => plain,
};
let Some(i18n) = instance else {
scope::uninstalled(key);
return self
.fallback(f, params)
.map(|keyed| keyed && !key.is_empty());
};
if let (Some(count), Some(rule)) = (count, &self.rule) {
let active = locale.is_none().then(|| i18n.locale());
let ctx = PluralCtx {
key,
count: count.as_f64(),
locale: locale.or(active.as_deref()).unwrap_or(""),
text: self,
i18n,
view: locale,
page,
quiet,
};
let answer = rule(&ctx).unwrap_or_default();
return f(Tpl::Literal(&answer), params).map(|()| false);
}
if key.is_empty() {
return f(Tpl::Literal(""), params).map(|()| false);
}
let mut miss = None;
let mut keyed = false;
let read = i18n.inner.read(|s| {
#[cfg(feature = "format")]
let params = match &self.number {
Some(shown) => Params {
number: Some(fill(s, locale, shown)),
..params
},
None => params,
};
let found = s.lookup(locale, page, key);
if let Some(count) = count {
let plural = match locale {
None => s.plural,
Some(code) => s.plural_of(code),
};
match found {
Some(Entry::Msg(Msg::Text(t))) => {
let (start, end) = t.single_range();
return f(
Tpl::Holes {
raw: t.raw,
start,
end,
holes: t.hole_slice(),
},
params,
);
}
Some(Entry::Msg(Msg::Plural(p))) => {
return match p.form(count, plural) {
Some((start, end, holes)) => f(
Tpl::Holes {
raw: p.text.raw,
start,
end,
holes,
},
params,
),
None => f(Tpl::Literal(""), params),
};
}
Some(Entry::Value(v)) if !matches!(&**v, "true" | "false") => {
return f(Tpl::Literal(v), params);
}
Some(_) => {}
None => miss = Some(s.locale.clone()),
}
} else {
match found {
Some(Entry::Msg(Msg::Text(t))) => {
return f(
Tpl::Holes {
raw: t.raw,
start: 0,
end: t.raw.len(),
holes: t.hole_slice(),
},
params,
);
}
Some(Entry::Msg(Msg::Plural(p))) => {
let t = &p.text;
return f(
Tpl::Holes {
raw: t.raw,
start: 0,
end: t.raw.len(),
holes: t.hole_slice(),
},
params,
);
}
Some(Entry::Value(v)) => return f(Tpl::Literal(v), params),
Some(Entry::Node) => {
keyed = true;
return self.key_tpl(f, params);
}
None => miss = Some(s.locale.clone()),
}
}
keyed = self.fallback(f, params)?;
Ok(())
});
if let Some(active) = miss
&& !quiet
&& !quiet_frame
{
i18n.report(Some(locale.unwrap_or(&active)), page, key);
}
read.map(|()| keyed)
}
fn fallback(
&self,
f: &mut dyn FnMut(Tpl<'_>, Params<'_>) -> fmt::Result,
params: Params<'_>,
) -> Result<bool, fmt::Error> {
if let Some(d) = self.default_text() {
return f(Tpl::Scan(d), params).map(|()| false);
}
self.key_tpl(f, params).map(|()| true)
}
fn key_tpl(
&self,
f: &mut dyn FnMut(Tpl<'_>, Params<'_>) -> fmt::Result,
params: Params<'_>,
) -> fmt::Result {
let key = &*self.key;
if self.html && needs_escape(key) {
f(Tpl::Scan(&key_text(key, true)), params)
} else {
f(Tpl::Scan(key), params)
}
}
}
impl fmt::Display for Text {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if f.width().is_some() || f.precision().is_some() {
return f.pad(&self.to_string());
}
self.emit(f)
}
}
impl fmt::Debug for Text {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut d = f.debug_struct("Text");
d.field("key", &self.key);
if self.i18n.is_some() {
d.field("instance", &"explicit");
}
if let Some(l) = &self.locale {
d.field("locale", &l.as_str());
}
if let Some(p) = &self.page {
d.field("page", &p.as_str());
}
if !self.args.is_empty() {
d.field("args", &self.args);
}
if let Some(c) = &self.count {
d.field("count", c);
}
#[cfg(feature = "format")]
if let Some(n) = &self.number {
match n {
Shown::Number(v, name) => d.field("number", &(v, name)),
Shown::When(v) => d.field("date", v),
};
}
if let Some(o) = &self.default {
d.field("or", o);
}
if self.rule.is_some() {
d.field("plural_rule", &"custom");
}
if self.html {
d.field("html", &true);
}
if self.hide {
d.field("hide_if_empty", &true);
}
d.finish()
}
}
impl PartialEq<&str> for Text {
fn eq(&self, other: &&str) -> bool {
let mut same = Same {
rest: other,
ok: true,
};
let _ = self.emit_as(&mut same, true);
same.ok && same.rest.is_empty()
}
}
impl PartialEq<str> for Text {
fn eq(&self, other: &str) -> bool {
*self == other
}
}
impl PartialEq<Text> for &str {
fn eq(&self, other: &Text) -> bool {
other == self
}
}
#[cfg(feature = "serde")]
impl serde::Serialize for Text {
fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
s.collect_str(self)
}
}
impl I18n {
#[must_use]
pub fn text(&self, key: impl Into<Cow<'static, str>>) -> Text {
Text::new(key.into(), Some(self.clone()))
}
}
impl View {
#[must_use]
pub fn text(&self, key: impl Into<Cow<'static, str>>) -> Text {
let mut t = Text::new(key.into(), Some(self.i18n.clone()));
t.locale = self.locale.clone().map(Code::Shared);
t.page = self.page.clone().map(Code::Shared);
t
}
}