Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quick (not ideal) timestamp fix #331

Merged
merged 1 commit into from
Jan 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/i18n.Domain/Abstract/ITranslationRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public interface ITranslationRepository
/// Save a template. A template differs from a translation in that a translation holds all messages but no translation data. It is used for updating translations to make sure all translations have all strings.
/// </summary>
/// <param name="items">All template items to save, in a dictionary indexed by their id</param>
void SaveTemplate(IDictionary<string, TemplateItem> items);
/// <returns>True if the template have been saved</returns>
bool SaveTemplate(IDictionary<string, TemplateItem> items);

/// <summary>
/// Returns a CacheDependency for a language. This can be a subclass such as <see cref="SqlCacheDependency"/>
Expand Down
24 changes: 20 additions & 4 deletions src/i18n.Domain/Concrete/POTranslationRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,22 +255,24 @@ public void SaveTranslation(Translation translation)
/// Saves a template file which is a all strings (needing translation) used in the entire project. Not language dependent
/// </summary>
/// <param name="items">A list of template items to save. The list should be all template items for the entire project.</param>
public void SaveTemplate(IDictionary<string, TemplateItem> items)
public bool SaveTemplate(IDictionary<string, TemplateItem> items)
{
if (_settings.GenerateTemplatePerFile)
{
bool result = false;
foreach (var item in items.GroupBy(x => x.Value.FileName))
{
SaveTemplate(item.ToDictionary(x => x.Key, x => x.Value), item.Key);
result |= SaveTemplate(item.ToDictionary(x => x.Key, x => x.Value), item.Key);
}
return result;
}
else
{
SaveTemplate(items, string.Empty);
return SaveTemplate(items, string.Empty);
}
}

private void SaveTemplate(IDictionary<string, TemplateItem> items, string fileName)
private bool SaveTemplate(IDictionary<string, TemplateItem> items, string fileName)
{
string filePath = GetAbsoluteLocaleDir() + "/" + (!string.IsNullOrWhiteSpace(fileName) ? fileName : _settings.LocaleFilename) + ".pot";
string backupPath = filePath + ".backup";
Expand Down Expand Up @@ -350,6 +352,20 @@ private void SaveTemplate(IDictionary<string, TemplateItem> items, string fileNa
stream.WriteLine("");
}
}

//we just compare output file with the backed up file to check for changes
if (File.Exists(filePath) && File.Exists(backupPath))
{
//We skip the four first lines since the fourth will always be different (the generation date)
var newContent = File.ReadAllLines(filePath).Skip(4).ToList();
var oldContent = File.ReadAllLines(backupPath).Skip(4).ToList();
if (newContent.Zip(oldContent, (n, o) => o != null && o.Equals(n)).All(b => b))
{
File.Copy(backupPath, filePath, true);
return false;
}
}
return true;
}

#endregion
Expand Down
9 changes: 5 additions & 4 deletions src/i18n.PostBuild/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,11 @@ private void Run()

var nuggetFinder = new FileNuggetFinder(settings);
var items = nuggetFinder.ParseAll();
repository.SaveTemplate(items);

var merger = new TranslationMerger(repository);
merger.MergeAllTranslation(items);
if (repository.SaveTemplate(items))
{
var merger = new TranslationMerger(repository);
merger.MergeAllTranslation(items);
}

Console.WriteLine("i18n.PostBuild completed successfully.");
}
Expand Down