use crate::error::Error;
#[inline]
pub(crate) fn missing(locale: &str, page: &str, key: &str) {
#[cfg(feature = "tracing")]
tracing::warn!(locale, page, key, "i18n-next: missing translation");
#[cfg(not(feature = "tracing"))]
let _ = (locale, page, key);
}
#[cfg(feature = "format")]
#[cold]
pub(crate) fn missing_format(kind: &str, name: &str, locale: &str) {
#[cfg(feature = "tracing")]
tracing::warn!(
kind,
name,
locale,
"i18n-next: missing format, default options used"
);
#[cfg(all(not(feature = "tracing"), debug_assertions))]
eprintln!(
"i18n-next: Not found '{name}' {kind} format in '{locale}' locale. Falling back to default Intl options."
);
#[cfg(all(not(feature = "tracing"), not(debug_assertions)))]
let _ = (kind, name, locale);
}
pub(crate) const MISSES: bool = cfg!(feature = "tracing");
#[cold]
pub(crate) fn broken(error: &Error) {
#[cfg(feature = "tracing")]
tracing::warn!(%error, "i18n-next: load failed");
#[cfg(all(not(feature = "tracing"), debug_assertions))]
eprintln!("i18n-next: load failed: {error}");
#[cfg(all(not(feature = "tracing"), not(debug_assertions)))]
let _ = error;
}
pub(crate) struct Timer {
#[cfg(all(
feature = "tracing",
not(all(target_arch = "wasm32", target_os = "unknown"))
))]
start: std::time::Instant,
}
impl Timer {
#[inline]
pub(crate) fn start() -> Timer {
Timer {
#[cfg(all(
feature = "tracing",
not(all(target_arch = "wasm32", target_os = "unknown"))
))]
start: std::time::Instant::now(),
}
}
#[inline]
pub(crate) fn done(self, what: &'static str, path: &str, bytes: usize) {
#[cfg(feature = "tracing")]
{
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
let micros = self.start.elapsed().as_micros() as u64;
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
let micros = 0u64;
tracing::debug!(path, bytes, micros, "i18n-next: {what}");
}
#[cfg(not(feature = "tracing"))]
let _ = (self, what, path, bytes);
}
}