private static void LoadUnit( FormatLength size, LdmlNode root, Dictionary<CldrUnit, UnitOfMeasure> map, FormatSizeEntry compoundUnitPattern) { foreach ( LdmlNode node in root.Children ) { switch ( node.Name ) { case "compoundUnit": foreach ( LdmlNode child in node.Children ) { if ( child.Name == "compoundUnitPattern" ) { compoundUnitPattern[size] = child.Value; break; } } break; case "unit": LdmlTypeUnitNode unitNode = node as LdmlTypeUnitNode; if ( unitNode != null ) { UnitOfMeasure measure; if ( !map.TryGetValue( unitNode.Unit, out measure ) ) { measure = new UnitOfMeasure( unitNode.Unit ); map.Add( unitNode.Unit, measure ); } measure.Load( size, unitNode ); } break; } } }
public string GetDateTimeFormatPattern(FormatLength length) { var node = this.Select(new NodePathEntry("dateTimeFormats"), new NodePathEntry("dateTimeFormatLength", new LdmlAttributeValue(LdmlAttribute.Type, length.ToCode())) ); if (node == null) { return(null); } return(node.Select("dateTimeFormat", "pattern").GetText()); }
//internal UnitOfMeasure( LocaleData locale, string name ) { // WellKnownUnit unit; // if ( XUtil.TryParseUnit( name, out unit ) ) { // Unit = unit; // Name = unit.ToCode(); // } else { // Name = name; // } //} //internal UnitSlot Load( FormatSize size, JObject root ) { // int idx = GetIndex( size ); // if ( idx < 0 ) { // return null; // } // UnitSlot slot = new UnitSlot( this, size ); // _sizes[ idx ] = slot; // slot.Load( root ); // return slot; //} internal UnitSlot Load(FormatLength size, LdmlTypeUnitNode root) { int idx = GetIndex(size); if (idx < 0) { return(null); } UnitSlot slot = new UnitSlot(this, size); _sizes[idx] = slot; slot.Load(root); return(slot); }
private static int GetIndex(FormatLength size) { switch (size) { case FormatLength.Long: return(0); case FormatLength.Short: return(1); case FormatLength.Narrow: return(2); } return(-1); }
public UnitSlot this[FormatLength size] { get { int idx = GetIndex(size); if (idx >= 0) { return(_sizes[idx]); } return(null); } set { int idx = GetIndex(size); if (idx >= 0) { _sizes[idx] = value; } } }
public string this[FormatLength size] { get { switch (size) { case FormatLength.Full: return(_full); case FormatLength.Long: return(_long); case FormatLength.Short: return(_short); case FormatLength.Narrow: return(_narrow); case FormatLength.Medium: return(_medium); } return(null); } internal set { switch (size) { case FormatLength.Full: _full = value; break; case FormatLength.Long: _long = value; break; case FormatLength.Short: _short = value; break; case FormatLength.Narrow: _narrow = value; break; case FormatLength.Medium: _medium = value; break; } } }
public static string ToCode(this FormatLength width) { switch (width) { case FormatLength.Full: return("full"); case FormatLength.Long: return("long"); case FormatLength.Medium: return("medium"); case FormatLength.Short: return("short"); case FormatLength.Narrow: return("narrow"); } return(null); }
public NumberFormatsNode.Format GetFormat(NumberType type, FormatLength length = FormatLength.Narrow, string numberSystem = null) { var root = GetFormatLength(type == NumberType.Accounting ? NumberType.Currency : type, length, numberSystem); if (root != null) { foreach (var fmt in root.GetFormats()) { var ftype = fmt.GetAttribute(LdmlAttribute.Type); if (ftype.SameName("accounting")) { if (type == NumberType.Accounting) { return(fmt); } } else if (type != NumberType.Accounting) { return(fmt); } } } return(null); }
public UnitSlot(UnitOfMeasure unit, FormatLength size) { Unit = unit; Size = size; }
public NumberFormatsNode.FormatLength GetFormatLength(NumberType type, FormatLength length = FormatLength.Narrow, string numberSystem = null) { return(GetFormats(type, numberSystem)?.GetFormatLength(length)); }