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
// Store these required constants here so they're in one place
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 CLIENT_TYPE = "StaticSite";
@ -132,7 +132,9 @@ namespace OpenLiveWriter.BlogClient.Clients.StaticSite
public void DeletePost(string blogId, string postId, bool publish)
{
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);
}
@ -196,7 +198,9 @@ namespace OpenLiveWriter.BlogClient.Clients.StaticSite
public void DeletePage(string blogId, string 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);
}
@ -529,7 +533,9 @@ namespace OpenLiveWriter.BlogClient.Clients.StaticSite
{
// Timeout reached
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 OpenLiveWriter.Extensibility.BlogClient;
using OpenLiveWriter.Localization;
namespace OpenLiveWriter.BlogClient.Clients.StaticSite
{
@ -30,16 +31,14 @@ namespace OpenLiveWriter.BlogClient.Clients.StaticSite
.ValidateBuildCommand()
.ValidatePublishCommand();
// TODO replace errors with strings from resources
#region Path Validation
public StaticSiteConfigValidator ValidateLocalSitePath()
{
if(!Directory.Exists(_config.LocalSitePath))
throw new StaticSiteConfigValidationException(
"Folder not found",
"Local Site Path '{0}' does not exist.",
Res.Get(StringId.SSGErrorPathFolderNotFound),
Res.Get(StringId.SSGErrorPathLocalSitePathNotFound),
_config.LocalSitePath);
return this;
@ -52,14 +51,14 @@ namespace OpenLiveWriter.BlogClient.Clients.StaticSite
// If the Posts path is empty, display an error
if (_config.PostsPath.Trim() == string.Empty)
throw new StaticSiteConfigValidationException(
"Folder not found",
"Posts path is empty.");
Res.Get(StringId.SSGErrorPathFolderNotFound),
Res.Get(StringId.SSGErrorPathPostsEmpty));
// If the Posts path doesn't exist, display an error
if (!Directory.Exists(postsPathFull))
throw new StaticSiteConfigValidationException(
"Folder not found",
"Posts path '{0}' does not exist.",
Res.Get(StringId.SSGErrorPathFolderNotFound),
Res.Get(StringId.SSGErrorPathPostsNotFound),
postsPathFull);
return this;
@ -74,15 +73,15 @@ namespace OpenLiveWriter.BlogClient.Clients.StaticSite
// If the Pages path is empty, display an error
if (_config.PagesPath.Trim() == string.Empty)
throw new StaticSiteConfigValidationException(
"Folder not found",
"Pages path is empty.");
Res.Get(StringId.SSGErrorPathFolderNotFound),
Res.Get(StringId.SSGErrorPathPagesEmpty));
// If the path doesn't exist, display an error
if (!Directory.Exists(pagesPathFull))
throw new StaticSiteConfigValidationException(
"Folder not found",
"Pages path '{0}' does not exist.",
pagesPathFull);
Res.Get(StringId.SSGErrorPathFolderNotFound),
Res.Get(StringId.SSGErrorPathPagesNotFound),
pagesPathFull);
return this;
}
@ -96,15 +95,15 @@ namespace OpenLiveWriter.BlogClient.Clients.StaticSite
// If the Drafts path is empty, display an error
if (_config.DraftsPath.Trim() == string.Empty)
throw new StaticSiteConfigValidationException(
"Folder not found",
"Drafts path is empty.");
Res.Get(StringId.SSGErrorPathFolderNotFound),
Res.Get(StringId.SSGErrorPathDraftsEmpty));
// If the path doesn't exist, display an error
if (!Directory.Exists(draftsPathFull))
throw new StaticSiteConfigValidationException(
"Folder not found",
"Drafts path '{0}' does not exist.",
draftsPathFull);
Res.Get(StringId.SSGErrorPathFolderNotFound),
Res.Get(StringId.SSGErrorPathDraftsNotFound),
draftsPathFull);
return this;
}
@ -118,15 +117,15 @@ namespace OpenLiveWriter.BlogClient.Clients.StaticSite
// If the Images path is empty, display an error
if (_config.ImagesPath.Trim() == string.Empty)
throw new StaticSiteConfigValidationException(
"Folder not found",
"Images path is empty.");
Res.Get(StringId.SSGErrorPathFolderNotFound),
Res.Get(StringId.SSGErrorPathImagesEmpty));
// If the path doesn't exist, display an error
if (!Directory.Exists(imagesPathFull))
throw new StaticSiteConfigValidationException(
"Folder not found",
"Images path '{0}' does not exist.",
imagesPathFull);
Res.Get(StringId.SSGErrorPathFolderNotFound),
Res.Get(StringId.SSGErrorPathImagesNotFound),
imagesPathFull);
return this;
}
@ -140,15 +139,15 @@ namespace OpenLiveWriter.BlogClient.Clients.StaticSite
// If the Output path is empty, display an error
if (_config.OutputPath.Trim() == string.Empty)
throw new StaticSiteConfigValidationException(
"Folder not found",
"Output path is empty.");
Res.Get(StringId.SSGErrorPathFolderNotFound),
Res.Get(StringId.SSGErrorPathOutputEmpty));
// If the path doesn't exist, display an error
if (!Directory.Exists(outputPathFull))
throw new StaticSiteConfigValidationException(
"Folder not found",
"Output path '{0}' does not exist.",
outputPathFull);
Res.Get(StringId.SSGErrorPathFolderNotFound),
Res.Get(StringId.SSGErrorPathOutputNotFound),
outputPathFull);
return this;
}
@ -161,8 +160,8 @@ namespace OpenLiveWriter.BlogClient.Clients.StaticSite
if (_config.BuildCommand.Trim() == string.Empty)
throw new StaticSiteConfigValidationException(
"Build command empty",
"A build command is required when local site building is enabled.");
Res.Get(StringId.SSGErrorBuildCommandEmptyTitle),
Res.Get(StringId.SSGErrorBuildCommandEmptyText));
return this;
}
@ -171,8 +170,8 @@ namespace OpenLiveWriter.BlogClient.Clients.StaticSite
{
if (_config.PublishCommand.Trim() == string.Empty)
throw new StaticSiteConfigValidationException(
"Publish command empty",
"A publish command is required.");
Res.Get(StringId.SSGErrorPublishCommandEmptyTitle),
Res.Get(StringId.SSGErrorPublishCommandEmptyText));
return this;
}

View File

@ -9,6 +9,7 @@ using System.Diagnostics;
using OpenLiveWriter.CoreServices;
using OpenLiveWriter.Extensibility.BlogClient;
using OpenLiveWriter.Localization;
namespace OpenLiveWriter.BlogClient.Clients.StaticSite
{
@ -208,7 +209,8 @@ namespace OpenLiveWriter.BlogClient.Clients.StaticSite
// Parse out everything between triple-hyphens into front matter parser
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 postContent = frontMatterMatchResult.Groups[2].Value;
@ -218,7 +220,8 @@ namespace OpenLiveWriter.BlogClient.Clients.StaticSite
StaticSiteItemFrontMatter.GetFromYaml(SiteConfig.FrontMatterKeys, frontMatterYaml).SaveToBlogPost(BlogPost);
// 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 = postFilePath;

View File

@ -474,7 +474,7 @@ namespace OpenLiveWriter.BlogClient.Detection
if (targetUrl == _blogHomepageUrl && _nextTryPostUrl != null && regionLocatorStrategy.CanRefetchPage)
{
// 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
regionLocatorStrategy.FetchTemporaryPostPage(SilentProgressHost.Instance, _nextTryPostUrl);
// Parse out the template

View File

@ -4831,7 +4831,7 @@ namespace OpenLiveWriter.Localization
/// </summary>
SSGConfigGeneralWizardButton,
/// <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>
SSGConfigGeneralWizardLabel,
/// <summary>

View File

@ -1448,7 +1448,7 @@ SSGConfigGeneralSiteTitle,Site &Title:,
SSGConfigGeneralSiteUrl,Site &URL:,
SSGConfigGeneralLocalSitePath,&Local Site Path:,
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,
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,

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>
</data>
<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 name="SSGConfigTitle" xml:space="preserve">
<value>Static Site Configuration for '{0}'</value>

View File

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

View File

@ -66,12 +66,30 @@ namespace OpenLiveWriter.PostEditor.Configuration.StaticSiteAdvanced
public GeneralPanel() : base()
{
InitializeComponent();
LocalizeStrings();
}
public GeneralPanel(StaticSitePreferencesController controller)
: base(controller)
{
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()

View File

@ -73,7 +73,7 @@ namespace OpenLiveWriter.PostEditor.Configuration.StaticSiteAdvanced
using (BlogClientUIContextScope uiContextScope = new BlogClientUIContextScope(formPreferences))
{
// 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();
// Add panels