Results 1 to 2 of 2

Thread: xGettext and Gettext

  1. #1
    Join Date
    Mar 2006
    Beans
    563

    xGettext and Gettext

    Hey,

    I'm (finally) adding language support to my open-source PHP CMS and after much thinking I've decided to go with Gettext for translations/locale. I've got it working great, however I have to create the Pot manually!

    The way I am doing Gettext is different to your normal:

    Code:
    echo _( 'Hello over there!' );
    // Or
    echo gettext( 'Hello over there!' );
    Instead, as I using a custom-built MVC Framework - in my View files I have tags like the following:

    Code:
    <p>{L_[Hello over there!]}</p>
    Then in my view class it simply uses reg-ex to get every language 'tag' - here is the code if you're interested:

    Code:
    		//---
    		// language_tags() provides the Zula framework with language support for
    		// views. It finds all tags that are in the format of {L_[phrase]} and replaces
    		// then with the correct translation
    		// @param string $content
    		// @return string
    		//---
    		private function language_tags( $content ) {
    			Registry::get( 'locale' )->update_text_domain( 'messages', Zula::get_dir( 'controllers' ).'/'.$this->module.'/locale' ); 
    			preg_match_all('@{L_\[(.[^\]]*)]}@', $content, $tags);
    			#Zula::debug_print( $tags );
    			if ( !empty( $tags[0] ) ) {							
    				foreach( $tags[0] as $key=>$tag ) {
    					$tag = trim( $tag, '{} ' );
    					$value = gettext( $tags[1][ $key ] );
    					$this->assign( array( $tag => $value ), false );
    				}
    			}
    		}
    As my View files also allow for PHP code, I do in _some_ of them have:

    Code:
    <?php echo gettext( 'Hello over there!' ); ?>
    Now, I have to create the pot files manually because xgettext only looks for _() or gettext() for it to generate the pot files from, and this just wont work with how I am doing it.

    I am wondering if there is a way to ... change how xgettext searches for the strings it needs, so I don't have to do the very painful process of creating my pot files manually!

    Thanks!

  2. #2
    Join Date
    Aug 2005
    Location
    Alcabideche, Portugal
    Beans
    232

    Re: xGettext and Gettext

    there is a way, I use:

    Code:
    xgettext -n *.php --keyword=msg
    where "msg" is my custom method that I use in php files for sending strings, for example:

    Code:
    print msg('My favorite foods are').":\n";
    print msg('french fries')."\n";
    after the "xgettext" call I end up with a .po file that contains:

    Code:
    #: index.php:41
    msgid "My favorite foods are"
    msgstr ""
    
    #: index.php:42
    msgid "french fries"
    msgstr ""

    EDIT: i know thread is old, probably not much use for the thread starter but I had the same problem and could be useful for others...
    Last edited by mihai.ile; April 22nd, 2009 at 11:00 PM.
    Collecting data is only the first step toward wisdom but sharing data is the first step toward community

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •