You are here

[Closed] Sumatra PDF: language switching broken?

11 posts / 0 new
Last post
Simeon
Simeon's picture
Offline
Last seen: 10 years 1 month ago
DeveloperTranslator
Joined: 2006-09-25 15:15
[Closed] Sumatra PDF: language switching broken?

Today I opened Sumatra PDF and it started in english although my platform is in german. I tried italian too but Sumatra remained in english. I even deleted the /Data folder and the problem was still there.
Can anyone reproduce this?

Ken Herbert
Ken Herbert's picture
Offline
Last seen: 1 hour 38 min ago
DeveloperModerator
Joined: 2010-05-25 18:19
Reproduced, plus some more info

Using a fresh install of Sumatra I can semi-reproduce this with the following results:

  1. Installed Sumatra
  2. Ran Sumatra - opened in English (as expected) - closed app
  3. Switched platform language to Finnish
  4. Ran Sumatra - opened in Finnish (as expected) - closed app
  5. Switched platform to English
  6. Ran Sumatra - opened in English (as expected)
  7. So far language switching working as expected

  8. Switched language within Sumatra to Estonian - closed app
  9. Switched platform to Farsi
  10. Ran Sumatra - opened in Estonian (not expected)
  11. Switched language within Sumatra to Farsi - closed app
  12. Switched platform to English
  13. Ran Sumatra - opened in English (as expected)
  14. Language switching not working when language is switched within the app

Edit: I believe it is because Sumatra is using custom code for lang switching, and is only checking/replacing the last language that Sumatra was switched to by the platform, not the last language switched to by the app.

The question is, is there a major reason why Sumatra requires a custom launcher and can't be done with PAL?

John T. Haller
John T. Haller's picture
Offline
Last seen: 8 hours 16 min ago
AdminDeveloperModeratorTranslator
Joined: 2005-11-28 22:21
Oddball

Sumatra uses a completely esoteric settings format. It isn't a config, INI, XML or similar. So, it can't be done in PAL. And we can't reference it within the file. We can only do a replace. So, if you ever switch it within Sumatra, it will stay switched unless you happen to sync it up to the platform again manually. There is no other fix.

Sometimes, the impossible can become possible, if you're awesome!

Ken Herbert
Ken Herbert's picture
Offline
Last seen: 1 hour 38 min ago
DeveloperModerator
Joined: 2010-05-25 18:19
I had noticed that. The

I had noticed that. The format does look semi-static, at least from my brief testing.

The entry for lang always begins with 10:UILanguage2: and is always followed by 12:, except for the prefs file in DefaultData, which has it followed by e12:. But deleting the Data dir and running Sumatra results in the entry being followed by 12: anyway.

Edit: No ignore that. Just noticed that 12: and e12: are the start of different entries.

3D1T0R
3D1T0R's picture
Offline
Last seen: 3 years 4 months ago
Developer
Joined: 2006-12-29 23:48
Funky Format: True; Only Option = Replace: False.

Hello,
While it is true that SumatraPDF's settings are saved in a way that our current tools can not edit the stored language setting any way other than the current Replace, there is another option. I have written a patch to the launcher which will make it use an other option, but before I upload it I would like to know how to make it respond to unsupported languages.

I can either write it so that opening SumatraPDF from the Platform whilst the Platform is set to a language SumatraPDF does not support will open SumatraPDF in English, or I can set it to open SumatraPDF in the language SumatraPDF was set to when it was last closed.

Note: I have no preference, and neither option is easier or harder as I've actually written both already.

~3D1T0R

John T. Haller
John T. Haller's picture
Offline
Last seen: 8 hours 16 min ago
AdminDeveloperModeratorTranslator
Joined: 2005-11-28 22:21
Last Closed

I'd suggest last closed. Rather than another custom launcher though, how about switching it to PAL as well? If you don't mind, that is. Smile

Sometimes, the impossible can become possible, if you're awesome!

3D1T0R
3D1T0R's picture
Offline
Last seen: 3 years 4 months ago
Developer
Joined: 2006-12-29 23:48
The current Custom Launcher still works:

Yes, I see that this would actually be a pretty simple thing to put in PAL, but I've already put together a patch for the current Launcher (and fixed it ‘cause it wasn't quite right the first time around), if I did rewrite it in PAL I'd want to integrate GhostScriptPortable support too (which also shouldn't be too difficult), and I think I've typed enough tonight.

So, if nobody else wants to do it, I might decide to give this the PAL treatment, but in the mean-time the current Custom Launcher does work.

Edit: Looked into GhostScriptPortable support, and (as stated here) it should work if you add the GhostScriptPortable's Directory to the PATH Environment Variable.

~3D1T0R

3D1T0R
3D1T0R's picture
Offline
Last seen: 3 years 4 months ago
Developer
Joined: 2006-12-29 23:48
EDIT: Patch.diff

EDIT: Hey, I went through and tested the effects of this patch Language by Language (rather than simply trusting the lists like I had at first), and I've updated the Patch accordingly.

OK,
So if started from the Platform the Language will be set with the "-lang ¿?" argument (Documented Here & Here) to match, if it's a Language which the Platform & Sumatra use different codes to identify (I based my list of Discrepancies on This [SumatraPDF] & This [PA.cPlatform]) it will fix it; and if a Language which SumatraPDF doesn't support is selected, or it is not launched from the Platform (or if the Platform is set not to ‘use this Language for all PortableApps’) it will not pass the -lang argument (meaning that SumatraPDF will simply remember what Language it was set to at the time of it's last exit.)

BTW: What is the preferred method of posting patches?
Do you like “Place the following in Source.File, between Lines X & Y”?
Or do you prefer .diff’s?
[.diff’s being like the following:]

--- X:/PortableApps/SumatraPDFPortable/Other/Source/SumatraPDFPortableU.nsi	Wed Apr 25 15:22:48 2012
+++ X:/PortableApps/SumatraPDFPortable/Other/Source/LangFix-SumatraPDFPortableU.nsi	Tue Oct 02 20:29:48 2012
@@ -208,13 +208,64 @@
 		WriteINIStr "$SETTINGSDIRECTORY\${NAME}Settings.ini" "${NAME}Settings" "LastDrive" "$CURRENTDRIVE"
 		WriteINIStr "$SETTINGSDIRECTORY\${NAME}Settings.ini" "${NAME}Settings" "LastPortableAppsRoot" "$strPortableAppsRoot"
 		
-	;GetCurrentLanguage
-		${ReadINIStrWithDefault} $0 "$SETTINGSDIRECTORY\${NAME}Settings.ini" "${NAME}Settings" "LastLanguage" "en"
-		ReadEnvStr $1 "PortableApps.comLocaleCode2"
-		StrCmp $1 "" LaunchNow ;If no env var, skip it
-		StrCmp $0 $1 LaunchNow ;If the same, skip it
-			${ReplaceInFile} "$PROGRAMDIRECTORY\sumatrapdfprefs.dat" 'UILanguage2:$0' 'UILanguage2:$1'
-			WriteINIStr "$SETTINGSDIRECTORY\${NAME}Settings.ini" "${NAME}Settings" "LastLanguage" "$1"
+	;SetCurrentLanguage
+		ReadEnvStr $0 "PortableApps.comLocaleglibc"
+		StrCmp $0 "" LaunchNow CheckForLocaleCodeDiscrepancies ;If no env var, skip it, else check for LocaleCode Discrepancies
+
+		;LocaleCode Discrepancy fixers
+	SetLangToBelarusian:	;This is in the list, so it's here, but it's not actually supported, however since it doesn't break anything I'd leave it for future use.
+		StrCpy $0 `by`
+		Goto SetLocale
+	SetLangToChineseSimple:
+		StrCpy $0 `cn`
+		Goto SetLocale
+	SetLangToChineseTraditional:
+		StrCpy $0 `tw`
+		Goto SetLocale
+	SetLangToCzech:
+		StrCpy $0 `cz`
+		Goto SetLocale
+	SetLangToDanish:
+		StrCpy $0 `dk`
+		Goto SetLocale
+	SetLangToEnglish:
+		StrCpy $0 `en` ;For both en_US & en_GB
+		Goto SetLocale
+	SetLangToKorean:
+		StrCpy $0 `kr`
+		Goto SetLocale
+	SetLangToMalay:	;Apparently Malay is also listed but not supported, Leaving it for future use.
+		StrCpy $0 `my`
+		Goto SetLocale
+	SetLangToNorwegian:
+		StrCpy $0 `no`
+		Goto SetLocale
+	SetLangToPortugueseBR:
+		StrCpy $0 `br` ;Portuguese is pt, Brasilian Portuguese is br
+		Goto SetLocale
+	SetLangToVietnamese:
+		StrCpy $0 `vn` ;Fix Vietnamese
+		Goto SetLocale
+
+	CheckForLocaleCodeDiscrepancies:
+		StrCmp $0 `be` SetLangToBelarusian ;Check for Belarusian
+		StrCmp $0 `zh_CN` SetLangToChineseSimple ;Check for SimpChinese
+		StrCmp $0 `zh_TW` SetLangToChineseTraditional ;Check for TradChinese
+		StrCmp $0 `cs` SetLangToCzech ;Check for Czech
+		StrCmp $0 `da` SetLangToDanish ;Check for Danish
+		StrCmp $0 `en_GB` SetLangToEnglish ;Check for EnglishGB
+		StrCmp $0 `en_US` SetLangToEnglish ;Check for EnglishUS
+		StrCmp $0 `ko` SetLangToKorean ;Check for Korean
+		StrCmp $0 `ms` SetLangToMalay ;Check for Malay
+		StrCmp $0 `nb` SetLangToNorwegian ;Check for Norwegian
+		StrCmp $0 `pt_BR` SetLangToPortugueseBR ;Check for PortugueseBR
+		StrCmp $0 `vi` SetLangToVietnamese ;Check for Vietnamese
+	;If the Platform is set to a language that SumatraPDF doesn't support, skip setting it (i.e. use what's still saved from last exit of SumatraPDF)
+		StrCmp $0 `lv` LaunchNow ;Latvian isn't supported
+		StrCmp $0 `lb` LaunchNow ;Luxembourgish isn't supported
+		StrCmp $0 `su` LaunchNow ;Luxembourgish isn't supported
+	SetLocale:
+		StrCpy $EXECSTRING `$EXECSTRING -lang $0`
 
 	LaunchNow:
 		ExecWait $EXECSTRING

P.S.: I chose Localeglibc because it had Portuguese (Portuguese [pt] & Brasilian [br/pt_BR] variants) & Chinese (Simple [cn/zh/zh_CN] & Traditional [tw/zh/zh_TW])separate, and already had Arabic [ar/ar-sa] & SpanishInternational [es/es-mx] as SumatraPDF requires them.

~3D1T0R

John T. Haller
John T. Haller's picture
Offline
Last seen: 8 hours 16 min ago
AdminDeveloperModeratorTranslator
Joined: 2005-11-28 22:21
Preferred

I prefer to just get the whole file as Windows doesn't have much in the way of solid diff utilities I've found.

Sometimes, the impossible can become possible, if you're awesome!

3D1T0R
3D1T0R's picture
Offline
Last seen: 3 years 4 months ago
Developer
Joined: 2006-12-29 23:48
Alright, Whole File in Paste.

Alright, I'll keep an eye out for a good DIFFing program on Windows. Wink
(Too bad WinMerge doesn't understand .diff patches, it makes them, so it should)

Whole File: Link to Paste on 0bin.net.

Edit: WinMerge2011 says it can "apply patches" if they're in "unified patch" format, and have a .patch extension, by Drag&Dropping them onto the file that needs patched while it is open in one of it's editor panes (left or right shouldn't matter). However this is a fork of WinMerge which appears to still be in a relatively unstable state. Haven't tried it out yet, maybe later.

~3D1T0R

3D1T0R
3D1T0R's picture
Offline
Last seen: 3 years 4 months ago
Developer
Joined: 2006-12-29 23:48
Oh yeah,

and with this Patch you no-longer need to have "LastLanguage=en" in the DefaultData\settings\SumatraPDFPortableSettings.ini.
(or do you not need that file at all any more?)

~3D1T0R

Log in or register to post comments