You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by 7zark7 <7z...@gmail.com> on 2010/08/20 19:37:59 UTC

Localizer from within a Model class?

Hi,

I'd like to use some localized strings within a model class.

Can I use any of Wicket's localization capabilities for this?
Localizer assumes you have a component reference to pass to the various 
getString (...) call, but I don't have access to one.


Here is an example below (sorry if it's not clear, it's Scala syntax):

--
class FileSizeModel (model: IModel[Long]) extends Model[String] {
	val KB = 1024
	val MB = KB * 1024
	val GB = MB * 1024

	override def getObject: String = {
		val size = model.getObject
		var label: String = ""
		if (size > GB) label = "%dG" format (size / GB)
		else if (size > MB) label = "%dM" format (size / MB)
		else if (size > KB) label = "%dk" format (size / KB)
		else label = "%d  bytes" format (size)
		label
	}
}
--

I would like to have a corresponding FileSizeModel.properties to set the 
various labels (G, M, k, bytes)


I know I can inject a Spring message source, etc., but unsure if I can 
leverage Wicket's localization for this.

Thanks

P.S. leave me alone about GB vs. GiB differences in the example, etc. ;-)

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org