Skip to content

Commit

Permalink
machinery: Drop Microsoft Terminology service
Browse files Browse the repository at this point in the history
The API is no longer provided by Microsoft, so there is no point in
keeping the integration.

Fixes WeblateOrg#10388
  • Loading branch information
nijel committed Nov 24, 2023
1 parent 525837b commit a2f0d88
Show file tree
Hide file tree
Showing 14 changed files with 30 additions and 279 deletions.
17 changes: 0 additions & 17 deletions docs/admin/machine.rst
Original file line number Diff line number Diff line change
Expand Up @@ -243,23 +243,6 @@ and there are several mirrors available to use the API for free.
`LibreTranslate repository <https://github.com/LibreTranslate/LibreTranslate>`_,
`LibreTranslate mirrors <https://github.com/LibreTranslate/LibreTranslate#user-content-mirrors>`_

.. _mt-microsoft-terminology:

Microsoft Terminology
---------------------

:Service ID: ``microsoft-terminology``
:Configuration: `This service has no configuration.`

The Microsoft Terminology Service API allows you to programmatically access the
terminology, definitions and user interface (UI) strings available in the
Language Portal through a web service.

.. seealso::

`Microsoft language resources <https://learn.microsoft.com/en-us/globalization/reference/microsoft-language-resources>`_


.. _mt-microsoft-translator:

Microsoft Translator
Expand Down
2 changes: 2 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Not yet released.

**Compatibility**

* Dropped Microsoft Terminology service for automatic suggestions as it is no longer provided by Microsoft.

**Upgrading**

Please follow :ref:`generic-upgrade-instructions` in order to perform update.
Expand Down
2 changes: 0 additions & 2 deletions requirements-optional.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,3 @@ psycopg[binary]>=3.1.8,<4
python-akismet>=0.4.2,<0.5
# SAML
python3-saml>=1.2.1
# MSTerminology
zeep>=4.1.0,<4.3.0
91 changes: 0 additions & 91 deletions weblate/machinery/microsoftterminology.py

This file was deleted.

1 change: 0 additions & 1 deletion weblate/machinery/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class WeblateConf(AppConf):
"weblate.machinery.googlev3.GoogleV3Translation",
"weblate.machinery.libretranslate.LibreTranslateTranslation",
"weblate.machinery.microsoft.MicrosoftCognitiveTranslation",
"weblate.machinery.microsoftterminology.MicrosoftTerminologyService",
"weblate.machinery.modernmt.ModernMTTranslation",
"weblate.machinery.mymemory.MyMemoryTranslation",
"weblate.machinery.netease.NeteaseSightTranslation",
Expand Down
159 changes: 0 additions & 159 deletions weblate/machinery/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@
from weblate.machinery.ibm import IBMTranslation
from weblate.machinery.libretranslate import LibreTranslateTranslation
from weblate.machinery.microsoft import MicrosoftCognitiveTranslation
from weblate.machinery.microsoftterminology import (
MST_API_URL,
MicrosoftTerminologyService,
)
from weblate.machinery.modernmt import ModernMTTranslation
from weblate.machinery.mymemory import MyMemoryTranslation
from weblate.machinery.netease import NETEASE_API_ROOT, NeteaseSightTranslation
Expand Down Expand Up @@ -151,111 +147,6 @@
]
}

TERMINOLOGY_LANGUAGES = b"""
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<GetLanguagesResponse xmlns="https://api.terminology.microsoft.com/terminology">
<GetLanguagesResult xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Language>
<Code>af-za</Code>
</Language>
<Language>
<Code>am-et</Code>
</Language>
<Language>
<Code>ar-dz</Code>
</Language>
<Language>
<Code>ar-eg</Code>
</Language>
<Language>
<Code>ar-sa</Code>
</Language>
<Language>
<Code>as-in</Code>
</Language>
<Language>
<Code>az-latn-az</Code>
</Language>
<Language>
<Code>be-by</Code>
</Language>
<Language>
<Code>bg-bg</Code>
</Language>
<Language>
<Code>bn-bd</Code>
</Language>
<Language>
<Code>bn-in</Code>
</Language>
<Language>
<Code>bs-cyrl-ba</Code>
</Language>
<Language>
<Code>bs-latn-ba</Code>
</Language>
<Language>
<Code>ca-es</Code>
</Language>
<Language>
<Code>ca-es-valencia</Code>
</Language>
<Language>
<Code>chr-cher-us</Code>
</Language>
<Language>
<Code>cs-cz</Code>
</Language>
<Language>
<Code>en-us</Code>
</Language>
</GetLanguagesResult>
</GetLanguagesResponse>
</s:Body>
</s:Envelope>
"""
TERMINOLOGY_TRANSLATE = b"""
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<GetTranslationsResponse xmlns="https://api.terminology.microsoft.com/terminology">
<GetTranslationsResult xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Match>
<ConfidenceLevel>100</ConfidenceLevel>
<Count>8</Count>
<Definition i:nil="true"/>
<OriginalText>Hello World</OriginalText>
<Product i:nil="true"/>
<ProductVersion i:nil="true"/>
<Source i:nil="true"/>
<Translations>
<Translation>
<Language>cs-cz</Language>
<TranslatedText>Hello World</TranslatedText>
</Translation>
</Translations>
</Match>
<Match>
<ConfidenceLevel>100</ConfidenceLevel>
<Count>1</Count>
<Definition i:nil="true"/>
<OriginalText>Hello world.</OriginalText>
<Product i:nil="true"/>
<ProductVersion i:nil="true"/>
<Source i:nil="true"/>
<Translations>
<Translation>
<Language>cs-cz</Language>
<TranslatedText>Ahoj sv&#x11B;te.</TranslatedText>
</Translation>
</Translations>
</Match>
</GetTranslationsResult>
</GetTranslationsResponse>
</s:Body>
</s:Envelope>
"""
TERMINOLOGY_WDSL = get_test_file("microsoftterminology.wsdl")

with open(get_test_file("googlev3.json")) as handle:
GOOGLEV3_KEY = handle.read()
Expand Down Expand Up @@ -619,56 +510,6 @@ def mock_response(self):
)


class MicrosoftTerminologyServiceTest(BaseMachineTranslationTest):
MACHINE_CLS = MicrosoftTerminologyService
ENGLISH = "en-us"
SUPPORTED = "cs-cz"
EXPECTED_LEN = 2

def mock_empty(self):
raise SkipTest("Not tested")

def mock_error(self):
self.mock_response(fail=True)

def mock_response(self, fail=False):
def request_callback_get(request):
headers = {}
if request.path_url == "/Terminology.svc?wsdl":
with open(TERMINOLOGY_WDSL, "rb") as handle:
return (200, headers, handle.read())
if request.path_url.startswith("/Terminology.svc?wsdl="):
suffix = request.path_url[22:]
with open(TERMINOLOGY_WDSL + "." + suffix, "rb") as handle:
return (200, headers, handle.read())
if request.path_url.startswith("/Terminology.svc?xsd="):
suffix = request.path_url[21:]
with open(TERMINOLOGY_WDSL + "." + suffix, "rb") as handle:
return (200, headers, handle.read())
return (500, headers, "")

def request_callback_post(request):
headers = {}
if fail:
return (500, headers, "")
if b"GetLanguages" in request.body:
return (200, headers, TERMINOLOGY_LANGUAGES)
return (200, headers, TERMINOLOGY_TRANSLATE)

responses.add_callback(
responses.GET,
MST_API_URL,
callback=request_callback_get,
content_type="text/xml",
)
responses.add_callback(
responses.POST,
MST_API_URL,
callback=request_callback_post,
content_type="text/xml",
)


class GoogleTranslationTest(BaseMachineTranslationTest):
MACHINE_CLS = GoogleTranslation
EXPECTED_LEN = 1
Expand Down
25 changes: 23 additions & 2 deletions weblate/machinery/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ def settings_dict(self):
return self.global_settings_dict


class DeprecatedMachinery:
def __init__(self, identifier: str):
self.identifier = self.name = identifier
self.settings_form = None

def get_identifier(self) -> str:
return self.identifier


class MachineryConfiguration:
def __init__(
self,
Expand All @@ -72,6 +81,10 @@ def __init__(
def is_enabled(self):
return self.configuration is not None

@property
def is_available(self):
return not isinstance(self.machinery, DeprecatedMachinery)

@property
def id(self):
return self.machinery.get_identifier()
Expand Down Expand Up @@ -122,8 +135,16 @@ def post_setup(self, request, kwargs):

def get_configured_services(self):
for service, configuration in self.settings_dict.items():
machinery = MACHINERY[service]
yield MachineryConfiguration(machinery, configuration, project=self.project)
try:
machinery = MACHINERY[service]
except KeyError:
yield MachineryConfiguration(
DeprecatedMachinery(service), configuration, project=self.project
)
else:
yield MachineryConfiguration(
machinery, configuration, project=self.project
)

def get_context_data(self, **kwargs):
result = super().get_context_data(**kwargs)
Expand Down
6 changes: 5 additions & 1 deletion weblate/templates/machinery/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@ <h4>
{% endif %}
{% endif %}
{{ service.name }}
{% documentation_icon "admin/machine" service.doc_anchor %}
{% if service.is_available %}
{% documentation_icon "admin/machine" service.doc_anchor %}
{% else %}
<span class="badge badge-danger">{% trans "Service is no longer available" %}</span>
{% endif %}
</h4>
1 change: 0 additions & 1 deletion weblate/trans/tests/data/microsoftterminology.wsdl

This file was deleted.

Loading

0 comments on commit a2f0d88

Please sign in to comment.