mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 11:38:51 +01:00
Make localization easier
use unicode chars, and allow partial jsons
This commit is contained in:
@@ -1,25 +1,25 @@
|
||||
{
|
||||
"emoji_reaction_google_messages_added": "^\u200A\u200B(.+?)\u200B to \u201C\u200A(.+?)\u200A\u201D\u200A$",
|
||||
"emoji_reaction_google_messages_removed": "^\u200ARemoved \u200C(.+?)\u200C from \u201C\u200A(.+?)\u200A\u201D\u200A$",
|
||||
"emoji_reaction_google_messages_added": "^\u200A\u200B(.+?)\u200B to “\u200A(.+?)\u200A”\u200A$",
|
||||
"emoji_reaction_google_messages_removed": "^\u200ARemoved \u200C(.+?)\u200C from “\u200A(.+?)\u200A”\u200A$",
|
||||
|
||||
"emoji_reaction_ios_generic_added": "^Reacted (.+?) to \u201C(.+?)\u201D$",
|
||||
"emoji_reaction_ios_generic_removed": "^Removed (.+?) from \u201C(.+?)\u201D$",
|
||||
"emoji_reaction_ios_generic_added": "^Reacted (.+?) to “(.+?)”$",
|
||||
"emoji_reaction_ios_generic_removed": "^Removed (.+?) from “(.+?)”$",
|
||||
|
||||
"emoji_reaction_ios_heart_added": "^Loved \u201C(.+?)\u201D$",
|
||||
"emoji_reaction_ios_heart_removed": "^Removed a heart from \u201C(.+?)\u201D$",
|
||||
"emoji_reaction_ios_heart_added": "^Loved “(.+?)”$",
|
||||
"emoji_reaction_ios_heart_removed": "^Removed a heart from “(.+?)”$",
|
||||
|
||||
"emoji_reaction_ios_like_added": "^Liked \u201C(.+?)\u201D$",
|
||||
"emoji_reaction_ios_like_removed": "^Removed a like from \u201C(.+?)\u201D$",
|
||||
"emoji_reaction_ios_like_added": "^Liked “(.+?)”$",
|
||||
"emoji_reaction_ios_like_removed": "^Removed a like from “(.+?)”$",
|
||||
|
||||
"emoji_reaction_ios_dislike_added": "^Disliked \u201C(.+?)\u201D$",
|
||||
"emoji_reaction_ios_dislike_removed": "^Removed a dislike from \u201C(.+?)\u201D$",
|
||||
"emoji_reaction_ios_dislike_added": "^Disliked “(.+?)”$",
|
||||
"emoji_reaction_ios_dislike_removed": "^Removed a dislike from “(.+?)”$",
|
||||
|
||||
"emoji_reaction_ios_laugh_added": "^Laughed at \u201C(.+?)\u201D$",
|
||||
"emoji_reaction_ios_laugh_removed": "^Removed a laugh from \u201C(.+?)\u201D$",
|
||||
"emoji_reaction_ios_laugh_added": "^Laughed at “(.+?)”$",
|
||||
"emoji_reaction_ios_laugh_removed": "^Removed a laugh from “(.+?)”$",
|
||||
|
||||
"emoji_reaction_ios_exclamation_added": "^Emphasized \u201C(.+?)\u201D$",
|
||||
"emoji_reaction_ios_exclamation_removed": "^Removed an exclamation from \u201C(.+?)\u201D$",
|
||||
"emoji_reaction_ios_exclamation_added": "^Emphasized “(.+?)”$",
|
||||
"emoji_reaction_ios_exclamation_removed": "^Removed an exclamation from “(.+?)”$",
|
||||
|
||||
"emoji_reaction_ios_question_mark_added": "^Questioned \u201C(.+?)\u201D$",
|
||||
"emoji_reaction_ios_question_mark_removed": "^Removed a question mark from \u201C(.+?)\u201D$"
|
||||
"emoji_reaction_ios_question_mark_added": "^Questioned “(.+?)”$",
|
||||
"emoji_reaction_ios_question_mark_removed": "^Removed a question mark from “(.+?)”$"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"emoji_reaction_google_messages_added": "^\u200AРеакция \u200B(.+?)\u200B на \"\u200A(.+?)\u200A\"\u200A$",
|
||||
"emoji_reaction_google_messages_removed": "^\u200AРеакция \u200C(.+?)\u200C удалена из \"\u200A(.+?)\u200A\"\u200A$"
|
||||
}
|
||||
@@ -23,6 +23,7 @@ import com.squareup.moshi.Moshi
|
||||
import dev.octoshrimpy.quik.manager.KeyManager
|
||||
import dev.octoshrimpy.quik.model.EmojiReaction
|
||||
import dev.octoshrimpy.quik.model.Message
|
||||
import dev.octoshrimpy.quik.util.EmojiPatternStrings
|
||||
import io.realm.Realm
|
||||
import io.realm.Sort
|
||||
import timber.log.Timber
|
||||
@@ -57,32 +58,43 @@ class EmojiReactionRepositoryImpl @Inject constructor(
|
||||
removalPatterns: LinkedHashMap<Regex, (MatchResult) -> ParsedEmojiReaction?>
|
||||
) {
|
||||
// Google Messages
|
||||
reactionPatterns[Regex(strings.googleAdded)] = { match -> ParsedEmojiReaction(match.groupValues[1], match.groupValues[2]) }
|
||||
removalPatterns[Regex(strings.googleRemoved)] = { match -> ParsedEmojiReaction(match.groupValues[1], match.groupValues[2], isRemoval = true) }
|
||||
strings.googleAdded?.let { pattern ->
|
||||
reactionPatterns[Regex(pattern)] = { match -> ParsedEmojiReaction(match.groupValues[1], match.groupValues[2]) }
|
||||
}
|
||||
strings.googleRemoved?.let { pattern ->
|
||||
removalPatterns[Regex(pattern)] = { match -> ParsedEmojiReaction(match.groupValues[1], match.groupValues[2], isRemoval = true) }
|
||||
}
|
||||
|
||||
// iOS tapbacks (order matters: specific before generic)
|
||||
val tapbacks = listOf(
|
||||
// iOS tapbacks (important to add these before generic emoji patterns as the regexes may overlap)
|
||||
listOf(
|
||||
Triple("❤️", strings.iosHeartAdded, strings.iosHeartRemoved),
|
||||
Triple("👍", strings.iosLikeAdded, strings.iosLikeRemoved),
|
||||
Triple("👎", strings.iosDislikeAdded, strings.iosDislikeRemoved),
|
||||
Triple("😂", strings.iosLaughAdded, strings.iosLaughRemoved),
|
||||
Triple("‼️", strings.iosExclamationAdded, strings.iosExclamationRemoved),
|
||||
Triple("❓", strings.iosQuestionMarkAdded, strings.iosQuestionMarkRemoved)
|
||||
)
|
||||
tapbacks.forEach { (emoji, added, removed) ->
|
||||
reactionPatterns[Regex(added)] = { match -> ParsedEmojiReaction(emoji, match.groupValues[1]) }
|
||||
|
||||
removalPatterns[Regex(removed)] = { match -> ParsedEmojiReaction(emoji, match.groupValues[1], isRemoval = true) }
|
||||
).forEach { (emoji, added, removed) ->
|
||||
added?.let {
|
||||
reactionPatterns[Regex(it)] =
|
||||
{ match -> ParsedEmojiReaction(emoji, match.groupValues[1]) }
|
||||
}
|
||||
removed?.let {
|
||||
removalPatterns[Regex(it)] =
|
||||
{ match -> ParsedEmojiReaction(emoji, match.groupValues[1], isRemoval = true) }
|
||||
}
|
||||
}
|
||||
|
||||
// Generic iOS emoji patterns
|
||||
reactionPatterns[Regex(strings.iosGenericAdded)] = { match ->
|
||||
if (match.groupValues.getOrNull(1) == "with a sticker") null // TODO: localize "with a sticker"
|
||||
else ParsedEmojiReaction(match.groupValues[1], match.groupValues[2])
|
||||
strings.iosGenericAdded?.let { pattern ->
|
||||
reactionPatterns[Regex(pattern)] = { match ->
|
||||
if (match.groupValues.getOrNull(1) == "with a sticker") null // TODO: localize "with a sticker"
|
||||
else ParsedEmojiReaction(match.groupValues[1], match.groupValues[2])
|
||||
}
|
||||
}
|
||||
removalPatterns[Regex(strings.iosGenericRemoved)] = { match ->
|
||||
// TODO: sticker?
|
||||
ParsedEmojiReaction(match.groupValues[1], match.groupValues[2], isRemoval = true)
|
||||
strings.iosGenericRemoved?.let { pattern ->
|
||||
removalPatterns[Regex(pattern)] = { match ->
|
||||
ParsedEmojiReaction(match.groupValues[1], match.groupValues[2], isRemoval = true)
|
||||
}
|
||||
}
|
||||
|
||||
Timber.d("Loaded emoji regex patterns for $localeTag from assets")
|
||||
|
||||
+18
-18
@@ -1,31 +1,31 @@
|
||||
package dev.octoshrimpy.quik.repository
|
||||
package dev.octoshrimpy.quik.util
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
||||
@JsonClass(generateAdapter = false)
|
||||
data class EmojiPatternStrings(
|
||||
@Json(name = "emoji_reaction_google_messages_added") val googleAdded: String,
|
||||
@Json(name = "emoji_reaction_google_messages_removed") val googleRemoved: String,
|
||||
@Json(name = "emoji_reaction_google_messages_added") val googleAdded: String? = null,
|
||||
@Json(name = "emoji_reaction_google_messages_removed") val googleRemoved: String? = null,
|
||||
|
||||
@Json(name = "emoji_reaction_ios_generic_added") val iosGenericAdded: String,
|
||||
@Json(name = "emoji_reaction_ios_generic_removed") val iosGenericRemoved: String,
|
||||
@Json(name = "emoji_reaction_ios_generic_added") val iosGenericAdded: String? = null,
|
||||
@Json(name = "emoji_reaction_ios_generic_removed") val iosGenericRemoved: String? = null,
|
||||
|
||||
@Json(name = "emoji_reaction_ios_heart_added") val iosHeartAdded: String,
|
||||
@Json(name = "emoji_reaction_ios_heart_removed") val iosHeartRemoved: String,
|
||||
@Json(name = "emoji_reaction_ios_heart_added") val iosHeartAdded: String? = null,
|
||||
@Json(name = "emoji_reaction_ios_heart_removed") val iosHeartRemoved: String? = null,
|
||||
|
||||
@Json(name = "emoji_reaction_ios_like_added") val iosLikeAdded: String,
|
||||
@Json(name = "emoji_reaction_ios_like_removed") val iosLikeRemoved: String,
|
||||
@Json(name = "emoji_reaction_ios_like_added") val iosLikeAdded: String? = null,
|
||||
@Json(name = "emoji_reaction_ios_like_removed") val iosLikeRemoved: String? = null,
|
||||
|
||||
@Json(name = "emoji_reaction_ios_dislike_added") val iosDislikeAdded: String,
|
||||
@Json(name = "emoji_reaction_ios_dislike_removed") val iosDislikeRemoved: String,
|
||||
@Json(name = "emoji_reaction_ios_dislike_added") val iosDislikeAdded: String? = null,
|
||||
@Json(name = "emoji_reaction_ios_dislike_removed") val iosDislikeRemoved: String? = null,
|
||||
|
||||
@Json(name = "emoji_reaction_ios_laugh_added") val iosLaughAdded: String,
|
||||
@Json(name = "emoji_reaction_ios_laugh_removed") val iosLaughRemoved: String,
|
||||
@Json(name = "emoji_reaction_ios_laugh_added") val iosLaughAdded: String? = null,
|
||||
@Json(name = "emoji_reaction_ios_laugh_removed") val iosLaughRemoved: String? = null,
|
||||
|
||||
@Json(name = "emoji_reaction_ios_exclamation_added") val iosExclamationAdded: String,
|
||||
@Json(name = "emoji_reaction_ios_exclamation_removed") val iosExclamationRemoved: String,
|
||||
@Json(name = "emoji_reaction_ios_exclamation_added") val iosExclamationAdded: String? = null,
|
||||
@Json(name = "emoji_reaction_ios_exclamation_removed") val iosExclamationRemoved: String? = null,
|
||||
|
||||
@Json(name = "emoji_reaction_ios_question_mark_added") val iosQuestionMarkAdded: String,
|
||||
@Json(name = "emoji_reaction_ios_question_mark_removed") val iosQuestionMarkRemoved: String,
|
||||
)
|
||||
@Json(name = "emoji_reaction_ios_question_mark_added") val iosQuestionMarkAdded: String? = null,
|
||||
@Json(name = "emoji_reaction_ios_question_mark_removed") val iosQuestionMarkRemoved: String? = null,
|
||||
)
|
||||
Reference in New Issue
Block a user