Java.text api parallel in Ruby

Hi

 Is there a parallel to Format/NumberFormat/DecimalFormat in ruby?

Thanks
Venkat

On 30.07.2009 00:32, Venkat A. wrote:

 Is there a parallel to Format/NumberFormat/DecimalFormat in ruby?

printf, sprintf and % operator for String comes to mind.

Kind regards

robert

Robert K. wrote:

On 30.07.2009 00:32, Venkat A. wrote:

 Is there a parallel to Format/NumberFormat/DecimalFormat in ruby?

printf, sprintf and % operator for String comes to mind.

Kind regards

robert

Thanks for the reply. But as you know java.text api provides the
facility to handle dates, text, numbers in a language independent
manner. In other words of sayin it will let you set date formats ,
number operators etc based on the locale you are dealing with. We have
resorted to writing an API after failing to find one.

Thanks again
Venkat

Did you look at stftime? Perhaps you could provide a concrete example of
what you’re trying to do? Chances are that it’s already been done.

James

On Thu, Jul 30, 2009 at 12:17 PM, Venkat A. <

James H. wrote:

Did you look at stftime? Perhaps you could provide a concrete example of
what you’re trying to do? Chances are that it’s already been done.

James

On Thu, Jul 30, 2009 at 12:17 PM, Venkat A. <

I am trying to translate an application from java to ruby. The actual
application uses decimal formats to provide localization facilities. I
have the code that I am trying to translate which I will attach with the
post.

char decimal = ‘.’;
char grouping = ‘,’;
String formatOutput = null;
String formatInternal = null;

DecimalFormatSymbols dfs = new DecimalFormatSymbols();
dfs.setDecimalSeparator(decimal);
dfs.setGroupingSeparator(grouping);
DecimalFormatSymbols dfsEsp = new DecimalFormatSymbols();
dfsEsp.setDecimalSeparator(’.’);
dfsEsp.setGroupingSeparator(’,’);
FormatCouple fc;
fc = new FormatCouple(new DecimalFormat(formatOutput, dfs), new
DecimalFormat(formatInternal,
dfsEsp));
hasFormats.put(formatName, fc);

Any help is appreciated.

Thanks
Venkat

Okay. So sample input and output? Normally I’d parse through the Java,
but
I’m feeling a little lazy.

James

On Thu, Jul 30, 2009 at 1:21 PM, Venkat A. <

Well, that’s what you get with incomplete specifications. You did not
mention that you need the locale awareness of those. :slight_smile:

Lesson Learned: Better the specification better the answer. In my 

defense, I think my mind was wandering around the strippers I have seen
last night. cheers.

AFAIK there is no locale aware version of the *printf family of methods.
Maybe there’s a gem though or a pointer in RAA.

Kind regards

robert

Thanks For the answer

Okay. So sample input and output? Normally I’d parse through the Java,
but I’m feeling a little lazy.

Subtle but poignant. Well I don’t have a testcase for the class which is
hindering me from posting an output.

The above code actually replaces the conventional numeric symbols used
in English speaking nations with any available local (i.e local to a
nation where it is being used) symbols. Thats about it.

As a solution we are just translating the java.text api into ruby as it
saves time in drafting our own api and it would mean adoption of a
stable draft developed by fully dedicated team. Comments, criticisms and
thoughts are welcome. If things go well we intend to offer the api as a
gem.

Thanks
Venkat

On 30.07.2009 18:17, Venkat A. wrote:

Robert K. wrote:

On 30.07.2009 00:32, Venkat A. wrote:

 Is there a parallel to Format/NumberFormat/DecimalFormat in ruby?

printf, sprintf and % operator for String comes to mind.

Thanks for the reply. But as you know java.text api provides the
facility to handle dates, text, numbers in a language independent
manner.

Well, that’s what you get with incomplete specifications. You did not
mention that you need the locale awareness of those. :slight_smile:

In other words of sayin it will let you set date formats ,
number operators etc based on the locale you are dealing with. We have
resorted to writing an API after failing to find one.

AFAIK there is no locale aware version of the *printf family of methods.
Maybe there’s a gem though or a pointer in RAA.

Kind regards

robert

2009/7/31 Venkat A. [email protected]:

As a solution we are just translating the java.text api into ruby as it
saves time in drafting our own api and it would mean adoption of a
stable draft developed by fully dedicated team. Comments, criticisms and
thoughts are welcome. If things go well we intend to offer the api as a
gem.

Have a look at mutoh’s gettext package[1], a rubyish implementation of
GNU’s gettext.
It is a mature message translation system of all purpose. You may
think it is good
to implement i18n’ed formatter of date/time/number etc atop of it.

[1] http://github.com/mutoh/gettext/tree/master

I realize that the gettext gem is a simili to java’s resourcebundle
hence will help me load key value resources from .po files(.properties
files in java). Definately saved me considerable amoount of work.

Thanks
Venkat

OZAWA Sakuro wrote:

2009/7/31 Venkat A. [email protected]:

As a solution we are just translating the java.text api into ruby as it
saves time in drafting our own api and it would mean adoption of a
stable draft developed by fully dedicated team. Comments, criticisms and
thoughts are welcome. If things go well we intend to offer the api as a
gem.

Have a look at mutoh’s gettext package[1], a rubyish implementation of
GNU’s gettext.
It is a mature message translation system of all purpose. You may
think it is good
to implement i18n’ed formatter of date/time/number etc atop of it.

[1] http://github.com/mutoh/gettext/tree/master

       Thanks for the information Ozawa. I have noticed that you are 

one of the developers. Could you point me to specific comprehensive
resources that will help me research and understand the workings of the
library. I found some documents on Yotabanana.

Thankyou once again.
Venkat

On 31.07.2009 13:30, Venkat A. wrote:

Well, that’s what you get with incomplete specifications. You did not
mention that you need the locale awareness of those. :slight_smile:

Lesson Learned: Better the specification better the answer. In my 

defense, I think my mind was wandering around the strippers I have seen
last night. cheers.

:slight_smile: No problem at all - it happens all the time.

The above code actually replaces the conventional numeric symbols used
in English speaking nations with any available local (i.e local to a
nation where it is being used) symbols. Thats about it.

As a solution we are just translating the java.text api into ruby as it
saves time in drafting our own api and it would mean adoption of a
stable draft developed by fully dedicated team. Comments, criticisms and
thoughts are welcome. If things go well we intend to offer the api as a
gem.

You could do something like this (untested):

LOCALE_SYMBOLS_US = {
‘%.’ => ‘.’,
‘%,’ => ‘,’,
}

def lprintf(pattern, *args)

emulate locale aware lookup

syms = LOCALE_SYMBOLS_US
pat = pattern.gsub(Regexp.new(Regexp.union(syms.keys))) do |m|
syms[m] || ‘’
end
printf(pat, *args)
end

The symbols then should really come from a resource file selected via
the current locale.

Kind regards

robert

I don’t have much, but firstly I recommend you to visit GNU’s gettext
page
(http://www.gnu.org/software/gettext/ ) and learn its design and
philosophy.

2009/8/1 Venkat A. [email protected]:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs