-
Notifications
You must be signed in to change notification settings - Fork 103
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
Retreiving text id ("#n": "g-x"
) at runtime for localisation
#166
Comments
This is an interesting idea! I don't have an answer to your question but if you or anyone else finds a solution please share it here, it seems like a problem worth solving :) |
thanks! |
Ok, think I found a pretty good solution (should at least work for my use case): most of the story.Continue ();
string key = story.state.currentPointer.path.ToString()[..^2]; To generate the dictionary to be exported as csv, this seems to be working: private static Dictionary<string, string> dialogueDictionary;
public static void BuildDictionary()
{
string jsonFile = AssetDatabase.LoadAssetAtPath<TextAsset>("Assets/Editor/Localisation/test.json").ToString();
Dictionary<string, object> rootObject = SimpleJson.TextToDictionary(jsonFile);
var rootToken = rootObject ["root"];
Container container = Json.JTokenToRuntimeObject (rootToken) as Container;
dialogueDictionary = new Dictionary<string, string>();
foreach (KeyValuePair<string,Object> keyValuePair in container.namedOnlyContent)
{
if(keyValuePair.Value is Container)
ExtractContent((Container)keyValuePair.Value);
}
}
static void ExtractContent(Container container)
{
if(container.content != null)
foreach (Object obj in container.content)
{
if(obj is Ink.Runtime.StringValue && obj.ToString().Trim().Length !=0)
{
dialogueDictionary.Add(container.path.ToString(), obj.ToString());
}
if(obj is Container)
ExtractContent((Container)obj);
}
} (obviously replace This can then easily be exported as csv for localisation. Still implementing the details, but seems to work so far :D |
Awesome!! Please keep us posted on how it goes, I’d love to try this out
myself.
…On Sat, 21 May 2022 at 15:08, Giezi ***@***.***> wrote:
Ok, think I fund a pretty good solution (should at least work for my use
case):
most of the path can be used as a key, works pretty well. You just need
to remove the index at the end, unused to generate the key:
story.Continue ();string key = story.state.currentPointer.path.ToString();key = key.Substring(0, key.Length - 2);
To generate the dictionary to be exported as csv, this seems to be working:
private static Dictionary<string, string> dialogueDictionary;
public static void BuildDictionary()
{
string jsonFile = AssetDatabase.LoadAssetAtPath<TextAsset>("Assets/Editor/Localisation/test.json").ToString();
Dictionary<string, object> rootObject = SimpleJson.TextToDictionary(jsonFile);
var rootToken = rootObject ["root"];
Container container = Json.JTokenToRuntimeObject (rootToken) as Container;
dialogueDictionary = new Dictionary<string, string>();
foreach (KeyValuePair<string,Object> keyValuePair in container.namedOnlyContent)
{
if(keyValuePair.Value is Container)
ExtractContent((Container)keyValuePair.Value);
}
}
static void ExtractContent(Container container)
{
if(container.content != null)
foreach (Object obj in container.content)
{
if(obj is Ink.Runtime.StringValue && obj.ToString().Trim().Length !=0)
{
dialogueDictionary.Add(container.path.ToString(), obj.ToString());
}
if(obj is Container)
ExtractContent((Container)obj);
}
}
(obviously replace Assets/Editor/Localisation/test.json with a path to
your file).
This can then easily be exported as csv for localisation. Still
implementing the details, but seems to work so far :D
—
Reply to this email directly, view it on GitHub
<#166 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJR3UEGYIMG2UPLYZTFX5LVLDU45ANCNFSM5VQITKJA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Hi @GieziJo! Did this work out for you? If it did, would you be willing to share it with the community? This seems like something others might find handy! |
Playing around with it yesterday I realized it doesn't work on tags anymore, did maybe something change @tomkail ? I modified the function a bit and this works, but maybe there is a more elegant solution? private static bool _isHashtag = false;
private static void ExtractContent(Container container)
{
if (container.content != null)
foreach (Object obj in container.content)
{
if (obj.ToString() == "BeginTag")
_isHashtag = true;
else if (obj.ToString() == "EndTag")
_isHashtag = false;
if (!_isHashtag && obj is Ink.Runtime.StringValue && obj.ToString().Trim().Length != 0)
{
dialogueDictionary.Add(container.path.ToString(), obj.ToString().Trim());
}
if (obj is Container)
ExtractContent((Container) obj);
}
} I also started playing around with the Jaro Winkler Distance yesterday when updating the csv, to see if any of the old strings match, and then copy the translation for the highest score, and it looks like it's working fairly well, will keep you posted. |
Oh my! This is absolutely fantastic, thank you so much for writing this up! Would you mind if I shared it on our discord? Would love to see any updates, like the string comparison idea you mentioned. As for tags - we added the ability to add tags to choices last year - that might be it? |
First off, just wanted to say thanks a lot for this amazing tool, we have been using it in our upcoming game Hermit, and it is just awesome to handle dialogues!
The one thing I am a big concerned about is localisation. After reading a lot of opinions I came to the conclusion that avoiding inline variables, using ids for each line and pairing this with a dictionary would be the way to go (here, here and inkle/ink#529).
I am not entirely convinced by the solutions provided in the linked articles to create these IDs though.
Looking at the generated
.json
, it seems like every text line already contains a tag, something of the sorts of"#n": "g-3"
. Pair this with the current knot and this creates a unique ID.My question is thus:
Is it possible to retrieve this g-tag at runtime?
I'm thinking about something of the like of
story.currentID
(which does not exists).I wouldn't mind adding this to the integration, but not sure where to do it.
In
JsonSerialisation.cs
I saw the linesBut I haven't been able to figure out how the tag is then used.
Extracting all the lines from the
json
should be easy enough if that part is possible.Thanks!
The text was updated successfully, but these errors were encountered: