package com.axelor.apps.base.web;

import com.axelor.apps.base.db.Language;
import com.axelor.apps.base.db.repo.LanguageRepository;
import com.axelor.apps.message.db.Template;
import com.axelor.apps.message.db.repo.TemplateRepository;
import com.axelor.apps.message.service.TemplateMessageService;
import com.axelor.rpc.ActionRequest;
import com.axelor.rpc.ActionResponse;
import com.axelor.rpc.Context;
import com.google.inject.Inject;

import java.util.LinkedHashMap;
import java.util.Map;

public class GenerateMessageController {

    @Inject
    private TemplateMessageService templateMessageService;

    @Inject
    private TemplateRepository templateRepo;

    @Inject
    private LanguageRepository languageRepo;

    public void templateDomain(ActionRequest request, ActionResponse response) {
        Context context = request.getContext();

        String model = (String) context.get("_templateContextModel");

//        Object templateObj = context.get("_xTemplate");
//        Template template;
//        if (templateObj == null) {
//            template = null;
//        } else if (templateObj instanceof Map) {
//            Map<String, Object> templateMap = (Map<String, Object>) templateObj;
//            template = templateRepo.find( Long.parseLong(templateMap.get("id").toString()) );
//        } else if (templateObj instanceof Template) {
//            template = (Template) templateObj;
//        } else {
//            throw new IllegalArgumentException("erreur...");
//        }

        Object languageObj = context.get("language");
        Language language;
        if (languageObj == null) {
            language = null;
        } else if (languageObj instanceof Map) {
            Map<String, Object> languageMap = (Map<String, Object>) languageObj;
            language = languageRepo.find( Long.parseLong(languageMap.get("id").toString()) );
        } else if (languageObj instanceof Language) {
            language = (Language) languageObj;
        } else {
            throw new IllegalArgumentException("erreur...");
        }

        String domain;

        if (language == null) {
            domain = "self.metaModel.fullName = '" + model + "' and self.isSystem != true";
        } else {
            domain = "self.metaModel.fullName = '" + model + "' and self.isSystem != true and self.language.id = " + language.getId();
        }

        response.setAttr("_xTemplate","domain",domain);
    }

}

package com.axelor.apps.base.web;

import com.axelor.apps.base.db.Language;
import com.axelor.apps.base.db.repo.LanguageRepository;
import com.axelor.apps.message.db.Template;
import com.axelor.apps.message.db.repo.TemplateRepository;
import com.axelor.apps.message.service.TemplateMessageService;
import com.axelor.rpc.ActionRequest;
import com.axelor.rpc.ActionResponse;
import com.axelor.rpc.Context;
import com.google.inject.Inject;

import java.util.LinkedHashMap;
import java.util.Map;

public class GenerateMessageController {

    @Inject
    private TemplateMessageService templateMessageService;

    @Inject
    private TemplateRepository templateRepo;

    @Inject
    private LanguageRepository languageRepo;

    public void templateDomain(ActionRequest request, ActionResponse response) {
        Context context = request.getContext();

        String model = (String) context.get("_templateContextModel");

        Object languageObj = context.get("language");
        Language language;
        if (languageObj == null) {
            language = null;
        } else if (languageObj instanceof Map) {
            Map<String, Object> languageMap = (Map<String, Object>) languageObj;
            language = languageRepo.find( Long.parseLong(languageMap.get("id").toString()) );
        } else if (languageObj instanceof Language) {
            language = (Language) languageObj;
        } else {
            throw new IllegalArgumentException("erreur...");
        }

        String domain;

        if (language == null) {
            domain = "self.metaModel.fullName = '" + model + "' and self.isSystem != true";
        } else {
            domain = "self.metaModel.fullName = '" + model + "' and self.isSystem != true and self.language.id = " + language.getId();
        }

        response.setAttr("_xTemplate","domain",domain);
    }

}

Update GenerateMessageController.java