Re: [PHP] 'lang' file editor ...

2007-04-12 Thread Jochem Maas
Matt Carlson wrote:
> I am running into the same problem.
> 
> A very VERY basic thing that I worked on for importing yielded this:
> 
> preg_match_all('/.*?(?:\$lang([^=]*)=(.*?); *$.*?)+/ms', 
> file_get_contents("localization/enUS.php"), $parsed);
> 
> It wasn't the best, but it worked 90% of the time.  Maybe this can help you 
> on the parsing front.

to be honest that regexp is rather too crude for all the variations I want/need 
to deal with,
it quite alot like the first attempt I made a few years ago ... although I 
notice you don't consider
the matching the string quotations (and/or use backreferences in the regexp to 
make sure the quotes match)

I've actually started work on an editor that is based around token_get_all() - 
and I'm finding it rather
easy going - alot easier than the regexp hell I got stuck itn last time round 
... when I'm done
I post what I have (although It'll be in a form that will require whoever want 
to do something
with it to hack it up a bit so it works within the confines of their CMS 
[and/or standalone])

> 
> - Original Message 
> From: Jochem Maas <[EMAIL PROTECTED]>
> To: Jim Lucas <[EMAIL PROTECTED]>
> Cc: [EMAIL PROTECTED]; [php] PHP General List <[EMAIL PROTECTED]>
> Sent: Thursday, April 12, 2007 5:11:39 AM
> Subject: Re: [PHP] 'lang' file editor ...
> 
> what I'm looking for is something that will make it possible for an end user
> to merge [the contents] existing language files (that contain the items for 
> the same language)
> *and* perform translations between languages in a visual/easy way (i.e. 
> without opening
> a text editor) but end up with lang files that still formatted and commented 
> when I'm done.
> 
> it's a three step process:
> 
> 1. 'parse' 2 files: a 'reference' and a 'translation' file
> 2. display an editing interface for the 2 files (textareas, filtering [e.g. 
> show only
> untranslated items], sorting, etc)
> 3. write out a merged/updated file.
> 
> probably the merging of 2 existing lang files of the same language will 
> require
> a seperate interface than the translation/comparison of 2 files containing 
> different
> languages.
> 
> I have made a half-assed attempt to do this some years ago and it worked ok
> but wasn't quite the level of sophistication I desired  - If no one has 
> anything like
> this lying around then I guess it's time for me to hack up a new thingummy,
> using var_export()/print_r() [and running the code to merge, etc] won't cut it
> (I've been down that road already) so probably I'm looking
> at using either the tokenizer (although how exactly is something I'd have to 
> look into)
> or a combination of preg_match()/preg_replace() (which is something I am 
> confident
> I can now do to the required level - when I tried before my regexp skills 
> sucked
> too much).
> 
> I'm quite sure I make it work, but I'd be surprised if no-one has gone before 
> me
> - there must be tons of projects out there with the same kind of language 
> file structure ...
> 
> maybe I should consider moving my 'shit' into gettext format.
> 
> Jim Lucas wrote:
>> Richard Lynch wrote:
>>> Seems to me you'd be better off just running the PHP code and dumping
>>> the arrays out with var_dump or print_r "like" function to generate
>>> your new language files...
>>>
>>> Otherwise, you're writing a fairly big chunk of the PHP parser, which
>>> is already in PHP, so you re-invent the wheel...
>>>
>>> On Wed, April 11, 2007 9:07 pm, Jochem Maas wrote:
>>>> anyone know of a decent script (or something I can rip out of an
>>>> existing OS tool)
>>>> that is capable of comparing, editing and saving 'old skool' lang
>>>> files - you know
>>>> the ones which define tons of array elements e.g.:
>>>>
>>>> $Lang['foo'] = 'bar';
>>>>
>>>> I'm looking for something that can handle quotes properly and 'weird'
>>>> array keys
>>>> (that include constants, for instance) as well as sprintf markers in
>>>> the 'translation'
>>>> text (e.g. "my %s hurts") and if at all possible the abiltiy to
>>>> recognise and not f'up
>>>> stuff like:
>>>>
>>>> $Lang['foo'] = 'my '.$Lang['bar'].' really hurts';
>>>>
>>>> and I'd prefer it to be able to keep file formatting, item 

Re: [PHP] 'lang' file editor ...

2007-04-12 Thread Matt Carlson
I am running into the same problem.

A very VERY basic thing that I worked on for importing yielded this:

preg_match_all('/.*?(?:\$lang([^=]*)=(.*?); *$.*?)+/ms', 
file_get_contents("localization/enUS.php"), $parsed);

It wasn't the best, but it worked 90% of the time.  Maybe this can help you on 
the parsing front.

- Original Message 
From: Jochem Maas <[EMAIL PROTECTED]>
To: Jim Lucas <[EMAIL PROTECTED]>
Cc: [EMAIL PROTECTED]; [php] PHP General List <[EMAIL PROTECTED]>
Sent: Thursday, April 12, 2007 5:11:39 AM
Subject: Re: [PHP] 'lang' file editor ...

what I'm looking for is something that will make it possible for an end user
to merge [the contents] existing language files (that contain the items for the 
same language)
*and* perform translations between languages in a visual/easy way (i.e. without 
opening
a text editor) but end up with lang files that still formatted and commented 
when I'm done.

it's a three step process:

1. 'parse' 2 files: a 'reference' and a 'translation' file
2. display an editing interface for the 2 files (textareas, filtering [e.g. 
show only
untranslated items], sorting, etc)
3. write out a merged/updated file.

probably the merging of 2 existing lang files of the same language will require
a seperate interface than the translation/comparison of 2 files containing 
different
languages.

I have made a half-assed attempt to do this some years ago and it worked ok
but wasn't quite the level of sophistication I desired  - If no one has 
anything like
this lying around then I guess it's time for me to hack up a new thingummy,
using var_export()/print_r() [and running the code to merge, etc] won't cut it
(I've been down that road already) so probably I'm looking
at using either the tokenizer (although how exactly is something I'd have to 
look into)
or a combination of preg_match()/preg_replace() (which is something I am 
confident
I can now do to the required level - when I tried before my regexp skills sucked
too much).

I'm quite sure I make it work, but I'd be surprised if no-one has gone before me
- there must be tons of projects out there with the same kind of language file 
structure ...

maybe I should consider moving my 'shit' into gettext format.

Jim Lucas wrote:
> Richard Lynch wrote:
>> Seems to me you'd be better off just running the PHP code and dumping
>> the arrays out with var_dump or print_r "like" function to generate
>> your new language files...
>>
>> Otherwise, you're writing a fairly big chunk of the PHP parser, which
>> is already in PHP, so you re-invent the wheel...
>>
>> On Wed, April 11, 2007 9:07 pm, Jochem Maas wrote:
>>> anyone know of a decent script (or something I can rip out of an
>>> existing OS tool)
>>> that is capable of comparing, editing and saving 'old skool' lang
>>> files - you know
>>> the ones which define tons of array elements e.g.:
>>>
>>> $Lang['foo'] = 'bar';
>>>
>>> I'm looking for something that can handle quotes properly and 'weird'
>>> array keys
>>> (that include constants, for instance) as well as sprintf markers in
>>> the 'translation'
>>> text (e.g. "my %s hurts") and if at all possible the abiltiy to
>>> recognise and not f'up
>>> stuff like:
>>>
>>> $Lang['foo'] = 'my '.$Lang['bar'].' really hurts';
>>>
>>> and I'd prefer it to be able to keep file formatting, item ordering
>>> and comments
>>> as they were when saving back into the file.
>>>
>>> I can't find anything really useful - the firefox 'php lang file'
>>> editor plugin, is,
>>> for instance, not up to the job.
>>>
>>> tar,
>>> Jochem
>>>
>>> -- 
>>> PHP General Mailing List (http://www.php.net/)
>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>
>>>
>>
>>
> From what he said, I read that he want to rip the contents out of the
> file, not actually parse it.
> 
> for example, if he parsed this out:
> $Lang['foo'] = 'my '.$Lang['bar'].' really hurts';
> 
> You would get the completed string, not a line that has the variable
> call in it.
> 
> Maybe I took it wrong, but that is what I thought he wanted.
> 
> a reader, not a parser.
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] 'lang' file editor ...

2007-04-12 Thread Satyam
- Original Message - 
From: "Jochem Maas" <[EMAIL PROTECTED]>

Satyam wrote:


maybe I should consider moving my 'shit' into gettext format.


That was just what I was going to sugest: using gettext format.


yeah, but I curerntly have 30 odd files each with upwards of 2000 strings
in them, and it would also require changing the code base to use gettext
(which is the easy part since I already use a wrap function for all
the string/translation grabbing)


Nevertheless, I find php-gettext far more flexible and, since it is in
source format, you might want to modifiy the part that reads in the


you mean this?:

http://savannah.nongnu.org/projects/php-gettext/

I'm not sure I want to use userland code that does what gettext extension 
does
[faster] (I'm quite happy to install/configure gettext and all the 
relevant locales)

especially given that the author begins with "I don't like php much"
... but none the less I'll check it out.



It is the gettext used by Wordpress and some other software that doesn't 
rely on people being happy installing and configuring gettext, so I guess it 
will be supported well beyond the likes or dislikes of the original 
developer.  Nevertheless, since you already have the part of wrapping the 
translatable strings done, you might also want to check the PHP Compiler: 
http://phpcompiler.org/ as an alternative way of finding tokens.



compiled translation file and use it to read in whatever format you find
suits your needs.

Satyam





--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.446 / Virus Database: 269.2.0/757 - Release Date: 11/04/2007 
17:14





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] 'lang' file editor ...

2007-04-12 Thread Jochem Maas
I just played around with token_get_all() and token_name() and by the looks of 
the
output it's going to be quite easy to create something that can rewrite the 
contents of a file and
or augment it ...

the only really tricky thing that I can't get my head round right away is
handling the following in a nice way:

$Lang['foo'] = 'bar';
$Lang['foo'] = 'my '.$Lang['bar'].' really hurts';

but part of the answer/solution to that problem lies in what I would like
to present (and/or require from0 the person who will use the lang file 'editor'

it's been a pleasure talking to myself ;-)

Jochem Maas wrote:
> anyone know of a decent script (or something I can rip out of an existing OS 
> tool)
> that is capable of comparing, editing and saving 'old skool' lang files - you 
> know
> the ones which define tons of array elements e.g.:
> 
> $Lang['foo'] = 'bar';
> 
> I'm looking for something that can handle quotes properly and 'weird' array 
> keys
> (that include constants, for instance) as well as sprintf markers in the 
> 'translation'
> text (e.g. "my %s hurts") and if at all possible the abiltiy to recognise and 
> not f'up
> stuff like:
> 
> $Lang['foo'] = 'my '.$Lang['bar'].' really hurts';
> 
> and I'd prefer it to be able to keep file formatting, item ordering and 
> comments
> as they were when saving back into the file.
> 
> I can't find anything really useful - the firefox 'php lang file' editor 
> plugin, is,
> for instance, not up to the job.
> 
> tar,
> Jochem
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] 'lang' file editor ...

2007-04-12 Thread Jochem Maas
Satyam wrote:
>>
>> maybe I should consider moving my 'shit' into gettext format.
> 
> That was just what I was going to sugest: using gettext format.

yeah, but I curerntly have 30 odd files each with upwards of 2000 strings
in them, and it would also require changing the code base to use gettext
(which is the easy part since I already use a wrap function for all
the string/translation grabbing)

> Nevertheless, I find php-gettext far more flexible and, since it is in
> source format, you might want to modifiy the part that reads in the

you mean this?:

http://savannah.nongnu.org/projects/php-gettext/

I'm not sure I want to use userland code that does what gettext extension does
[faster] (I'm quite happy to install/configure gettext and all the relevant 
locales)
especially given that the author begins with "I don't like php much"
... but none the less I'll check it out.

> compiled translation file and use it to read in whatever format you find
> suits your needs.
> 
> Satyam
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] 'lang' file editor ...

2007-04-12 Thread Satyam


maybe I should consider moving my 'shit' into gettext format.


That was just what I was going to sugest: using gettext format. 
Nevertheless, I find php-gettext far more flexible and, since it is in 
source format, you might want to modifiy the part that reads in the compiled 
translation file and use it to read in whatever format you find suits your 
needs.


Satyam

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] 'lang' file editor ...

2007-04-12 Thread Jochem Maas
what I'm looking for is something that will make it possible for an end user
to merge [the contents] existing language files (that contain the items for the 
same language)
*and* perform translations between languages in a visual/easy way (i.e. without 
opening
a text editor) but end up with lang files that still formatted and commented 
when I'm done.

it's a three step process:

1. 'parse' 2 files: a 'reference' and a 'translation' file
2. display an editing interface for the 2 files (textareas, filtering [e.g. 
show only
untranslated items], sorting, etc)
3. write out a merged/updated file.

probably the merging of 2 existing lang files of the same language will require
a seperate interface than the translation/comparison of 2 files containing 
different
languages.

I have made a half-assed attempt to do this some years ago and it worked ok
but wasn't quite the level of sophistication I desired  - If no one has 
anything like
this lying around then I guess it's time for me to hack up a new thingummy,
using var_export()/print_r() [and running the code to merge, etc] won't cut it
(I've been down that road already) so probably I'm looking
at using either the tokenizer (although how exactly is something I'd have to 
look into)
or a combination of preg_match()/preg_replace() (which is something I am 
confident
I can now do to the required level - when I tried before my regexp skills sucked
too much).

I'm quite sure I make it work, but I'd be surprised if no-one has gone before me
- there must be tons of projects out there with the same kind of language file 
structure ...

maybe I should consider moving my 'shit' into gettext format.

Jim Lucas wrote:
> Richard Lynch wrote:
>> Seems to me you'd be better off just running the PHP code and dumping
>> the arrays out with var_dump or print_r "like" function to generate
>> your new language files...
>>
>> Otherwise, you're writing a fairly big chunk of the PHP parser, which
>> is already in PHP, so you re-invent the wheel...
>>
>> On Wed, April 11, 2007 9:07 pm, Jochem Maas wrote:
>>> anyone know of a decent script (or something I can rip out of an
>>> existing OS tool)
>>> that is capable of comparing, editing and saving 'old skool' lang
>>> files - you know
>>> the ones which define tons of array elements e.g.:
>>>
>>> $Lang['foo'] = 'bar';
>>>
>>> I'm looking for something that can handle quotes properly and 'weird'
>>> array keys
>>> (that include constants, for instance) as well as sprintf markers in
>>> the 'translation'
>>> text (e.g. "my %s hurts") and if at all possible the abiltiy to
>>> recognise and not f'up
>>> stuff like:
>>>
>>> $Lang['foo'] = 'my '.$Lang['bar'].' really hurts';
>>>
>>> and I'd prefer it to be able to keep file formatting, item ordering
>>> and comments
>>> as they were when saving back into the file.
>>>
>>> I can't find anything really useful - the firefox 'php lang file'
>>> editor plugin, is,
>>> for instance, not up to the job.
>>>
>>> tar,
>>> Jochem
>>>
>>> -- 
>>> PHP General Mailing List (http://www.php.net/)
>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>
>>>
>>
>>
> From what he said, I read that he want to rip the contents out of the
> file, not actually parse it.
> 
> for example, if he parsed this out:
> $Lang['foo'] = 'my '.$Lang['bar'].' really hurts';
> 
> You would get the completed string, not a line that has the variable
> call in it.
> 
> Maybe I took it wrong, but that is what I thought he wanted.
> 
> a reader, not a parser.
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] 'lang' file editor ...

2007-04-11 Thread Jim Lucas

Richard Lynch wrote:

Seems to me you'd be better off just running the PHP code and dumping
the arrays out with var_dump or print_r "like" function to generate
your new language files...

Otherwise, you're writing a fairly big chunk of the PHP parser, which
is already in PHP, so you re-invent the wheel...

On Wed, April 11, 2007 9:07 pm, Jochem Maas wrote:

anyone know of a decent script (or something I can rip out of an
existing OS tool)
that is capable of comparing, editing and saving 'old skool' lang
files - you know
the ones which define tons of array elements e.g.:

$Lang['foo'] = 'bar';

I'm looking for something that can handle quotes properly and 'weird'
array keys
(that include constants, for instance) as well as sprintf markers in
the 'translation'
text (e.g. "my %s hurts") and if at all possible the abiltiy to
recognise and not f'up
stuff like:

$Lang['foo'] = 'my '.$Lang['bar'].' really hurts';

and I'd prefer it to be able to keep file formatting, item ordering
and comments
as they were when saving back into the file.

I can't find anything really useful - the firefox 'php lang file'
editor plugin, is,
for instance, not up to the job.

tar,
Jochem

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php






From what he said, I read that he want to rip the contents out of the file, not 
actually parse it.

for example, if he parsed this out:
$Lang['foo'] = 'my '.$Lang['bar'].' really hurts';

You would get the completed string, not a line that has the variable call in it.

Maybe I took it wrong, but that is what I thought he wanted.

a reader, not a parser.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] 'lang' file editor ...

2007-04-11 Thread Richard Lynch
Seems to me you'd be better off just running the PHP code and dumping
the arrays out with var_dump or print_r "like" function to generate
your new language files...

Otherwise, you're writing a fairly big chunk of the PHP parser, which
is already in PHP, so you re-invent the wheel...

On Wed, April 11, 2007 9:07 pm, Jochem Maas wrote:
> anyone know of a decent script (or something I can rip out of an
> existing OS tool)
> that is capable of comparing, editing and saving 'old skool' lang
> files - you know
> the ones which define tons of array elements e.g.:
>
> $Lang['foo'] = 'bar';
>
> I'm looking for something that can handle quotes properly and 'weird'
> array keys
> (that include constants, for instance) as well as sprintf markers in
> the 'translation'
> text (e.g. "my %s hurts") and if at all possible the abiltiy to
> recognise and not f'up
> stuff like:
>
> $Lang['foo'] = 'my '.$Lang['bar'].' really hurts';
>
> and I'd prefer it to be able to keep file formatting, item ordering
> and comments
> as they were when saving back into the file.
>
> I can't find anything really useful - the firefox 'php lang file'
> editor plugin, is,
> for instance, not up to the job.
>
> tar,
> Jochem
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php