Skip to content

Commit

Permalink
Simplify the language file
Browse files Browse the repository at this point in the history
We just need to creating the file and load it via config
  • Loading branch information
danpros committed May 3, 2020
1 parent a5a3d66 commit 73e103b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 2 additions & 10 deletions system/htmly.php
Expand Up @@ -3,16 +3,8 @@
// Load the configuration file
config('source', $config_file);

// Settings for the language
if ( config('language') === "de" ) {
i18n('source', 'lang/lang-de.ini'); // Load the German language file
$date_format = '%d. %B %Y'; // Date format German style
setlocale(LC_TIME, 'de_DE', 'de_DE.utf8', "German"); // Change time format to German
} else { // Default: English ("en")
i18n('source', 'lang/lang-en.ini'); // Load the English language file
$date_format = '%B %d, %Y'; // Date format English style
setlocale(LC_TIME, 'en_US', 'en_US.utf8', "English"); // Change time format to English
}
// Load the language file
get_language();

// Set the timezone
if (config('timezone')) {
Expand Down
23 changes: 23 additions & 0 deletions system/includes/functions.php
Expand Up @@ -3201,3 +3201,26 @@ function replace_href($string, $tag, $class, $url)
return preg_replace('~<(?:!DOCTYPE|/?(?:html|head|body))[^>]*>\s*~i', '', utf8_decode($doc->saveHTML($doc->documentElement)));

}

function get_language()
{

$langID = config('language');
$langFile = 'lang/'. $langID . '.ini';
$local = strtolower($langID);

// Settings for the language
if (!isset($langID) || config('language') === 'en') {
i18n('source', 'lang/en.ini'); // Load the English language file
setlocale(LC_ALL, 'en_US'); // Change time format to English
} else {
if (file_exists($langFile)) {
i18n('source', 'lang/' . $langID . '.ini');
setlocale(LC_ALL, $local);
} else {
i18n('source', 'lang/en.ini'); // Load the English language file
setlocale(LC_ALL, 'en_US'); // Change time format to English
}
}

}

3 comments on commit 73e103b

@bluebirch
Copy link
Contributor

Choose a reason for hiding this comment

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

This approach is neat, but it leaves the problem on how to format dates in themes. Currently the strftime function is used with a global variable $date_format. What should be used instead? Format %x is locale dependent but only numbers which doesn't look too good on a blog.

@danpros
Copy link
Owner Author

@danpros danpros commented on 73e103b May 3, 2020

Choose a reason for hiding this comment

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

@bluebirch perhaps we should creating new function eg. format_date and than proceeding all of the things there. With this we will have flexibility:

Old ways

<?php echo date('F d, Y', $p->date) ?>

New ways (perhaps):

<?php echo format_date($p->date) ?>

@bluebirch
Copy link
Contributor

Choose a reason for hiding this comment

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

@danpros I support that idea. Currently, both <?php echo date( 'F d, Y', $p->date ) ?> and <?php echo strftime( $date_format, $p->date ) are used throughout the themes, with $date_format defined as a global variable. A format_date() function would make things cleaner.

Please sign in to comment.