Skip to content
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
10 changes: 7 additions & 3 deletions Editor/PhraseClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,16 @@ public PhraseClient(PhraseProvider provider)
Client.BaseAddress = new Uri(ApiUrl);
}

public async Task<string> DownloadLocale(string projectID, string localeID, string tag)
public async Task<string> DownloadLocale(string projectID, string localeID, string tag, string keyPrefix)
{
string url = string.Format("projects/{0}/locales/{1}/download?file_format=csv&format_options%5Bexport_max_characters_allowed%5D=true&format_options%5Bexport_key_id%5D=true&include_empty_translations=true", projectID, localeID);
if (tag != null)
{
url += "&tags=" + Uri.EscapeDataString(tag);
url += "&tags=" + WebUtility.UrlEncode(tag);
}
if (keyPrefix != null)
{
url += "&filter_by_prefix=true&translation_key_prefix=" + WebUtility.UrlEncode(keyPrefix);
}
HttpResponseMessage response = await Client.GetAsync(url);
response.EnsureSuccessStatusCode();
Expand Down Expand Up @@ -230,7 +234,7 @@ public void DeleteScreenshotMarker(string projectID, string screenshotID, string

public async Task<Key> GetKey(string projectID, string keyName)
{
string url = string.Format($"projects/{{0}}/keys?q=name:{Uri.EscapeDataString(keyName)}", projectID);
string url = string.Format($"projects/{{0}}/keys?q=name:{WebUtility.UrlEncode(keyName)}", projectID);
HttpResponseMessage response = await Client.GetAsync(url);
response.EnsureSuccessStatusCode();
string jsonResponse = await response.Content.ReadAsStringAsync();
Expand Down
7 changes: 2 additions & 5 deletions Editor/PhraseCsvColumns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public override void WriteBegin(StringTableCollection collection, CsvWriter writ
public override void WriteRow(SharedTableData.SharedTableEntry keyEntry, IList<StringTableEntry> tableEntries, CsvWriter writer)
{
string keyName = keyEntry.Key;
if (!string.IsNullOrEmpty(m_KeyPrefix))
keyName = m_KeyPrefix + keyName;
writer.WriteField(keyName);

var metadata = keyEntry.Metadata.GetMetadata<PhraseMetadata>();
Expand Down Expand Up @@ -101,11 +103,6 @@ public SharedTableData.SharedTableEntry ReadKey(CsvReader reader)
string keyName = reader.GetField(m_KeyNameIndex);
if (string.IsNullOrEmpty(keyName))
return null;
if (!string.IsNullOrEmpty(m_KeyPrefix))
{
if (!keyName.StartsWith(m_KeyPrefix))
return null;
}
return m_SharedTableData.GetEntry(keyName) ?? m_SharedTableData.AddKey(keyName);
}
}
Expand Down
4 changes: 2 additions & 2 deletions Editor/PhraseProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,10 @@ private async void PullSingleLocale(StringTableCollection collection, Locale sel
Log("Downloading locale " + selectedLocale.code);
var phraseExtension = collection.Extensions.FirstOrDefault(e => e is PhraseExtension) as PhraseExtension;
string tag = phraseExtension.m_identifierType == TableIdentifierType.Tag ? phraseExtension.m_identifier : null;
var csvContent = await Client.DownloadLocale(m_selectedProjectId, selectedLocale.id, tag);
string keyPrefix = phraseExtension.m_identifierType == TableIdentifierType.KeyPrefix ? phraseExtension.m_identifier : null;
var csvContent = await Client.DownloadLocale(m_selectedProjectId, selectedLocale.id, tag, keyPrefix);
using (var reader = new StringReader(csvContent))
{
string keyPrefix = phraseExtension.m_identifierType == TableIdentifierType.KeyPrefix ? phraseExtension.m_identifier : null;
var columnMappings = ColumnMappings(selectedLocale, keyPrefix);
Csv.ImportInto(reader, collection, columnMappings);
}
Expand Down
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,19 @@ You can perform push/pull from Phrase Provider screen, but also from “Phrase E

![Phrase Extension on a String Table Collection](docs/phrase_extension.png)

There you push/pull only the target table. This extension also enables you to constrain the subset of keys that will be pushed/pulled to the particular table, by selecting the “Identifyer Type”:
There you push/pull only from/to the table in question.

* “Key Prefix” – only keys with the given prefix in their names will be imported to the target table.
### Working with multiple String Table Collections

* “Tag” – only keys with matching tag will be imported to the target table. Upon pushing, all keys from this table will get this tag assigned.
It's common that a user might organize their translations into multiple String Table Collections, for example based on the game section or the type of the items referred to (e.g. Weapons, Items, Characters etc). In that case one would want to connect the collection with only a subset of all existing [translation keys](https://support.phrase.com/hc/en-us/articles/5784119185436-Keys-Strings) in Phrase Strings. For this purpose, you can use key name prefixes or [key tags](https://support.phrase.com/hc/en-us/articles/5822598372252-Tags-Strings).

* “None” – all keys will be imported to the target table.
You can constrain the subset of keys that will be pushed/pulled to the particular table, by selecting the “Identifyer Type” in the Collection Extension:

* “Key Prefix” – only keys with the given prefix in their names will be imported (pull) to the target table. The Unity key names will not contain the prefix itself. On push, the whole table will get uploaded to Phrase, and prefix will be automatically appended to the key names.

* “Tag” – only keys with matching tag will be pulled to the target table. Upon pushing, all keys from this table will get this tag assigned.

* “None” – all Phrase keys will be imported to the target table on pull (this is typical when you have only a single Collection connected with Phrase).

### Phrase window

Expand Down