Skip to content

Commit

Permalink
Add comment functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
vicr123 committed Oct 7, 2024
1 parent 34ac7c8 commit df7e915
Show file tree
Hide file tree
Showing 17 changed files with 63 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@
"THREAD_REOPEN_FAILURE_PROMPT": "Unable to reopen the thread",
"THREAD_TITLE": "Thread title",
"TRANSLATE": "Translate",
"TRANSLATION_AREA_DEVELOPER_COMMENT_TITLE": "Comment from the developer",
"TRANSLATION_AREA_INDICATOR_PLURAL_FORM": "Plural form {{numbers}}",
"TRANSLATION_AREA_MARK_COMPLETE": "Mark as Complete",
"TRANSLATION_AREA_NEXT": "Next",
Expand Down
1 change: 1 addition & 0 deletions Parlance.ClientApp/src/interfaces/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export interface BaseEntry {
source: string;
oldSourceString?: string;
translation: TranslationEntry;
comment?: string;
}

export interface BaseTranslationEntry {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,16 @@ export default function TranslationArea({
<span className={Styles.keyText}>{entry.key}</span>
</div>
</Box>
{entry.comment && (
<Box className={Styles.sourceTranslationContainer}>
<div className={Styles.sourceTranslationContainerInner}>
<div className={Styles.sourceTranslationIndicator}>
{t("TRANSLATION_AREA_DEVELOPER_COMMENT_TITLE")}
</div>
{entry.comment}
</div>
</Box>
)}
<Box>
<div
className={Styles.commentsButton}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ private async Task LoadFile(string file, Locale locale, string baseFile, Locale
Source = x.Source,
Context = Path.GetFileName(file),
RequiresPluralisation = false,
Comment = null,
Translation = new List<TranslationWithPluralType>
{
new()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ namespace Parlance.Project.TranslationFiles.AppleStrings;

public class AppleStringsTranslationFileEntry : IParlanceTranslationFileEntry
{
public string Key { get; init; }
public string Source { get; init; }
public IList<TranslationWithPluralType> Translation { get; set; }
public string Context { get; init; }
public required string Key { get; init; }
public required string Source { get; init; }
public required IList<TranslationWithPluralType> Translation { get; set; }
public required string Context { get; init; }
public bool RequiresPluralisation { get; set; }
public required string? Comment { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ private async Task LoadFile(string file, Locale locale, string baseFile, Locale
Source = bases[key],
Context = Path.GetFileName(file),
RequiresPluralisation = false,
Translation = translationEntry
Translation = translationEntry,
Comment = null,
};
}).Cast<IParlanceTranslationFileEntry>().ToList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ namespace Parlance.Project.TranslationFiles.DotNetResources;

public class DotNetResourcesTranslationFileEntry : IParlanceTranslationFileEntry
{
public string Key { get; set; }
public string Source { get; set; }
public IList<TranslationWithPluralType> Translation { get; set; }
public string Context { get; set; }
public required string Key { get; set; }
public required string Source { get; set; }
public required IList<TranslationWithPluralType> Translation { get; set; }
public required string Context { get; set; }
public bool RequiresPluralisation { get; set; }
public required string? Comment { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ public class GettextTranslationFileEntry : IParlanceTranslationFileEntry
public string? RealContext { get; set; }
public IList<string> PreLines { get; set; } = new List<string>();
public bool RequiresPluralisation { get; set; }
public string? Comment { get; set; } = "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ public class I18NextJsonTranslationFileEntry : IParlanceTranslationFileEntry
public IList<TranslationWithPluralType> Translation { get; set; } = null!;
public string Context { get; set; } = null!;
public bool RequiresPluralisation { get; set; }
public string? Comment { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ public interface IParlanceTranslationFileEntry
public IList<TranslationWithPluralType> Translation { get; set; }
public string Context { get; }
public bool RequiresPluralisation { get; set; }
public string? Comment { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,33 +46,31 @@ private async Task LoadFile(string file, Locale locale)
RealKey = (string)msg.Element("source")! + "-" + (string)msg.Parent!.Element("name")!,
Context = ((string)msg.Parent!.Element("name"))!,
Source = (string)msg.Element("source")!,
TsComment = (string?)msg.Element("comment"),
TsExtraComment = (string?)msg.Element("extracomment"),
Translation = msg.Attribute("numerus")?.Value == "yes"
// ? msg.Descendants("numerusform").Select((content, idx2) => new TranslationWithPluralType
// {
// PluralType = pluralRules[idx2].Category,
// TranslationContent = (string)content
// }).ToList()
? pluralRules.Select((rule, idx2) => new TranslationWithPluralType
{
PluralType = rule.Category,
TranslationContent = pluralDescendants.Count > idx2 ? (string)pluralDescendants[idx2] : ""
}).ToList()
: new List<TranslationWithPluralType>
{
:
[
new()
{
PluralType = "singular",
TranslationContent = (string)msg.Element("translation")!
}
},
],
Type = (string?)msg.Element("translation")!.Attribute("type") ?? "finished",
RequiresPluralisation = msg.Attribute("numerus")?.Value == "yes",
Locations = msg.Elements("location")
.Where(loc => loc.Attribute("filename") is not null && loc.Attribute("line") is not null).Select(
loc =>
new QtLinguistTranslationFileEntry.Location((string)loc.Attribute("filename")!,
(string)loc.Attribute("line")!))
};
}).Cast<IParlanceTranslationFileEntry>().ToList();
}).Where(entry => entry.Type != "vanished").Cast<IParlanceTranslationFileEntry>().ToList();
}

private protected override Task UseAsBaseImpl(string filename, Locale locale)
Expand Down Expand Up @@ -102,7 +100,7 @@ public override async Task Save()

var doc = new XDocument(
new XElement("TS", new XAttribute("version", "2.1"), new XAttribute("language", _locale.ToUnderscored()),
Entries.GroupBy(entry => entry.Context).Select(context =>
Entries.Cast<QtLinguistTranslationFileEntry>().GroupBy(entry => entry.Context).Select(context =>
new XElement("context",
new XElement("name", new XText(context.Key)),
context.Select(entry => new XElement("message",
Expand All @@ -120,10 +118,12 @@ public override async Task Save()
: new XElement("translation",
new XText(entry.Translation.Single(x => x.PluralType == "singular")
.TranslationContent)),
((QtLinguistTranslationFileEntry)entry).Locations.Select(location =>
entry.Locations.Select(location =>
new XElement("location", new XAttribute("filename", location.Filename),
new XAttribute("line", location.Line))),
new XElement("source", new XText(((QtLinguistTranslationFileEntry)entry).Source))
new XElement("source", new XText(entry.Source)),
new XElement("comment", entry.TsComment),
new XElement("extracomment", entry.TsExtraComment)
))
)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Security.Cryptography;
using System.Text;
using System.Xml.Linq;

namespace Parlance.Project.TranslationFiles.QtLinguist;

Expand All @@ -8,10 +9,14 @@ public class QtLinguistTranslationFileEntry : IParlanceTranslationFileEntry
public record Location(string Filename, string Line);

public string Key => Convert.ToHexString(SHA256.HashData(Encoding.UTF8.GetBytes(RealKey)));
public string RealKey { get; init; } = null!;
public string Source { get; init; } = null!;
public IList<TranslationWithPluralType> Translation { get; set; } = null!;
public string Context { get; init; } = null!;
public required string RealKey { get; init; }
public required string Source { get; init; }
public required IList<TranslationWithPluralType> Translation { get; set; }
public required string Context { get; init; }
public bool RequiresPluralisation { get; set; }
public IEnumerable<Location> Locations { get; init; } = null!;
public required string? TsComment { get; init; }
public required string? TsExtraComment { get; init; }
public string? Comment => TsComment ?? TsExtraComment;
public required IEnumerable<Location> Locations { get; init; }
public required string Type { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ private async Task LoadFile(string file, Locale locale, string baseFile, Locale
{
Key = path.ToString(),
Source = isPlural ? source.Split(pluralSeparator).Last() : source,
Comment = null,
Translation = isPlural
? translation?.Split(pluralSeparator).Where((x, i) => pluralRules.Length > i).Select(
(x, i) => new TranslationWithPluralType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ namespace Parlance.Project.TranslationFiles.VueI18n;
// ReSharper disable once InconsistentNaming
public class VueI18nTranslationFileEntry : IParlanceTranslationFileEntry
{
public required string Key { get; set; } = null!;
public required string Source { get; set; } = null!;
public required IList<TranslationWithPluralType> Translation { get; set; } = null!;
public required string Context { get; set; } = null!;
public required string Key { get; set; }
public required string Source { get; set; }
public required IList<TranslationWithPluralType> Translation { get; set; }
public required string Context { get; set; }
public required bool RequiresPluralisation { get; set; }
public required string? Comment { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ private async Task LoadFile(string file, Locale locale, string baseFile, Locale
Description = tItem?.description,
Placeholders = tItem?.placeholders,
RequiresPluralisation = false,
Comment = null,
Translation = new List<TranslationWithPluralType>
{
new()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ namespace Parlance.Project.TranslationFiles.WebextensionJson;

public class WebextensionJsonTranslationFileEntry : IParlanceTranslationFileEntry
{
public string Key { get; set; } = null!;
public string Source { get; set; } = null!;
public IList<TranslationWithPluralType> Translation { get; set; } = null!;
public string Context { get; set; } = null!;
public required string Key { get; set; }
public required string Source { get; set; }
public required IList<TranslationWithPluralType> Translation { get; set; }
public required string Context { get; set; }
public bool RequiresPluralisation { get; set; }
public required string? Comment { get; set; }
public string? Description { get; set; }
public JsonObject? Placeholders { get; set; }
}
2 changes: 1 addition & 1 deletion Parlance/Controllers/ProjectsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ public async Task<IActionResult> GetProjectEntries(string project, string subpro

return Json(await Task.WhenAll(translationFile.Entries.Select(async entry => new
{
entry.Key, entry.Context, entry.Source, entry.Translation, entry.RequiresPluralisation,
entry.Key, entry.Context, entry.Source, entry.Translation, entry.RequiresPluralisation, entry.Comment,
OldSourceString = await sourceStringsService.GetSourceStringChange(subprojectLanguage, entry)
})));
}
Expand Down

0 comments on commit df7e915

Please sign in to comment.