Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ Cities*
.sass-cache
*.pyc
data
*.mo
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ RUN apt-get update \

RUN curl -sSL https://install.python-poetry.org | python3 -
ENV PATH="/root/.local/bin:$PATH"

RUN echo "cy_GB.UTF-8 UTF-8" >> /etc/locale.gen
RUN /usr/sbin/locale-gen

RUN a2enmod rewrite
35 changes: 35 additions & 0 deletions bin/generate-translations
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

# Helper script to regenerate the Welsh translation file
# if '--test' is added as a command parameter, this script should fail if there are any untranslated strings

# Find all PHP files
find ./ -regex '.*\.\(html\|php\)' |grep -v commonlib|grep -v vendor |sort > POTFILES
# Use that list to generate .pot file.
# NB: forces PHP as otherwise it errors about .html files
xgettext -c -L PHP --from-code=UTF-8 --files-from=POTFILES -d WriteToThem -o locale/WriteToThem.pot
# Merge with existing Welsh file
msgmerge --no-wrap -o New.po locale/cy_GB.UTF-8/LC_MESSAGES/WriteToThem.po locale/WriteToThem.pot
# Move on top of old Welsh file
mv New.po locale/cy_GB.UTF-8/LC_MESSAGES/WriteToThem.po
# Remove temporary files
rm POTFILES

if [ "$1" == "--test" ]; then
# Check for untranslated or fuzzy strings
OUTPUT=$(msgfmt --output=/dev/null --statistics locale/cy_GB.UTF-8/LC_MESSAGES/WriteToThem.po 2>&1)
echo $OUTPUT
# if 'untranslated' or 'fuzzy' are found in the output, there are untranslated strings
echo $OUTPUT | grep -q "untranslated"
if [ $? -eq 0 ]; then
echo "There are untranslated strings in the Welsh translation file"
exit 1
fi
echo $OUTPUT | grep -q "fuzzy"
if [ $? -eq 0 ]; then
echo "There are fuzzy strings in the Welsh translation file"
exit 1
fi
fi

commonlib/bin/gettext-makemo WriteToThem
1 change: 1 addition & 0 deletions conf/packages
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
gettext
libconvert-base32-perl
libcrypt-cbc-perl
libemail-address-perl
Expand Down
24 changes: 24 additions & 0 deletions locale/WriteToThem.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-11-18 12:24+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"

#: web/index.php:304
msgid ""
"<h2 id=\"title\">Write to your politicians, national or local, for free.</"
"h2><p>Over 200,000 messages sent last year.</p>"
msgstr ""
17 changes: 17 additions & 0 deletions locale/cy_GB.UTF-8/LC_MESSAGES/WriteToThem.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
msgid ""
msgstr ""
"Project-Id-Version: 1.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-11-18 12:24+0000\n"
"PO-Revision-Date: 2023-03-20 17:59-0000\n"
"Last-Translator: mySociety\n"
"Language-Team: mySociety\n"
"Language: cy\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"

#: web/index.php:304
msgid "<h2 id=\"title\">Write to your politicians, national or local, for free.</h2><p>Over 200,000 messages sent last year.</p>"
msgstr "<h2 id=\"title\">Ysgrifennwch at eich gwleidyddion, cenedlaethol neu leol, am ddim.</h2><p>Anfonwyd dros 200,000 o negeseuon y llynedd.</p>"
32 changes: 31 additions & 1 deletion phplib/fyr.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,27 @@

template_set_style($dir . "/../templates/website");

bindtextdomain('WriteToThem', $dir . '/../locale');

# syndication type, read from domain name
global $cobrand;
$cobrand = null;
if (array_key_exists('HTTP_HOST', $_SERVER)) {
# if localhost or localhost:8085, skip the dot exploding step
$localhost_values = array('localhost', 'localhost:8085');
if (in_array( $_SERVER['HTTP_HOST'], $localhost_values)) {
if (in_array($_SERVER['HTTP_HOST'], $localhost_values)) {
$host_parts = array('localhost', 'localhost');
} else {
$host_parts = explode('.', $_SERVER['HTTP_HOST'], 2);
}
if ($host_parts[1] == OPTION_WEB_DOMAIN && $host_parts[0] != 'www') {
$cobrand = $host_parts[0];
}

$cobrand = fyr_set_language($cobrand);
}


if (is_dir("../templates/$cobrand")) {
template_set_style("../templates/$cobrand", true);
}
Expand All @@ -64,6 +69,31 @@
}
}

/* fyr_set_language COBRAND
* Check if the cobrand is a language and set locale etc accordingly. */
function fyr_set_language($cobrand) {
$language = "en";
$locale = "en_GB.UTF-8";
$available_languages = ["cy"];
$lang_map = [
"cy" => "cy_GB.UTF-8",
];

if (in_array($cobrand, $available_languages)) {
$language = $cobrand;
$locale = $lang_map[$cobrand];
$cobrand = null;

}

define('LANGUAGE', $language);
setlocale(LC_ALL, $locale);
putenv("LC_ALL=$locale");
textdomain('WriteToThem');

return $cobrand;
}

/* fyr_display_error NUMBER MESSAGE
* Display an error message to the user. */
function fyr_display_error($num, $message, $file, $line) {
Expand Down
2 changes: 1 addition & 1 deletion web/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ function postcode_form($pc, $cobrand, $cocode, $a_forward, $error_message, $opti
$title = "Email your Councillor, MP, MSP, MS, MLA or London Assembly Member for free";
}

$blurb_top = '<h2 id="title">Write to your politicians, national or local, for free.</h2><p>Over 200,000 messages sent last year.</p>';
$blurb_top = _('<h2 id="title">Write to your politicians, national or local, for free.</h2><p>Over 200,000 messages sent last year.</p>');

$fyr_all_url = null;
$area_types = null;
Expand Down