AdamN, thanks so much for your solution. I've applied it to my app,
and so far everything seems to be working fine.
I just want to share two points that I implemented when using your
solution for the sake of anyone else dealing with this problem.
Firstly, my situation was such that I converting information in a pre-
existing collection to a multi-lingual field. I didn't want to alter
field names, and not every entry had multi-lingual data. In order to
account for this I modified your from_mongo as follows:
def self.from_mongo(value)
value.is_a?(String) ? value : LocalizedString.new(value || {})
end
This way, if I was querying an entry that had legacy data in String
type, I would still be able to access it.
Also, I built my app such that my public API would serve to_json dumps
of my mongomapper objects. Adopting this solution outputted my
LocalizedString field as a hash in my JSON, which wasn't desirable. To
circumvent this, I used the as_json method in my model code. For
example:
def as_json(options={})
{ :title => self.title.to_s }
end
This made sure that my JSON was clean.
On more point I'd like to point out for others that might not realize
it is that its still possible to pass the value of the LocalizedString
using "=" or update_attributes!, but the value has to be passed as a
Hash, and that Hash has to have all of the multilingual values in it,
like:
Foo.update_attributes!(:title => {"en" => "English", "de" =>
"German"})
Thanks again, AdamN! I can finally move this project forward.