Commit 4387cac6 authored by Thomas's avatar Thomas
Browse files

Use language of messages for translations with MinT

parent fec6b851
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -190,7 +190,7 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload
            binding.mediaDescription.setText(description);
            binding.translate.setOnClickListener(v -> {
                String descriptionToTranslate = attachments.get(mediaPosition - 1).description;
                TranslateHelper.translate(MediaActivity.this, descriptionToTranslate, translated -> {
                TranslateHelper.translate(MediaActivity.this, descriptionToTranslate, status.language, translated -> {
                    if (translated != null) {
                        attachments.get(mediaPosition - 1).translation = translated;
                        binding.mediaDescriptionTranslated.setText(translated);
@@ -239,7 +239,7 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload
                }
                binding.translate.setOnClickListener(v -> {
                    String descriptionToTranslate = attachments.get(position).description;
                    TranslateHelper.translate(MediaActivity.this, descriptionToTranslate, translated -> {
                    TranslateHelper.translate(MediaActivity.this, descriptionToTranslate, status.language, translated -> {
                        if (translated != null) {
                            attachments.get(position).translation = translated;
                            binding.mediaDescriptionTranslated.setText(translated);
+10 −2
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@ import es.dmoral.toasty.Toasty;

public class TranslateHelper {

    public static void translate(Context context, String toTranslate, Translate callback) {
    public static void translate(Context context, String toTranslate, String languageSource, Translate callback) {
        String statusToTranslate;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
            statusToTranslate = Html.fromHtml(toTranslate, Html.FROM_HTML_MODE_LEGACY).toString();
@@ -61,7 +61,15 @@ public class TranslateHelper {
        Params params = new Params();
        params.setSplit_sentences(false);
        params.setFormat(Params.fType.TEXT);
        if(et != MyTransL.translatorEngine.MINT) {
            params.setSource_lang("auto");
        } else {
            if(languageSource != null && !languageSource.isEmpty()) {
                params.setSource_lang(languageSource);
            } else {
                params.setSource_lang("en");
            }
        }
        if (translator.compareToIgnoreCase("FEDILAB") == 0) {
            myTransL.setLibretranslateDomain("translate.fedilab.app");
        } else if (translator.compareToIgnoreCase("LINGVA") == 0) {
+1 −1
Original line number Diff line number Diff line
@@ -74,7 +74,7 @@ public class ReleaseNoteAdapter extends RecyclerView.Adapter<ReleaseNoteAdapter.
            holder.binding.containerTrans.setVisibility(View.GONE);
            holder.binding.translate.setVisibility(View.VISIBLE);
        }
        holder.binding.translate.setOnClickListener(v -> TranslateHelper.translate(context, note.note, translated -> {
        holder.binding.translate.setOnClickListener(v -> TranslateHelper.translate(context, note.note, "en", translated -> {
            if (translated != null) {
                note.noteTranslated = translated;
                notifyItemChanged(holder.getBindingAdapterPosition());
+1 −1
Original line number Diff line number Diff line
@@ -2765,7 +2765,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
            statusToTranslate = Html.fromHtml(statusToDeal.content).toString();
        int countMorseChar = ComposeAdapter.countMorseChar(statusToTranslate);
        if (countMorseChar < 4) {
            TranslateHelper.translate(context, statusToDeal.content, translated -> {
            TranslateHelper.translate(context, statusToDeal.content, statusToDeal.language, translated -> {
                if (translated != null) {
                    statusToDeal.translationShown = true;
                    statusToDeal.translationContent = translated;
+0 −1
Original line number Diff line number Diff line
@@ -29,6 +29,5 @@ android {
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation("com.github.pemistahl:lingua:1.2.2")
    implementation "com.google.code.gson:gson:2.10.1"
}
Loading