deformed-offering

Free Weather Website Templates

They're free, but use at your own risk

The scripts referenced here are used in the operation of this weather station, and may be freely copied and used to support your station. Please note that you use these scripts at your own risk. No warranty is expressed or implied. I accept no liability for any damages that may ensue from their use.
You will need to configure them for your own particular weather station website.
RSS feed for Scripts Updates A RSS Feed is available to help keep you informed on updates to the scripts.

Many of these scripts are now available on GitHub at https://github.com/ktrue

Buy Me A Coffee If you find one or more of the scripts useful to you, please consider making a donation to help offset the routine expenses of operation of this website.
Thanks for your kind support!

A Version History is available -- check back from time to time to see if there are updates to scripts you have downloaded earlier. Announcements of version updates and new scripts are made on WXForum.net and Weather-Watch forums and saratogaWXPHP Twitter account as they become available.

Note: Twitter widget has been disabled 3-Jul-2023 since it no longer displays the recent update Tweets.

This page was updated Friday, 20-Jul-2012 11:09 AM

PHP/AJAX Website Template Set - multilanguage support

The multilanguage feature of the template sets uses exact match string substitution to replace English words/phrases with their counterpart word/phrase in another language. The technology used is the same as for the multilanguage support in the WXSIM plaintext-parser.php. The WXSIM translation files are included with the distribution .zip. Each supported language has four files necessary to provide full support for the language. The LL is the two-character language abbreviation (en=English, dk=Danish, el=Greek, etc):

language-LL.txt
This file contains the primary lookups for translation of English to language LL. It also specifies the character set for the language. Each 'langlookup' entry is stored in a $LANGLOOKUP[] array for use by the langtrans() and langtransstr() functions in common.php on the webpages (see below for operation).
language-LL-local.txt
This file contains additional lookups for translation of English to language LL. Put your local additions to the language lookups in these files (which are loaded AFTER the language-LL.txt files) so you can add menu item additions and override a translation from the main file here, and still keep your primary language file updated from the master distribution. Each 'langlookup' entry is stored in a $LANGLOOKUP[] array for use by the langtrans() and langtransstr() functions on the webpages (see below for operation).
NOTE: it is strongly recommended that you use this feature to add translations specific to your site rather than changing the released language file as it will be easier to update the main language file from the distribution as new languages become available, and still preserve your local modifications.
 
language.LL.js
This file contains the JavaScript to configure the AJAX routine (ajax[WXsftw]wx.js) so certain words/phrases created by the AJAX updates will be in the language desired. Some of the entries (like wind cardinal directions, Beaufort and Heat Color Word text) are directly imported into $LANGLOOKUP[] for use by the langtrans() and langtransstr() functions on the webpages.
plaintext-parser-lang-LL.txt
This file contains the translation entries to convert an English WXSIM plaintext.txt forecast into another language. It is exactly the same file as used by plaintext-parser.php for the WXSIM forecast.
wxabout-LL.html
This file contains the language-specific text for use in the wxabout.php page and should be customized for your individual website for each language to be offered. You can use the basic design of the wxabout.php page and it's associated wxabout-LL.html pages to add a new multilingual page to your site if the new page is anticipated to have a lot of static text on it.

How the multilanguage feature works

In the common.php script, a set of load functions will read/parse the language-LL.txt, language-LL-local.txt and language-LL.js files to load the global $LANGLOOKUP[] array with the translation values.

In exact match replacement, a text entry like this sample from language-dk.txt:

langlookup|Enable JavaScript for live updates|Aktiver JavaScript for lever opdaterer|

is read and parsed when each page is loaded (by routines in common.php). The English (second field) is used as a 'key' and when a langtrans() or langtransstr() function is called using that field, the functions will return the contents of the third field (in this case, Danish) for use on the page. If the exact match is not found, then the English words will be returned unchanged.

To maintain consistent display using other languages, it is important to keep the third-field (translation phrase) in the langlookup entry updated using the default character set for that language. Unless otherwise specified below, the ISO-8859-1 (Latin) character set is used. The other character sets in use in the templates are:

  • ISO-8859-5 for Bulgarian (bg)
  • ISO-8859-7 for Greek (el)
  • ISO-8859-2 for Hungarian (hu), Polish (pl), Romanian (ro)
  • UTF-8 for Hebrew (he)

Make sure your editor supports saving files using those character sets (and not the default Windows-nnnn sets) or strange display results on the webpages may occur.

The preferences of a website visitor for a language are retained by PHP session variables (and cookies), and any page can be switched to a new language by using a ?lang=LL parameter (assuming 'LL' is in the list of supported languages).

Using langtrans() and langtransstr() on your own pages

Two globally available functions residing in common.php let you construct your pages using English words/phrases, and have them automatically translate when the page is displayed in a different language (assuming you have the appropriate langlookup entries in the language-LL-local.txt file, that is).

The primary difference between the two functions is:

  • langtrans() will perform a print/echo of the translated word/phrase where it is placed on the PHP page
  • langtransstr() will return a string with the translated word/phrase, but not print/echo it

Examples of usage:

<h2><?php langtrans('Custom Title'); ?></h2>

<?php $thing = $WX['somevalue'] . ' '. langtransstr('Custom thing');
echo $thing; ?>

This assumes there are

langlookup|Custom Title|<some translation for Custom Title>|
langlookup|Custom thing|<some translation for Custom thing>|

in the language-LL-local.txt for the translation to work. Note that spaces before and after a field are ignored in the langlookup line and when searching for an exact match with langtrans() and langtransstr() functions. The case (upper/lower) of the English search field must also match the case (upper/lower) in the langtrans() and langtransstr() function calls.

A support function is built-in the footer.php so that if you browse to any wx....php page on your site and append ?show=missing to the URL in the browser location bar, you can then do a view-source on the page, and after the </html> at the bottom of the page you will see something like:

</html>
<!-- missing langlookup entries for lang=en
langlookup|World Multilingual Website with PHP &amp; AJAX|World Multilingual Website with PHP &amp; AJAX|
langlookup|Sample Blank Page|Sample Blank Page|
langlookup|Local Weather Exchange Stations|Local Weather Exchange Stations|
langlookup|Mesonet|Mesonet|
langlookup|NOAA reports|NOAA reports|
langlookup|Status of weather software|Status of weather software|
langlookup|Status|Status|

7 entries. End of missing langlookup entries -->

You can copy those prototype langlookup entries into your language-LL-local.txt, add your translation for the third field, and easily fix any missing translation values.

Multilanguage support requires weather software to run in English

Be advised that the translation provided by the template set is FROM ENGLISH ONLY. If you run your your weather software using a language other than English, it is very likely that some of the multi-language support won't work on some features as there is currently no provision to convert from <language> to English so the English to <language> translation is not possible.

Language Packs for easy update for a language

With the template set, I've added distributions for current versions of individual language translation sets to help you keep your language files up-to-date. They can be downloaded individually from the install page as they are updated, then unpacked and uploaded to your template website to replace those language files. The full distribution ZIP file will always contain the current set of languages offered.

deformed-offering