Skip to content

Translations #898

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "code/translate_repo"]
path = code/translate_repo
url = https://github.com/buildingSMART/IFC4.3.x-output.git
branch = translations
2 changes: 1 addition & 1 deletion code/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ To load example files, you can clone the sample files into a directory called
```bash
$ cd /path/to/IFC4.3.x-development
$ cd ..
$ git clone https://github.com/buildingSMART/Sample-Test-Files.git examples
$ git clone https://github.com/buildingSMART/IFC4.3.x-sample-models examples
```

You can now visit `http://127.0.0.1:5000/` to see the running website.
Expand Down
1 change: 1 addition & 0 deletions code/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ numpy
pydot
pysolr
tabulate
polib
90 changes: 84 additions & 6 deletions code/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ def BeautifulSoup(*args):
import md as mdp
from extract_concepts_from_xmi import parse_bindings

from translate import translate

app = Flask(__name__)

is_iso = os.environ.get('ISO', '0') == '1'
Expand All @@ -58,6 +60,44 @@ def BeautifulSoup(*args):
else:
base = "/IFC/RELEASE/IFC4x3/HTML"

language_flag_map = {
"English_UK": "🇬🇧",
"Arabic": "🇸🇦",
"Chinese Simplified": "🇨🇳",
"Croatian": "🇭🇷",
"Czech": "🇨🇿",
"Danish": "🇩🇰",
"Dutch": "🇳🇱",
"English": "🇺🇸",
"Finnish": "🇫🇮",
"French": "🇫🇷",
"German": "🇩🇪",
"Hindi": "🇮🇳",
"Icelandic": "🇮🇸",
"Italian": "🇮🇹",
"Japanese": "🇯🇵",
"Korean": "🇰🇷",
"Lithuanian": "🇱🇹",
"Norwegian": "🇳🇴",
"Polish": "🇵🇱",
"Portuguese": "🇵🇹",
"Portuguese_Brazilian": "🇧🇷",
"Romanian": "🇷🇴",
"Slovenian": "🇸🇮",
"Spanish": "🇪🇸",
"Swedish": "🇸🇪",
"Turkish": "🇹🇷",
}

def get_translation_data(resource):
language_preference = request.cookies.get('languagePreference', 'English_UK')
translation = translate(resource, language_preference)
language_icon = language_flag_map.get(language_preference, '🇬🇧')
return {
'translation': translation,
'language_icon': language_icon,
'language_preference': language_preference
}


def make_url(fragment=None):
Expand Down Expand Up @@ -850,6 +890,7 @@ def api_resource(resource):

@app.route(make_url("property/<prop>.htm"))
def property(prop):
translation_data = get_translation_data(prop)
prop = "".join(c for c in prop if c.isalnum() or c in "_")
md = os.path.join(REPO_DIR, "docs", "properties", prop[0].lower(), prop + ".md")
try:
Expand All @@ -865,13 +906,15 @@ def property(prop):
html = process_markdown(prop, mdc)

html += tabulate.tabulate(psets, headers=["Referenced in"], tablefmt="html")

return render_template(
"property.html",
navigation=get_navigation(),
content=html,
number=idx,
entity=prop,
translation=translation_data.get('translation', ''),
language_icon = translation_data.get('language_icon', '🇬🇧'),
path=md[len(REPO_DIR) + 1 :].replace("\\", "/"),
)

Expand Down Expand Up @@ -1000,6 +1043,7 @@ def process_markdown(resource, mdc, process_quotes=True, number_headings=False,

@app.route(make_url("lexical/<resource>.htm"))
def resource(resource):
translation_data = get_translation_data(resource)
try:
idx = name_to_number()[resource]
except:
Expand Down Expand Up @@ -1054,7 +1098,9 @@ def resource(resource):
is_deprecated=resource in R.deprecated_entities,
is_abstract=resource in R.abstract_entities,
mvds=mvds,
is_product_or_type=is_product_or_type
is_product_or_type=is_product_or_type,
translation=translation_data.get('translation'),
language_icon=translation_data.get('language_icon')
)
elif resource in R.pset_definitions.keys():
return render_template(
Expand All @@ -1068,25 +1114,47 @@ def resource(resource):
applicability=get_applicability(resource),
properties=get_properties(resource, mdc),
changelog=get_changelog(resource),
translation=translation_data.get('translation'),
language_icon = translation_data.get('language_icon')
)
builder = resource_documentation_builder(resource)
content = get_definition(resource, mdc)
type_values = get_type_values(resource, mdc, request.cookies.get('languagePreference', 'English_UK'))

# check and append if the translated type values contain an addition to class description translation.
additional_class_description_translation = next(iter(s), None) if len(s := set([v['translated_description'] for v in type_values['schema_values'] if v['translated_description'].strip()])) == 1 else None

# in case there is a translated description, add it to the class description (one block down)
if additional_class_description_translation:
soup = BeautifulSoup(content)
translated_p = soup.new_tag("p")
translated_p['style'] = 'color: #0277bd' # to be adjusted to the BSI style color
translated_p.string = f"{translation_data.get('language_icon')} {additional_class_description_translation}"

last_p = soup.body.find_all('p')[-1]
last_p.insert_after(translated_p)

content = str(soup)

return render_template(
"type.html",
navigation=get_navigation(resource),
content=get_definition(resource, mdc),
content=content,
number=idx,
definition_number=definition_number,
entity=resource,
path=md[len(REPO_DIR) :].replace("\\", "/"),
type_values=get_type_values(resource, mdc),
type_values=type_values,
formal_propositions=get_formal_propositions(resource, builder),
formal_representation=get_formal_representation(resource),
references=get_references(resource),
changelog=get_changelog(resource),
translation=translation_data.get('translation'),
language_icon = translation_data.get('language_icon')
)


def get_type_values(resource, mdc):
def get_type_values(resource, mdc, language_preference):
values = R.type_values.get(resource)
if not values:
return
Expand All @@ -1105,7 +1173,17 @@ def get_type_values(resource, mdc):
break
description.append(sibling)
description = str(description)
described_values.append({"name": value, "description": description})
translation_lookup_v = f"{resource.removesuffix('Enum')}{value}"
translation = translate(translation_lookup_v, language_preference)
described_values.append(
{
"name": value,
"name_translation": translation.get('resource_translation'),
"description": description,
"translated_definition": translation.get('definition'),
'translated_description': translation.get('description')
}
)
values = described_values
return {"number": SectionNumberGenerator.generate(), "has_description": has_description, "schema_values": values}

Expand Down
24 changes: 23 additions & 1 deletion code/templates/entity.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
{% extends "main.html" %}
{% block pagecontent %}

<h1>{{ number }} {{ entity}}</h1>
<h1>{{ number }} {{ entity }}</h1>

<p>
<aside class="aside-note">
<mark>TRANSLATION</mark>
<div>
{% set translations = {
'resource_translation': 'Name:',
'definition': 'Definition:',
'description': 'Description:'
} %}

{% for key, label in translations.items() %}
{% if translation[key] %}
<div>
<span style="color: #0277bd;">&nbsp;{{ language_icon }}</span>
<em style="color: black;">{{ label }}</em>
<span style="color: #0277bd;">&nbsp;{{ translation[key] | safe }}</span>
</div>
{% endif %}
{% endfor %}
</div>
</aside>
</p>
{% if not is_iso %}
{% if is_product_or_type %}
<p><aside class="aside-note"><mark>NOTE</mark> This entity is a subtype of IfcProduct or IfcTypeProduct and hence part of every standardized schema subset and implementation level.</aside></p>
Expand Down
36 changes: 35 additions & 1 deletion code/templates/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,42 @@
{% endif %}
</p>
{% endif %}

{% if not is_iso %}
<!-- WIP; adjust to the BSI Styling and/or insert nicer button -->
<div style="float: left; margin-left: 80px;">
<label for="language-selector" style="font-weight: bold; margin-right: 10px;"></label>
<select id="language-selector" onchange="setLanguagePreference(this.value)" style="border: none; background: none; color: inherit;">
<option value="English_UK" selected>🇬🇧 English</option>
<option value="Arabic">🇸🇦 Arabic</option>
<option value="Chinese Simplified">🇨🇳 Chinese</option>
<option value="Croatian">🇭🇷 Croatian</option>
<option value="Czech">🇨🇿 Czech</option>
<option value="Danish">🇩🇰 Danish</option>
<option value="Dutch">🇳🇱 Dutch</option>
<option value="English">🇺🇸 English (US)</option>
<option value="Finnish">🇫🇮 Finnish</option>
<option value="French">🇫🇷 French</option>
<option value="German">🇩🇪 German</option>
<option value="Hindi">🇮🇳 Hindi</option>
<option value="Icelandic">🇮🇸 Icelandic</option>
<option value="Italian">🇮🇹 Italian</option>
<option value="Japanese">🇯🇵 Japanese</option>
<option value="Korean">🇰🇷 Korean</option>
<option value="Lithuanian">🇱🇹 Lithuanian</option>
<option value="Norwegian">🇳🇴 Norwegian</option>
<option value="Polish">🇵🇱 Polish</option>
<option value="Portuguese">🇵🇹 Portuguese</option>
<option value="Portuguese_Brazilian">🇧🇷 Portuguese (Brazilian)</option>
<option value="Romanian">🇷🇴 Romanian</option>
<option value="Slovenian">🇸🇮 Slovenian</option>
<option value="Spanish">🇪🇸 Spanish</option>
<option value="Swedish">🇸🇪 Swedish</option>
<option value="Turkish">🇹🇷 Turkish</option>
</select>
</div>


<ul>
<li>
{% if is_package %}
Expand Down
10 changes: 10 additions & 0 deletions code/templates/property.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@

<h1>{{ number }} {{ entity}}</h1>

<p>
<aside class="aside-note">
<mark>TRANSLATION</mark>
<div>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To do; styling similar as entity.html

<p><strong></strong> {{ translation.definition | safe}}</p>
<p><strong></strong> {{ translation.description | safe }}</p>
</div>
</aside>
</p>

<h2>
{{ definition_number }} Semantic definition
</h2>
Expand Down
25 changes: 22 additions & 3 deletions code/templates/type.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@

<h1>{{ number }} {{ entity}}</h1>

<p>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To do; styling similar as entity.html

<aside class="aside-note">
<mark>TRANSLATION</mark>
<div>
<p><strong></strong> {{ translation.definition | safe}}</p>
<p><strong></strong> {{ translation.description | safe }}</p>
</div>
</aside>
</p>


<h2>
{{ definition_number }} Semantic definition
</h2>
Expand All @@ -25,19 +36,27 @@ <h2>
<tbody>
{% for value in type_values.schema_values %}
<tr>
<td data-label="Name">
<code>{{ value.name }}</code>
{% if value.name_translation %}
<br>
<span style="color: #0277bd;">&nbsp;{{ language_icon }} &nbsp;{{ value.name_translation | safe }}</span>
{% endif %}
</td>
{% if type_values.has_description %}
<td data-label="Name"><code>{{ value.name }}</code</td>
<td data-label="Description">
{% if value.description %}
{{ value.description | safe }}
{% if value.translated_definition %}
<br>
<span style="color: #0277bd;">{{ language_icon }} &nbsp;{{value.translated_definition | safe }}</span>
{% endif %}
{% else %}
<p>
<em>No description available.</em>
</p>
{% endif %}
</td>
{% else %}
<td data-label="Name">{{ value }}</td>
{% endif %}
</tr>
{% endfor %}
Expand Down
Loading