Localization

101 views
Skip to first unread message

Karen K

unread,
Mar 24, 2021, 3:42:04 PM3/24/21
to weewx-development
Localization seems difficult to me in the moment. It works like that that the user defines a lot of entries in weewx.conf or skin.conf. 

The disadvantages are to me:
  • It makes the configuration files very long. 
  • Changing localization involes changing lots of entries.
  • Skins cannot come with multiple localizations included.
So I thought about it for a long time, and I gave it a try. I want to present a possible solution.

To simplify the process a localization file is used that is referenced in weewx.conf. To change localization simply the file name is changed. Then the values come from another file. Each localization file has the same structure as skin.conf. If the localization file has no entry for a label the value from weewx.conf or skin.conf is returned instead. 

Usage is simple: for example $locale('obs.label.outTemp') looks for an entry 'outTemp' in section [Labels][[Generic]] in the localization file. It it is there, its value is returned. Otherwise the value from skin_dict is returned.

Advantages are:
  • Label value texts can be "outsourced" to separate files.
  • Localization can be changed by changing one single entry.
  • Skin authors can ship their packages with multiple localizations included.
  • No breaking changes.
An alternative to that solution would be to include the localization lookup into the standard $obs.label... or $Extras... lookup.

skin_locale.py

Tom Keffer

unread,
Mar 27, 2021, 9:13:42 AM3/27/21
to Karen K, weewx-development
Karen,

I have not forgotten you. I'm in the midst of the V4.5 deployment, but should have some time later to take a look at this.

--
You received this message because you are subscribed to the Google Groups "weewx-development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-developm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-development/259e43e6-efe9-467e-9949-862dda0f13c8n%40googlegroups.com.

Karen K

unread,
Mar 27, 2021, 5:14:55 PM3/27/21
to weewx-development
No problem at all. Meanwhile I put it up for discussion at Belchertown on github. And I worked further on it, and I learnt a lot more how WeeWX works. So it is simpler now: preceeding a label tag by $locale, only. For example: $locale.obs.label.outTemp.

I wish you to find all the bug that are still there easily.
skin_locale.py

Karen K

unread,
Mar 28, 2021, 8:37:21 AM3/28/21
to weewx-development
More detailed description of usage and possibilities:

Instead of using label tags directly, they are prepended by the $locale tag. $locale provides a language dependent label string if some is available und otherwise the entry from weewx.conf or skin.conf
  
Example:
    $locale.obs.label.outTemp

The extension looks for an entry in the appropriate localization file. If it finds one it returns it. If it finds no entry the value from skin_dict (weewx.conf or skin.conf) is returned.

For template dependent labels use Cheetah variable as parameter to the $locale tag.
  
Example:
    #set $page = "mypage"
    $locale(tmpl=$page).html_description
    
This tag is first looked up in the [Templates] section of the localization file in the subsection defined by (in this example) $page. If it is found there, it is used. If it is not found there, the entry in section [Labels][[Generic]] is used, either from skin.conf or weewx.conf. In general you would have the #set line at the beginning of the template file and the $locale line within some #include file, called from that template file. It replaces long #if - #if else etc. constructs as found in several skins today by a single line.

To make lookup more flexible, it is also possible to provide the label entry as a parameter to $locale.
  
Example:
    #set $mylabel = "outTemp"
    #set $xxx = 'obs.label'+$mylabel
    $locale(tag=$xxx)
  
That looks for $locale.obs.label.outTemp, too. It may be useful in Cheetah loops.
  
The extension needs an additional entry called 'lang_file' directly in the skin section of weewx.conf. It points to the localization file to use. Relative paths are relative to the skin directory.
  
The localization file has the same structure as the skin.conf file. Entries that depend on language need to be defined there, only. Other entries remain defined in weewx.conf or skin.conf
  
The localization file is not restricted to "Extras" and "Labels" section, but can process all sections of the file.

Karen K

unread,
Apr 17, 2021, 7:17:51 AM4/17/21
to weewx-development
See PR #665
Reply all
Reply to author
Forward
0 new messages