+
+ pub(crate) async fn new_multiple(
+ langs: Vec<LanguageId>,
+ pool: &DbPool,
+ ) -> Result<Vec<LanguageTag>, LemmyError> {
+ let langs = blocking(pool, move |conn| {
+ langs
+ .into_iter()
+ .map(|l| Language::read_from_id(conn, l))
+ .collect::<Result<Vec<Language>, diesel::result::Error>>()
+ })
+ .await??;
+
+ let langs = langs
+ .into_iter()
+ .map(|l| LanguageTag {
+ identifier: l.code,
+ name: l.name,
+ })
+ .collect();
+ Ok(langs)
+ }
+
+ pub(crate) async fn to_language_id_single(
+ lang: Option<Self>,
+ pool: &DbPool,
+ ) -> Result<Option<LanguageId>, LemmyError> {
+ let identifier = lang.map(|l| l.identifier);
+ let language = blocking(pool, move |conn| {
+ Language::read_id_from_code_opt(conn, identifier.as_deref())
+ })
+ .await??;
+
+ Ok(language)
+ }
+
+ pub(crate) async fn to_language_id_multiple(
+ langs: Vec<Self>,
+ pool: &DbPool,
+ ) -> Result<Vec<LanguageId>, LemmyError> {
+ let languages = blocking(pool, move |conn| {
+ langs
+ .into_iter()
+ .map(|l| l.identifier)
+ .map(|l| Language::read_id_from_code(conn, &l))
+ .collect::<Result<Vec<LanguageId>, diesel::result::Error>>()
+ })
+ .await??;
+ Ok(languages)
+ }