Repository: jesseduffield/lazygit (language: go)

Issue:
Not launching in Korean environment with default `language: 'auto'` config
**Describe the bug**


After upgrading to version 0.43.0, lazygit does not launch with the default language setting ‘auto’.


I have resolved the issue temporarily by setting the language to 'ko' or 'en' in the config file as follows:

```yaml
gui:
    language: ko
```
(config file : `~/Library/Application\ Support/lazygit/config.yml`)

**To Reproduce**


1. Install lazygit `0.43.0` (using homebrew)
2. Open a terminal and run lazygit.

error
```bash
2024/07/13 16:35:26 open translations/ko-KR.json: file does not exist
```

**Expected behavior**

lazygit should launch.


**Screenshots**

<img width="1097" alt="image" src="https://github.com/user-attachments/assets/a3a2dd83-30b3-48f0-a6a4-6ea0826fefa1">



**Version info:**
_Run `lazygit --version` and paste the result here_
```
commit=, build date=, build source=homebrew, version=0.43.0, os=darwin, arch=arm64, git version=2.39.3 (Apple Git-146)
```
_Run `git --version` and paste the result here_
```
git version 2.39.3 (Apple Git-146)
```

**Additional context**
Add any other context about the problem here.

**Note:** please try updating to the latest version or [manually building](https://github.com/jesseduffield/lazygit/#manual) the latest `master` to see if the issue still occurs.

<!--
If you want to try and debug this issue yourself, you can run `lazygit --debug` in one terminal panel and `lazygit --logs` in another to view the logs.
-->



Discussion / hints:

Fix patch:
diff --git a/pkg/i18n/i18n.go b/pkg/i18n/i18n.go
index f9febbe01ec..3848d42cf4c 100644
--- a/pkg/i18n/i18n.go
+++ b/pkg/i18n/i18n.go
@@ -24,7 +24,7 @@ func NewTranslationSetFromConfig(log *logrus.Entry, configLanguage string) (*Tra
 		language := detectLanguage(jibber_jabber.DetectIETF)
 		for _, languageCode := range languageCodes {
 			if strings.HasPrefix(language, languageCode) {
-				return newTranslationSet(log, language)
+				return newTranslationSet(log, languageCode)
 			}
 		}
 


Test patch:
diff --git a/pkg/i18n/i18n_test.go b/pkg/i18n/i18n_test.go
index 7023ea40acc..8c5787fcb32 100644
--- a/pkg/i18n/i18n_test.go
+++ b/pkg/i18n/i18n_test.go
@@ -2,8 +2,11 @@ package i18n
 
 import (
 	"fmt"
+	"io"
+	"runtime"
 	"testing"
 
+	"github.com/sirupsen/logrus"
 	"github.com/stretchr/testify/assert"
 )
 
@@ -33,3 +36,84 @@ func TestDetectLanguage(t *testing.T) {
 		assert.EqualValues(t, s.expected, detectLanguage(s.langDetector))
 	}
 }
+
+// Can't use utils.NewDummyLog() because of a cyclic dependency
+func newDummyLog() *logrus.Entry {
+	log := logrus.New()
+	log.Out = io.Discard
+	return log.WithField("test", "test")
+}
+
+func TestNewTranslationSetFromConfig(t *testing.T) {
+	if runtime.GOOS == "windows" {
+		// These tests are based on setting the LANG environment variable, which
+		// isn't respected on Windows.
+		t.Skip("Skipping test on Windows")
+	}
+
+	scenarios := []struct {
+		name           string
+		configLanguage string
+		envLanguage    string
+		expected       string
+		expectedErr    bool
+	}{
+		{
+			name:           "configLanguage is nl",
+			configLanguage: "nl",
+			envLanguage:    "en_US",
+			expected:       "nl",
+			expectedErr:    false,
+		},
+		{
+			name:           "configLanguage is an unsupported language",
+			configLanguage: "xy",
+			envLanguage:    "en_US",
+			expectedErr:    true,
+		},
+		{
+			name:           "auto-detection without LANG set",
+			configLanguage: "auto",
+			envLanguage:    "",
+			expected:       "en",
+			expectedErr:    false,
+		},
+		{
+			name:           "auto-detection with LANG set to nl_NL",
+			configLanguage: "auto",
+			envLanguage:    "nl_NL",
+			expected:       "nl",
+			expectedErr:    false,
+		},
+		{
+			name:           "auto-detection with LANG set to zh-CN",
+			configLanguage: "auto",
+			envLanguage:    "zh-CN",
+			expected:       "zh-CN",
+			expectedErr:    false,
+		},
+		{
+			name:           "auto-detection with LANG set to an unsupported language",
+			configLanguage: "auto",
+			envLanguage:    "xy_XY",
+			expected:       "en",
+			expectedErr:    false,
+		},
+	}
+
+	for _, s := range scenarios {
+		t.Run(s.name, func(t *testing.T) {
+			log := newDummyLog()
+			t.Setenv("LANG", s.envLanguage)
+			actualTranslationSet, err := NewTranslationSetFromConfig(log, s.configLanguage)
+			if s.expectedErr {
+				assert.Error(t, err)
+			} else {
+				assert.NoError(t, err)
+
+				expectedTranslationSet, _ := newTranslationSet(log, s.expected)
+				assert.Equal(t, expectedTranslationSet, actualTranslationSet)
+			}
+		})
+	}
+}