(t *testing.T)
| 236 | } |
| 237 | |
| 238 | func TestSetCustomLoadTranslationsFunc(t *testing.T) { |
| 239 | resetLazyLoading() |
| 240 | |
| 241 | // Set a custom translations func that loads translations from a directory |
| 242 | err := SetLoadTranslationsFunc(func() error { |
| 243 | gettext.BindLocale(gettext.New("k8s", "./translations/test")) |
| 244 | gettext.SetDomain("k8s") |
| 245 | gettext.SetLanguage("en_US") |
| 246 | return nil |
| 247 | }) |
| 248 | if err != nil { |
| 249 | t.Errorf("unexpected error: %v", err) |
| 250 | } |
| 251 | if translationsLoaded { |
| 252 | t.Errorf("expected translationsLoaded to be false, but it was true") |
| 253 | } |
| 254 | |
| 255 | // Translation should succeed |
| 256 | result := T("test_string") |
| 257 | if result != "baz" { |
| 258 | t.Errorf("expected: %s, saw: %s", "baz", result) |
| 259 | } |
| 260 | if !translationsLoaded { |
| 261 | t.Errorf("expected translationsLoaded to be true, but it was false") |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | func TestSetCustomLoadTranslationsFuncAfterTranslationsLoadedShouldFail(t *testing.T) { |
| 266 | resetLazyLoading() |
nothing calls this directly
no test coverage detected
searching dependent graphs…