Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i18n #321

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft

i18n #321

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,7 @@ psutil = "3.2.2"
rust-fuzzy-search = "0.1.1"
moka = { version = "0.11.2", features = ["future"] }
cached = "0.44.0"
rosetta-i18n = "0.1.3"

[build-dependencies]
rosetta-build = "0.1.3"
10 changes: 8 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
// generated by `sqlx migrate build-script`
fn main() {
// trigger recompilation when a new migration is added
println!("cargo:rerun-if-changed=migrations");
println!("cargo:rerun-if-changed=locales");

rosetta_build::config()
.source("en", "locales/en.json")
.source("pt", "locales/pt.json")
.fallback("en")
.generate()
.unwrap();
}
428 changes: 428 additions & 0 deletions locales/en.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions locales/pt.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
2 changes: 1 addition & 1 deletion src/interactions/autocomplete/autoredeem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub async fn autoredeem_autocomplete(
.cache
.guilds
.with(&id, |_, g| g.as_ref().map(|g| format!("{} {id}", g.name)))
.unwrap_or_else(|| format!("Unkown Server {id}"))
.unwrap_or_else(|| ctx.user_lang().unknown_server(id))
};
let guild_names = guild_ids
.iter()
Expand Down
37 changes: 23 additions & 14 deletions src/interactions/commands/chat/autostar/create.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use twilight_interactions::command::{CommandModel, CreateCommand};
use twilight_mention::Mention;
use twilight_model::application::interaction::application_command::InteractionChannel;

use crate::{
Expand All @@ -8,16 +9,27 @@ use crate::{
errors::StarboardResult,
get_guild_id,
interactions::context::CommandCtx,
locale_func,
utils::id_as_i64::GetI64,
};

locale_func!(autostar_create);
locale_func!(autostar_create_option_name);
locale_func!(autostar_create_option_channel);

#[derive(CommandModel, CreateCommand)]
#[command(name = "create", desc = "Create an autostar channel.")]
#[command(
name = "create",
desc = "Create an autostar channel.",
desc_localizations = "autostar_create"
)]
pub struct CreateAutoStarChannel {
/// The name of the autostar channel.
#[command(desc_localizations = "autostar_create_option_name")]
name: String,
/// The channel to create an autostar channel in.
#[command(channel_types = r#"
#[command(
channel_types = r#"
guild_text
guild_voice
guild_stage_voice
Expand All @@ -26,7 +38,9 @@ pub struct CreateAutoStarChannel {
public_thread
private_thread
guild_forum
"#)]
"#,
desc_localizations = "autostar_create_option_channel"
)]
channel: InteractionChannel,
}

Expand All @@ -53,11 +67,8 @@ impl CreateAutoStarChannel {
};
if count >= limit {
ctx.respond_str(
&format!(
"You can only have up to {} autostar channels. The premium limit is {}.",
limit,
constants::MAX_PREM_AUTOSTAR,
),
&ctx.user_lang()
.autostar_create_limit_reached(limit, constants::MAX_PREM_AUTOSTAR),
true,
)
.await?;
Expand All @@ -67,16 +78,14 @@ impl CreateAutoStarChannel {
let ret = AutoStarChannel::create(&ctx.bot.pool, &name, channel_id, guild_id).await?;

if ret.is_none() {
ctx.respond_str(
&format!("An autostar channel with the name '{name}' already exists."),
true,
)
.await?;
ctx.respond_str(&ctx.user_lang().autostar_channel_already_exists(name), true)
.await?;
} else {
ctx.bot.cache.autostar_channel_ids.insert(self.channel.id);

ctx.respond_str(
&format!("Created autostar channel '{name}' in <#{channel_id}>."),
&ctx.user_lang()
.autostar_create_success(self.channel.id.mention(), name),
false,
)
.await?;
Expand Down
31 changes: 17 additions & 14 deletions src/interactions/commands/chat/autostar/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,34 @@ use crate::{
errors::StarboardResult,
get_guild_id,
interactions::context::CommandCtx,
locale_func,
utils::{id_as_i64::GetI64, views::confirm},
};

locale_func!(autostar_delete);
locale_func!(autostar_delete_option_name);

#[derive(CreateCommand, CommandModel)]
#[command(name = "delete", desc = "Delete an autostar channel.")]
#[command(
name = "delete",
desc = "Delete an autostar channel.",
desc_localizations = "autostar_delete"
)]
pub struct DeleteAutoStarChannel {
/// The name of the autostar channel to delete.
#[command(autocomplete = true)]
#[command(
autocomplete = true,
desc_localizations = "autostar_delete_option_name"
)]
name: String,
}

impl DeleteAutoStarChannel {
pub async fn callback(self, mut ctx: CommandCtx) -> StarboardResult<()> {
let guild_id = get_guild_id!(ctx);

let mut btn_ctx = match confirm::simple(
&mut ctx,
&format!(
"Are you sure you want to delete the autostar channel '{}'?",
self.name
),
true,
)
.await?
{
let conf = ctx.user_lang().autostar_delete_confirm(&self.name);
let mut btn_ctx = match confirm::simple(&mut ctx, &conf, true).await? {
None => return Ok(()),
Some(btn_ctx) => btn_ctx,
};
Expand All @@ -44,11 +47,11 @@ impl DeleteAutoStarChannel {
.await?;
if ret.is_none() {
btn_ctx
.edit_str("No autostar channel with that name was found.", true)
.edit_str(&ctx.user_lang().autostar_channel_missing(self.name), true)
.await?;
} else {
btn_ctx
.edit_str(&format!("Deleted autostar channel '{}'.", self.name), true)
.edit_str(&ctx.user_lang().autostar_delete_done(self.name), true)
.await?;
}
Ok(())
Expand Down
53 changes: 40 additions & 13 deletions src/interactions/commands/chat/autostar/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,58 @@ use crate::{
errors::StarboardResult,
get_guild_id,
interactions::context::CommandCtx,
locale_func,
utils::id_as_i64::GetI64,
};

locale_func!(autostar_edit);
locale_func!(autostar_edit_option_name);
locale_func!(autostar_edit_option_emojis);
locale_func!(autostar_edit_option_min_chars);
locale_func!(autostar_edit_option_max_chars);
locale_func!(autostar_edit_option_require_image);
locale_func!(autostar_edit_option_delete_invalid);

#[derive(CommandModel, CreateCommand)]
#[command(name = "edit", desc = "Set the emojis for an autostar channel.")]
#[command(
name = "edit",
desc = "Edit the settings for an autostar channel.",
desc_localizations = "autostar_edit"
)]
pub struct EditAutoStar {
/// The name of the autostar channel to edit.
#[command(autocomplete = true)]
#[command(autocomplete = true, desc_localizations = "autostar_edit_option_name")]
name: String,

/// The emojis to use. Use "none" to set to none.
#[command(desc_localizations = "autostar_edit_option_emojis")]
emojis: Option<String>,

/// The minimum number of characters a message needs.
#[command(rename = "min-chars", min_value = 0, max_value = 5_000)]
#[command(
rename = "min-chars",
min_value = 0,
max_value = 5_000,
desc_localizations = "autostar_edit_option_min_chars"
)]
min_chars: Option<i64>,

/// The maximum number of characters a message can have. Set to -1 to disable.
#[command(rename = "max-chars", min_value = -1, max_value = 5_000)]
#[command(rename = "max-chars", min_value = -1, max_value = 5_000, desc_localizations = "autostar_edit_option_max_chars")]
max_chars: Option<i64>,

/// Whether or not a message must include an image.
#[command(rename = "require-image")]
#[command(
rename = "require-image",
desc_localizations = "autostar_edit_option_require_image"
)]
require_image: Option<bool>,

/// Whether to delete messages that don't meet requirements.
#[command(rename = "delete-invalid")]
#[command(
rename = "delete-invalid",
desc_localizations = "autostar_edit_option_delete_invalid"
)]
delete_invalid: Option<bool>,
}

Expand All @@ -42,7 +72,7 @@ impl EditAutoStar {
let asc = AutoStarChannel::get_by_name(&ctx.bot.pool, &self.name, guild_id_i64).await?;
let mut asc = match asc {
None => {
ctx.respond_str("No autostar channel with that name was found.", true)
ctx.respond_str(&ctx.user_lang().autostar_channel_missing(self.name), true)
.await?;
return Ok(());
}
Expand Down Expand Up @@ -82,17 +112,14 @@ impl EditAutoStar {
let asc = asc.update_settings(&ctx.bot.pool).await?;

if asc.is_none() {
ctx.respond_str("No autostar channels with that name were found.", true)
ctx.respond_str(&ctx.user_lang().autostar_channel_missing(self.name), true)
.await?;
return Ok(());
}

// set the emojis
ctx.respond_str(
&format!("Updated the settings for autostar channel '{}'.", self.name),
false,
)
.await?;
ctx.respond_str(&ctx.user_lang().autostar_edit_done(self.name), false)
.await?;

Ok(())
}
Expand Down
Loading