Skip to content

Commit 500a26c

Browse files
committed
add option to provide translation strings
1 parent e0bcc4a commit 500a26c

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ The content is encrypted with AES-256 in Python using PyCryptodome, and decrypte
4646
* [Add button](#add-button)
4747
* [Reload scripts](#reload-scripts)
4848
* [Self-host crypto-js](#self-host-crypto-js) **(NEW)**
49+
* [Translations](#translations) **(NEW)**
4950
* [Contributing](#contributing)
5051

5152

@@ -62,7 +63,7 @@ Install the package from source with pip:
6263
```bash
6364
cd mkdocs-encryptcontent-plugin/
6465
python setup.py sdist bdist_wheel
65-
pip install dist/mkdocs_encryptcontent_plugin-2.4.1-py3-none-any.whl
66+
pip install dist/mkdocs_encryptcontent_plugin-2.4.2-py3-none-any.whl
6667
```
6768

6869
Enable the plugin in your `mkdocs.yml`:
@@ -524,6 +525,22 @@ plugins:
524525
selfhost_download: false
525526
```
526527

528+
### Translations
529+
530+
If the plugin is used in conjunction with the [static-i18n](https://ultrabug.github.io/mkdocs-static-i18n/) plugin you can provide `translations` for the used `i18n_page_file_locale`.
531+
532+
```yaml
533+
- encryptcontent:
534+
#...
535+
translations:
536+
de:
537+
title_prefix: '[Verschlüsselt] '
538+
summary: 'Der Inhalt dieser Seite ist mit AES verschlüsselt. '
539+
placeholder: 'Mit Strg+Enter wird das Passwort global gesetzt'
540+
password_button_text: 'Entschlüsseln'
541+
decryption_failure_message: 'Falsches passwort.'
542+
encryption_info_message: 'Bitte wenden Sie sich an den Systemadministrator um auf diese Seite zuzugreifen.'
543+
```
527544

528545

529546
# Contributing

encryptcontent/plugin.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class encryptContentPlugin(BasePlugin):
8181
('inject', config_options.Type(dict, default={})),
8282
('selfhost', config_options.Type(bool, default=False)),
8383
('selfhost_download', config_options.Type(bool, default=True)),
84+
('translations', config_options.Type(dict, default={}, required=False)),
8485
# legacy features, doesn't exist anymore
8586
('disable_cookie_protection', config_options.Type(bool, default=False)),
8687
('decrypt_search', config_options.Type(bool, default=False)),
@@ -335,6 +336,23 @@ def on_page_context(self, context, page, config, **kwargs):
335336
:param nav: global navigation object
336337
:return: dict of template context variables
337338
"""
339+
if hasattr(page, 'html_to_encrypt') or self.config['inject']:
340+
if 'i18n_page_file_locale' in context:
341+
locale = context['i18n_page_file_locale']
342+
if locale in self.config['translations']:
343+
translations = self.config['translations'][locale]
344+
if 'title_prefix' in translations:
345+
self.config['title_prefix'] = translations['title_prefix']
346+
if 'summary' in translations:
347+
self.config['summary'] = translations['summary']
348+
if 'placeholder' in translations:
349+
self.config['placeholder'] = translations['placeholder']
350+
if 'password_button_text' in translations:
351+
self.config['password_button_text'] = translations['password_button_text']
352+
if 'decryption_failure_message' in translations:
353+
self.config['decryption_failure_message'] = translations['decryption_failure_message']
354+
if 'encryption_info_message' in translations:
355+
self.config['encryption_info_message'] = translations['encryption_info_message']
338356
if hasattr(page, 'html_to_encrypt'):
339357
page.content = self.__encrypt_content__(
340358
page.html_to_encrypt,

0 commit comments

Comments
 (0)