Nucleus Support Forum Index

Find on the forum:
any terms  all terms  Advanced Search

RSS 2.0
Browse posts: Unanswered | Mark all read

« »
Loading Nucleus FAQ ticker...
Post new topic Reply to topic
Author Message
Armon
Nucleus Guru
Nucleus Guru


Joined: 16 Feb 2005
Posts: 1832
Location: Zaandam, Netherlands

Post Posted: Thu Jan 18, 2007 12:53 pm   Post subject: NEW: Language files for skins through Armon's NP_Text!!
Reply with quote

Edit by Leng: As suggested in Adding new Skin and Template vars

Leng wrote:
Armon wrote:
What exactly do you want to add? Translating skins need to be easier but this way people (designers) would have to dig in the language files... Right?

Yup, unfortunately that's right. Initially I was thinking maybe skin authors could just provide a text file which users can copy/paste into their language file (I mean, firing up notepad isn't too hard, right?).

However, if there is a way to get this plugin to look in the current skin directory under a /language/ directory for skin language files, that would be awesome!


Sticky as this is an easy project which we can set up the framework for in the next week or so. Will be unstickied when the framework (skins site, FAQ, etc) is up and running.

Original post

NP_Text 0.2

Code:
<?php
 
class NP_Text extends NucleusPlugin {
 
   function getEventList() { return array(); }
   function getName() { return 'Text'; }
   function getAuthor() { return 'Armon Toubman'; }
   function getURL() { return ''; }
   function getVersion() { return '0.2'; }
   function getDescription() {
      return 'Display constants from language files: <%Text(_CONSTANT)%>';
   }
   function supportsFeature($feature) {
        switch($feature) {
            case 'SqlTablePrefix': return 1;
            default: return 0;
        }
   }
   function install() {}
   function uninstall() {}
   
   function doSkinVar(&$skinType, $constant) {
      global $currentSkinName, $CONF, $member, $DIR_SKINS;
      
      $prefix = "__SL_"; // Nucleus language constants start with 1x _
      
      // get skin dir, includedir
      $sql = "SELECT * FROM ".sql_table("skin_desc")." WHERE sdname = '".$currentSkinName."'";
      $result = mysql_query($sql);
      $row = mysql_fetch_array($result, MYSQL_ASSOC);
      $includeMode = $row['sdincmode'];
      $includePrefix = $row['sdincpref'];
      if( $includeMode == 'normal' ) {
         // nothing to include?
         ACTIONLOG::add(4, "NP_Text is fired with includeMode == normal");
         return;
      }
      else {
         if( $member->getLanguage() != '' ) {
            $language = $member->getLanguage();
         }
         else {
            $language = $CONF['Language'];
         }
         $file = $DIR_SKINS.$includePrefix."language/".$language.".php";
         if( !is_file($file) ) {
            ACTIONLOG::add(1, "NP_Text cannot find skin language file to include for language '".$language."'");
            return;
         }
         else {
            include($file);
            $value = constant($constant);
            echo $value;
         }
      }
   }
   
}

?>


Requires skin language file (skins/skin/language/language.php) where language is the language set by member, if it is not set it will default to globally set language.

Language file must be of the following form:

Code:
<?php

define("__SL_NAME", "value");
// ... etc.

?>


I have chosen __SL_ as the prefix (mind the 2x _) because Nucleus internally uses the _WHAT_ prefix (where WHAT can be SKIN, ADMIN, etc.).

If the skin language file is not found no text will be output but an error will be thrown in the Action Log.


Maybe the language files should be even php-less. Maybe xml or something, more userfriendly. What do you think?

_________________
Please update any "ported by Armon Toubman" links to http://www.armontoubman.com Thanks!

Is your question not solved yet?

Back to top

View user's profile Send private message Visit poster's website
Nefelim
Nucleus Addict


Joined: 30 May 2006
Posts: 56
Location: RUSSIA, Moscow

Post Posted: Thu Jan 18, 2007 12:55 pm   Post subject:
Reply with quote

Nice idea, Leng! Cool I found it and will try to apply. Thanx for advice.

As for me, I think PHP is ok, because any Nucleus CMS Site Administrator have to know it even basically. "Define" function is simple, there is no problem of creating language files.

_________________
~~~ Sith'ari ~~~

Back to top

View user's profile Send private message Visit poster's website MSN Messenger ICQ Number
Leng
Nucleus Guru
Nucleus Guru


Joined: 19 Sep 2004
Posts: 2830
Location: Australia

Post Posted: Thu Jan 18, 2007 1:12 pm   Post subject:
Reply with quote

I think it is fine at the moment, the php-ness of the language file is not too overwhelming, as long as we provide some instructions on how to use to skin authors.

If no one else gets a chance to, I will write up an FAQ for it next week (will be busy this weekend so can't do it then), link on skins site and add it to the skin contribution guidelines.

I will also email Christian who did the skin translations to do some language files to save him the trouble, then get rid of the translated skins on the skins site. Maybe while the new SkinAdmin is under construction (http://forum.nucleuscms.org/viewtopic.php?t=13487), we can have language files hosted on a temporary section on the skins site?

Also, splitting this topic into other improvements. Armon, perhaps you can do a cross-post in Plugin Announce so users are aware of this option when the framework is up and running?

_________________

deborahlau.com | To-Do List
Questions? See the FAQ, read the docs, or browse our plugins!!

Back to top

View user's profile Send private message Send e-mail Visit poster's website AIM Address ICQ Number
Armon
Nucleus Guru
Nucleus Guru


Joined: 16 Feb 2005
Posts: 1832
Location: Zaandam, Netherlands

Post Posted: Thu Jan 18, 2007 1:36 pm   Post subject:
Reply with quote

http://forum.nucleuscms.org/viewtopic.php?t=14906
_________________
Please update any "ported by Armon Toubman" links to http://www.armontoubman.com Thanks!

Is your question not solved yet?

Back to top

View user's profile Send private message Visit poster's website
Nefelim
Nucleus Addict


Joined: 30 May 2006
Posts: 56
Location: RUSSIA, Moscow

Post Posted: Thu Jan 18, 2007 3:40 pm   Post subject:
Reply with quote

Great! Let's see some details... Imagine, I'm an unregistered user, visiting some Nucleus based site. The default language is English, but I see an icon, displaying my native language (my country flag, for example). I need a click, that's simple to understand... But how a site designer should set a correct link or command to change skin language for user? And how should this setting be remembered (cookies?) for some time?
_________________
~~~ Sith'ari ~~~

Back to top

View user's profile Send private message Visit poster's website MSN Messenger ICQ Number
Armon
Nucleus Guru
Nucleus Guru


Joined: 16 Feb 2005
Posts: 1832
Location: Zaandam, Netherlands

Post Posted: Thu Jan 18, 2007 4:08 pm   Post subject:
Reply with quote

Nefelim wrote:
Great! Let's see some details... Imagine, I'm an unregistered user, visiting some Nucleus based site. The default language is English, but I see an icon, displaying my native language (my country flag, for example). I need a click, that's simple to understand... But how a site designer should set a correct link or command to change skin language for user? And how should this setting be remembered (cookies?) for some time?


Not with (only) this plugin. For this you'd need a different plugin that would set and read a cookie and set the language for an unregistered member. I don't know if setting the language for an unregistered member is possible at all with the Nucleus internal workings.

_________________
Please update any "ported by Armon Toubman" links to http://www.armontoubman.com Thanks!

Is your question not solved yet?

Back to top

View user's profile Send private message Visit poster's website
Armon
Nucleus Guru
Nucleus Guru


Joined: 16 Feb 2005
Posts: 1832
Location: Zaandam, Netherlands

Post Posted: Thu Jan 18, 2007 4:12 pm   Post subject:
Reply with quote

Leng wrote:
I think it is fine at the moment, the php-ness of the language file is not too overwhelming, as long as we provide some instructions on how to use to skin authors.


Well then, skin translations need to be checked and only be made available on and only be downloaded from the skins site. Because the words "malicious" and "code" just flashed through my head. Shocked

_________________
Please update any "ported by Armon Toubman" links to http://www.armontoubman.com Thanks!

Is your question not solved yet?

Back to top

View user's profile Send private message Visit poster's website
Nefelim
Nucleus Addict


Joined: 30 May 2006
Posts: 56
Location: RUSSIA, Moscow

Post Posted: Thu Jan 18, 2007 4:21 pm   Post subject:
Reply with quote

Well, Armon. I personally think there is no need to remember unregistered visitor settings, because if he wants his settings to be remembered, he should register. The much important moment is how to select language for a current Skin. Rolling Eyes I implemented your NP_Text, it works wonderful, but I can't change skin language, using something like a command link. The only way I see now is to write some PHP-code to submit requested language variable for the plugin.
_________________
~~~ Sith'ari ~~~

Back to top

View user's profile Send private message Visit poster's website MSN Messenger ICQ Number
Armon
Nucleus Guru
Nucleus Guru


Joined: 16 Feb 2005
Posts: 1832
Location: Zaandam, Netherlands

Post Posted: Thu Jan 18, 2007 5:00 pm   Post subject:
Reply with quote

When the plugin is installed and all the language files are done, you select the language here:
login, admin area, "username", settings, language

To set the default language go to Global Options, language.

_________________
Please update any "ported by Armon Toubman" links to http://www.armontoubman.com Thanks!

Is your question not solved yet?

Back to top

View user's profile Send private message Visit poster's website
Nefelim
Nucleus Addict


Joined: 30 May 2006
Posts: 56
Location: RUSSIA, Moscow

Post Posted: Thu Jan 18, 2007 5:25 pm   Post subject:
Reply with quote

It seems you did not understand me, Armon. It's actually not a problem to set your language, if your're registered user. But what if you're just a visitor? He wants to register or read something, but he can't, cause he don't know the "default" (usually, English) language. In that case I want a visitor to click "the button" and change the language. I do understand this operation can be restricted by Nucleus internals, but...

Btw, whay did you choose double underscoped variable (__SL_)? Why not something like "_TEXT_" or "TEXT"? Just wondering, I can change the plugin code, if I need. Smile

_________________
~~~ Sith'ari ~~~

Back to top

View user's profile Send private message Visit poster's website MSN Messenger ICQ Number
Post new topic Reply to topic
Display posts from previous:   

Goto page 1, 2, 3, 4, 5  Next

Page 1 of 5

All times are GMT + 1 Hour

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2001, 2002 phpBB Group