Add granular language metadata to instructions page

dev
gravel 5 months ago
parent 72b6174552
commit 412c83c671
Signed by: gravel
GPG Key ID: C0538F3C906B308F

@ -2,7 +2,15 @@
require_once '+getenv.php';
$instruction_files = glob("+instructions/*.txt");
function file_language($file) { return pathinfo($file)['filename']; }
function file_language($file) {
$filename = pathinfo($file)['filename'];
return explode(" ", $filename)[0];
}
function file_language_code($file) {
$filename = pathinfo($file)['filename'];
$code_in_brackets = explode(" ", $filename)[1];
return mb_substr($code_in_brackets, 1, mb_strlen($code_in_brackets) - 2);
}
$languages = array_map('file_language', array_slice($instruction_files, 0, 10));
$language_enumeration = join(", ", $languages);
@ -56,15 +64,13 @@
type="radio"
<?=file_language($file) == 'English' ? 'checked="checked"' : ''?>
><label for="language-selection-<?=$i?>">&nbsp;<?=
// Name of the language
// Can be later parsed from i.e. first line of file
file_language($file);
?></label>
<?php endforeach; ?>
<article id="instructions">
<?php foreach ($instruction_files as $i => $file): ?>
<section id="instructions-<?=$i?>" class="instructions"><?php
<section id="instructions-<?=$i?>" class="instructions" lang="<?=file_language_code($file)?>"><?php
// Sanitization as second layer of protection
// for user-submitted instruction files.
// Should not ever have to be used.

Loading…
Cancel
Save