-
Notifications
You must be signed in to change notification settings - Fork 0
feat: localization token dropdown #87
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
base: master
Are you sure you want to change the base?
Changes from 9 commits
b9a0eac
99aa103
1294505
2eeca85
8b9aeac
bed7f30
9cc33c3
d1c53bb
b94748d
26e066c
f4624f4
e605660
4ae8a58
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,7 +52,7 @@ public static LocalizationClient Default | |
| if (s_DefaultLocalizationClient == null) | ||
| { | ||
| var spr = GetSettingsLocalizationSpreadsheet(); | ||
| s_DefaultLocalizationClient = new LocalizationClient(spr, GoogleDocConnectorLocalization.LocalizationSheetId); | ||
| s_DefaultLocalizationClient = new LocalizationClient(spr, GoogleDocConnectorLocalization.SheetId); | ||
| } | ||
|
|
||
| return s_DefaultLocalizationClient; | ||
|
|
@@ -70,6 +70,7 @@ internal static void ClearDefault() | |
| /// <exception cref="Exception">Will return an error if the sheet hasn't been selected</exception> | ||
| internal LocalizationClient(Spreadsheet spreadsheet, int sheetId) | ||
| { | ||
| spreadsheet.OnDataStoredOnDisk += NotifyLanguageChanged; | ||
| Refresh(spreadsheet, sheetId); | ||
| } | ||
|
|
||
|
|
@@ -308,6 +309,30 @@ public string GetLocalizedString(ILocalizationToken localizationToken, string la | |
| var token = localizationToken.Token.Trim(); | ||
| var section = localizationToken.Section.Trim(); | ||
|
|
||
| Sheet localizationSheet = m_LocalizationSpreadsheet.Sheets.FirstOrDefault(s => s.Name == section); | ||
| if (localizationSheet == null) | ||
| { | ||
| throw new InvalidOperationException("There are no selected sheet"); | ||
| } | ||
|
|
||
| if (!localizationSheet.Rows.Any()) | ||
| { | ||
| throw new InvalidOperationException("There are no filled lines on the first sheet of the table"); | ||
| } | ||
|
|
||
| var row = localizationSheet.Rows.First(); | ||
| if (!row.Cells.Any()) | ||
| { | ||
| throw new InvalidOperationException("The first row on the first sheet of the table has no filled cells"); | ||
| } | ||
|
|
||
| var cellToken = row.Cells.FirstOrDefault(); | ||
| if (cellToken != null && cellToken.Value.StringValue.ToLower() != "token" && cellToken.Value.StringValue.ToLower() != "tokens") | ||
| { | ||
| throw new InvalidOperationException("Token column name not found"); | ||
| } | ||
|
|
||
|
|
||
| if (!m_Sections.TryGetValue(section, out var sheetIndex)) | ||
| { | ||
| throw new Exception($"Can't find sheet with name = {section}"); | ||
|
|
@@ -348,6 +373,14 @@ public string GetLocalizedString(ILocalizationToken localizationToken, string la | |
|
|
||
| return finalText; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Notify that the language settings of the spreadsheet have been changed | ||
| /// </summary> | ||
| void NotifyLanguageChanged() | ||
| { | ||
| OnLanguageChanged?.Invoke(); | ||
|
||
| } | ||
|
|
||
| /// <summary> | ||
| /// Returns string converted by the textType | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -48,6 +48,11 @@ public enum SyncState | |||||
| /// An event to track spreadsheet sync state. | ||||||
| /// </summary> | ||||||
| public event Action<Spreadsheet> OnSyncStateChange = delegate { }; | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// An event track the saving of spreadsheet data. | ||||||
| /// </summary> | ||||||
| public event Action OnDataStoredOnDisk = delegate { }; | ||||||
|
||||||
| public event Action OnDataStoredOnDisk = delegate { }; | |
| public event Action<DataStoredOnDiskArgs> OnDataStoredOnDisk = delegate { }; |
We should consider providing an Arguments struct for this event Action (yes, it will be just an empty struct DataStoredOnDiskArgs{} for the moment). It will save us from breaking changes in future updates. Just in case we will need to pass additional data with this Action.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| OnDataStoredOnDisk?.Invoke(); | |
| OnDataStoredOnDisk.Invoke(); |
Redundant null-check here. If you initialize event Action with an empty delegate (just like on Line 55), there is no need to check it for a null before invocation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The callback method name is out of our convention. Please, consider renaming.