How to compare LocalizedString objects

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

How to compare LocalizedString objects

Peter Schneider
Hi there,

how do I compare two LocalizedString objects, ore even against a JavaScript
literal String (in qooxdoo 0.8.4 or higher)?

In qooxdoo 0.7.4 you could do this:
<code class=javascript>
  var vLabel = this.tr("Alle Benutzer");

  // Evaluated into <true>:
  if (vLabel.getId() == "Alle Benutzer") {
    //...
  }
  // Even this worked:
  if (vLabel.getId() === "Alle Benutzer") {
    //...
  }
</code>

While the LocalizedString Class in qooxdoo 0.8.4 (and 1.0 and trunk)
do not have any id property...

Even this evaluates to false:
<code class=javascript>
  this.tr("same") == this.tr("same")
</code>

I have to somehow compare against the private "__messageId", or is there any
static Class providing a compare(a, b) method in the framework?

I would have written my own compare class/method, but I don't like to access
private members :) ...

Thanks in advance,
  Peter


------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: [qooxdoo-devel] How to compare LocalizedString objects

Peter Schneider
Why is it always that you get an idea just _after_ you posted your question? ;)

For my "problem with privates" I will apply a patch:

<code class=javascript>
  // Patch #1: Add getId() method to LocalizedString (qooxdoo 0.7.4 like)
  qx.Class.patch(qx.locale.LocalizedString,
    qx.Mixin.define("app.patch.MLocalizedString",
    {
      members :
      {
        getId : function () {
          return this.__messageId;
        }
      }
    })
  );
</code>

Nevertheless, nice weekend everybody

  Peter

>[...]
> I would have written my own compare class/method, but I don't like to access
> private members :) ...
>
> Thanks in advance,
>   Peter
>[...]


------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: [qooxdoo-devel] How to compare LocalizedString objects

Burak Arslan-2
In reply to this post by Peter Schneider

hi,

i did have a need to do this a while ago. i did what you are reluctant
to do and just added a method (get_message_id) that returns the __messageId.

i think it should be made into a property.

best,
burak

Peter Schneider wrote:

> Hi there,
>
> how do I compare two LocalizedString objects, ore even against a JavaScript
> literal String (in qooxdoo 0.8.4 or higher)?
>
> In qooxdoo 0.7.4 you could do this:
> <code class=javascript>
>   var vLabel = this.tr("Alle Benutzer");
>
>   // Evaluated into <true>:
>   if (vLabel.getId() == "Alle Benutzer") {
>     //...
>   }
>   // Even this worked:
>   if (vLabel.getId() === "Alle Benutzer") {
>     //...
>   }
> </code>
>
> While the LocalizedString Class in qooxdoo 0.8.4 (and 1.0 and trunk)
> do not have any id property...
>
> Even this evaluates to false:
> <code class=javascript>
>   this.tr("same") == this.tr("same")
> </code>
>
> I have to somehow compare against the private "__messageId", or is there any
> static Class providing a compare(a, b) method in the framework?
>
> I would have written my own compare class/method, but I don't like to access
> private members :) ...
>
> Thanks in advance,
>   Peter
>
>
> ------------------------------------------------------------------------------
> Throughout its 18-year history, RSA Conference consistently attracts the
> world's best and brightest in the field, creating opportunities for Conference
> attendees to learn about information security's most important issues through
> interactions with peers, luminaries and emerging and established companies.
> http://p.sf.net/sfu/rsaconf-dev2dev
> _______________________________________________
> qooxdoo-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
>  


------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: [qooxdoo-devel] How to compare LocalizedString objects

Fabian Jakobs
Administrator
In reply to this post by Peter Schneider
Hi Peter,

in qooxdoo 1.0 LocalizedString instances are sub classes of String. If
you compare two of those with the "==" operator, the JavaScript
interpreter will compare the object references, which are different:

this.tr("foo") == this.tr("foo") // false

if you convert one of the localized Strings to a string, you are able to
compare them:

this.tr("foo") == this.tr("foo") + "" // true
this.tr("foo") == this.tr("foo").toString() // true

Best Fabian

> Hi there,
>
> how do I compare two LocalizedString objects, ore even against a JavaScript
> literal String (in qooxdoo 0.8.4 or higher)?
>
> In qooxdoo 0.7.4 you could do this:
> <code class=javascript>
>   var vLabel = this.tr("Alle Benutzer");
>
>   // Evaluated into <true>:
>   if (vLabel.getId() == "Alle Benutzer") {
>     //...
>   }
>   // Even this worked:
>   if (vLabel.getId() === "Alle Benutzer") {
>     //...
>   }
> </code>
>
> While the LocalizedString Class in qooxdoo 0.8.4 (and 1.0 and trunk)
> do not have any id property...
>
> Even this evaluates to false:
> <code class=javascript>
>   this.tr("same") == this.tr("same")
> </code>
>
> I have to somehow compare against the private "__messageId", or is there any
> static Class providing a compare(a, b) method in the framework?
>
> I would have written my own compare class/method, but I don't like to access
> private members :) ...
>
> Thanks in advance,
>   Peter
>
>
> ------------------------------------------------------------------------------
> Throughout its 18-year history, RSA Conference consistently attracts the
> world's best and brightest in the field, creating opportunities for Conference
> attendees to learn about information security's most important issues through
> interactions with peers, luminaries and emerging and established companies.
> http://p.sf.net/sfu/rsaconf-dev2dev
> _______________________________________________
> qooxdoo-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
>
>
>  


--
Fabian Jakobs
JavaScript Framework Developer

1&1 Internet AG - Web Technologies
Ernst-Frey-Straße 9 · DE-76135 Karlsruhe
Telefon: +49 721 91374-6784
[hidden email]

Amtsgericht Montabaur / HRB 6484
Vorstände: Henning Ahlert, Ralph Dommermuth, Matthias Ehrlich, Thomas Gottschlich, Robert Hoffmann, Markus Huhn, Hans-Henning Kettler, Dr. Oliver Mauss, Jan Oetjen
Aufsichtsratsvorsitzender: Michael Scheeren


------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: [qooxdoo-devel] How to compare LocalizedString objects

Thomas Herchenroeder
In reply to this post by Peter Schneider
Mh... why don't you just use the .translate() method?! It will give you
the string in the current locale (or the id, if there is no translation
for it). Isn't that what you mostly want?

T.

On 01/22/2010 05:03 PM, Peter Schneider wrote:

> Hi there,
>
> how do I compare two LocalizedString objects, ore even against a JavaScript
> literal String (in qooxdoo 0.8.4 or higher)?
>
> In qooxdoo 0.7.4 you could do this:
> <code class=javascript>
>   var vLabel = this.tr("Alle Benutzer");
>
>   // Evaluated into <true>:
>   if (vLabel.getId() == "Alle Benutzer") {
>     //...
>   }
>   // Even this worked:
>   if (vLabel.getId() === "Alle Benutzer") {
>     //...
>   }
> </code>
>
> While the LocalizedString Class in qooxdoo 0.8.4 (and 1.0 and trunk)
> do not have any id property...
>
> Even this evaluates to false:
> <code class=javascript>
>   this.tr("same") == this.tr("same")
> </code>
>
> I have to somehow compare against the private "__messageId", or is there any
> static Class providing a compare(a, b) method in the framework?
>
> I would have written my own compare class/method, but I don't like to access
> private members :) ...
>
> Thanks in advance,
>   Peter
>
>
> ------------------------------------------------------------------------------
> Throughout its 18-year history, RSA Conference consistently attracts the
> world's best and brightest in the field, creating opportunities for Conference
> attendees to learn about information security's most important issues through
> interactions with peers, luminaries and emerging and established companies.
> http://p.sf.net/sfu/rsaconf-dev2dev
> _______________________________________________
> qooxdoo-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
>
>

------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: [qooxdoo-devel] How to compare LocalizedString objects

Derrell Lipman
In reply to this post by Peter Schneider
On Fri, Jan 22, 2010 at 11:30, Peter Schneider <[hidden email]> wrote:
Why is it always that you get an idea just _after_ you posted your question? ;)

For my "problem with privates" I will apply a patch:

<code class=javascript>
 // Patch #1: Add getId() method to LocalizedString (qooxdoo 0.7.4 like)
 qx.Class.patch(qx.locale.LocalizedString,
   qx.Mixin.define("app.patch.MLocalizedString",
   {
     members :
     {
       getId : function () {
         return this.__messageId;
       }
     }
   })
 );
</code>

Unfortunately that won't work in the "build" version. Mixins can't currently touch private members (those with leading double underscores). It will work fine in the source version, but then fail with the build version.

See the comments others have made for alternative solutions.

Derrell


------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: [qooxdoo-devel] How to compare LocalizedString objects

Burak Arslan-2
In reply to this post by Thomas Herchenroeder
thron7 wrote:
> Mh... why don't you just use the .translate() method?! It will give you
> the string in the current locale (or the id, if there is no translation
> for it). Isn't that what you mostly want?
>
>  


hello thomas,

my use case was with a relatively populated selectbox, where i did not
want to duplicate the information that was already inside __message_id
with setModel().

i don't think it'd hurt to provide read-only access to that member. i do
suspect making it a writable property could cause trouble.

burak






------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: [qooxdoo-devel] How to compare LocalizedString objects

Peter Schneider
In reply to this post by Derrell Lipman
Hi Derrell,


> [...]
> Unfortunately that won't work in the "build" version. Mixins can't currently
> touch private members (those with leading double underscores). It will work
> fine in the source version, but then fail with the build version.
>
> See the comments others have made for alternative solutions.
>
> Derrell
> [...]

Thanks a lot for that info! Is there any documentation on this behavior?
I can't find it. Neither for 0.8 nor for 1.0 ...
It should be mentioned here [1] & [2].
  Is it a "normal" behavior of Mixins in other languages to disallow for
private access? If that is the case and this behavior is wanted in qooxdoo, the
generator should inform about mis-use. A warning would be nice.

  Peter


[1] http://qooxdoo.org/documentation/0.8/mixins
[2] http://qooxdoo.org/documentation/1.0/mixins


------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: [qooxdoo-devel] How to compare LocalizedString objects

Fabian Jakobs
Administrator
Peter Schneider schrieb:

> Hi Derrell,
>
>
>  
>> [...]
>> Unfortunately that won't work in the "build" version. Mixins can't currently
>> touch private members (those with leading double underscores). It will work
>> fine in the source version, but then fail with the build version.
>>
>> See the comments others have made for alternative solutions.
>>
>> Derrell
>> [...]
>>    
>
> Thanks a lot for that info! Is there any documentation on this behavior?
> I can't find it. Neither for 0.8 nor for 1.0 ...
> It should be mentioned here [1] & [2].
>   Is it a "normal" behavior of Mixins in other languages to disallow for
> private access? If that is the case and this behavior is wanted in qooxdoo, the
> generator should inform about mis-use. A warning would be nice.
>
>   Peter
>  
Hi Peter,

it is the private optimizer, which will make this fail. It you turn it
off for your build your mixin will work in the build version as well.
Since JavaScript is dynamically typed, the generator cannot "know" that
two private in different files refer to the same field - it can only
guess. The guessing works only reasonably well within a single file. For
this reason it is hard to print useful error messages.

Best Fabian

--
Fabian Jakobs
JavaScript Framework Developer

1&1 Internet AG - Web Technologies
Ernst-Frey-Straße 9 · DE-76135 Karlsruhe
Telefon: +49 721 91374-6784
[hidden email]

Amtsgericht Montabaur / HRB 6484
Vorstände: Henning Ahlert, Ralph Dommermuth, Matthias Ehrlich, Thomas Gottschlich, Robert Hoffmann, Markus Huhn, Hans-Henning Kettler, Dr. Oliver Mauss, Jan Oetjen
Aufsichtsratsvorsitzender: Michael Scheeren


------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: [qooxdoo-devel] How to compare LocalizedString objects

Peter Schneider
Hi Fabian,

I agree that it is not "very easy" to detect the access violation. It was only
a wish that can be ignored, if too expensive to implement ;)

But a clearer overview of what Mixins can do, what they can't and what they
shouldn't do would be nice. When I read the documentation and API (both only
for Version 1.0) I come to the following overview:

* A mixin may not access private or protected members that were not defined in
  the mixin itself.
* A mixin can not overwrite methods/properties of the class that it will be
  merged into. (Except if applied to a class via qx.Class.patch())

Is this correct? Please _do_ correct any false statement!

Thanks
  Peter


P.S.: If those statements were already valid for qooxdoo 0.7.x, or if they do
      vary, please make a note on that.

-------- Original --------
From: Fabian Jakobs
Date: 25.01.2010 09:47

> Peter Schneider schrieb:
>> Hi Derrell,
>>
>>
>>  
>>> [...]
>>> Unfortunately that won't work in the "build" version. Mixins can't currently
>>> touch private members (those with leading double underscores). It will work
>>> fine in the source version, but then fail with the build version.
>>>
>>> See the comments others have made for alternative solutions.
>>>
>>> Derrell
>>> [...]
>>>    
>> Thanks a lot for that info! Is there any documentation on this behavior?
>> I can't find it. Neither for 0.8 nor for 1.0 ...
>> It should be mentioned here [1] & [2].
>>   Is it a "normal" behavior of Mixins in other languages to disallow for
>> private access? If that is the case and this behavior is wanted in qooxdoo, the
>> generator should inform about mis-use. A warning would be nice.
>>
>>   Peter
>>  
> Hi Peter,
>
> it is the private optimizer, which will make this fail. It you turn it
> off for your build your mixin will work in the build version as well.
> Since JavaScript is dynamically typed, the generator cannot "know" that
> two private in different files refer to the same field - it can only
> guess. The guessing works only reasonably well within a single file. For
> this reason it is hard to print useful error messages.
>
> Best Fabian
>


------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: [qooxdoo-devel] How to compare LocalizedString objects

Fabian Jakobs
Administrator
Peter Schneider schrieb:

> Hi Fabian,
>
> I agree that it is not "very easy" to detect the access violation. It was only
> a wish that can be ignored, if too expensive to implement ;)
>
> But a clearer overview of what Mixins can do, what they can't and what they
> shouldn't do would be nice. When I read the documentation and API (both only
> for Version 1.0) I come to the following overview:
>
> * A mixin may not access private or protected members that were not defined in
>   the mixin itself.
>  

Access to protected members is OK but might not be good style.
> * A mixin can not overwrite methods/properties of the class that it will be
>   merged into. (Except if applied to a class via qx.Class.patch())
>  
Correct
> Is this correct? Please _do_ correct any false statement!
>
> Thanks
>   Peter
>
>
> P.S.: If those statements were already valid for qooxdoo 0.7.x, or if they do
>       vary, please make a note on that.
>  
I'm pretty sure that this also applies to 0.7

Best Fabian


--
Fabian Jakobs
JavaScript Framework Developer

1&1 Internet AG - Web Technologies
Ernst-Frey-Straße 9 · DE-76135 Karlsruhe
Telefon: +49 721 91374-6784
[hidden email]

Amtsgericht Montabaur / HRB 6484
Vorstände: Henning Ahlert, Ralph Dommermuth, Matthias Ehrlich, Thomas Gottschlich, Robert Hoffmann, Markus Huhn, Hans-Henning Kettler, Dr. Oliver Mauss, Jan Oetjen
Aufsichtsratsvorsitzender: Michael Scheeren


------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel