github.com/rakutentech/cli@v6.12.5-0.20151006231303-24468b65536e+incompatible/cf/i18n/init_windows_test.go (about)

     1  // +build windows
     2  
     3  package i18n_test
     4  
     5  import (
     6  	"path/filepath"
     7  
     8  	"github.com/cloudfoundry/cli/cf/configuration/core_config"
     9  	"github.com/cloudfoundry/cli/cf/i18n"
    10  	"github.com/cloudfoundry/cli/cf/i18n/detection/fakes"
    11  	testconfig "github.com/cloudfoundry/cli/testhelpers/configuration"
    12  
    13  	. "github.com/onsi/ginkgo"
    14  	. "github.com/onsi/gomega"
    15  )
    16  
    17  var _ = Describe("i18n.Init() function", func() {
    18  	var (
    19  		configRepo core_config.ReadWriter
    20  		detector   *fakes.FakeDetector
    21  	)
    22  
    23  	BeforeEach(func() {
    24  		i18n.Resources_path = filepath.Join("cf", "i18n", "test_fixtures")
    25  		configRepo = testconfig.NewRepositoryWithDefaults()
    26  		detector = &fakes.FakeDetector{}
    27  	})
    28  
    29  	Describe("When a user has a locale configuration set", func() {
    30  		Context("creates a valid T function", func() {
    31  			BeforeEach(func() {
    32  				configRepo.SetLocale("en_US")
    33  			})
    34  
    35  			It("returns a usable T function for simple strings", func() {
    36  				T := i18n.Init(configRepo, detector)
    37  				Ω(T).ShouldNot(BeNil())
    38  
    39  				translation := T("Hello world!")
    40  				Ω("Hello world!").Should(Equal(translation))
    41  			})
    42  
    43  			It("returns a usable T function for complex strings (interpolated)", func() {
    44  				T := i18n.Init(configRepo, detector)
    45  				Ω(T).ShouldNot(BeNil())
    46  
    47  				translation := T("Deleting domain {{.DomainName}} as {{.Username}}...", map[string]interface{}{"DomainName": "foo.com", "Username": "Anand"})
    48  				Ω("Deleting domain foo.com as Anand...").Should(Equal(translation))
    49  			})
    50  		})
    51  	})
    52  
    53  	Describe("When a user does not have a locale configuration set", func() {
    54  		BeforeEach(func() {
    55  			detector.DetectIETFReturns("en-US", nil)
    56  		})
    57  
    58  		Context("creates a valid T function", func() {
    59  			It("returns a usable T function for simple strings", func() {
    60  				T := i18n.Init(configRepo, detector)
    61  				Ω(T).ShouldNot(BeNil())
    62  
    63  				translation := T("Change user password")
    64  				Ω("Change user password").Should(Equal(translation))
    65  			})
    66  
    67  			It("returns a usable T function for complex strings (interpolated)", func() {
    68  				T := i18n.Init(configRepo, detector)
    69  				Ω(T).ShouldNot(BeNil())
    70  
    71  				translation := T("Deleting domain {{.DomainName}} as {{.Username}}...", map[string]interface{}{"DomainName": "foo", "Username": "Anand"})
    72  				Ω("Deleting domain foo as Anand...").Should(Equal(translation))
    73  			})
    74  		})
    75  
    76  	})
    77  
    78  	Describe("When locale is HK/TW", func() {
    79  		It("matches zh_CN to zh_Hans", func() {
    80  			detector.DetectIETFReturns("zh-CN.UTF-8", nil)
    81  			detector.DetectLanguageReturns("zh", nil)
    82  			T := i18n.Init(configRepo, detector)
    83  			Ω(T).ShouldNot(BeNil())
    84  
    85  			translation := T("No buildpacks found")
    86  			Ω("buildpack未找到").Should(Equal(translation))
    87  		})
    88  
    89  		It("matches zh_TW to zh_Hant", func() {
    90  			detector.DetectIETFReturns("zh-TW.UTF-8", nil)
    91  			T := i18n.Init(configRepo, detector)
    92  			Ω(T).ShouldNot(BeNil())
    93  
    94  			translation := T("No buildpacks found")
    95  			Ω("(Hant)No buildpacks found").Should(Equal(translation))
    96  		})
    97  
    98  		It("matches zh_HK to zh_Hant", func() {
    99  			detector.DetectIETFReturns("zh-HK.UTF-8", nil)
   100  			T := i18n.Init(configRepo, detector)
   101  			Ω(T).ShouldNot(BeNil())
   102  
   103  			translation := T("No buildpacks found")
   104  			Ω("(Hant)No buildpacks found").Should(Equal(translation))
   105  		})
   106  	})
   107  })