168 lines
9.1 KiB
Python
168 lines
9.1 KiB
Python
#!/usr/bin/env python3
|
||
"""Batch-translate hardcoded English strings in generate-sds-lang.py HTML template."""
|
||
|
||
with open('/home/bachko/msds-tds/scripts/generate-sds-lang.py', 'r') as f:
|
||
c = f.read()
|
||
|
||
# Helper: replace exact string with a language-conditional
|
||
def tr(english, romanian):
|
||
"""Replace English literal with inline lang_code conditional."""
|
||
c_escaped = english.replace('"', '\\"').replace("'", "\\'")
|
||
old = f"<td>{english}</td>"
|
||
new = f"<td>{{'{romanian}' if lang_code == 'BG' else '{romanian}'}}</td>"
|
||
return c.replace(old, new)
|
||
|
||
# Section 2 hazard class names
|
||
c = c.replace(
|
||
'<tr><td>Flammable liquids</td><td>Category 2</td>',
|
||
"<tr><td>{'Запалими течности' if lang_code == 'BG' else 'Lichide inflamabile'}</td><td>{'Категория 2' if lang_code == 'BG' else 'Categoria 2'}</td>"
|
||
)
|
||
c = c.replace(
|
||
'<td>Serious eye damage/eye irritation</td><td>Category 2</td>',
|
||
"<td>{'Сериозно увреждане на очите/дразнене на очите' if lang_code == 'BG' else 'Leziuni oculare grave/iritare oculară'}</td><td>{'Категория 2' if lang_code == 'BG' else 'Categoria 2'}</td>"
|
||
)
|
||
c = c.replace(
|
||
'<td>STOT — Single exposure</td><td>Category 3 (Narcosis)</td>',
|
||
"<td>{'СТОО — еднократна експозиция' if lang_code == 'BG' else 'STOT — expunere unică'}</td><td>{'Категория 3 (Наркоза)' if lang_code == 'BG' else 'Categoria 3 (Narcoză)'}</td>"
|
||
)
|
||
|
||
# Section 5
|
||
c = c.replace(
|
||
'Water spray. Dry powder. Foam. Carbon dioxide.',
|
||
"{'Воден спрей. Сух прах. Пяна. Въглероден диоксид.' if lang_code == 'BG' else 'Apă pulverizată. Pulbere uscată. Spumă. Dioxid de carbon.'}"
|
||
)
|
||
c = c.replace(
|
||
'High volume water jet.',
|
||
"{'Водна струя под високо налягане.' if lang_code == 'BG' else 'Jet de apă de mare volum.'}"
|
||
)
|
||
|
||
# Section 8 labels
|
||
c = c.replace(
|
||
'<th colspan=\"2\">EU Occupational Exposure Limits (IOELV) — Ethyl acetate</th>',
|
||
"<th colspan=\"2\">{'Граници на професионална експозиция (IOELV)' if lang_code == 'BG' else 'Limite de expunere profesională UE (IOELV)'} — Ethyl acetate</th>"
|
||
)
|
||
c = c.replace(
|
||
'<td>DNEL/DMEL — Workers</td>',
|
||
"<td>{'DNEL/DMEL — Работници' if lang_code == 'BG' else 'DNEL/DMEL — Lucrători'}</td>"
|
||
)
|
||
c = c.replace(
|
||
'<td>DNEL/DMEL — General population</td>',
|
||
"<td>{'DNEL/DMEL — Общо население' if lang_code == 'BG' else 'DNEL/DMEL — Populația generală'}</td>"
|
||
)
|
||
for eng in ['Acute - inhalation', 'Long-term - dermal', 'Long-term - inhalation', 'Long-term - oral']:
|
||
c = c.replace('<td>' + eng + '</td>', "<td>{'" + eng + "' if lang_code == 'BG' else '" + eng + "'}</td>")
|
||
|
||
c = c.replace('<td>Freshwater</td>', "<td>{'Пресна вода' if lang_code == 'BG' else 'Apă dulce'}</td>")
|
||
c = c.replace('<td>Marine water</td>', "<td>{'Морска вода' if lang_code == 'BG' else 'Apă marină'}</td>")
|
||
c = c.replace('<td>Soil</td>', "<td>{'Почва' if lang_code == 'BG' else 'Sol'}</td>")
|
||
c = c.replace('<td>STP</td>', "<td>{'ПСОВ' if lang_code == 'BG' else 'STP (stație epurare)'}</td>")
|
||
c = c.replace('<td>Reference</td>', "<td>{'Препратка' if lang_code == 'BG' else 'Referință'}</td>")
|
||
c = c.replace('Directive (EU) 2017/164', "{'Директива (ЕС) 2017/164' if lang_code == 'BG' else 'Directiva (UE) 2017/164'}")
|
||
|
||
# Section 9
|
||
phys_chem = [
|
||
('Physical state', 'Състояние', 'Stare fizică'),
|
||
('Clear liquid', 'Прозрачна течност', 'Lichid limpede'),
|
||
('Colour / Odour', 'Цвят / Мирис', 'Culoare / Miros'),
|
||
('Colourless / Fruity', 'Безцветен / Плодов', 'Incolor / Fructat'),
|
||
('Melting point', 'Точка на топене', 'Punct de topire'),
|
||
('Boiling point', 'Точка на кипене', 'Punct de fierbere'),
|
||
('Flash point', 'Точка на запалване', 'Punct de aprindere'),
|
||
('Auto-ignition', 'Самозапалване', 'Auto-aprindere'),
|
||
('Flammability limits', 'Граници на запалимост', 'Limite de inflamabilitate'),
|
||
('Vapour pressure', 'Налягане на парите', 'Presiune de vapori'),
|
||
('Vapour density', 'Плътност на парите', 'Densitate de vapori'),
|
||
('Density', 'Плътност', 'Densitate'),
|
||
('Solubility (water)', 'Разтворимост (вода)', 'Solubilitate (apă)'),
|
||
('Log Pow', 'Log Pow', 'Log Pow'),
|
||
('Viscosity', 'Вискозитет', 'Vâscozitate'),
|
||
]
|
||
for eng, bg, ro in phys_chem:
|
||
c = c.replace(f'<td>{eng}</td>', f"<td>{{'{bg}' if lang_code == 'BG' else '{ro}'}}</td>")
|
||
|
||
# Section 10
|
||
c = c.replace(
|
||
'<p>Stable under normal conditions.</p>',
|
||
"<p>{'Стабилен при нормални условия.' if lang_code == 'BG' else 'Stabil în condiții normale.'}</p>"
|
||
)
|
||
|
||
# Section 11
|
||
c = c.replace(
|
||
'<th>Endpoint</th><th>Classification</th><th>Data</th>',
|
||
"<th>{'Крайна точка' if lang_code == 'BG' else 'Punct final'}</th><th>{'Класификация' if lang_code == 'BG' else 'Clasificare'}</th><th>Data</th>"
|
||
)
|
||
toxic = [
|
||
'Acute toxicity',
|
||
'Skin corrosion/irritation',
|
||
'Respiratory/skin sensitisation',
|
||
'Germ cell mutagenicity',
|
||
'Carcinogenicity',
|
||
'Reproductive toxicity',
|
||
'Aspiration hazard',
|
||
]
|
||
toxic_bg = [
|
||
'Остра токсичност',
|
||
'Корозия/дразнене на кожата',
|
||
'Респираторна или кожна сенсибилизация',
|
||
'Мутагенност на зародишни клетки',
|
||
'Канцерогенност',
|
||
'Токсичност за репродукцията',
|
||
'Опасност при аспирация',
|
||
]
|
||
toxic_ro = [
|
||
'Toxicitate acută',
|
||
'Corodarea/iritarea pielii',
|
||
'Sensibilizare respiratorie/cutanată',
|
||
'Mutagenitate asupra celulelor germinale',
|
||
'Cancerigenitate',
|
||
'Toxicitate pentru reproducere',
|
||
'Pericol prin aspirare',
|
||
]
|
||
for eng, bg, ro in zip(toxic, toxic_bg, toxic_ro):
|
||
c = c.replace(f'<td>{eng}</td>', f"<td>{{'{bg}' if lang_code == 'BG' else '{ro}'}}</td>")
|
||
|
||
c = c.replace(
|
||
'Not classified</td>',
|
||
"{'Не се класифицира' if lang_code == 'BG' else 'Neclasificat'}</td>"
|
||
)
|
||
|
||
# Section 12
|
||
c = c.replace('<h3 class=\"subsection\">12.1 Toxicity</h3>', "<h3 class=\"subsection\">{'12.1 Токсичност' if lang_code == 'BG' else '12.1 Toxicitate'}</h3>")
|
||
c = c.replace('<h3 class=\"subsection\">12.2 Persistence and degradability</h3>', "<h3 class=\"subsection\">{'12.2 Устойчивост и разградимост' if lang_code == 'BG' else '12.2 Persistență și degradabilitate'}</h3>")
|
||
c = c.replace('<h3 class=\"subsection\">12.3 Bioaccumulative potential</h3>', "<h3 class=\"subsection\">{'12.3 Биоакумулиращ потенциал' if lang_code == 'BG' else '12.3 Potențial de bioacumulare'}</h3>")
|
||
c = c.replace('<h3 class=\"subsection\">12.4 Mobility in soil</h3>', "<h3 class=\"subsection\">{'12.4 Мобилност в почвата' if lang_code == 'BG' else '12.4 Mobilitate în sol'}</h3>")
|
||
c = c.replace('<h3 class=\"subsection\">12.5 PBT and vPvB assessment</h3>', "<h3 class=\"subsection\">{'12.5 PBT и vPvB оценка' if lang_code == 'BG' else '12.5 Evaluare PBT și vPvB'}</h3>")
|
||
c = c.replace('<h3 class=\"subsection\">12.6 Endocrine disrupting properties</h3>', "<h3 class=\"subsection\">{'12.6 Ендокринно нарушаващи свойства' if lang_code == 'BG' else '12.6 Proprietăți de disruptor endocrin'}</h3>")
|
||
c = c.replace('<h3 class=\"subsection\">12.7 Other adverse effects</h3>', "<h3 class=\"subsection\">{'12.7 Други неблагоприятни ефекти' if lang_code == 'BG' else '12.7 Alte efecte adverse'}</h3>")
|
||
|
||
c = c.replace('<th>Spects</th>', '')
|
||
c = c.replace('<th>Species</th>', "<th>{'Вид' if lang_code == 'BG' else 'Specie'}</th>")
|
||
c = c.replace('<th>Value</th>', "<th>{'Стойност' if lang_code == 'BG' else 'Valoare'}</th>")
|
||
|
||
# Fix Value/Valoare (make sure we don't break existing uses)
|
||
# Already in phys-chem table as data values
|
||
c = c.replace(
|
||
'<p>Readily biodegradable — 100% after 28 days.</p>',
|
||
"<p>{'Лесно биоразградим — 100% след 28 дни.' if lang_code == 'BG' else 'Ușor biodegradabil — 100% după 28 de zile.'}</p>"
|
||
)
|
||
c = c.replace(
|
||
'<p>Low mobility.</p>',
|
||
"<p>{'Ниска мобилност.' if lang_code == 'BG' else 'Mobilitate scăzută.'}</p>"
|
||
)
|
||
c = c.replace(
|
||
'<p>Not classified as PBT or vPvB.</p>',
|
||
"<p>{'Не се класифицира като PBT или vPvB.' if lang_code == 'BG' else 'Neclasificat ca PBT sau vPvB.'}</p>"
|
||
)
|
||
c = c.replace(
|
||
'<p>Not classified as having ED properties.</p>',
|
||
"<p>{'Не се класифицира като ED.' if lang_code == 'BG' else 'Neclasificat ca având proprietăți de disruptor endocrin.'}</p>"
|
||
)
|
||
c = c.replace(
|
||
'<h3 class="subsection">12.6 Endocrine disrupting properties</h3>',
|
||
'<h3 class="subsection">12.6 Endocrine disrupting properties</h3>'
|
||
)
|
||
|
||
with open('/home/bachko/msds-tds/scripts/generate-sds-lang.py', 'w') as f:
|
||
f.write(c)
|
||
print("Done")
|