Skip to content

Commit

Permalink
Fix sdcsrm 626 add google analytics (#54)
Browse files Browse the repository at this point in the history
* Removed an old comment

* Update cookies info table

* Update translation

* Readme improvements
  • Loading branch information
kacperpONS authored Aug 21, 2024
1 parent 54cdb42 commit 0b40967
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 180 deletions.
23 changes: 15 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,44 @@ or to run it in Pycharm, use the run template that's specified and it should wor

## Translations

The site uses babel for translations.
The site uses PyBabel for translations.

Text to translate is marked up in html and py templates and files, then a messages.pot is build via pybabel, which
collates all the text to translate into a single file.
Text to translate is marked up in `.html` and `.py` templates and files with the [gettext](https://en.wikipedia.org/wiki/Gettext) mechanism. Then a `messages.pot` file is build via Pybabel, which collates all the text to translate. Based on the content of the `.pot` file translation files `messages.po` are created for all specified language codes. Finally, the `.po` files are compiled into `.mo` files, which are then used on the page.

1. Extract text to translation

To build/re-build the translation messages.pot use:

```
pipenv run pybabel extract -F babel.cfg -o rh_ui/translations/messages.pot .
```

2. Create new language file
> [!CAUTION]
> Follow this step only when you want to add translation for a new language. Running it for an existing language code will overwrite the existing translations.
To create a new language messages file, run the following, changing the 2 character language code at the end to the
required language code. Only generate a individual language file once.

Note that this implementation includes an English translation. This is needed due to an issue with implementing pybabel
with aiohttp.

```
pipenv run pybabel init -i rh_ui/translations/messages.pot -d rh_ui/translations -l cy
```

3. Update translation files

Once created, you can update the existing language messages.po files to include changes in the messages.pot by running
the following. This will update ALL language files.

```
pipenv run pybabel update -i rh_ui/translations/messages.pot -d rh_ui/translations
```

4. Compile the translations

> [!NOTE]
> Double check your translation files (messages.po) for the `#, fuzzy` comment. This indicates that the tranlsation isn't an exact match and won't be rendered on the page. Double check the translations and remove any incorrectly matched lines, then remove the `fuzzy` comment.
To compile updates to the messages.po files into messages.mo (the file actually used by the site) use:
(If you've only changes made one small change and there's a `#, fuzzy` entry in the translation,
double-check the translation then remove the comment before compiling)
```
pipenv run pybabel compile -d rh_ui/translations
```
Expand Down
5 changes: 0 additions & 5 deletions rh_ui/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@
<!-- Google tag (gtag.js) -->
<script nonce="{{ csp_nonce() }}" async src={{ script_src_url }}></script>
<script nonce="{{ csp_nonce() }}">
// NOTE!!!
// We currently don't have an option to turn this cookie on/off on the cookies page in rh
// It is set to false by default and can only be set to true
// When the participant accepts all cookies on the cookies banner
// (and can't be swithced back to false unless the user clear their cookies)
var allowTrackingCookies = /^(.*)?\s*'usage':true\s*[^;]+(.*)?$/;

if (document.cookie.match(allowTrackingCookies)) {
Expand Down
21 changes: 4 additions & 17 deletions rh_ui/templates/info_pages/cookies.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ <h3>{{ _("Cookies that measure website use") }}</h3>
"value": "<code>_ga</code>"
},
{
"value": _('This helps us count how many people visit ons.gov.uk by tracking if you’ve visited before')
"value": _('Used to distinguish users.')
},
{
"value": _("2 years")
Expand All @@ -106,26 +106,13 @@ <h3>{{ _("Cookies that measure website use") }}</h3>
{
"tds": [
{
"value": "<code>_gid</code>"
"value": "<code>_ga_&lt;container-id&gt;</code>"
},
{
"value": _('This helps us count how many people visit ons.gov.uk by tracking if you’ve visited before')
"value": _('Used to persist session state.')
},
{
"value": _("24 hours")
}
]
},
{
"tds": [
{
"value": "<code>_gat</code>"
},
{
"value": _('Used to manage the rate at which page view requests are made')
},
{
"value": _("10 minutes")
"value": _("2 years")
}
]
}
Expand Down
Binary file modified rh_ui/translations/cy/LC_MESSAGES/messages.mo
Binary file not shown.
Loading

0 comments on commit 0b40967

Please sign in to comment.