Skip to content

Commit

Permalink
localization
Browse files Browse the repository at this point in the history
  • Loading branch information
rhunk committed May 15, 2023
1 parent 5df7d06 commit 185fee2
Show file tree
Hide file tree
Showing 15 changed files with 199 additions and 134 deletions.
76 changes: 76 additions & 0 deletions app/src/main/assets/lang/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"category": {
"general": "General",
"spy": "Spy",
"media_download": "Media Downloader",
"privacy": "Privacy",
"ui": "UI",
"extras": "Extras",
"tweaks": "Tweaks",
"experimental": "Experimental"
},

"property": {
"save_folder": "Save Folder",
"prevent_read_receipts": "Prevent Read Receipts",
"hide_bitmoji_presence": "Hide Bitmoji Presence",
"show_message_content": "Show Message Content",
"message_logger": "Message Logger",
"auto_download_snaps": "Auto Download Snaps",
"auto_download_stories": "Auto Download Stories",
"auto_download_public_stories": "Auto Download Public Stories",
"auto_download_spotlight": "Auto Download Spotlight",
"overlay_merge": "Snap Image Overlay Merge",
"download_inchat_snaps": "Download Inchat Snaps",
"anti_auto_download_button": "Anti Auto Download Button",
"disable_metrics": "Disable Metrics",
"prevent_screenshots": "Prevent Screenshots",
"prevent_status_notifications": "Prevent Status Notifications (Screenrecord, media save)",
"anonymous_story_view": "Anonymous Story View",
"hide_typing_notification": "Hide Typing Notification",
"menu_slot_id": "Friend Menu Slot ID",
"message_preview_length": "Message Preview Length",
"auto_save": "Auto Save",
"snapchat_plus": "Snapchat Plus",
"remove_voice_record_button": "Remove Voice Record Button",
"remove_stickers_button": "Remove Stickers Button",
"remove_cognac_button": "Remove Cognac Button",
"remove_call_buttons": "Remove Call Buttons",
"long_snap_sending": "Long Snap Sending",
"block_ads": "Block Ads",
"streak_expiration_info": "Show Streak Expiration Info",
"new_map_ui": "New Map UI",
"use_download_manager": "Use Android Download Manager"
},


"friend_menu_option": {
"preview": "Preview",
"stealth_mode": "Stealth Mode",
"anti_auto_download": "Anti Auto Download"
},

"message_context_menu_option": {
"download": "Download",
"preview": "Preview"
},

"modal_option": {
"profile_info": "Profile Info",
"close": "Close"
},

"conversation_preview": {
"streak_expiration": "expires in %s days %s hours %s minutes",
"title": "Preview",
"unknown_user": "Unknown User"
},

"profile_info": {
"title": "Profile Info",
"username": "Username",
"display_name": "Display Name",
"added_date": "Added Date",
"birthday": "Birthday : {month} {day}"
}
}
6 changes: 6 additions & 0 deletions app/src/main/kotlin/me/rhunk/snapenhance/ModContext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ class ModContext {
exitProcess(0)
}

fun crash(message: String, throwable: Throwable? = null) {
Logger.xposedLog(message, throwable)
longToast(message)
delayForceCloseApp(100)
}

fun delayForceCloseApp(delay: Long) = Handler(Looper.getMainLooper()).postDelayed({
forceCloseApp()
}, delay)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ class BridgeClient(
BridgeMessageType.FILE_ACCESS_RESULT -> FileAccessResult()
BridgeMessageType.DOWNLOAD_CONTENT_RESULT -> DownloadContentResult()
BridgeMessageType.MESSAGE_LOGGER_RESULT -> MessageLoggerResult()
BridgeMessageType.LOCALE_RESULT -> LocaleResult()
else -> {
log("Unknown message type: ${msg.what}")
null
future.completeExceptionally(IllegalStateException("Unknown message type: ${msg.what}"))
return
}
} ?: return
}

with(message) {
read(msg.data)
Expand Down Expand Up @@ -220,6 +221,16 @@ class BridgeClient(
)
}

fun fetchTranslations(): LocaleResult {
sendMessage(
BridgeMessageType.LOCALE_REQUEST,
LocaleRequest(),
LocaleResult::class
).run {
return this
}
}

override fun onServiceConnected(name: ComponentName, service: IBinder) {
messenger = Messenger(service)
future.complete(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,10 @@ package me.rhunk.snapenhance.bridge.common.impl
import android.os.Bundle
import me.rhunk.snapenhance.bridge.common.BridgeMessage

class LocaleRequest(
var locale: String? = null
) : BridgeMessage() {

class LocaleRequest() : BridgeMessage() {
override fun write(bundle: Bundle) {
bundle.putString("locale", locale)
}

override fun read(bundle: Bundle) {
locale = bundle.getString("locale")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import me.rhunk.snapenhance.Logger
import me.rhunk.snapenhance.bridge.common.BridgeMessageType
import me.rhunk.snapenhance.bridge.common.impl.*
import java.io.File
import java.util.*

class BridgeService : Service() {
companion object {
Expand Down Expand Up @@ -112,9 +113,13 @@ class BridgeService : Service() {
}

private fun handleLocaleRequest(msg: LocaleRequest, reply: (Message) -> Unit) {
val locale = resources.configuration.locales[0]
Logger.log("Locale: ${locale.language}_${locale.country}")
TODO()
val deviceLocale = Locale.getDefault().language
val compatibleLocale = resources.assets.list("lang")?.find { it.startsWith(deviceLocale) }?.substring(0, 2) ?: "en"

resources.assets.open("lang/$compatibleLocale.json").use { inputStream ->
val json = inputStream.bufferedReader().use { it.readText() }
reply(LocaleResult(compatibleLocale, json.toByteArray(Charsets.UTF_8)).toMessage(BridgeMessageType.LOCALE_RESULT.value))
}
}

private fun handleDownloadContent(msg: DownloadContentRequest, reply: (Message) -> Unit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package me.rhunk.snapenhance.config
enum class ConfigCategory(
val key: String
) {
GENERAL("general"),
SPY("spy"),
MEDIA_DOWNLOADER("media_download"),
PRIVACY("privacy"),
UI("ui"),
EXTRAS("extras"),
TWEAKS("tweaks"),
EXPERIMENTS("experiments");
GENERAL("category.general"),
SPY("category.spy"),
MEDIA_DOWNLOADER("category.media_download"),
PRIVACY("category.privacy"),
UI("category.ui"),
EXTRAS("category.extras"),
TWEAKS("category.tweaks"),
EXPERIMENTAL("category.experimental");
}
88 changes: 35 additions & 53 deletions app/src/main/kotlin/me/rhunk/snapenhance/config/ConfigProperty.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,174 +10,156 @@ enum class ConfigProperty(
val defaultValue: Any
) {
SAVE_FOLDER(
"save_folder", "description.save_folder", ConfigCategory.GENERAL,
"property.save_folder", "description.save_folder", ConfigCategory.GENERAL,
File(
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).absolutePath + "/Snapchat",
"SnapEnhance"
).absolutePath
),

PREVENT_READ_RECEIPTS(
"prevent_read_receipts",
"property.prevent_read_receipts",
"description.prevent_read_receipts",
ConfigCategory.SPY,
false
),
HIDE_BITMOJI_PRESENCE(
"hide_bitmoji_presence",
"property.hide_bitmoji_presence",
"description.hide_bitmoji_presence",
ConfigCategory.SPY,
false
),
SHOW_MESSAGE_CONTENT(
"show_message_content",
"property.show_message_content",
"description.show_message_content",
ConfigCategory.SPY,
false
),
MESSAGE_LOGGER("message_logger", "description.message_logger", ConfigCategory.SPY, false),
MESSAGE_LOGGER("property.message_logger", "description.message_logger", ConfigCategory.SPY, false),

MEDIA_DOWNLOADER(
"media_downloader",
"description.media_downloader",
ConfigCategory.MEDIA_DOWNLOADER,
true
),
AUTO_DOWNLOAD_SNAPS(
"auto_download_snaps",
"property.auto_download_snaps",
"description.auto_download_snaps",
ConfigCategory.MEDIA_DOWNLOADER,
true
),
AUTO_DOWNLOAD_STORIES(
"auto_download_stories",
"property.auto_download_stories",
"description.auto_download_stories",
ConfigCategory.MEDIA_DOWNLOADER,
false
),
AUTO_DOWNLOAD_PUBLIC_STORIES(
"auto_download_public_stories",
"property.auto_download_public_stories",
"description.auto_download_public_stories",
ConfigCategory.MEDIA_DOWNLOADER,
false
),
AUTO_DOWNLOAD_SPOTLIGHT(
"auto_download_spotlight",
"property.auto_download_spotlight",
"description.auto_download_spotlight",
ConfigCategory.MEDIA_DOWNLOADER,
false
),
OVERLAY_MERGE(
"overlay_merge",
"property.overlay_merge",
"description.overlay_merge",
ConfigCategory.MEDIA_DOWNLOADER,
true
),
DOWNLOAD_INCHAT_SNAPS(
"download_inchat_snaps",
"property.download_inchat_snaps",
"description.download_inchat_snaps",
ConfigCategory.MEDIA_DOWNLOADER,
true
),
ANTI_DOWNLOAD_BUTTON(
"anti_download_button",
"description.anti_download_button",
"property.anti_auto_download_button",
"description.anti_auto_download_button",
ConfigCategory.MEDIA_DOWNLOADER,
false
),

DISABLE_METRICS("disable_metrics", "description.disable_metrics", ConfigCategory.PRIVACY, true),
DISABLE_METRICS("property.disable_metrics", "description.disable_metrics", ConfigCategory.PRIVACY, true),
PREVENT_SCREENSHOTS(
"prevent_screenshots",
"property.prevent_screenshots",
"description.prevent_screenshots",
ConfigCategory.PRIVACY,
true
),
PREVENT_STATUS_NOTIFICATIONS(
"prevent_status_notifications",
"property.prevent_status_notifications",
"description.prevent_status_notifications",
ConfigCategory.PRIVACY,
true
),
ANONYMOUS_STORY_VIEW(
"anonymous_story_view",
"property.anonymous_story_view",
"description.anonymous_story_view",
ConfigCategory.PRIVACY,
false
),
HIDE_TYPING_NOTIFICATION(
"hide_typing_notification",
"property.hide_typing_notification",
"description.hide_typing_notification",
ConfigCategory.PRIVACY,
false
),

MENU_SLOT_ID("menu_slot_id", "description.menu_slot_id", ConfigCategory.UI, 1),
MENU_SLOT_ID("property.menu_slot_id", "description.menu_slot_id", ConfigCategory.UI, 1),
MESSAGE_PREVIEW_LENGTH(
"message_preview_length",
"property.message_preview_length",
"description.message_preview_length",
ConfigCategory.UI,
20
),

AUTO_SAVE("auto_save", "description.auto_save", ConfigCategory.EXTRAS, false),
/*EXTERNAL_MEDIA_AS_SNAP(
"external_media_as_snap",
"description.external_media_as_snap",
ConfigCategory.EXTRAS,
false
),
CONVERSATION_EXPORT(
"conversation_export",
"description.conversation_export",
ConfigCategory.EXTRAS,
false
),*/
SNAPCHAT_PLUS("snapchat_plus", "description.snapchat_plus", ConfigCategory.EXTRAS, false),
AUTO_SAVE("property.auto_save", "description.auto_save", ConfigCategory.EXTRAS, false),
SNAPCHAT_PLUS("property.snapchat_plus", "description.snapchat_plus", ConfigCategory.EXTRAS, false),

REMOVE_VOICE_RECORD_BUTTON(
"remove_voice_record_button",
"property.remove_voice_record_button",
"description.remove_voice_record_button",
ConfigCategory.TWEAKS,
false
),
REMOVE_STICKERS_BUTTON(
"remove_stickers_button",
"property.remove_stickers_button",
"description.remove_stickers_button",
ConfigCategory.TWEAKS,
false
),
REMOVE_COGNAC_BUTTON(
"remove_cognac_button",
"property.remove_cognac_button",
"description.remove_cognac_button",
ConfigCategory.TWEAKS,
false
),
REMOVE_CALLBUTTONS(
"remove_callbuttons",
"description.remove_callbuttons",
REMOVE_CALL_BUTTONS(
"property.remove_call_buttons",
"description.remove_call_buttons",
ConfigCategory.TWEAKS,
false
),
LONG_SNAP_SENDING(
"long_snap_sending",
"property.long_snap_sending",
"description.long_snap_sending",
ConfigCategory.TWEAKS,
false
),
BLOCK_ADS("block_ads", "description.block_ads", ConfigCategory.TWEAKS, false),
STREAKEXPIRATIONINFO(
"streakexpirationinfo",
BLOCK_ADS("property.block_ads", "description.block_ads", ConfigCategory.TWEAKS, false),
STREAK_EXPIRATION_INFO(
"property.streak_expiration_info",
"description.streakexpirationinfo",
ConfigCategory.TWEAKS,
false
),
NEW_MAP_UI("new_map_ui", "description.new_map_ui", ConfigCategory.TWEAKS, false),
NEW_MAP_UI("property.new_map_ui", "description.new_map_ui", ConfigCategory.TWEAKS, false),

USE_DOWNLOAD_MANAGER(
"use_download_manager",
"property.use_download_manager",
"description.use_download_manager",
ConfigCategory.EXPERIMENTS,
ConfigCategory.EXPERIMENTAL,
false
);

Expand Down

0 comments on commit 185fee2

Please sign in to comment.