parent
d260895828
commit
d84931f2b5
@ -1,9 +1,10 @@
|
||||
use sqlx::{Postgres, Pool};
|
||||
use sqlx::postgres::PgPoolOptions;
|
||||
use sqlx::{Pool, Postgres};
|
||||
|
||||
pub async fn connect() -> Pool<Postgres> {
|
||||
PgPoolOptions::new()
|
||||
.max_connections(8)
|
||||
.connect("postgres://ibihf:ibihf@localhost/ibihf").await
|
||||
.unwrap()
|
||||
PgPoolOptions::new()
|
||||
.max_connections(8)
|
||||
.connect("postgres://ibihf:ibihf@localhost/ibihf")
|
||||
.await
|
||||
.unwrap()
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
pub fn seconds_as_time(secs: &i32) -> ::askama::Result<String> {
|
||||
let minutes = secs / 60;
|
||||
let seconds = secs % 60;
|
||||
Ok(format!("{}:{}", minutes, seconds))
|
||||
let minutes = secs / 60;
|
||||
let seconds = secs % 60;
|
||||
Ok(format!("{}:{}", minutes, seconds))
|
||||
}
|
||||
|
@ -1,68 +1,73 @@
|
||||
use askama::i18n::FluentValue;
|
||||
use crate::LOCALES;
|
||||
use askama::i18n::{langid, LanguageIdentifier, Locale};
|
||||
use askama::i18n::fluent_templates::Loader;
|
||||
use serde::{
|
||||
Serialize,
|
||||
Deserialize,
|
||||
};
|
||||
use strum::{
|
||||
IntoEnumIterator,
|
||||
};
|
||||
use strum_macros::{
|
||||
EnumIter,
|
||||
AsRefStr,
|
||||
EnumVariantNames,
|
||||
EnumCount,
|
||||
};
|
||||
|
||||
use askama::i18n::FluentValue;
|
||||
use askama::i18n::{langid, LanguageIdentifier, Locale};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use strum::IntoEnumIterator;
|
||||
use strum_macros::{AsRefStr, EnumCount, EnumIter, EnumVariantNames};
|
||||
|
||||
use derive_more::Display;
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Copy, Debug, Display, EnumIter, EnumCount, EnumVariantNames, AsRefStr, PartialEq, Eq)]
|
||||
#[derive(
|
||||
Serialize,
|
||||
Deserialize,
|
||||
Clone,
|
||||
Copy,
|
||||
Debug,
|
||||
Display,
|
||||
EnumIter,
|
||||
EnumCount,
|
||||
EnumVariantNames,
|
||||
AsRefStr,
|
||||
PartialEq,
|
||||
Eq,
|
||||
)]
|
||||
pub enum SupportedLanguage {
|
||||
#[serde(rename="en-ca")]
|
||||
#[display(fmt="en-ca")]
|
||||
English,
|
||||
#[serde(rename="fr-ca")]
|
||||
#[display(fmt="fr-ca")]
|
||||
French,
|
||||
#[serde(rename = "en-ca")]
|
||||
#[display(fmt = "en-ca")]
|
||||
English,
|
||||
#[serde(rename = "fr-ca")]
|
||||
#[display(fmt = "fr-ca")]
|
||||
French,
|
||||
}
|
||||
impl From<SupportedLanguage> for FluentValue<'_> {
|
||||
fn from(n: SupportedLanguage) -> Self {
|
||||
n.to_string().into()
|
||||
}
|
||||
fn from(n: SupportedLanguage) -> Self {
|
||||
n.to_string().into()
|
||||
}
|
||||
}
|
||||
impl Into<LanguageIdentifier> for SupportedLanguage {
|
||||
fn into(self) -> LanguageIdentifier {
|
||||
match self {
|
||||
Self::English => langid!("en-ca"),
|
||||
Self::French => langid!("fr-ca"),
|
||||
fn into(self) -> LanguageIdentifier {
|
||||
match self {
|
||||
Self::English => langid!("en-ca"),
|
||||
Self::French => langid!("fr-ca"),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<'a> Into<Locale<'a>> for SupportedLanguage {
|
||||
fn into(self) -> Locale<'a> {
|
||||
Locale::new(self.into(), &LOCALES)
|
||||
}
|
||||
fn into(self) -> Locale<'a> {
|
||||
Locale::new(self.into(), &LOCALES)
|
||||
}
|
||||
}
|
||||
impl SupportedLanguage {
|
||||
pub fn lookup(&self, key: &str) -> String {
|
||||
LOCALES.lookup(&(*self).into(), key).expect("Unable to find key {key} in locale {self}.")
|
||||
}
|
||||
pub fn other_langs(&self) -> impl Iterator<Item=Self> + '_ {
|
||||
Self::iter()
|
||||
.filter(move |lang| lang != self)
|
||||
}
|
||||
pub fn native_name(&self) -> String {
|
||||
match self {
|
||||
Self::English => "English",
|
||||
Self::French => "Français"
|
||||
}.to_string()
|
||||
}
|
||||
pub fn lookup(&self, key: &str) -> String {
|
||||
LOCALES
|
||||
.lookup(&(*self).into(), key)
|
||||
.expect("Unable to find key {key} in locale {self}.")
|
||||
}
|
||||
pub fn other_langs(&self) -> impl Iterator<Item = Self> + '_ {
|
||||
Self::iter().filter(move |lang| lang != self)
|
||||
}
|
||||
pub fn native_name(&self) -> String {
|
||||
match self {
|
||||
Self::English => "English",
|
||||
Self::French => "Français",
|
||||
}
|
||||
.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct LangLink {
|
||||
pub href: String,
|
||||
pub name: String,
|
||||
pub href: String,
|
||||
pub name: String,
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
pub trait TemplateUrl {
|
||||
const URL_KEY: &'static str;
|
||||
const URL_KEY_TEMPLATE: &'static str;
|
||||
const URL_KEY: &'static str;
|
||||
const URL_KEY_TEMPLATE: &'static str;
|
||||
}
|
||||
|
Loading…
Reference in new issue