Skip to content

Commit

Permalink
Rework function send_doctype()
Browse files Browse the repository at this point in the history
  • Loading branch information
bbannon committed Oct 31, 2023
1 parent 8ecfdce commit 3d0255b
Show file tree
Hide file tree
Showing 3 changed files with 1,926 additions and 207 deletions.
20 changes: 13 additions & 7 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5555,22 +5555,28 @@ function remember_this_view ( $view = false ) {
/**
* This just sends the DOCTYPE used in a lot of places in the code.
*
* @param string lang
* @param string $doc_title
*
* @global string charset Usually 'utc-8'.
* @global string lang User's browser language preference.
* @global string LANGUAGE What we think the user wants.
*
* @return string HTML snippet
*/
function send_doctype ( $doc_title = '' ) {
global $charset, $lang, $LANGUAGE;

$lang = ( empty ( $LANGUAGE ) ? '' : languageToAbbrev ( $LANGUAGE ) );
if ( empty ( $lang ) )
$lang = 'en';

$charset = ( empty ( $LANGUAGE ) ? 'iso-8859-1' : translate ( 'charset' ) );
$charset = ( translate ( 'charset' ) ?: 'utc-8' );
$lang = ( languageToAbbrev ( $LANGUAGE ) ?: $_COOKIE['lang'] ?: 'en' );

return "<!DOCTYPE html>
<html lang=\"$lang\">
<head>
<meta charset=\"$charset\">"
. ( empty ( $doc_title ) ? '' : "
// 'viewport' makes things fit on whatever screen size.
. '
<meta name="viewport" content="width=device-width, initial-scale=1.0">'
. ( ! $doc_title ? '' : "
<title>$doc_title</title>" );
}

Expand Down
200 changes: 0 additions & 200 deletions translations/Elven.txt

This file was deleted.

Loading

4 comments on commit 3d0255b

@bbannon
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function send_doctype()
/**

  • Can we determine user's browser language?
  • Do we want to?
  • <script>
  • // a cookie so we can get it into PHP.
  • document.cookie = "lang=" + navigator.language; // "en-US"
  • const langs = navigator.languages; // ["en-US", "zh-CN", "ja-JP"]
  • </script>

*/

// '?:' accepts first truthy value. As of PHP 7.4
// Eventually, will always be 'utc-8'.
$charset = ( translate ( 'charset' ) ?: 'utc-8' );

// todo: Rename 'translation/*.txt' files to 'navigator.language' format.
// todo: Only copy the user's 'navigator.languages' files from
// 'translations/', 'captcha/', 'ckeditor/', 'phpmailer/', etc.
// to the 'dst/' (distribution) folder.
// Maybe have PHP modify/create Makefile from the cookie?
// todo: Minify EVERYTHING in the 'dst/' folder, except the .txt files.
$lang = ( languageToAbbrev ( $LANGUAGE ) ?: $_COOKIE['lang'] ?: 'en' );

@bbannon
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove 'Elven.txt'. It was fun, but too hard to maintain. Also, it's basically English with a fantasy font.
Add 'en_US.txt'. Start to make things easier.

@wurtel2
Copy link

@wurtel2 wurtel2 commented on 3d0255b Nov 1, 2023 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bbannon
Copy link
Contributor Author

@bbannon bbannon commented on 3d0255b Nov 1, 2023 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.