Skip to content

Commit

Permalink
Add QE APIs support in Language pages (#549)
Browse files Browse the repository at this point in the history
* Add QE APIs to languages and fix languages nav bar

* Exclude languages from nav bar and improve wording

---------

Co-authored-by: Tovmas <[email protected]>
  • Loading branch information
tovmasharrison and Tovmas authored Oct 21, 2023
1 parent a2188c5 commit 1184139
Show file tree
Hide file tree
Showing 229 changed files with 2,050 additions and 250 deletions.
35 changes: 32 additions & 3 deletions _layouts/language.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ <h2>
<p>
Machine translation for the <strong>{{ page.title }}</strong> language is supported by <a href="#machine-translation">{{ page.supported_apis | size }} machine translation APIs</a>.
</p>
<p>
Quality estimation for the <strong>{{ page.title }}</strong> language is supported by <a href="#quality-estimation">{{ page.supported_qe_apis | size }} quality estimation APIs</a>.
</p>

<blockquote>

Expand Down Expand Up @@ -54,13 +57,13 @@ <h2>
{{ content }}

<section id="machine-translation">
<h2>API support</h2>
<h2>Machine translation</h2>
<details>
<summary>
{% if page.supported_apis.size == 1 %}
<strong>1</strong> API supports {{ page.title }}.
<strong>1</strong> machine translation API supports {{ page.title }}.
{% else %}
<strong>{{ page.supported_apis | size }}</strong> APIs support {{ page.title }}.
<strong>{{ page.supported_apis | size }}</strong> machine translation APIs support {{ page.title }}.
{% endif %}
<p class="preview hint">
{{ page.supported_apis | slice: 0, 5 | map: 'name' | join: ', ' }}
Expand All @@ -78,3 +81,29 @@ <h2>API support</h2>
</ul>
</details>
</section>

<section id="quality-estimation">
<h2>Quality estimation</h2>
<details>
<summary>
{% if page.supported_qe_apis.size == 1 %}
<strong>1</strong> quality estimation API supports {{ page.title }}.
{% else %}
<strong>{{ page.supported_qe_apis | size }}</strong> quality estimation APIs support {{ page.title }}.
{% endif %}
<p class="preview hint">
{{ page.supported_qe_apis | slice: 0, 5 | map: 'name' | join: ', ' }}
{% if page.supported_qe_apis.size > 5 %}, …{% endif %}
</p>
</summary>
<ul>
{% for qe_api in page.supported_qe_apis %}
<li>
<a href="/{{ qe_api.slug }}">
{{ qe_api.name }}
</a>
</li>
{% endfor %}
</ul>
</details>
</section>
56 changes: 36 additions & 20 deletions generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def slugify(name):
def flatten(l):
_ = []
for item in l:
if type(item) is list:
if isinstance(item, list):
_ += flatten(item)
else:
_.append(item)
Expand All @@ -122,22 +122,20 @@ def read_content(filepath):
i += len('\n---\n')
return page[i:].strip()

SUPPORTED_LANGUAGE_BASE_CODES = {}
for api in APIS:
api_id = api['id']

codes = flatten(api['languages'])


def normalize(code):
return normalize_language_code(code, api_id)

codes = map(normalize, codes)

codes = map(base_language_code, codes)
def supported_language_base_codes(file_name):
SUPPORTED_LANGUAGE_BASE_CODES = {}
for api in file_name:
api_id = api['id']
codes = flatten(api['languages'])

def normalize(code):
return normalize_language_code(code, api_id)

codes = map(normalize, codes)
codes = map(base_language_code, codes)

SUPPORTED_LANGUAGE_BASE_CODES[api_id] = list(set(codes))
SUPPORTED_LANGUAGE_BASE_CODES[api_id] = list(set(codes))
return SUPPORTED_LANGUAGE_BASE_CODES


### Write language families
Expand Down Expand Up @@ -191,6 +189,8 @@ def normalize(code):


### Write languages
API_SUPPORTED_LANGUAGE_BASE_CODES = supported_language_base_codes(APIS)
QE_API_SUPPORTED_LANGUAGE_BASE_CODES = supported_language_base_codes(QUALITY_ESTIMATION)
for language in LANGUAGES:
code = language['codes'][0]

Expand All @@ -212,7 +212,7 @@ def normalize(code):
# "Join"
supported_apis = []
for api in APIS:
codes = SUPPORTED_LANGUAGE_BASE_CODES[api['id']]
codes = API_SUPPORTED_LANGUAGE_BASE_CODES[api['id']]
if code in codes:
supported_apis.append({
'id': api['id'],
Expand All @@ -222,19 +222,34 @@ def normalize(code):

supported_apis.sort(key=lambda api: api['supported_language_count'])

supported_qe_apis =[]
for qe_api in QUALITY_ESTIMATION:
codes = QE_API_SUPPORTED_LANGUAGE_BASE_CODES[qe_api['id']]
if code in codes:
supported_qe_apis.append({
'slug': slugify(qe_api['name']),
'id': qe_api['id'],
'name': qe_api['name'],
'supported_language_count': len(codes)
})

supported_qe_apis.sort(key=lambda api: api['supported_language_count'])


desc = f'Machine translation for { name }'

frontmatter = {
'autogenerated': True,
'nav_exclude': True,
'nav_order': 1000 - len(supported_apis),
'nav_exclude': True,
'parent': 'Languages',
'layout': 'language',
'title': name,
'description': desc,
**language,
'family': family,
'supported_apis': supported_apis,
'supported_qe_apis': supported_qe_apis,
'seo': {
'name': desc,
'type': 'Language'
Expand Down Expand Up @@ -398,6 +413,7 @@ def normalize(code):

print(f'[{ text }]({ link })')


# Generate TMS files
QE_APIS_BY_ID = {api['id']: api for api in QUALITY_ESTIMATION}
APIS_BY_ID = {api['id']: api for api in APIS + AGGREGATORS}
Expand Down Expand Up @@ -492,7 +508,6 @@ def normalize(code):


### Generate Aggregators files

for a in AGGREGATORS:
a_id = a['id']
a_name = a['name']
Expand Down Expand Up @@ -548,8 +563,8 @@ def normalize(code):
{ content }
''')

### Generate Quality Estimation files

### Generate Quality Estimation files
for estimation in QUALITY_ESTIMATION:

name = estimation['name']
Expand Down Expand Up @@ -664,7 +679,8 @@ def normalize(code):
}
}

slug = slugify(name.replace('-', '').replace(' ', ' '))
slug = slugify(name)

filepath = f'quality-estimation/{ slug }.md'

content = read_content(filepath)
Expand Down
3 changes: 2 additions & 1 deletion languages/abkhaz.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
autogenerated: true
nav_exclude: true
nav_order: 998
nav_exclude: true
parent: Languages
layout: language
title: Abkhaz
Expand Down Expand Up @@ -30,6 +30,7 @@ supported_apis:
- id: alibaba
name: Alibaba Translate
supported_language_count: 212
supported_qe_apis: []
seo:
name: Machine translation for Abkhaz
type: Language
Expand Down
3 changes: 2 additions & 1 deletion languages/acehnese.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
autogenerated: true
nav_exclude: true
nav_order: 997
nav_exclude: true
parent: Languages
layout: language
title: Acehnese
Expand Down Expand Up @@ -33,6 +33,7 @@ supported_apis:
- id: niutrans
name: Niutrans
supported_language_count: 381
supported_qe_apis: []
seo:
name: Machine translation for Acehnese
type: Language
Expand Down
3 changes: 2 additions & 1 deletion languages/acholi.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
autogenerated: true
nav_exclude: true
nav_order: 998
nav_exclude: true
parent: Languages
layout: language
title: Acholi
Expand Down Expand Up @@ -31,6 +31,7 @@ supported_apis:
- id: niutrans
name: Niutrans
supported_language_count: 381
supported_qe_apis: []
seo:
name: Machine translation for Acholi
type: Language
Expand Down
15 changes: 14 additions & 1 deletion languages/afrikaans.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
autogenerated: true
nav_exclude: true
nav_order: 982
nav_exclude: true
parent: Languages
layout: language
title: Afrikaans
Expand Down Expand Up @@ -84,6 +84,19 @@ supported_apis:
- id: niutrans
name: Niutrans
supported_language_count: 381
supported_qe_apis:
- slug: phrase-mtqe
id: phrase-mtqe
name: Phrase MTQE
supported_language_count: 65
- slug: demt-estimate
id: demt-estimate
name: DeMT Estimate
supported_language_count: 109
- slug: modelfront
id: modelfront
name: ModelFront
supported_language_count: 126
seo:
name: Machine translation for Afrikaans
type: Language
Expand Down
3 changes: 2 additions & 1 deletion languages/akan.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
autogenerated: true
nav_exclude: true
nav_order: 996
nav_exclude: true
parent: Languages
layout: language
title: Akan
Expand Down Expand Up @@ -38,6 +38,7 @@ supported_apis:
- id: alibaba
name: Alibaba Translate
supported_language_count: 212
supported_qe_apis: []
seo:
name: Machine translation for Akan
type: Language
Expand Down
15 changes: 14 additions & 1 deletion languages/albanian.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
autogenerated: true
nav_exclude: true
nav_order: 983
nav_exclude: true
parent: Languages
layout: language
title: Albanian
Expand Down Expand Up @@ -85,6 +85,19 @@ supported_apis:
- id: niutrans
name: Niutrans
supported_language_count: 381
supported_qe_apis:
- slug: phrase-mtqe
id: phrase-mtqe
name: Phrase MTQE
supported_language_count: 65
- slug: demt-estimate
id: demt-estimate
name: DeMT Estimate
supported_language_count: 109
- slug: modelfront
id: modelfront
name: ModelFront
supported_language_count: 126
seo:
name: Machine translation for Albanian
type: Language
Expand Down
3 changes: 2 additions & 1 deletion languages/alemannic.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
autogenerated: true
nav_exclude: true
nav_order: 999
nav_exclude: true
parent: Languages
layout: language
title: Alemannic
Expand Down Expand Up @@ -42,6 +42,7 @@ supported_apis:
- id: textshuttle
name: Textshuttle
supported_language_count: 21
supported_qe_apis: []
seo:
name: Machine translation for Alemannic
type: Language
Expand Down
3 changes: 2 additions & 1 deletion languages/algerian-arabic.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
autogenerated: true
nav_exclude: true
nav_order: 999
nav_exclude: true
parent: Languages
layout: language
title: Algerian Arabic
Expand Down Expand Up @@ -34,6 +34,7 @@ supported_apis:
- id: baidu
name: Baidu Translate
supported_language_count: 197
supported_qe_apis: []
seo:
name: Machine translation for Algerian Arabic
type: Language
Expand Down
11 changes: 10 additions & 1 deletion languages/amharic.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
autogenerated: true
nav_exclude: true
nav_order: 987
nav_exclude: true
parent: Languages
layout: language
title: Amharic
Expand Down Expand Up @@ -66,6 +66,15 @@ supported_apis:
- id: niutrans
name: Niutrans
supported_language_count: 381
supported_qe_apis:
- slug: demt-estimate
id: demt-estimate
name: DeMT Estimate
supported_language_count: 109
- slug: modelfront
id: modelfront
name: ModelFront
supported_language_count: 126
seo:
name: Machine translation for Amharic
type: Language
Expand Down
Loading

0 comments on commit 1184139

Please sign in to comment.