Skip to content

Commit

Permalink
Merge pull request #2591 from Dazzar56/auto-locale-fix
Browse files Browse the repository at this point in the history
fix incorrect interface locale on first render
  • Loading branch information
elfmz authored Dec 23, 2024
2 parents e087a3c + 38e1a9f commit 7c68a7f
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions far2l/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ static void UpdatePathOptions(const FARString &strDestName, bool IsActivePanel)
}

static int MainProcess(FARString strEditViewArg, FARString strDestName1, FARString strDestName2,
int StartLine, int StartChar)
int StartLine, int StartChar, bool cfgNeedSave)
{
InterThreadCallsDispatcherThread itc_dispatcher_thread;

Expand Down Expand Up @@ -306,15 +306,6 @@ static int MainProcess(FARString strEditViewArg, FARString strDestName1, FARStri
fprintf(stderr, "STARTUP: %llu\n", (unsigned long long)(clock() - cl_start));

if( Opt.IsFirstStart ) {

const char *locale = setlocale(LC_CTYPE, NULL);
// Only Russian translation can be currently considered complete
if (IsLocaleMatches(locale, "ru_RU")) {
Opt.strLanguage = L"Russian";
Opt.strHelpLanguage = L"Russian";
ConfigOptSave(false);
}

Help::Present(L"Far2lGettingStarted",L"",FHELP_NOSHOWERROR);

DWORD tweaks = WINPORT(SetConsoleTweaks)(TWEAKS_ONLY_QUERY_SUPPORTED);
Expand All @@ -336,10 +327,14 @@ static int MainProcess(FARString strEditViewArg, FARString strDestName1, FARStri
} else {
Opt.OSC52ClipSet = 1;
}
ConfigOptSave(false);
cfgNeedSave = true;
}
}

if (cfgNeedSave) {
ConfigOptSave(false);
}

FrameManager->EnterMainLoop();
}

Expand Down Expand Up @@ -604,10 +599,10 @@ int FarAppMain(int argc, char **argv)
std::string kblo_path = StrPrintf("%lskblayouts.ini", far2l_path);
KeyboardLayouts.reset(new KeyFileHelper(kblo_path.c_str()));

const char *lc = setlocale(LC_CTYPE, NULL);
const char *locale = setlocale(LC_CTYPE, NULL);
char LangCode[3];
LangCode[0] = lc[0];
LangCode[1] = lc[1];
LangCode[0] = locale[0];
LangCode[1] = locale[1];
LangCode[2] = 0;

KbLayoutsTrIn = KeyboardLayouts->GetString(LangCode, "Latin");
Expand Down Expand Up @@ -637,6 +632,18 @@ int FarAppMain(int argc, char **argv)
InitConsole();
WINPORT(SetConsoleCursorBlinkTime)(NULL, Opt.CursorBlinkTime);

bool cfgNeedSave = false;
//нужно проверить локаль до начала отрисовки интерфейса
if (Opt.IsFirstStart)
{
// Only Russian translation can be currently considered complete
if (IsLocaleMatches(locale, "ru_RU")) {
Opt.strLanguage = L"Russian";
Opt.strHelpLanguage = L"Russian";
cfgNeedSave = true;
}
}

static_assert(!IsPtr(Msg::NewFileName._id),
"Too many language messages. Need to refactor code to eliminate use of IsPtr.");

Expand Down Expand Up @@ -667,7 +674,7 @@ int FarAppMain(int argc, char **argv)
if ( Opt.OnlyEditorViewerUsed == Options::ONLY_EDITOR && strEditViewArg.IsEmpty() )
strEditViewArg = Msg::NewFileName;

int Result = MainProcess(strEditViewArg, DestNames[0], DestNames[1], StartLine, StartChar);
int Result = MainProcess(strEditViewArg, DestNames[0], DestNames[1], StartLine, StartChar, cfgNeedSave);

EmptyInternalClipboard();
doneMacroVarTable(1);
Expand Down

0 comments on commit 7c68a7f

Please sign in to comment.