11using GetText ;
22using Nickvision . Desktop . Application ;
3- using Nickvision . Desktop . System ;
43using System ;
54using System . Collections . Generic ;
65using System . Globalization ;
@@ -14,7 +13,7 @@ namespace Nickvision.Desktop.Globalization;
1413/// </summary>
1514public class GettextTranslationService : ITranslationService
1615{
17- private readonly AppInfo _appInfo ;
16+ private readonly string _domainName ;
1817 private Catalog ? _catalog ;
1918 private string _language ;
2019
@@ -29,19 +28,19 @@ public class GettextTranslationService : ITranslationService
2928 /// </remarks>
3029 public GettextTranslationService ( AppInfo appInfo , string language = "" )
3130 {
32- _appInfo = appInfo ;
31+ _domainName = appInfo . EnglishShortName . Replace ( " " , "" ) . ToLower ( ) ;
3332 _language = language ;
3433 if ( string . IsNullOrEmpty ( _language ) )
3534 {
36- _catalog = new Catalog ( _appInfo . EnglishShortName , System . Environment . ExecutingDirectory ) ;
35+ _catalog = new Catalog ( _domainName , System . Environment . ExecutingDirectory ) ;
3736 }
3837 else if ( _language == "C" )
3938 {
4039 _catalog = null ;
4140 }
4241 else
4342 {
44- _catalog = ! AvailableLanguages . Contains ( _language ) ? new Catalog ( _appInfo . EnglishShortName , System . Environment . ExecutingDirectory ) : _catalog = new Catalog ( _appInfo . EnglishShortName , System . Environment . ExecutingDirectory , new CultureInfo ( language ) ) ;
43+ _catalog = ! AvailableLanguages . Contains ( _language ) ? new Catalog ( _domainName , System . Environment . ExecutingDirectory ) : _catalog = new Catalog ( _domainName , System . Environment . ExecutingDirectory , new CultureInfo ( language ) ) ;
4544 }
4645 }
4746
@@ -61,15 +60,15 @@ public string Language
6160 _language = value ;
6261 if ( string . IsNullOrEmpty ( _language ) )
6362 {
64- _catalog = new Catalog ( _appInfo . EnglishShortName , System . Environment . ExecutingDirectory ) ;
63+ _catalog = new Catalog ( _domainName , System . Environment . ExecutingDirectory ) ;
6564 }
6665 else if ( _language == "C" )
6766 {
6867 _catalog = null ;
6968 }
7069 else
7170 {
72- _catalog = ! AvailableLanguages . Contains ( _language ) ? new Catalog ( _appInfo . EnglishShortName , System . Environment . ExecutingDirectory ) : _catalog = new Catalog ( _appInfo . EnglishShortName , System . Environment . ExecutingDirectory , new CultureInfo ( _language ) ) ;
71+ _catalog = ! AvailableLanguages . Contains ( _language ) ? new Catalog ( _domainName , System . Environment . ExecutingDirectory ) : _catalog = new Catalog ( _domainName , System . Environment . ExecutingDirectory , new CultureInfo ( _language ) ) ;
7372 }
7473 }
7574 }
@@ -84,7 +83,7 @@ public IEnumerable<string> AvailableLanguages
8483 var languages = new List < string > ( ) ;
8584 foreach ( var directory in Directory . EnumerateDirectories ( System . Environment . ExecutingDirectory ) )
8685 {
87- if ( File . Exists ( Path . Combine ( directory , $ "{ _appInfo . EnglishShortName } .mo") ) )
86+ if ( File . Exists ( Path . Combine ( directory , $ "{ _domainName } .mo") ) )
8887 {
8988 languages . Add ( new DirectoryInfo ( directory ) . Name ) ;
9089 }
@@ -164,36 +163,4 @@ public IEnumerable<string> AvailableLanguages
164163 /// <param name="args">The arguments for the format string</param>
165164 /// <returns>The translated plural format string if n != 1, else the translated non-plural format string for the context</returns>
166165 public string _pn ( string context , string text , string pluralText , long n , params object [ ] args ) => _catalog ? . GetParticularPluralString ( context , text , pluralText , n , args ) ?? ( n == 1 ? text : pluralText ) ;
167-
168- /// <summary>
169- /// Gets the localized help page url for a given page name.
170- /// </summary>
171- /// <param name="pageName">The name of the help page</param>
172- /// <returns>The help page url for the current system locale</returns>
173- public Uri GetHelpUrl ( string pageName )
174- {
175- if ( OperatingSystem . IsLinux ( ) )
176- {
177- if ( System . Environment . DeploymentMode == DeploymentMode . Flatpak )
178- {
179- return new Uri ( $ "help:{ _appInfo . EnglishShortName . ToLower ( ) } /{ pageName } ") ;
180- }
181- }
182- var lang = "C" ;
183- var sysLocale = CultureInfo . CurrentCulture . Name . Replace ( '-' , '_' ) ;
184- if ( ! string . IsNullOrEmpty ( sysLocale ) && sysLocale != "C" && sysLocale != "en_US" && sysLocale != "*" )
185- {
186- var twoLetter = sysLocale . Split ( '_' ) [ 0 ] ;
187- foreach ( var language in AvailableLanguages )
188- {
189- if ( language != sysLocale && language != twoLetter )
190- {
191- continue ;
192- }
193- lang = language ;
194- break ;
195- }
196- }
197- return new Uri ( $ "https://htmlpreview.github.io/?{ _appInfo . DocumentationStore } /{ lang } /{ pageName } .html") ;
198- }
199166}
0 commit comments