cognate
Cognate is a set of translation tools for Flash/Animate CC
Features
- Creates text files from your Flash project, which you can send out for translations
- Writes translated text back into your Flash project
- Preserves formatting of text in your project
- Translated text can be rearranged and those changes will be reflected in Flash
- The format of the text files can be customized
- Supports the
.xfl
file format - Supports the
.fla
file format - Can be used as a library for your own scripts
- Can be used as a command-line tool
- Supports incremental translation
Installation
npm install flash-cognate` ## Usage Generating translations files a Flash project:```jsvar cognate = require, fs = require; // "segments" are a <div> and <span> representation of your textvar segments = cognate.getSegmentsForXflFileAtPath; fs.writeFileSync
Writing translations to a Flash project:
var cognate = fs = ; var translated = fs;var segments = cognate; cognate;
Internals
Cognate is essentially a wrapper around the fantastic Cheerio library, with various utility functions. Cognate has a load
method which mirrors Cheerio's, but the result has some extended functionality that helps to manipulate Flash's symbol files.
Let's say that mySymbol.xml
has these contents, in part:
... apple banana ...
You can access them like so:
var cognate = fs = ; var symbolFile = fs;var $ = cognate; var result = ;
That would produce the output:
apple banana
You can then modify the output and then save it back into your file:
...result = result;var newSegment = cognate;;
Hooks
Every translator or translation system is different, so they're not all going to want <div>
and <span>
tags and so on. There are a number of different requirements for the format. To meet with this, the stringify()
and parse()
functions can be customized.
Here are Cognate's default ones:
{ return this;}
{ var $ = exp; // exp is a reference to cognate return $;}
Here is an example of stringify/parse functions that enclose the <div>
contents in a CDATA tag during translations:
var cognate = ; cognate { var $ = cognate; this; return this;} cognate { var $ = cognate; ; return $;}