Umlauts in Attribute names
-
I have a client who wants to use Umlauts, etc. in attribute names in SpaceDesign, such as Länge.
(This is a lot of "fun" for us to make work properly.)
I tried using this name for a Dynamic Component and was warned that I can only use letters and numbers. I was able to use Umlauts in attribute values.
Has anyone had any experience with problems and/or successes using Umlauts or other accents with Dynamic Components?
-
You can't as far as I know... it's '7-bit ASCII' = letters and numbers and '_' only [I also avoid the use of initial uppercase letters]... Built-in attributes like 'Name' are actually stored as '_name' anyway!
Your client will have to put up with simply missing them off, or adding an extra 'e', which are the ways most German speakers resolve it...
Biskuittörtchen >> Biskuittortchen or BiskuittoertchenYou can use it in value 'strings' though...
Accented characters cause all sorts of problems with Ruby - especially in file-paths !
Even if you got it working in a DC then its use in a file-name could cause a false not exist? result if it contains a umlaut... Encourage your client to be 'sensible'... -
Thanks TIG
-
You might be able to store special characters in attribute dictionaries, but it's Ruby's lack of Unicode that makes it difficult to handle such strings. It might be this that is the root to the DC limitations. ...maybe,,,
-
How do Russian users give their DC attributes names ?
dc.definition.set_attribute("dynamic_attributes", "ë", "E+Umlaut")
WILL write the value without an error [initially]... BUT if you open the DC dialog it displays as a 'Ã' instead and the value isn't there... and then the error messages start.
So you can get/set a non ASCII key in code, BUT the DC webdialog fails to interpret anything other than straight ASCII codes -
It gets confusing.
Sometimes an umlaut-a is stored in ANSI as a single byte #e4 and sometimes it is stored as two bytes (UTF8 or multi-byte) as #c3 #a4.
We made two routines to_ansi() and to_utf8() to switch back and forth.
Many things work better if you call to_ansi() on them and convert them to single byte ansi.
(This will work for European characters, but not for Kanji and other multi-byte characters)def to_ansi(string) return(string) if (!string || string == "" || !string.kind_of?(String)) a1 = string.unpack("U*") # extract utf8 as integers s1 = a1.pack("C*") # repack as ansi return(s1) end#def to_ansi def to_utf8(string) a2 = string.unpack("C*") # extract extended ansi as integers s2 = a2.pack("U*") # repack as utf8 return(s2) end#def to_utf8
and we wrote a get_ansi_attribute() which converts string attributes to ansi format which may work better.
def get_ansi_attribute(parent, dictionary_name, attribute_name, default = nil) # gets the attribute and converts to extended ansi format satt = parent.get_attribute(dictionary_name, attribute_name, default) if (satt.kind_of?(String)) satt = to_ansi(satt) end#if return(satt) end#def get_ansi_attribute
-
to_ansi() helped a lot. I couldn't figure out how to do the same thing in C++, so I just called the internal ruby packing functions from C++.
CString cl_ruby;;to_ansi(VALUE string_value) { static VALUE unpack_intern = rb_intern("unpack"); static VALUE pack_intern = rb_intern("pack"); CString string = CString(value_to_CString(string_value)); if (string == "") return(string); //a1 = string.unpack("U*") # extract utf8 as integers VALUE a1 = rb_funcall(string_value, unpack_intern, 1, CString_to_value("U*")); //s1 = a1.pack("C*") # repack as ansi VALUE s1 = rb_funcall(a1, pack_intern, 1, CString_to_value("C*")); CString sret = value_to_CString(s1); return(sret); }
Here is a report with umlauts in the component definition name, attribute titles, and attribute values, (using SpaceDesign)
-
You can have umlauts in other attributes_dictionaries' keys, BUT if it's a DC [dynamic_attributes dictionary] that has a key with an umlaut in it [made your way] will it be displayed/reported/edited properly in the dialog and/or NOT mess up the DC's 'operations' ?
-
No - neither the Ansi ä or the Multi-byte ä can be used in a DC attribute name.
I got off track a bit on this post. The to_ansi() function is useful when dealing with Umlauts and/or accents which are converted from ANSI/Extender ASCII to Multi-Byte automatically by Ruby or SketchUp. But still doesn't solve the original problem.
I will be interested to see if it help with Web Dialogs or other problems.
Advertisement