ssg: switch string literals to string resources 1/...

This commit is contained in:
Nick Vella 2019-08-04 02:05:38 +10:00
parent 8ca2693615
commit 7706b85796
10 changed files with 76 additions and 51 deletions

View File

@ -24,7 +24,7 @@ namespace OpenLiveWriter.BlogClient.Clients.StaticSite
// The 'provider' concept doesn't really apply to local static sites // The 'provider' concept doesn't really apply to local static sites
// Store these required constants here so they're in one place // Store these required constants here so they're in one place
public const string PROVIDER_ID = "D0E0062F-7540-4462-94FD-DC55004D95E6"; public const string PROVIDER_ID = "D0E0062F-7540-4462-94FD-DC55004D95E6";
public const string SERVICE_NAME = "Static Site Generator"; // TODO- Move to Strings public const string SERVICE_NAME = "Static Site Generator";
public const string POST_API_URL = "http://localhost/"; // A valid URI is required for BlogClientManager to instantiate a URI object on. public const string POST_API_URL = "http://localhost/"; // A valid URI is required for BlogClientManager to instantiate a URI object on.
public const string CLIENT_TYPE = "StaticSite"; public const string CLIENT_TYPE = "StaticSite";
@ -132,7 +132,9 @@ namespace OpenLiveWriter.BlogClient.Clients.StaticSite
public void DeletePost(string blogId, string postId, bool publish) public void DeletePost(string blogId, string postId, bool publish)
{ {
var post = StaticSitePost.GetPostById(Config, postId); var post = StaticSitePost.GetPostById(Config, postId);
if (post == null) throw new BlogClientException("Post does not exist", "Could not find post with specified ID."); // TODO use strings resources if (post == null) throw new BlogClientException(
Res.Get(StringId.SSGErrorPostDoesNotExistTitle),
Res.Get(StringId.SSGErrorPostDoesNotExistText));
DoDeleteItem(post); DoDeleteItem(post);
} }
@ -196,7 +198,9 @@ namespace OpenLiveWriter.BlogClient.Clients.StaticSite
public void DeletePage(string blogId, string pageId) public void DeletePage(string blogId, string pageId)
{ {
var page = StaticSitePage.GetPageById(Config, pageId); var page = StaticSitePage.GetPageById(Config, pageId);
if (page == null) throw new BlogClientException("Page does not exist", "Could not find page with specified ID."); // TODO use strings resources if (page == null) throw new BlogClientException(
Res.Get(StringId.SSGErrorPageDoesNotExistTitle),
Res.Get(StringId.SSGErrorPageDoesNotExistText));
DoDeleteItem(page); DoDeleteItem(page);
} }
@ -529,7 +533,9 @@ namespace OpenLiveWriter.BlogClient.Clients.StaticSite
{ {
// Timeout reached // Timeout reached
try { proc.Kill(); } catch { } // Attempt to kill the process try { proc.Kill(); } catch { } // Attempt to kill the process
throw new BlogClientException("Command execution timeout", "Blog command timed out. Please check your commands, or lengthen the command timeout."); // TODO move into strings throw new BlogClientException(
Res.Get(StringId.SSGErrorCommandTimeoutTitle),
Res.Get(StringId.SSGErrorCommandTimeoutText));
} }
} }

View File

@ -7,6 +7,7 @@ using System.Threading.Tasks;
using System.IO; using System.IO;
using OpenLiveWriter.Extensibility.BlogClient; using OpenLiveWriter.Extensibility.BlogClient;
using OpenLiveWriter.Localization;
namespace OpenLiveWriter.BlogClient.Clients.StaticSite namespace OpenLiveWriter.BlogClient.Clients.StaticSite
{ {
@ -30,16 +31,14 @@ namespace OpenLiveWriter.BlogClient.Clients.StaticSite
.ValidateBuildCommand() .ValidateBuildCommand()
.ValidatePublishCommand(); .ValidatePublishCommand();
// TODO replace errors with strings from resources
#region Path Validation #region Path Validation
public StaticSiteConfigValidator ValidateLocalSitePath() public StaticSiteConfigValidator ValidateLocalSitePath()
{ {
if(!Directory.Exists(_config.LocalSitePath)) if(!Directory.Exists(_config.LocalSitePath))
throw new StaticSiteConfigValidationException( throw new StaticSiteConfigValidationException(
"Folder not found", Res.Get(StringId.SSGErrorPathFolderNotFound),
"Local Site Path '{0}' does not exist.", Res.Get(StringId.SSGErrorPathLocalSitePathNotFound),
_config.LocalSitePath); _config.LocalSitePath);
return this; return this;
@ -52,14 +51,14 @@ namespace OpenLiveWriter.BlogClient.Clients.StaticSite
// If the Posts path is empty, display an error // If the Posts path is empty, display an error
if (_config.PostsPath.Trim() == string.Empty) if (_config.PostsPath.Trim() == string.Empty)
throw new StaticSiteConfigValidationException( throw new StaticSiteConfigValidationException(
"Folder not found", Res.Get(StringId.SSGErrorPathFolderNotFound),
"Posts path is empty."); Res.Get(StringId.SSGErrorPathPostsEmpty));
// If the Posts path doesn't exist, display an error // If the Posts path doesn't exist, display an error
if (!Directory.Exists(postsPathFull)) if (!Directory.Exists(postsPathFull))
throw new StaticSiteConfigValidationException( throw new StaticSiteConfigValidationException(
"Folder not found", Res.Get(StringId.SSGErrorPathFolderNotFound),
"Posts path '{0}' does not exist.", Res.Get(StringId.SSGErrorPathPostsNotFound),
postsPathFull); postsPathFull);
return this; return this;
@ -74,15 +73,15 @@ namespace OpenLiveWriter.BlogClient.Clients.StaticSite
// If the Pages path is empty, display an error // If the Pages path is empty, display an error
if (_config.PagesPath.Trim() == string.Empty) if (_config.PagesPath.Trim() == string.Empty)
throw new StaticSiteConfigValidationException( throw new StaticSiteConfigValidationException(
"Folder not found", Res.Get(StringId.SSGErrorPathFolderNotFound),
"Pages path is empty."); Res.Get(StringId.SSGErrorPathPagesEmpty));
// If the path doesn't exist, display an error // If the path doesn't exist, display an error
if (!Directory.Exists(pagesPathFull)) if (!Directory.Exists(pagesPathFull))
throw new StaticSiteConfigValidationException( throw new StaticSiteConfigValidationException(
"Folder not found", Res.Get(StringId.SSGErrorPathFolderNotFound),
"Pages path '{0}' does not exist.", Res.Get(StringId.SSGErrorPathPagesNotFound),
pagesPathFull); pagesPathFull);
return this; return this;
} }
@ -96,15 +95,15 @@ namespace OpenLiveWriter.BlogClient.Clients.StaticSite
// If the Drafts path is empty, display an error // If the Drafts path is empty, display an error
if (_config.DraftsPath.Trim() == string.Empty) if (_config.DraftsPath.Trim() == string.Empty)
throw new StaticSiteConfigValidationException( throw new StaticSiteConfigValidationException(
"Folder not found", Res.Get(StringId.SSGErrorPathFolderNotFound),
"Drafts path is empty."); Res.Get(StringId.SSGErrorPathDraftsEmpty));
// If the path doesn't exist, display an error // If the path doesn't exist, display an error
if (!Directory.Exists(draftsPathFull)) if (!Directory.Exists(draftsPathFull))
throw new StaticSiteConfigValidationException( throw new StaticSiteConfigValidationException(
"Folder not found", Res.Get(StringId.SSGErrorPathFolderNotFound),
"Drafts path '{0}' does not exist.", Res.Get(StringId.SSGErrorPathDraftsNotFound),
draftsPathFull); draftsPathFull);
return this; return this;
} }
@ -118,15 +117,15 @@ namespace OpenLiveWriter.BlogClient.Clients.StaticSite
// If the Images path is empty, display an error // If the Images path is empty, display an error
if (_config.ImagesPath.Trim() == string.Empty) if (_config.ImagesPath.Trim() == string.Empty)
throw new StaticSiteConfigValidationException( throw new StaticSiteConfigValidationException(
"Folder not found", Res.Get(StringId.SSGErrorPathFolderNotFound),
"Images path is empty."); Res.Get(StringId.SSGErrorPathImagesEmpty));
// If the path doesn't exist, display an error // If the path doesn't exist, display an error
if (!Directory.Exists(imagesPathFull)) if (!Directory.Exists(imagesPathFull))
throw new StaticSiteConfigValidationException( throw new StaticSiteConfigValidationException(
"Folder not found", Res.Get(StringId.SSGErrorPathFolderNotFound),
"Images path '{0}' does not exist.", Res.Get(StringId.SSGErrorPathImagesNotFound),
imagesPathFull); imagesPathFull);
return this; return this;
} }
@ -140,15 +139,15 @@ namespace OpenLiveWriter.BlogClient.Clients.StaticSite
// If the Output path is empty, display an error // If the Output path is empty, display an error
if (_config.OutputPath.Trim() == string.Empty) if (_config.OutputPath.Trim() == string.Empty)
throw new StaticSiteConfigValidationException( throw new StaticSiteConfigValidationException(
"Folder not found", Res.Get(StringId.SSGErrorPathFolderNotFound),
"Output path is empty."); Res.Get(StringId.SSGErrorPathOutputEmpty));
// If the path doesn't exist, display an error // If the path doesn't exist, display an error
if (!Directory.Exists(outputPathFull)) if (!Directory.Exists(outputPathFull))
throw new StaticSiteConfigValidationException( throw new StaticSiteConfigValidationException(
"Folder not found", Res.Get(StringId.SSGErrorPathFolderNotFound),
"Output path '{0}' does not exist.", Res.Get(StringId.SSGErrorPathOutputNotFound),
outputPathFull); outputPathFull);
return this; return this;
} }
@ -161,8 +160,8 @@ namespace OpenLiveWriter.BlogClient.Clients.StaticSite
if (_config.BuildCommand.Trim() == string.Empty) if (_config.BuildCommand.Trim() == string.Empty)
throw new StaticSiteConfigValidationException( throw new StaticSiteConfigValidationException(
"Build command empty", Res.Get(StringId.SSGErrorBuildCommandEmptyTitle),
"A build command is required when local site building is enabled."); Res.Get(StringId.SSGErrorBuildCommandEmptyText));
return this; return this;
} }
@ -171,8 +170,8 @@ namespace OpenLiveWriter.BlogClient.Clients.StaticSite
{ {
if (_config.PublishCommand.Trim() == string.Empty) if (_config.PublishCommand.Trim() == string.Empty)
throw new StaticSiteConfigValidationException( throw new StaticSiteConfigValidationException(
"Publish command empty", Res.Get(StringId.SSGErrorPublishCommandEmptyTitle),
"A publish command is required."); Res.Get(StringId.SSGErrorPublishCommandEmptyText));
return this; return this;
} }

View File

@ -9,6 +9,7 @@ using System.Diagnostics;
using OpenLiveWriter.CoreServices; using OpenLiveWriter.CoreServices;
using OpenLiveWriter.Extensibility.BlogClient; using OpenLiveWriter.Extensibility.BlogClient;
using OpenLiveWriter.Localization;
namespace OpenLiveWriter.BlogClient.Clients.StaticSite namespace OpenLiveWriter.BlogClient.Clients.StaticSite
{ {
@ -208,7 +209,8 @@ namespace OpenLiveWriter.BlogClient.Clients.StaticSite
// Parse out everything between triple-hyphens into front matter parser // Parse out everything between triple-hyphens into front matter parser
var frontMatterMatchResult = POST_PARSE_REGEX.Match(fileContents); var frontMatterMatchResult = POST_PARSE_REGEX.Match(fileContents);
if (!frontMatterMatchResult.Success || frontMatterMatchResult.Groups.Count < 3) throw new BlogClientException("Post load error", "Could not read post front matter"); // TODO Use strings resources if (!frontMatterMatchResult.Success || frontMatterMatchResult.Groups.Count < 3)
throw new BlogClientException(Res.Get(StringId.SSGErrorItemLoadTitle), Res.Get(StringId.SSGErrorItemLoadTextFM));
var frontMatterYaml = frontMatterMatchResult.Groups[1].Value; var frontMatterYaml = frontMatterMatchResult.Groups[1].Value;
var postContent = frontMatterMatchResult.Groups[2].Value; var postContent = frontMatterMatchResult.Groups[2].Value;
@ -218,7 +220,8 @@ namespace OpenLiveWriter.BlogClient.Clients.StaticSite
StaticSiteItemFrontMatter.GetFromYaml(SiteConfig.FrontMatterKeys, frontMatterYaml).SaveToBlogPost(BlogPost); StaticSiteItemFrontMatter.GetFromYaml(SiteConfig.FrontMatterKeys, frontMatterYaml).SaveToBlogPost(BlogPost);
// Throw error if post does not have an ID // Throw error if post does not have an ID
if (Id == null || Id == string.Empty) throw new BlogClientException("Post load error", "Post does not have an ID"); if (Id == null || Id == string.Empty)
throw new BlogClientException(Res.Get(StringId.SSGErrorItemLoadTitle), Res.Get(StringId.SSGErrorItemLoadTextId));
// FilePathById will be the path we loaded this post from // FilePathById will be the path we loaded this post from
FilePathById = postFilePath; FilePathById = postFilePath;

View File

@ -474,7 +474,7 @@ namespace OpenLiveWriter.BlogClient.Detection
if (targetUrl == _blogHomepageUrl && _nextTryPostUrl != null && regionLocatorStrategy.CanRefetchPage) if (targetUrl == _blogHomepageUrl && _nextTryPostUrl != null && regionLocatorStrategy.CanRefetchPage)
{ {
// Try fetching the URL that has been specified, and reparse // Try fetching the URL that has been specified, and reparse
progress.UpdateProgress("Post contents not present on homepage, checking post..."); // TODO use strings progress.UpdateProgress(Res.Get(StringId.ProgressDownloadingWeblogEditingStyleDeep));
// Fetch the post page // Fetch the post page
regionLocatorStrategy.FetchTemporaryPostPage(SilentProgressHost.Instance, _nextTryPostUrl); regionLocatorStrategy.FetchTemporaryPostPage(SilentProgressHost.Instance, _nextTryPostUrl);
// Parse out the template // Parse out the template

View File

@ -4831,7 +4831,7 @@ namespace OpenLiveWriter.Localization
/// </summary> /// </summary>
SSGConfigGeneralWizardButton, SSGConfigGeneralWizardButton,
/// <summary> /// <summary>
/// You can chose to run the Account Wizard again if you wish to be guided through the core static site configuration options interactively. /// You can choose to run the Account Wizard again if you wish to be guided through the core static site configuration options interactively.
/// </summary> /// </summary>
SSGConfigGeneralWizardLabel, SSGConfigGeneralWizardLabel,
/// <summary> /// <summary>

View File

@ -1448,7 +1448,7 @@ SSGConfigGeneralSiteTitle,Site &Title:,
SSGConfigGeneralSiteUrl,Site &URL:, SSGConfigGeneralSiteUrl,Site &URL:,
SSGConfigGeneralLocalSitePath,&Local Site Path:, SSGConfigGeneralLocalSitePath,&Local Site Path:,
SSGConfigGeneralOptionsGroup,Options, SSGConfigGeneralOptionsGroup,Options,
SSGConfigGeneralWizardLabel,You can chose to run the Account Wizard again if you wish to be guided through the core static site configuration options interactively., SSGConfigGeneralWizardLabel,You can choose to run the Account Wizard again if you wish to be guided through the core static site configuration options interactively.,
SSGConfigGeneralWizardButton,Run Account &Wizard, SSGConfigGeneralWizardButton,Run Account &Wizard,
SSGConfigGeneralDetectLabel,"Open Live Writer can also reattempt to detect relevant configuration options for your static site. This may not result in a complete configuration, so please use the fields on the following pages to ensure all settings are set correctly.", SSGConfigGeneralDetectLabel,"Open Live Writer can also reattempt to detect relevant configuration options for your static site. This may not result in a complete configuration, so please use the fields on the following pages to ensure all settings are set correctly.",
SSGConfigGeneralDetectButton,Run Auto-&Detect, SSGConfigGeneralDetectButton,Run Auto-&Detect,

Can't render this file because it contains an unexpected character in line 146 and column 69.

View File

@ -3751,7 +3751,7 @@ Command STDERR:
<value>Run Account &amp;Wizard</value> <value>Run Account &amp;Wizard</value>
</data> </data>
<data name="SSGConfigGeneralWizardLabel" xml:space="preserve"> <data name="SSGConfigGeneralWizardLabel" xml:space="preserve">
<value>You can chose to run the Account Wizard again if you wish to be guided through the core static site configuration options interactively.</value> <value>You can choose to run the Account Wizard again if you wish to be guided through the core static site configuration options interactively.</value>
</data> </data>
<data name="SSGConfigTitle" xml:space="preserve"> <data name="SSGConfigTitle" xml:space="preserve">
<value>Static Site Configuration for '{0}'</value> <value>Static Site Configuration for '{0}'</value>

View File

@ -122,14 +122,13 @@ namespace OpenLiveWriter.PostEditor.Configuration.StaticSiteAdvanced
_keyRowMap = new Dictionary<KeyIdentifier, DataGridViewRow>(); _keyRowMap = new Dictionary<KeyIdentifier, DataGridViewRow>();
dataGridView.Rows.Clear(); dataGridView.Rows.Clear();
// TODO use strings resource for below AddTableRow(KeyIdentifier.Id, Res.Get(StringId.SSGFrontMatterId), value.IdKey);
AddTableRow(KeyIdentifier.Id, "ID", value.IdKey); AddTableRow(KeyIdentifier.Title, Res.Get(StringId.SSGFrontMatterTitle), value.TitleKey);
AddTableRow(KeyIdentifier.Title, "Title", value.TitleKey); AddTableRow(KeyIdentifier.Date, Res.Get(StringId.SSGFrontMatterDate), value.DateKey);
AddTableRow(KeyIdentifier.Date, "Date", value.DateKey); AddTableRow(KeyIdentifier.Layout, Res.Get(StringId.SSGFrontMatterLayout), value.LayoutKey);
AddTableRow(KeyIdentifier.Layout, "Layout", value.LayoutKey); AddTableRow(KeyIdentifier.Tags, Res.Get(StringId.SSGFrontMatterTags), value.TagsKey);
AddTableRow(KeyIdentifier.Tags, "Tags", value.TagsKey); AddTableRow(KeyIdentifier.Permalink, Res.Get(StringId.SSGFrontMatterPermalink), value.PermalinkKey);
AddTableRow(KeyIdentifier.Permalink, "Permalink", value.PermalinkKey); AddTableRow(KeyIdentifier.ParentId, Res.Get(StringId.SSGFrontMatterParentId), value.ParentIdKey);
AddTableRow(KeyIdentifier.ParentId, "Parent ID", value.ParentIdKey);
// Recompute row sizes // Recompute row sizes
dataGridView?.AutoResizeRows(); dataGridView?.AutoResizeRows();

View File

@ -66,12 +66,30 @@ namespace OpenLiveWriter.PostEditor.Configuration.StaticSiteAdvanced
public GeneralPanel() : base() public GeneralPanel() : base()
{ {
InitializeComponent(); InitializeComponent();
LocalizeStrings();
} }
public GeneralPanel(StaticSitePreferencesController controller) public GeneralPanel(StaticSitePreferencesController controller)
: base(controller) : base(controller)
{ {
InitializeComponent(); InitializeComponent();
LocalizeStrings();
}
private void LocalizeStrings()
{
PanelName = Res.Get(StringId.SSGConfigGeneralTitle);
groupBoxSetup.Text = Res.Get(StringId.SSGConfigGeneralSetupGroup);
labelSiteTitle.Text = Res.Get(StringId.SSGConfigGeneralSiteTitle);
labelSiteUrl.Text = Res.Get(StringId.SSGConfigGeneralSiteUrl);
labelLocalSitePath.Text = Res.Get(StringId.SSGConfigGeneralLocalSitePath);
groupBoxOptions.Text = Res.Get(StringId.SSGConfigGeneralOptionsGroup);
labelRunWizardAgain.Text = Res.Get(StringId.SSGConfigGeneralWizardLabel);
buttonRunAccountWizard.Text = Res.Get(StringId.SSGConfigGeneralWizardButton);
labelAutoDetect.Text = Res.Get(StringId.SSGConfigGeneralDetectLabel);
buttonRunAutoDetect.Text = Res.Get(StringId.SSGConfigGeneralDetectButton);
} }
public override void LoadConfig() public override void LoadConfig()

View File

@ -73,7 +73,7 @@ namespace OpenLiveWriter.PostEditor.Configuration.StaticSiteAdvanced
using (BlogClientUIContextScope uiContextScope = new BlogClientUIContextScope(formPreferences)) using (BlogClientUIContextScope uiContextScope = new BlogClientUIContextScope(formPreferences))
{ {
// Customize form title and behavior // Customize form title and behavior
formPreferences.Text = $"Static Site Configuration for '{_temporarySettings.BlogName}'"; //TODO use strings formPreferences.Text = string.Format(Res.Get(StringId.SSGConfigTitle), _temporarySettings.BlogName);
formPreferences.HideApplyButton(); formPreferences.HideApplyButton();
// Add panels // Add panels