ソースを参照

add regular currency logic

joeybloggs 10 年 前
コミット
5e30685010
100 ファイル変更1934 行追加1765 行削除
  1. 16 19
      af/af.go
  2. 16 19
      af_NA/af_NA.go
  3. 16 19
      af_ZA/af_ZA.go
  4. 16 11
      agq/agq.go
  5. 16 11
      agq_CM/agq_CM.go
  6. 16 11
      ak/ak.go
  7. 16 11
      ak_GH/ak_GH.go
  8. 16 19
      am/am.go
  9. 16 19
      am_ET/am_ET.go
  10. 16 19
      ar/ar.go
  11. 16 19
      ar_001/ar_001.go
  12. 16 19
      ar_AE/ar_AE.go
  13. 16 19
      ar_BH/ar_BH.go
  14. 16 19
      ar_DJ/ar_DJ.go
  15. 16 19
      ar_DZ/ar_DZ.go
  16. 16 19
      ar_EG/ar_EG.go
  17. 16 19
      ar_EH/ar_EH.go
  18. 16 19
      ar_ER/ar_ER.go
  19. 16 19
      ar_IL/ar_IL.go
  20. 16 19
      ar_IQ/ar_IQ.go
  21. 16 19
      ar_JO/ar_JO.go
  22. 16 19
      ar_KM/ar_KM.go
  23. 16 19
      ar_KW/ar_KW.go
  24. 16 19
      ar_LB/ar_LB.go
  25. 16 19
      ar_LY/ar_LY.go
  26. 16 19
      ar_MA/ar_MA.go
  27. 16 19
      ar_MR/ar_MR.go
  28. 16 19
      ar_OM/ar_OM.go
  29. 16 19
      ar_PS/ar_PS.go
  30. 16 19
      ar_QA/ar_QA.go
  31. 16 19
      ar_SA/ar_SA.go
  32. 16 19
      ar_SD/ar_SD.go
  33. 16 19
      ar_SO/ar_SO.go
  34. 16 19
      ar_SS/ar_SS.go
  35. 16 19
      ar_SY/ar_SY.go
  36. 16 19
      ar_TD/ar_TD.go
  37. 16 19
      ar_TN/ar_TN.go
  38. 16 19
      ar_YE/ar_YE.go
  39. 16 19
      as/as.go
  40. 16 19
      as_IN/as_IN.go
  41. 16 19
      asa/asa.go
  42. 16 19
      asa_TZ/asa_TZ.go
  43. 16 19
      ast/ast.go
  44. 16 19
      ast_ES/ast_ES.go
  45. 16 19
      az/az.go
  46. 16 19
      az_Cyrl/az_Cyrl.go
  47. 16 19
      az_Cyrl_AZ/az_Cyrl_AZ.go
  48. 16 19
      az_Latn/az_Latn.go
  49. 16 19
      az_Latn_AZ/az_Latn_AZ.go
  50. 16 11
      bas/bas.go
  51. 16 11
      bas_CM/bas_CM.go
  52. 16 11
      be/be.go
  53. 16 11
      be_BY/be_BY.go
  54. 16 19
      bem/bem.go
  55. 16 19
      bem_ZM/bem_ZM.go
  56. 16 11
      bez/bez.go
  57. 16 11
      bez_TZ/bez_TZ.go
  58. 16 19
      bg/bg.go
  59. 16 19
      bg_BG/bg_BG.go
  60. 16 19
      bm/bm.go
  61. 16 19
      bm_ML/bm_ML.go
  62. 16 19
      bn/bn.go
  63. 16 19
      bn_BD/bn_BD.go
  64. 16 19
      bn_IN/bn_IN.go
  65. 16 19
      bo/bo.go
  66. 16 19
      bo_CN/bo_CN.go
  67. 16 19
      bo_IN/bo_IN.go
  68. 16 11
      br/br.go
  69. 16 11
      br_FR/br_FR.go
  70. 16 19
      brx/brx.go
  71. 16 19
      brx_IN/brx_IN.go
  72. 16 19
      bs/bs.go
  73. 16 19
      bs_Cyrl/bs_Cyrl.go
  74. 16 19
      bs_Cyrl_BA/bs_Cyrl_BA.go
  75. 16 19
      bs_Latn/bs_Latn.go
  76. 16 19
      bs_Latn_BA/bs_Latn_BA.go
  77. 16 19
      ca/ca.go
  78. 16 19
      ca_AD/ca_AD.go
  79. 16 19
      ca_ES/ca_ES.go
  80. 16 19
      ca_ES_VALENCIA/ca_ES_VALENCIA.go
  81. 16 19
      ca_FR/ca_FR.go
  82. 16 19
      ca_IT/ca_IT.go
  83. 16 11
      ce/ce.go
  84. 16 11
      ce_RU/ce_RU.go
  85. 16 11
      cgg/cgg.go
  86. 16 11
      cgg_UG/cgg_UG.go
  87. 16 19
      chr/chr.go
  88. 16 19
      chr_US/chr_US.go
  89. 16 11
      ckb/ckb.go
  90. 16 11
      ckb_IQ/ckb_IQ.go
  91. 16 11
      ckb_IR/ckb_IR.go
  92. 2 2
      cmd/currency.tmpl
  93. 214 104
      cmd/generate_resources.go
  94. 179 16
      cmd/translator.tmpl
  95. 16 11
      cs/cs.go
  96. 16 11
      cs_CZ/cs_CZ.go
  97. 16 11
      cu/cu.go
  98. 16 11
      cu_RU/cu_RU.go
  99. 3 3
      currency/currency.go
  100. 16 19
      cy/cy.go

ファイルの差分が大きいため隠しています
+ 16 - 19
af/af.go


ファイルの差分が大きいため隠しています
+ 16 - 19
af_NA/af_NA.go


ファイルの差分が大きいため隠しています
+ 16 - 19
af_ZA/af_ZA.go


ファイルの差分が大きいため隠しています
+ 16 - 11
agq/agq.go


ファイルの差分が大きいため隠しています
+ 16 - 11
agq_CM/agq_CM.go


ファイルの差分が大きいため隠しています
+ 16 - 11
ak/ak.go


ファイルの差分が大きいため隠しています
+ 16 - 11
ak_GH/ak_GH.go


ファイルの差分が大きいため隠しています
+ 16 - 19
am/am.go


ファイルの差分が大きいため隠しています
+ 16 - 19
am_ET/am_ET.go


ファイルの差分が大きいため隠しています
+ 16 - 19
ar/ar.go


ファイルの差分が大きいため隠しています
+ 16 - 19
ar_001/ar_001.go


ファイルの差分が大きいため隠しています
+ 16 - 19
ar_AE/ar_AE.go


ファイルの差分が大きいため隠しています
+ 16 - 19
ar_BH/ar_BH.go


ファイルの差分が大きいため隠しています
+ 16 - 19
ar_DJ/ar_DJ.go


ファイルの差分が大きいため隠しています
+ 16 - 19
ar_DZ/ar_DZ.go


ファイルの差分が大きいため隠しています
+ 16 - 19
ar_EG/ar_EG.go


ファイルの差分が大きいため隠しています
+ 16 - 19
ar_EH/ar_EH.go


ファイルの差分が大きいため隠しています
+ 16 - 19
ar_ER/ar_ER.go


ファイルの差分が大きいため隠しています
+ 16 - 19
ar_IL/ar_IL.go


ファイルの差分が大きいため隠しています
+ 16 - 19
ar_IQ/ar_IQ.go


ファイルの差分が大きいため隠しています
+ 16 - 19
ar_JO/ar_JO.go


ファイルの差分が大きいため隠しています
+ 16 - 19
ar_KM/ar_KM.go


ファイルの差分が大きいため隠しています
+ 16 - 19
ar_KW/ar_KW.go


ファイルの差分が大きいため隠しています
+ 16 - 19
ar_LB/ar_LB.go


ファイルの差分が大きいため隠しています
+ 16 - 19
ar_LY/ar_LY.go


ファイルの差分が大きいため隠しています
+ 16 - 19
ar_MA/ar_MA.go


ファイルの差分が大きいため隠しています
+ 16 - 19
ar_MR/ar_MR.go


ファイルの差分が大きいため隠しています
+ 16 - 19
ar_OM/ar_OM.go


ファイルの差分が大きいため隠しています
+ 16 - 19
ar_PS/ar_PS.go


ファイルの差分が大きいため隠しています
+ 16 - 19
ar_QA/ar_QA.go


ファイルの差分が大きいため隠しています
+ 16 - 19
ar_SA/ar_SA.go


ファイルの差分が大きいため隠しています
+ 16 - 19
ar_SD/ar_SD.go


ファイルの差分が大きいため隠しています
+ 16 - 19
ar_SO/ar_SO.go


ファイルの差分が大きいため隠しています
+ 16 - 19
ar_SS/ar_SS.go


ファイルの差分が大きいため隠しています
+ 16 - 19
ar_SY/ar_SY.go


ファイルの差分が大きいため隠しています
+ 16 - 19
ar_TD/ar_TD.go


ファイルの差分が大きいため隠しています
+ 16 - 19
ar_TN/ar_TN.go


ファイルの差分が大きいため隠しています
+ 16 - 19
ar_YE/ar_YE.go


ファイルの差分が大きいため隠しています
+ 16 - 19
as/as.go


ファイルの差分が大きいため隠しています
+ 16 - 19
as_IN/as_IN.go


ファイルの差分が大きいため隠しています
+ 16 - 19
asa/asa.go


ファイルの差分が大きいため隠しています
+ 16 - 19
asa_TZ/asa_TZ.go


ファイルの差分が大きいため隠しています
+ 16 - 19
ast/ast.go


ファイルの差分が大きいため隠しています
+ 16 - 19
ast_ES/ast_ES.go


ファイルの差分が大きいため隠しています
+ 16 - 19
az/az.go


ファイルの差分が大きいため隠しています
+ 16 - 19
az_Cyrl/az_Cyrl.go


ファイルの差分が大きいため隠しています
+ 16 - 19
az_Cyrl_AZ/az_Cyrl_AZ.go


ファイルの差分が大きいため隠しています
+ 16 - 19
az_Latn/az_Latn.go


ファイルの差分が大きいため隠しています
+ 16 - 19
az_Latn_AZ/az_Latn_AZ.go


ファイルの差分が大きいため隠しています
+ 16 - 11
bas/bas.go


ファイルの差分が大きいため隠しています
+ 16 - 11
bas_CM/bas_CM.go


ファイルの差分が大きいため隠しています
+ 16 - 11
be/be.go


ファイルの差分が大きいため隠しています
+ 16 - 11
be_BY/be_BY.go


ファイルの差分が大きいため隠しています
+ 16 - 19
bem/bem.go


ファイルの差分が大きいため隠しています
+ 16 - 19
bem_ZM/bem_ZM.go


ファイルの差分が大きいため隠しています
+ 16 - 11
bez/bez.go


ファイルの差分が大きいため隠しています
+ 16 - 11
bez_TZ/bez_TZ.go


ファイルの差分が大きいため隠しています
+ 16 - 19
bg/bg.go


ファイルの差分が大きいため隠しています
+ 16 - 19
bg_BG/bg_BG.go


ファイルの差分が大きいため隠しています
+ 16 - 19
bm/bm.go


ファイルの差分が大きいため隠しています
+ 16 - 19
bm_ML/bm_ML.go


ファイルの差分が大きいため隠しています
+ 16 - 19
bn/bn.go


ファイルの差分が大きいため隠しています
+ 16 - 19
bn_BD/bn_BD.go


ファイルの差分が大きいため隠しています
+ 16 - 19
bn_IN/bn_IN.go


ファイルの差分が大きいため隠しています
+ 16 - 19
bo/bo.go


ファイルの差分が大きいため隠しています
+ 16 - 19
bo_CN/bo_CN.go


ファイルの差分が大きいため隠しています
+ 16 - 19
bo_IN/bo_IN.go


ファイルの差分が大きいため隠しています
+ 16 - 11
br/br.go


ファイルの差分が大きいため隠しています
+ 16 - 11
br_FR/br_FR.go


ファイルの差分が大きいため隠しています
+ 16 - 19
brx/brx.go


ファイルの差分が大きいため隠しています
+ 16 - 19
brx_IN/brx_IN.go


ファイルの差分が大きいため隠しています
+ 16 - 19
bs/bs.go


ファイルの差分が大きいため隠しています
+ 16 - 19
bs_Cyrl/bs_Cyrl.go


ファイルの差分が大きいため隠しています
+ 16 - 19
bs_Cyrl_BA/bs_Cyrl_BA.go


ファイルの差分が大きいため隠しています
+ 16 - 19
bs_Latn/bs_Latn.go


ファイルの差分が大きいため隠しています
+ 16 - 19
bs_Latn_BA/bs_Latn_BA.go


ファイルの差分が大きいため隠しています
+ 16 - 19
ca/ca.go


ファイルの差分が大きいため隠しています
+ 16 - 19
ca_AD/ca_AD.go


ファイルの差分が大きいため隠しています
+ 16 - 19
ca_ES/ca_ES.go


ファイルの差分が大きいため隠しています
+ 16 - 19
ca_ES_VALENCIA/ca_ES_VALENCIA.go


ファイルの差分が大きいため隠しています
+ 16 - 19
ca_FR/ca_FR.go


ファイルの差分が大きいため隠しています
+ 16 - 19
ca_IT/ca_IT.go


ファイルの差分が大きいため隠しています
+ 16 - 11
ce/ce.go


ファイルの差分が大きいため隠しています
+ 16 - 11
ce_RU/ce_RU.go


ファイルの差分が大きいため隠しています
+ 16 - 11
cgg/cgg.go


ファイルの差分が大きいため隠しています
+ 16 - 11
cgg_UG/cgg_UG.go


ファイルの差分が大きいため隠しています
+ 16 - 19
chr/chr.go


ファイルの差分が大きいため隠しています
+ 16 - 19
chr_US/chr_US.go


ファイルの差分が大きいため隠しています
+ 16 - 11
ckb/ckb.go


ファイルの差分が大きいため隠しています
+ 16 - 11
ckb_IQ/ckb_IQ.go


ファイルの差分が大きいため隠しています
+ 16 - 11
ckb_IR/ckb_IR.go


+ 2 - 2
cmd/currency.tmpl

@@ -1,8 +1,8 @@
 {{ define "currencies" }}
 package currency
 
-// Currency is the type associated with the locales currency enum
-type Currency int
+// Type is the currency type associated with the locales currency enum
+type Type int
 
 // locale currencies
 const (

+ 214 - 104
cmd/generate_resources.go

@@ -85,9 +85,25 @@ type translator struct {
 	FmtPercentInPrefix          bool
 	FmtPercentLeft              bool
 
+	// FmtCurrency vars
+	FmtCurrencyExists            bool
+	FmtCurrencyGroupLen          int
+	FmtCurrencySecondaryGroupLen int
+	FmtCurrencyMinDecimalLen     int
+	FmtCurrencyPrefix            string
+	FmtCurrencySuffix            string
+	FmtCurrencyInPrefix          bool
+	FmtCurrencyLeft              bool
+	FmtCurrencyNegativePrefix    string
+	FmtCurrencyNegativeSuffix    string
+	FmtCurrencyNegativeInPrefix  bool
+	FmtCurrencyNegativeLeft      bool
+
 	// calculation only fields
-	DecimalNumberFormat string
-	PercentNumberFormat string
+	DecimalNumberFormat          string
+	PercentNumberFormat          string
+	CurrencyNumberFormat         string
+	NegativeCurrencyNumberFormat string
 }
 
 func main() {
@@ -116,7 +132,7 @@ func main() {
 	for i, curr := range globalCurrencies {
 
 		if i == 0 {
-			currencies = curr + " Currency = iota\n"
+			currencies = curr + " Type = iota\n"
 			continue
 		}
 
@@ -149,7 +165,12 @@ func main() {
 
 	for _, trans := range translators {
 
-		fmt.Println("Writing Data:", trans.PercentNumberFormat, len(trans.FmtPercentPrefix), trans.FmtPercentPrefix, len(trans.FmtPercentSuffix), trans.FmtPercentSuffix, trans.Locale)
+		fmt.Println("Writing Data:", trans.Locale)
+
+		if trans.Locale == "en" {
+			fmt.Println("\t", trans.CurrencyNumberFormat)
+			fmt.Println("\t", trans.NegativeCurrencyNumberFormat)
+		}
 
 		if err = os.MkdirAll(fmt.Sprintf(locDir, trans.Locale), 0777); err != nil {
 			log.Fatal(err)
@@ -289,6 +310,20 @@ func postProcess(cldr *cldr.CLDR) {
 			}
 		}
 
+		if len(trans.CurrencyNumberFormat) == 0 {
+
+			if found {
+				trans.CurrencyNumberFormat = base.CurrencyNumberFormat
+			}
+		}
+
+		if len(trans.NegativeCurrencyNumberFormat) == 0 {
+
+			if found {
+				trans.NegativeCurrencyNumberFormat = base.NegativeCurrencyNumberFormat
+			}
+		}
+
 		ldml := cldr.RawLDML(trans.Locale)
 
 		currencies := make([][]byte, len(globalCurrencies), len(globalCurrencies))
@@ -324,6 +359,7 @@ func postProcess(cldr *cldr.CLDR) {
 
 		parseDecimalNumberFormat(trans)
 		parsePercentNumberFormat(trans)
+		parseCurrencyNumberFormat(trans)
 		// trans.FmtNumberFunc = parseDecimalNumberFormat(trans.DecimalNumberFormat, trans.BaseLocale)
 	}
 }
@@ -421,30 +457,24 @@ func preProcess(cldr *cldr.CLDR) {
 				}
 			}
 
-			// var decimalFormat, currencyFormat, currencyAccountingFormat, percentageFormat string
-
-			// if len(ldml.Numbers.DecimalFormats) > 0 && len(ldml.Numbers.DecimalFormats[0].DecimalFormatLength) > 0 {
-			// 	decimalFormat = ldml.Numbers.DecimalFormats[0].DecimalFormatLength[0].DecimalFormat[0].Pattern[0].Data()
-			// }
+			if len(ldml.Numbers.CurrencyFormats) > 0 && len(ldml.Numbers.CurrencyFormats[0].CurrencyFormatLength) > 0 {
 
-			// if len(ldml.Numbers.CurrencyFormats) > 0 && len(ldml.Numbers.CurrencyFormats[0].CurrencyFormatLength) > 0 {
+				if len(ldml.Numbers.CurrencyFormats[0].CurrencyFormatLength[0].CurrencyFormat) > 1 {
 
-			// 	currencyFormat = ldml.Numbers.CurrencyFormats[0].CurrencyFormatLength[0].CurrencyFormat[0].Pattern[0].Data()
-			// 	currencyAccountingFormat = currencyFormat
+					split := strings.SplitN(ldml.Numbers.CurrencyFormats[0].CurrencyFormatLength[0].CurrencyFormat[1].Pattern[0].Data(), ";", 2)
 
-			// 	if len(ldml.Numbers.CurrencyFormats[0].CurrencyFormatLength[0].CurrencyFormat) > 1 {
-			// 		currencyAccountingFormat = ldml.Numbers.CurrencyFormats[0].CurrencyFormatLength[0].CurrencyFormat[1].Pattern[0].Data()
-			// 	}
-			// }
+					trans.CurrencyNumberFormat = split[0]
 
-			// if len(ldml.Numbers.PercentFormats) > 0 && len(ldml.Numbers.PercentFormats[0].PercentFormatLength) > 0 {
-			// 	percentageFormat = ldml.Numbers.PercentFormats[0].PercentFormatLength[0].PercentFormat[0].Pattern[0].Data()
-			// }
-
-			// // parse Number values
-			// parseNumbers(decimal, group, minus, percent, permille, decimalFormat, currencyFormat, currencyAccountingFormat, percentageFormat)
-
-			// end number values
+					if len(split) > 1 && len(split[1]) > 0 {
+						trans.NegativeCurrencyNumberFormat = split[1]
+					} else {
+						trans.NegativeCurrencyNumberFormat = trans.CurrencyNumberFormat
+					}
+				} else {
+					trans.CurrencyNumberFormat = ldml.Numbers.CurrencyFormats[0].CurrencyFormatLength[0].CurrencyFormat[0].Pattern[0].Data()
+					trans.NegativeCurrencyNumberFormat = trans.CurrencyNumberFormat
+				}
+			}
 		}
 	}
 
@@ -459,20 +489,169 @@ func preProcess(cldr *cldr.CLDR) {
 	}
 }
 
-func parsePercentNumberFormat(trans *translator) (results string) {
+func parseCurrencyNumberFormat(trans *translator) {
 
-	if len(trans.PercentNumberFormat) == 0 {
+	if len(trans.CurrencyNumberFormat) == 0 {
 		return
 	}
 
-	trans.FmtPercentExists = true
+	trans.FmtCurrencyExists = true
+	negativeEqual := trans.CurrencyNumberFormat == trans.NegativeCurrencyNumberFormat
+
+	match := groupLenRegex.FindString(trans.CurrencyNumberFormat)
+	if len(match) > 0 {
+		trans.FmtCurrencyGroupLen = len(match) - 2
+	}
+
+	match = requiredDecimalRegex.FindString(trans.CurrencyNumberFormat)
+	if len(match) > 0 {
+		trans.FmtCurrencyMinDecimalLen = len(match) - 1
+	}
 
-	// formats := strings.SplitN(trans.PercentNumberFormat, ";", 2)
+	match = secondaryGroupLenRegex.FindString(trans.CurrencyNumberFormat)
+	if len(match) > 0 {
+		trans.FmtCurrencySecondaryGroupLen = len(match) - 2
+	}
+
+	idx := 0
+
+	for idx = 0; idx < len(trans.CurrencyNumberFormat); idx++ {
+		if trans.CurrencyNumberFormat[idx] == '#' || trans.CurrencyNumberFormat[idx] == '0' {
+			trans.FmtCurrencyPrefix = trans.CurrencyNumberFormat[:idx]
+			break
+		}
+	}
 
-	// if len(formats) > 1 {
-	// 	trans.FmtNumberHasNegativeFormat = true
+	for idx = len(trans.CurrencyNumberFormat) - 1; idx >= 0; idx-- {
+		if trans.CurrencyNumberFormat[idx] == '#' || trans.CurrencyNumberFormat[idx] == '0' {
+			idx++
+			trans.FmtCurrencySuffix = trans.CurrencyNumberFormat[idx:]
+			break
+		}
+	}
+
+	for idx = 0; idx < len(trans.FmtCurrencyPrefix); idx++ {
+		if trans.FmtCurrencyPrefix[idx] == '¤' {
+
+			trans.FmtCurrencyInPrefix = true
+			trans.FmtCurrencyPrefix = strings.Replace(trans.FmtCurrencyPrefix, string(trans.FmtCurrencyPrefix[idx]), "", 1)
+
+			if idx == 0 {
+				trans.FmtCurrencyLeft = true
+			} else {
+				trans.FmtCurrencyLeft = false
+			}
+
+			break
+		}
+	}
+
+	for idx = 0; idx < len(trans.FmtCurrencySuffix); idx++ {
+		if trans.FmtCurrencySuffix[idx] == '¤' {
+
+			trans.FmtCurrencyInPrefix = false
+			trans.FmtCurrencySuffix = strings.Replace(trans.FmtCurrencySuffix, string(trans.FmtCurrencySuffix[idx]), "", 1)
+
+			if idx == 0 {
+				trans.FmtCurrencyLeft = true
+			} else {
+				trans.FmtCurrencyLeft = false
+			}
+
+			break
+		}
+	}
+
+	if len(trans.FmtCurrencyPrefix) > 0 {
+		trans.FmtCurrencyPrefix = fmt.Sprintf("%#v", []byte(trans.FmtCurrencyPrefix))
+	}
+
+	if len(trans.FmtCurrencySuffix) > 0 {
+		trans.FmtCurrencySuffix = fmt.Sprintf("%#v", []byte(trans.FmtCurrencySuffix))
+	}
+
+	// if trans.Locale == "en" {
+	// 	fmt.Println("Equal? ", negativeEqual)
 	// }
 
+	// no need to parse again if true....
+	if negativeEqual {
+
+		trans.FmtCurrencyNegativePrefix = trans.FmtCurrencyPrefix
+		trans.FmtCurrencyNegativeSuffix = trans.FmtCurrencySuffix
+		trans.FmtCurrencyNegativeInPrefix = trans.FmtCurrencyInPrefix
+		trans.FmtCurrencyNegativeLeft = trans.FmtCurrencyLeft
+
+		return
+	}
+
+	for idx = 0; idx < len(trans.NegativeCurrencyNumberFormat); idx++ {
+		if trans.NegativeCurrencyNumberFormat[idx] == '#' || trans.NegativeCurrencyNumberFormat[idx] == '0' {
+
+			trans.FmtCurrencyNegativePrefix = trans.NegativeCurrencyNumberFormat[:idx]
+			break
+		}
+	}
+
+	for idx = len(trans.NegativeCurrencyNumberFormat) - 1; idx >= 0; idx-- {
+		if trans.NegativeCurrencyNumberFormat[idx] == '#' || trans.NegativeCurrencyNumberFormat[idx] == '0' {
+			idx++
+			trans.FmtCurrencyNegativeSuffix = trans.NegativeCurrencyNumberFormat[idx:]
+			break
+		}
+	}
+
+	for idx = 0; idx < len(trans.FmtCurrencyNegativePrefix); idx++ {
+		if trans.FmtCurrencyNegativePrefix[idx] == '¤' {
+
+			trans.FmtCurrencyNegativeInPrefix = true
+			trans.FmtCurrencyNegativePrefix = strings.Replace(trans.FmtCurrencyNegativePrefix, string(trans.FmtCurrencyNegativePrefix[idx]), "", 1)
+
+			if idx == 0 {
+				trans.FmtCurrencyNegativeLeft = true
+			} else {
+				trans.FmtCurrencyNegativeLeft = false
+			}
+
+			break
+		}
+	}
+
+	for idx = 0; idx < len(trans.FmtCurrencyNegativeSuffix); idx++ {
+		if trans.FmtCurrencyNegativeSuffix[idx] == '¤' {
+
+			trans.FmtCurrencyNegativeInPrefix = false
+			trans.FmtCurrencyNegativeSuffix = strings.Replace(trans.FmtCurrencyNegativeSuffix, string(trans.FmtCurrencyNegativeSuffix[idx]), "", 1)
+
+			if idx == 0 {
+				trans.FmtCurrencyNegativeLeft = true
+			} else {
+				trans.FmtCurrencyNegativeLeft = false
+			}
+
+			break
+		}
+	}
+
+	if len(trans.FmtCurrencyNegativePrefix) > 0 {
+		trans.FmtCurrencyNegativePrefix = fmt.Sprintf("%#v", []byte(trans.FmtCurrencyNegativePrefix))
+	}
+
+	if len(trans.FmtCurrencyNegativeSuffix) > 0 {
+		trans.FmtCurrencyNegativeSuffix = fmt.Sprintf("%#v", []byte(trans.FmtCurrencyNegativeSuffix))
+	}
+
+	return
+}
+
+func parsePercentNumberFormat(trans *translator) {
+
+	if len(trans.PercentNumberFormat) == 0 {
+		return
+	}
+
+	trans.FmtPercentExists = true
+
 	match := groupLenPercentRegex.FindString(trans.PercentNumberFormat)
 	if len(match) > 0 {
 		trans.FmtPercentGroupLen = len(match) - 1
@@ -488,17 +667,6 @@ func parsePercentNumberFormat(trans *translator) (results string) {
 		trans.FmtPercentSecondaryGroupLen = len(match) - 2
 	}
 
-	// 	FmtPercentPrefix            string
-	// FmtPercentSuffix            string
-	// FmtPercentInPrefix          bool
-	// FmtPercentLeft              bool
-
-	// if formats[0][0] == '%' {
-	// 	trans.FmtPercentLeft = true
-	// }
-
-	// trans.FmtPercentLeft
-
 	idx := 0
 
 	for idx = 0; idx < len(trans.PercentNumberFormat); idx++ {
@@ -518,14 +686,14 @@ func parsePercentNumberFormat(trans *translator) (results string) {
 
 	for idx = 0; idx < len(trans.FmtPercentPrefix); idx++ {
 		if trans.FmtPercentPrefix[idx] == '%' {
+
 			trans.FmtPercentInPrefix = true
+			trans.FmtPercentPrefix = strings.Replace(trans.FmtPercentPrefix, string(trans.FmtPercentPrefix[idx]), "", 1)
 
 			if idx == 0 {
 				trans.FmtPercentLeft = true
-				trans.FmtPercentPrefix = trans.FmtPercentPrefix[idx+1:]
 			} else {
 				trans.FmtPercentLeft = false
-				trans.FmtPercentPrefix = trans.FmtPercentPrefix[:idx]
 			}
 
 			break
@@ -534,14 +702,14 @@ func parsePercentNumberFormat(trans *translator) (results string) {
 
 	for idx = 0; idx < len(trans.FmtPercentSuffix); idx++ {
 		if trans.FmtPercentSuffix[idx] == '%' {
+
 			trans.FmtPercentInPrefix = false
+			trans.FmtPercentSuffix = strings.Replace(trans.FmtPercentSuffix, string(trans.FmtPercentSuffix[idx]), "", 1)
 
 			if idx == 0 {
 				trans.FmtPercentLeft = true
-				trans.FmtPercentSuffix = trans.FmtPercentSuffix[idx+1:]
 			} else {
 				trans.FmtPercentLeft = false
-				trans.FmtPercentSuffix = trans.FmtPercentSuffix[:idx]
 			}
 
 			break
@@ -556,37 +724,10 @@ func parsePercentNumberFormat(trans *translator) (results string) {
 		trans.FmtPercentSuffix = fmt.Sprintf("%#v", []byte(trans.FmtPercentSuffix))
 	}
 
-	// if len(trans.FmtPercentPrefix) == 1 && trans.FmtPercentPrefix[0] == '%' {
-	// 	trans.FmtPercentPrefix = ""
-	// 	trans.FmtPercentInPrefix = true
-	// }
-
-	// if len(trans.FmtPercentSuffix) == 1 && trans.FmtPercentSuffix[0] == '%' {
-	// 	trans.FmtPercentSuffix = ""
-	// 	trans.FmtPercentSuffix = false
-	// }
-
-	// // if start > 0 {
-	// // 	prefix = formats[0][:start]
-	// // }
-
-	// end := 0
-
-	// // positive prefix
-	// for end = len(formats[0]) - 1; end >= 0; end-- {
-	// 	if formats[0][end] == '#' || formats[0][end] == '0' {
-	// 		end++
-	// 		break
-	// 	}
-	// }
-
-	// fmt.Println(start)
-	// fmt.Println(end)
-
 	return
 }
 
-func parseDecimalNumberFormat(trans *translator) (results string) {
+func parseDecimalNumberFormat(trans *translator) {
 
 	if len(trans.DecimalNumberFormat) == 0 {
 		return
@@ -596,10 +737,6 @@ func parseDecimalNumberFormat(trans *translator) (results string) {
 
 	formats := strings.SplitN(trans.DecimalNumberFormat, ";", 2)
 
-	// if len(formats) > 1 {
-	// 	trans.FmtNumberHasNegativeFormat = true
-	// }
-
 	match := groupLenRegex.FindString(formats[0])
 	if len(match) > 0 {
 		trans.FmtNumberGroupLen = len(match) - 2
@@ -615,33 +752,6 @@ func parseDecimalNumberFormat(trans *translator) (results string) {
 		trans.FmtNumberSecondaryGroupLen = len(match) - 2
 	}
 
-	// start := 0
-	// // prefix := ""
-
-	// // positive prefix
-	// for start = 0; start < len(formats[0]); start++ {
-	// 	if formats[0][start] == '#' || formats[0][start] == '0' {
-	// 		break
-	// 	}
-	// }
-
-	// // if start > 0 {
-	// // 	prefix = formats[0][:start]
-	// // }
-
-	// end := 0
-
-	// // positive prefix
-	// for end = len(formats[0]) - 1; end >= 0; end-- {
-	// 	if formats[0][end] == '#' || formats[0][end] == '0' {
-	// 		end++
-	// 		break
-	// 	}
-	// }
-
-	// fmt.Println(start)
-	// fmt.Println(end)
-
 	return
 }
 

+ 179 - 16
cmd/translator.tmpl

@@ -5,20 +5,25 @@ import (
 	"math"
 
 	"github.com/go-playground/locales"
+	"github.com/go-playground/locales/currency"
 )
 
 type {{ .Locale }} struct {
-	locale     		string
-	pluralsCardinal []locales.PluralRule
-	pluralsOrdinal  []locales.PluralRule
-	decimal    		[]byte
-	group      		[]byte
-	minus      		[]byte
-	percent    		[]byte
-	percentPrefix   []byte
-	percentSuffix   []byte
-	perMille   		[]byte
-	currencies 		[][]byte // idx = enum of currency code
+	locale     			   string
+	pluralsCardinal 	   []locales.PluralRule
+	pluralsOrdinal  	   []locales.PluralRule
+	decimal    			   []byte
+	group      			   []byte
+	minus      			   []byte
+	percent    			   []byte
+	percentPrefix   	   []byte
+	percentSuffix   	   []byte
+	perMille   			   []byte
+	currencies 			   [][]byte // idx = enum of currency code
+	currencyPositivePrefix []byte
+	currencyPositiveSuffix []byte
+	currencyNegativePrefix []byte
+	currencyNegativeSuffix []byte
 }
 
 // New returns a new instance of translator for the '{{ .Locale }}' locale
@@ -33,12 +38,24 @@ func New() locales.Translator {
 		percent:  		 {{ .Percent }},
 		perMille:        {{ .PerMille }},
 		currencies:      {{ .Currencies }},
-		{{ if gt (len .FmtPercentPrefix) 0}}
+		{{- if gt (len .FmtPercentPrefix) 0}}
 		percentPrefix:   {{ .FmtPercentPrefix }},
 		{{ end -}}
-		{{ if gt (len .FmtPercentSuffix) 0}}
+		{{- if gt (len .FmtPercentSuffix) 0}}
 		percentSuffix:   {{ .FmtPercentSuffix }},
 		{{ end -}}
+		{{- if gt (len .FmtCurrencyPrefix) 0}}
+		currencyPositivePrefix:   {{ .FmtCurrencyPrefix }},
+		{{ end -}}
+		{{- if gt (len .FmtCurrencySuffix) 0}}
+		currencyPositiveSuffix:   {{ .FmtCurrencySuffix }},
+		{{ end -}}
+		{{- if gt (len .FmtCurrencyNegativePrefix) 0}}
+		currencyNegativePrefix:   {{ .FmtCurrencyNegativePrefix }},
+		{{ end -}}
+		{{- if gt (len .FmtCurrencyNegativeSuffix) 0}}
+		currencyNegativeSuffix:   {{ .FmtCurrencyNegativeSuffix }},
+		{{ end -}}
 	}
 }
 
@@ -306,6 +323,19 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtPercent(num float64, v uint64) []byte
 		b[i], b[j] = b[j], b[i]
 	}
 
+	{{ if gt .FmtPercentMinDecimalLen 0 }}
+	if int(v) < {{ .FmtPercentMinDecimalLen }} {
+
+		if v == 0 {
+			b = append(b, {{ .BaseLocale }}.decimal...)
+		}
+
+		for i := 0; i < {{ .FmtPercentMinDecimalLen }}-int(v); i++ {
+			b = append(b, '0')
+		}
+	}
+	{{ end }}
+
 	{{ if and (not .FmtPercentInPrefix) .FmtPercentLeft }}
 		b = append(b, {{ .BaseLocale }}.percent...)
 	{{ end }}
@@ -318,19 +348,152 @@ func({{ .BaseLocale }} *{{ .Locale }}) FmtPercent(num float64, v uint64) []byte
 		b = append(b, {{ .BaseLocale }}.percent...)
 	{{ end }}
 
-	{{ if gt .FmtPercentMinDecimalLen 0 }}
-	if int(v) < {{ .FmtPercentMinDecimalLen }} {
+	return b
+	{{ else }}
+	return []byte(s)
+	{{ end -}}
+}
+
+// FmtCurrency returns the currency representation of 'num' with digits/precision of 'v' for '{{ .Locale }}'
+// returned as a []byte just in case the caller wishes to add more and can help
+// avoid allocations; otherwise just cast as string.
+func({{ .BaseLocale }} *{{ .Locale }}) FmtCurrency(num float64, v uint64, currency currency.Type) []byte {
+	
+	s := strconv.FormatFloat(math.Abs(num), 'f', int(v), 64)
+	symbol := {{ .BaseLocale }}.currencies[currency]
+	{{- if eq .FmtCurrencyExists true }}
+	{{- if gt .FmtCurrencyGroupLen 0 }}
+	l := len(s) + len({{ .BaseLocale }}.decimal) + len({{ .BaseLocale }}.group) * len(s[:len(s)-int(v)-1]) / {{ .FmtCurrencyGroupLen }}
+	count := 0
+	inWhole := v == 0
+	{{- if gt .FmtCurrencySecondaryGroupLen 0}}
+	inSecondary := false
+	groupThreshold := {{ .FmtCurrencyGroupLen }}
+	{{ end -}}
+	{{ else }}
+	l := len(s) + len({{ .BaseLocale }}.decimal)
+	{{ end }}
+	b := make([]byte, 0, l)
+
+	for i := len(s) - 1; i >= 0; i-- {
+
+		if s[i] == '.' {
+
+			{{- if eq .DecimalLen 1 }}
+			b = append(b, {{ .BaseLocale }}.decimal[0])
+			{{- else }}
+			for j := len({{ .BaseLocale }}.decimal) - 1; j >= 0; j-- {
+				b = append(b, {{ .BaseLocale }}.decimal[j])
+			}
+			{{ end -}}
+			{{- if gt .FmtCurrencyGroupLen 0 }}
+			inWhole = true
+			{{ end }}
+			continue
+		}
+
+		{{ if gt .FmtCurrencyGroupLen 0 }}
+		if inWhole {
+
+			{{- if gt .FmtCurrencySecondaryGroupLen 0}}
+			
+			if count == groupThreshold {
+				{{- if eq .GroupLen 1 }}
+				b = append(b, {{ .BaseLocale }}.group[0])
+				{{- else }}
+				for j := len({{ .BaseLocale }}.group) - 1; j >= 0; j-- {
+					b = append(b, {{ .BaseLocale }}.group[j])
+				}
+				{{ end }}
+				count = 1
+
+				if !inSecondary {
+					inSecondary = true
+					groupThreshold = {{ .FmtCurrencySecondaryGroupLen }}
+				}
+			{{ else }}
+			if count == {{ .FmtCurrencyGroupLen }} {
+				{{- if eq .GroupLen 1 }}
+				b = append(b, {{ .BaseLocale }}.group[0])
+				{{- else }}
+				for j := len({{ .BaseLocale }}.group) - 1; j >= 0; j-- {
+					b = append(b, {{ .BaseLocale }}.group[j])
+				}
+				{{ end }}
+				count = 1
+			{{ end -}}
+			} else {
+				count++
+			}
+		}
+
+		{{ end }}
+
+		b = append(b, s[i])
+	}
+
+	{{ if and .FmtCurrencyInPrefix (not .FmtCurrencyLeft) }}
+		for j := len(symbol) - 1; j >= 0; j-- {
+			b = append(b, symbol[j])
+		}
+	{{ end }}
+
+	{{ if gt (len .FmtCurrencyPrefix) 0}}
+		{{- if eq (len .FmtCurrencyPrefix) 1 }}
+		b = append(b, {{ .BaseLocale }}.currencyPositivePrefix[0])
+		{{ else }}
+		for j := len({{ .BaseLocale }}.currencyPositivePrefix) - 1; j >= 0; j-- {
+			b = append(b, {{ .BaseLocale }}.currencyPositivePrefix[j])
+		}
+		{{ end }}
+	{{ end }}
+
+	{{ if and .FmtCurrencyInPrefix .FmtCurrencyLeft }}
+		for j := len(symbol) - 1; j >= 0; j-- {
+			b = append(b, symbol[j])
+		}
+	{{ end }}
+
+	if num < 0 {
+		{{- if eq .MinusLen 1 }}
+		b = append(b, {{ .BaseLocale }}.minus[0])
+		{{ else }}
+		for j := len({{ .BaseLocale }}.minus) - 1; j >= 0; j-- {
+			b = append(b, {{ .BaseLocale }}.minus[j])
+		}
+		{{ end -}}
+	}
+
+	// reverse
+	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
+		b[i], b[j] = b[j], b[i]
+	}
+
+	{{ if gt .FmtCurrencyMinDecimalLen 0 }}
+	if int(v) < {{ .FmtCurrencyMinDecimalLen }} {
 
 		if v == 0 {
 			b = append(b, {{ .BaseLocale }}.decimal...)
 		}
 
-		for i := 0; i < {{ .FmtPercentMinDecimalLen }}-int(v); i++ {
+		for i := 0; i < {{ .FmtCurrencyMinDecimalLen }}-int(v); i++ {
 			b = append(b, '0')
 		}
 	}
 	{{ end }}
 
+	{{ if and (not .FmtCurrencyInPrefix) .FmtCurrencyLeft }}
+		b = append(b, symbol...)
+	{{ end }}
+
+	{{ if gt (len .FmtCurrencySuffix) 0}}
+		b = append(b, {{ .BaseLocale }}.currencyPositiveSuffix...)
+	{{ end }}
+
+	{{ if and (not .FmtCurrencyInPrefix) (not .FmtCurrencyLeft) }}
+		b = append(b, symbol...)
+	{{ end }}
+
 	return b
 	{{ else }}
 	return []byte(s)

ファイルの差分が大きいため隠しています
+ 16 - 11
cs/cs.go


ファイルの差分が大きいため隠しています
+ 16 - 11
cs_CZ/cs_CZ.go


ファイルの差分が大きいため隠しています
+ 16 - 11
cu/cu.go


ファイルの差分が大きいため隠しています
+ 16 - 11
cu_RU/cu_RU.go


+ 3 - 3
currency/currency.go

@@ -1,11 +1,11 @@
 package currency
 
-// Currency is the type associated with the locales currency enum
-type Currency int
+// Type is the currency type associated with the locales currency enum
+type Type int
 
 // locale currencies
 const (
-	ADP Currency = iota
+	ADP Type = iota
 	AED
 	AFA
 	AFN

ファイルの差分が大きいため隠しています
+ 16 - 19
cy/cy.go


この差分においてかなりの量のファイルが変更されているため、一部のファイルを表示していません