Skip to content

Commit

Permalink
Fully working i18n + Configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
AnnsAnns committed Mar 16, 2024
1 parent dcf6fd0 commit d4dbf9b
Show file tree
Hide file tree
Showing 11 changed files with 200 additions and 32 deletions.
9 changes: 5 additions & 4 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ members = [
resolver = "2"

[workspace.package]
version = "8.3.0"
version = "9.0.0"
authors = ["AnnsAnn"]
35 changes: 35 additions & 0 deletions locales/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# i18n ReadME

This folder contains internationalization (i18n) files for translating the bot messages into different languages. When translating, follow these instructions:

1. **File Naming:** Create a new file named `<language_code>.yml` for your language within this folder.

2. **Base File:** Start by copying the contents of the `en.yml` file into your newly created file.

3. **Translation:** Replace the English strings with their translated counterparts in your language. Ensure that the structure of the file remains intact, including placeholders and formatting.

4. **Testing:** Test the translations thoroughly to ensure accuracy and readability.
- I'd recommend [i18n Ally](https://marketplace.visualstudio.com/items?itemName=Lokalise.i18n-ally) for VSCode to help you with the translations.

5. **Contributing:** If you've made significant improvements or translations for a language that doesn't exist yet, consider submitting a pull request to the repository.

## Example Translation File Structure

```yaml
_version: 1
referenced: "🔗 Your message was referenced by <@%{USER_ID}< (%{AUTHOR_NICKNAME}) in: %{MESSAGE_URL}"
error_sending_message: "🚨 Error sending message: %{WHY}"
nothing_selected: "🚨 Nothing selected"
```
## Notes
- **Placeholder Usage:** Do not alter the placeholders (`%{...}`). They are used for dynamic content insertion and should be retained in your translations.

- **URLs and Links:** Be cautious when translating URLs or links. Ensure that they remain functional and relevant in your language context.

- **Consistency:** Maintain consistency in tone, style, and formatting throughout the translation for a seamless user experience.

- **Fallback Language:** If a user's language is not supported or the specific string hasn't been translated, the bot will default to English.

Thank you for your contribution to making the bot accessible to users worldwide! 🌍✨
6 changes: 3 additions & 3 deletions locales/de-DE.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
_version: 1
referenced: "🔗 Deine Nachricht wurde von <@%{USER_ID}< (%{AUTHOR_NICKNAME}) in: %{MESSAGE_URL} referenziert"
error_sending_message: "🚨 Fehler beim Senden der Nachricht: ${WHY}"
error_sending_message: "🚨 Fehler beim Senden der Nachricht: %{WHY}"
nothing_selected: "🚨 Nichts ausgewählt"
error_delete_message: "🚨 Fehler beim Löschen der Nachricht: ${WHY}"
error_delete_message: "🚨 Fehler beim Löschen der Nachricht: %{WHY}"
source_code: "☁️ Der Quellcode ist hier zu finden: %{URL}"
menu_meme: "🕺 https://www.youtube.com/watch?v=dQw4w9WgXcQ" # Bitte harmlos halten, wenn geändert
disable: "⛔ Deaktiviere diesen Bot für diese Seite mit dem Befehl /change!"
Expand All @@ -14,7 +14,7 @@ remove: "❌ Entferne diese Nachricht"
change_info: "⛔ Verwende /change, um den Bot für diese Seite zu deaktivieren!"
menu: "Menü"
download: "⏬ Medien herunterladen"
version: "🏳️‍⚧️ Läuft v${VERSION} von Sphene unter Verwendung von Thorium"
version: "🏳️‍⚧️ Läuft v%{VERSION} von Sphene unter Verwendung von Thorium"
psky: "🔄️ Ändern zu: Psky"
fixbluesky: "🔄️ Ändern zu: FixBluesky"
media_only: "🖼️ Nur Medien"
Expand Down
11 changes: 7 additions & 4 deletions locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
_version: 1
referenced: "🔗 Your message has been referenced by <@%{USER_ID}< (%{AUTHOR_NICKNAME}) in: %{MESSAGE_URL}"
error_sending_message: "🚨 Error sending message: ${WHY}"
error_sending_message: "🚨 Error sending message: %{WHY}"
nothing_selected: "🚨 Nothing selected"
error_delete_message: "🚨 Error deleting message: ${WHY}"
error_delete_message: "🚨 Error deleting message: %{WHY}"
source_code: "☁️ The Source Code can be found at: %{URL}"
menu_meme: "🕺 https://www.youtube.com/watch?v=dQw4w9WgXcQ" # Please keep it harmless when changing
disable: "⛔ Disable this bot for this site using the /change slash command!"
Expand All @@ -14,7 +14,7 @@ remove: "❌ Remove this Message"
change_info: "⛔ Use /change to disable bot for this site!"
menu: "Menu"
download: "⏬ Download Media"
version: "🏳️‍⚧️ Running v${VERSION} of Sphene using Thorium"
version: "🏳️‍⚧️ Running v%{VERSION} of Sphene using Thorium"
psky: "🔄️ Change to: Psky"
fixbluesky: "🔄️ Change to: FixBluesky"
media_only: "🖼️ Media Only"
Expand All @@ -29,4 +29,7 @@ show_original_instagram: "📸 Show original Instagram URL"
tiktxk: "🔄️ Change to: TikTxk"
tnktok: "🔄️ Change to: Tnktok"
show_media_only_tiktok: "🖼️ Media Only"
show_original_tiktok: "👶 Show original TikTok URL"
show_original_tiktok: "👶 Show original TikTok URL"
change_language: "🌐 Change language with /set_guild_language!"
contribute_language: "🌐 Contribute to the translations at: %{URL} - Any contributions are welcome!"
contribute_languages_option: "🌐 Contribute to the translations"
32 changes: 32 additions & 0 deletions locales/nl-NL.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
_version: 1
referenced: "🔗 Je bericht is genoemd door <@%{USER_ID}< (%{AUTHOR_NICKNAME}) in: %{MESSAGE_URL}"
error_sending_message: "🚨 Fout bij het verzenden van bericht: %{WHY}"
nothing_selected: "🚨 Niets geselecteerd"
error_delete_message: "🚨 Fout bij het verwijderen van bericht: %{WHY}"
source_code: "☁️ De broncode is te vinden op: %{URL}"
menu_meme: "🕺 https://www.youtube.com/watch?v=dQw4w9WgXcQ" # Houd het alsjeblieft onschadelijk bij het wijzigen
disable: "⛔ Schakel deze bot uit voor deze site met behulp van de /change slash-opdracht!"
download_url: "⏬ Jouw download-URL is: <%{URL}>"
no_download: "⚠️ Geen download-URL gevonden!"
not_author: "⚠️ Jij bent niet de auteur van dit bericht!"
deleted_message: "💣 Verwijderd bericht"
remove: "❌ Verwijder dit bericht"
change_info: "⛔ Gebruik /change om de bot voor deze site uit te schakelen!"
menu: "Menu"
download: "⏬ Media downloaden"
version: "🏳️‍⚧️ Draait v%{VERSION} van Sphene met behulp van Thorium"
psky: "🔄️ Verander naar: Psky"
fixbluesky: "🔄️ Verander naar: FixBluesky"
media_only: "🖼️ Alleen media"
show_original_bluesky: "☁️ Toon originele Bluesky URL"
vxtwitter: "🔄️ Verander naar: VXTwitter"
fxtwitter: "🔄️ Verander naar: FXTwitter"
media_only_vxtwitter: "🖼️ Alleen media (VXTwitter)"
media_only_fxtwitter: "🖼️ Alleen media (FXTwitter)"
show_original_twitter: "🤨 Toon originele Twitter URL"
ddinstagram: "🔄️ Verander naar: DDInstagram"
show_original_instagram: "📸 Toon originele Instagram URL"
tiktxk: "🔄️ Verander naar: TikTxk"
tnktok: "🔄️ Verander naar: Tnktok"
show_media_only_tiktok: "🖼️ Alleen media"
show_original_tiktok: "👶 Toon originele TikTok URL"
16 changes: 10 additions & 6 deletions sphene/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use options::get_instagram_options;
use options::get_tik_tok_options;
use options::get_twitter_options;
use regex::Regex;
use rust_i18n::available_locales;
use serenity::async_trait;
use serenity::builder::CreateSelectMenuOption;

Expand All @@ -25,7 +26,7 @@ use thorium::*;

use rust_i18n::t;

rust_i18n::i18n!("locales", fallback = "en");
rust_i18n::i18n!("../locales", fallback = "en");

mod options;

Expand Down Expand Up @@ -184,11 +185,8 @@ impl EventHandler for Handler {
return;
}

let id = if msg.guild_id.is_some() {
msg.guild_id.unwrap().0
} else {
msg.author.id.0
};
// Get guild ID
let id = msg.author.id.0;
let get_lang = match self.dbconn.lock().await.get_server(id, false).language {
Some(lang) => lang,
None => "en".to_string(),
Expand All @@ -203,13 +201,17 @@ impl EventHandler for Handler {
|| command == "download"
|| command == "menu"
|| command == "disable"
|| command == "set_language"
|| command == "contribute_language"
{
let content = if command == "version" {
t!("source_code", locale=lang, URL = "https://github.com/AnnsAnns/sphene").to_string()
} else if command == "menu" {
t!("menu_meme").to_string()
} else if command == "disable" {
t!("disable").to_string()
} else if command == "set_language" || command == "contribute_language"{
t!("contribute_language", locale=lang, URL="https://github.com/AnnsAnns/sphene/locales").to_string()
} else if command == "download" {
let extracted_url = self
.regex_pattern
Expand Down Expand Up @@ -384,6 +386,8 @@ async fn main() {

let dbconn = Mutex::new(DBConn::new().unwrap());

println!("Available Languages: {:?}", available_locales!());

let mut client = Client::builder(&token, intents)
.event_handler(Handler {
regex_pattern,
Expand Down
28 changes: 22 additions & 6 deletions sphene/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,20 @@ pub fn get_disable_option(lang: &str) -> CreateSelectMenuOption {
CreateSelectMenuOption::new(t!("change_info", locale = lang), "disable")
}

pub fn get_defaul_option(lang: &str) -> CreateSelectMenuOption {
pub fn get_default_option(lang: &str) -> CreateSelectMenuOption {
CreateSelectMenuOption::new(t!("menu", locale = lang), "menu")
.default_selection(true)
.to_owned()
}

pub fn get_set_language_option(lang: &str) -> CreateSelectMenuOption {
CreateSelectMenuOption::new(t!("change_language", locale = lang), "set_language")
}

pub fn get_contribute_language_option(lang: &str) -> CreateSelectMenuOption {
CreateSelectMenuOption::new(t!("contribute_languages_option", locale = lang), "contribute_language")
}

pub fn get_download_option(lang: &str) -> CreateSelectMenuOption {
CreateSelectMenuOption::new(t!("download", locale = lang), "download")
}
Expand All @@ -34,15 +42,17 @@ pub fn get_blueksy_options(lang: &str) -> Vec<CreateSelectMenuOption> {
get_download_option(lang),
CreateSelectMenuOption::new(t!("psky", locale = lang), bluesky::PSKY_URL),
CreateSelectMenuOption::new(t!("fixbluesky", locale = lang), bluesky::FIXBLUESKY_URL),
CreateSelectMenuOption::new(t!("mediaonly", locale = lang), "direct_fxbsky"),
CreateSelectMenuOption::new(t!("media_only", locale = lang), "direct_fxbsky"),
CreateSelectMenuOption::new(
t!("show_original_bluesky", locale = lang),
bluesky::BLUESKY_URL,
),
get_remove_option(lang),
get_set_language_option(lang),
get_contribute_language_option(lang),
get_disable_option(lang),
get_version_option(lang),
get_defaul_option(lang),
get_default_option(lang),
]
}

Expand All @@ -58,9 +68,11 @@ pub fn get_twitter_options(lang: &str) -> Vec<CreateSelectMenuOption> {
twitter::TWITTER_URL,
),
get_remove_option(lang),
get_set_language_option(lang),
get_contribute_language_option(lang),
get_disable_option(lang),
get_version_option(lang),
get_defaul_option(lang),
get_default_option(lang),
]
}

Expand All @@ -72,9 +84,11 @@ pub fn get_instagram_options(lang: &str) -> Vec<CreateSelectMenuOption> {
instagram::INSTAGRAM_URL,
),
get_remove_option(lang),
get_set_language_option(lang),
get_contribute_language_option(lang),
get_disable_option(lang),
get_version_option(lang),
get_defaul_option(lang),
get_default_option(lang),
]
}

Expand All @@ -89,8 +103,10 @@ pub fn get_tik_tok_options(lang: &str) -> Vec<CreateSelectMenuOption> {
tiktok::TIKTOK_URL,
),
get_remove_option(lang),
get_set_language_option(lang),
get_contribute_language_option(lang),
get_disable_option(lang),
get_version_option(lang),
get_defaul_option(lang),
get_default_option(lang),
]
}
3 changes: 2 additions & 1 deletion sphene_config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ authors.workspace = true
dotenv = "0.15.0"
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
poise = "0.5.6"
thorium = { path = "../thorium" }
thorium = { path = "../thorium" }
rust-i18n = "3.0.1"
Loading

0 comments on commit d4dbf9b

Please sign in to comment.