Translations for Akkoma (#934)
* Translations for Akkoma * simplify akkoma translation code --------- Co-authored-by: sk <sk22@mailbox.org>
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
package org.joinmastodon.android.model;
|
||||
|
||||
public class AkkomaTranslation extends BaseModel{
|
||||
public String text;
|
||||
public String detectedLanguage;
|
||||
|
||||
public Translation toTranslation() {
|
||||
Translation translation=new Translation();
|
||||
translation.content=text;
|
||||
translation.detectedSourceLanguage=detectedLanguage;
|
||||
translation.provider="Akkoma";
|
||||
return translation;
|
||||
}
|
||||
}
|
||||
@@ -161,11 +161,15 @@ public class Instance extends BaseModel{
|
||||
case BUBBLE_TIMELINE -> pleromaFeatures
|
||||
.map(f -> f.contains("bubble_timeline"))
|
||||
.orElse(false);
|
||||
case MACHINE_TRANSLATION -> pleromaFeatures
|
||||
.map(f -> f.contains("akkoma:machine_translation"))
|
||||
.orElse(false);
|
||||
};
|
||||
}
|
||||
|
||||
public enum Feature {
|
||||
BUBBLE_TIMELINE
|
||||
BUBBLE_TIMELINE,
|
||||
MACHINE_TRANSLATION
|
||||
}
|
||||
|
||||
@Parcel
|
||||
|
||||
@@ -220,10 +220,11 @@ public class Status extends BaseModel implements DisplayItemsParent, Searchable{
|
||||
|
||||
public static final Pattern BOTTOM_TEXT_PATTERN = Pattern.compile("(?:[\uD83E\uDEC2\uD83D\uDC96✨\uD83E\uDD7A,]+|❤️)(?:\uD83D\uDC49\uD83D\uDC48(?:[\uD83E\uDEC2\uD83D\uDC96✨\uD83E\uDD7A,]+|❤️))*\uD83D\uDC49\uD83D\uDC48");
|
||||
public boolean isEligibleForTranslation(AccountSession session){
|
||||
Instance instanceInfo = AccountSessionManager.getInstance().getInstanceInfo(session.domain);
|
||||
boolean translateEnabled = instanceInfo != null &&
|
||||
instanceInfo.v2 != null && instanceInfo.v2.configuration.translation != null &&
|
||||
instanceInfo.v2.configuration.translation.enabled;
|
||||
Instance instanceInfo=AccountSessionManager.getInstance().getInstanceInfo(session.domain);
|
||||
boolean translateEnabled=instanceInfo!=null && (
|
||||
(instanceInfo.v2!=null && instanceInfo.v2.configuration.translation!=null && instanceInfo.v2.configuration.translation.enabled) ||
|
||||
(instanceInfo.isAkkoma() && instanceInfo.hasFeature(Instance.Feature.MACHINE_TRANSLATION))
|
||||
);
|
||||
|
||||
try {
|
||||
Pair<String, List<String>> decoded=BOTTOM_TEXT_PATTERN.matcher(getStrippedText()).find()
|
||||
|
||||
Reference in New Issue
Block a user