Skip to content

Commit 66777d7

Browse files
committed
Add format-agnostic SourceText support to entities and DTOs
- Add SourceText and SourcePluralText fields to ResourceKey entity - Update ResourceKeyDto and TranslationDto with SourceText properties - Add SourceText/SourcePluralText to KeySyncDtos for sync operations
1 parent 2d21318 commit 66777d7

5 files changed

Lines changed: 49 additions & 7 deletions

File tree

cloud/src/LrmCloud.Api/Services/Translation/CloudTranslationService.cs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,27 @@ public async Task<TranslateResponseDto> TranslateKeysAsync(
213213
}
214214
else
215215
{
216-
// Look up source translation - check both conventions:
217-
// - CLI sync stores default language with LanguageCode = ""
218-
// - Web import stores with actual code (e.g., "en")
219-
var sourceTranslation = key.Translations
220-
.FirstOrDefault(t => (t.LanguageCode == sourceLanguageDbCode || t.LanguageCode == sourceLanguage)
221-
&& t.PluralForm == pluralForm);
222-
sourceText = sourceTranslation?.Value;
216+
// Priority 1: Use ResourceKey.SourceText (format-agnostic source)
217+
if (string.IsNullOrEmpty(pluralForm) && !string.IsNullOrEmpty(key.SourceText))
218+
{
219+
sourceText = key.SourceText;
220+
}
221+
// Priority 2: Use ResourceKey.SourcePluralText for plural "other" form
222+
else if (pluralForm == "other" && !string.IsNullOrEmpty(key.SourcePluralText))
223+
{
224+
sourceText = key.SourcePluralText;
225+
}
226+
// Priority 3: Fall back to translation lookup (backward compatibility)
227+
else
228+
{
229+
// Look up source translation - check both conventions:
230+
// - CLI sync stores default language with LanguageCode = ""
231+
// - Web import stores with actual code (e.g., "en")
232+
var sourceTranslation = key.Translations
233+
.FirstOrDefault(t => (t.LanguageCode == sourceLanguageDbCode || t.LanguageCode == sourceLanguage)
234+
&& t.PluralForm == pluralForm);
235+
sourceText = sourceTranslation?.Value;
236+
}
223237
}
224238

225239
// Skip empty source texts (but don't skip the whole key for plurals)

cloud/src/LrmCloud.Shared/DTOs/Resources/ResourceKeyDto.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ public class ResourceKeyDto
1010
public string? KeyPath { get; set; }
1111
public bool IsPlural { get; set; }
1212
/// <summary>
13+
/// Source text for this key (value from default language file, msgid for PO format).
14+
/// </summary>
15+
public string? SourceText { get; set; }
16+
/// <summary>
1317
/// For plural keys, the source plural text pattern (PO msgid_plural or "other" form).
1418
/// </summary>
1519
public string? SourcePluralText { get; set; }

cloud/src/LrmCloud.Shared/DTOs/Resources/TranslationDto.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,10 @@ public class TranslationDto
1919
/// Translation-specific comment (per-language note).
2020
/// </summary>
2121
public string? Comment { get; set; }
22+
23+
/// <summary>
24+
/// True if this translation was synthesized (e.g., from SourceText for display),
25+
/// not stored in the database.
26+
/// </summary>
27+
public bool IsVirtual { get; set; }
2228
}

cloud/src/LrmCloud.Shared/DTOs/Sync/KeySyncDtos.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ public class EntryChangeDto
6868
/// </summary>
6969
public Dictionary<string, string>? PluralForms { get; set; }
7070

71+
/// <summary>
72+
/// Source text for the key (value from default language, msgid for PO format).
73+
/// Only set when pushing from source/default language.
74+
/// </summary>
75+
public string? SourceText { get; set; }
76+
7177
/// <summary>
7278
/// For plural keys, the source plural text pattern (PO msgid_plural or "other" form).
7379
/// Only set when pushing from source/default language.
@@ -285,6 +291,11 @@ public class EntryDataDto
285291
/// </summary>
286292
public bool IsPlural { get; set; }
287293

294+
/// <summary>
295+
/// Source text for the key (value from default language, msgid for PO format).
296+
/// </summary>
297+
public string? SourceText { get; set; }
298+
288299
/// <summary>
289300
/// For plural keys, the source plural text pattern (PO msgid_plural or "other" form).
290301
/// </summary>

cloud/src/LrmCloud.Shared/Entities/ResourceKey.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ public class ResourceKey
3232
[Column("is_plural")]
3333
public bool IsPlural { get; set; }
3434

35+
/// <summary>
36+
/// Source text for this key (value from default language file, msgid for PO format).
37+
/// This is the authoritative source text used for translation.
38+
/// </summary>
39+
[Column("source_text")]
40+
public string? SourceText { get; set; }
41+
3542
/// <summary>
3643
/// For plural keys, stores the source plural text pattern.
3744
/// For PO format: this is the msgid_plural value.

0 commit comments

Comments
 (0)