Skip to content
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

Fix sdcsrm 626 add google analytics #54

Merged
merged 28 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9b81ba2
An attempt at extracting the uac form components
kacperpONS Aug 5, 2024
af51957
Reverted the changes
kacperpONS Aug 5, 2024
4f40f42
Cleaned up the start template
kacperpONS Aug 5, 2024
7ec5904
Some more cleanup/refactoring
kacperpONS Aug 5, 2024
fe88de6
Added the gtag.js script
kacperpONS Aug 5, 2024
351be77
Add the config variable to vulture whitelist
kacperpONS Aug 6, 2024
e70e37a
Added the tracking label attributes
kacperpONS Aug 6, 2024
e4bac6e
Removed unused attributes from the error templates
kacperpONS Aug 6, 2024
fce41b3
Add tracking attributes to uac error pages and server error pages
kacperpONS Aug 6, 2024
5b5a763
Updated the CSP whitelist
kacperpONS Aug 6, 2024
e690aac
Mock value for gtag_id, reformat base.html
kacperpONS Aug 6, 2024
15ced91
Added the tracking cookies check with a comment
kacperpONS Aug 6, 2024
459c3f5
Moved the gtagid mock value to dev config
kacperpONS Aug 6, 2024
57a7810
Add nonce and whitelist to make CSP happy
kacperpONS Aug 7, 2024
5f69b7b
w 👍
kacperpONS Aug 7, 2024
11657f2
Added the GA paragraph
kacperpONS Aug 13, 2024
9dd21b5
Added translations
kacperpONS Aug 13, 2024
6bed605
Fixed the translations
kacperpONS Aug 13, 2024
3d117ad
Removed the old comment
kacperpONS Aug 15, 2024
004a25f
Merge branch 'main' into fix-SDCSRM-626-add-google-analytics
kacperpONS Aug 15, 2024
d207cc6
Update cookies info table
kacperpONS Aug 15, 2024
52d4836
Update translation
kacperpONS Aug 15, 2024
0bded00
Merge branch 'fix-SDCSRM-626-add-google-analytics' of github.com:ONSd…
kacperpONS Aug 15, 2024
275ff89
Readme improvement
kacperpONS Aug 15, 2024
1e2ade2
More improvements to readme
kacperpONS Aug 15, 2024
46c49cd
Fixed
kacperpONS Aug 15, 2024
01932c4
Update README.md
kacperpONS Aug 19, 2024
6fd5230
Update README.md
kacperpONS Aug 19, 2024
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
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