#!/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"{english}" new = f"{{'{romanian}' if lang_code == 'BG' else '{romanian}'}}" return c.replace(old, new) # Section 2 hazard class names c = c.replace( 'Flammable liquidsCategory 2', "{'Запалими течности' if lang_code == 'BG' else 'Lichide inflamabile'}{'Категория 2' if lang_code == 'BG' else 'Categoria 2'}" ) c = c.replace( 'Serious eye damage/eye irritationCategory 2', "{'Сериозно увреждане на очите/дразнене на очите' if lang_code == 'BG' else 'Leziuni oculare grave/iritare oculară'}{'Категория 2' if lang_code == 'BG' else 'Categoria 2'}" ) c = c.replace( 'STOT — Single exposureCategory 3 (Narcosis)', "{'СТОО — еднократна експозиция' if lang_code == 'BG' else 'STOT — expunere unică'}{'Категория 3 (Наркоза)' if lang_code == 'BG' else 'Categoria 3 (Narcoză)'}" ) # 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( 'EU Occupational Exposure Limits (IOELV) — Ethyl acetate', "{'Граници на професионална експозиция (IOELV)' if lang_code == 'BG' else 'Limite de expunere profesională UE (IOELV)'} — Ethyl acetate" ) c = c.replace( 'DNEL/DMEL — Workers', "{'DNEL/DMEL — Работници' if lang_code == 'BG' else 'DNEL/DMEL — Lucrători'}" ) c = c.replace( 'DNEL/DMEL — General population', "{'DNEL/DMEL — Общо население' if lang_code == 'BG' else 'DNEL/DMEL — Populația generală'}" ) for eng in ['Acute - inhalation', 'Long-term - dermal', 'Long-term - inhalation', 'Long-term - oral']: c = c.replace('' + eng + '', "{'" + eng + "' if lang_code == 'BG' else '" + eng + "'}") c = c.replace('Freshwater', "{'Пресна вода' if lang_code == 'BG' else 'Apă dulce'}") c = c.replace('Marine water', "{'Морска вода' if lang_code == 'BG' else 'Apă marină'}") c = c.replace('Soil', "{'Почва' if lang_code == 'BG' else 'Sol'}") c = c.replace('STP', "{'ПСОВ' if lang_code == 'BG' else 'STP (stație epurare)'}") c = c.replace('Reference', "{'Препратка' if lang_code == 'BG' else 'Referință'}") 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'{eng}', f"{{'{bg}' if lang_code == 'BG' else '{ro}'}}") # Section 10 c = c.replace( '

Stable under normal conditions.

', "

{'Стабилен при нормални условия.' if lang_code == 'BG' else 'Stabil în condiții normale.'}

" ) # Section 11 c = c.replace( 'EndpointClassificationData', "{'Крайна точка' if lang_code == 'BG' else 'Punct final'}{'Класификация' if lang_code == 'BG' else 'Clasificare'}Data" ) 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'{eng}', f"{{'{bg}' if lang_code == 'BG' else '{ro}'}}") c = c.replace( 'Not classified', "{'Не се класифицира' if lang_code == 'BG' else 'Neclasificat'}" ) # Section 12 c = c.replace('

12.1 Toxicity

', "

{'12.1 Токсичност' if lang_code == 'BG' else '12.1 Toxicitate'}

") c = c.replace('

12.2 Persistence and degradability

', "

{'12.2 Устойчивост и разградимост' if lang_code == 'BG' else '12.2 Persistență și degradabilitate'}

") c = c.replace('

12.3 Bioaccumulative potential

', "

{'12.3 Биоакумулиращ потенциал' if lang_code == 'BG' else '12.3 Potențial de bioacumulare'}

") c = c.replace('

12.4 Mobility in soil

', "

{'12.4 Мобилност в почвата' if lang_code == 'BG' else '12.4 Mobilitate în sol'}

") c = c.replace('

12.5 PBT and vPvB assessment

', "

{'12.5 PBT и vPvB оценка' if lang_code == 'BG' else '12.5 Evaluare PBT și vPvB'}

") c = c.replace('

12.6 Endocrine disrupting properties

', "

{'12.6 Ендокринно нарушаващи свойства' if lang_code == 'BG' else '12.6 Proprietăți de disruptor endocrin'}

") c = c.replace('

12.7 Other adverse effects

', "

{'12.7 Други неблагоприятни ефекти' if lang_code == 'BG' else '12.7 Alte efecte adverse'}

") c = c.replace('Spects', '') c = c.replace('Species', "{'Вид' if lang_code == 'BG' else 'Specie'}") c = c.replace('Value', "{'Стойност' if lang_code == 'BG' else 'Valoare'}") # Fix Value/Valoare (make sure we don't break existing uses) # Already in phys-chem table as data values c = c.replace( '

Readily biodegradable — 100% after 28 days.

', "

{'Лесно биоразградим — 100% след 28 дни.' if lang_code == 'BG' else 'Ușor biodegradabil — 100% după 28 de zile.'}

" ) c = c.replace( '

Low mobility.

', "

{'Ниска мобилност.' if lang_code == 'BG' else 'Mobilitate scăzută.'}

" ) c = c.replace( '

Not classified as PBT or vPvB.

', "

{'Не се класифицира като PBT или vPvB.' if lang_code == 'BG' else 'Neclasificat ca PBT sau vPvB.'}

" ) c = c.replace( '

Not classified as having ED properties.

', "

{'Не се класифицира като ED.' if lang_code == 'BG' else 'Neclasificat ca având proprietăți de disruptor endocrin.'}

" ) c = c.replace( '

12.6 Endocrine disrupting properties

', '

12.6 Endocrine disrupting properties

' ) with open('/home/bachko/msds-tds/scripts/generate-sds-lang.py', 'w') as f: f.write(c) print("Done")