npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

flash-cognate

v1.1.0

Published

Translation tools for Flash/Animate CC

Downloads

28

Readme

cognate

Cognate is a set of translation tools for Flash/Animate CC

Features

  • [x] Creates text files from your Flash project, which you can send out for translations
  • [x] Writes translated text back into your Flash project
  • [x] Preserves formatting of text in your project
  • [x] Translated text can be rearranged and those changes will be reflected in Flash
  • [x] The format of the text files can be customized
  • [x] Supports the .xfl file format
  • [ ] Supports the .fla file format
  • [x] 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:
```js
var cognate = require('flash-cognate'),
	fs 		= require('fs');

// "segments" are a <div> and <span> representation of your text
var segments = cognate.getSegmentsForXflFileAtPath('~/Flash/project/main.xfl');

fs.writeFileSync('~/text/toBeTranslated.xml', segments.stringify());

Writing translations to a Flash project:

var cognate = require('flash-cognate'),
	fs 		= require('fs');

var translated = fs.readFileSync('~/text/translated.xml');
var segments = cognate.parse(translated);

cognate.writeSegmentsToXflFileAtPath('~/Flash/project_german/main.xfl');

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:

...
<DOMStaticText>
  <matrix>
    <Matrix tx="2" ty="2"/>
  </matrix>
  <textRuns>
    <DOMTextRun>
      <characters>apple </characters>
      <textAttrs>
        <DOMTextAttrs face="Times" fillColor="#FFFFFF"/>
      </textAttrs>
    </DOMTextRun>
    <DOMTextRun>
      <characters>banana</characters>
      <textAttrs>
        <DOMTextAttrs face="Tahoma" fillColor="#FFE953"/>
      </textAttrs>
    </DOMTextRun>
  </textRuns>
</DOMStaticText>
...

You can access them like so:

var cognate = require('flash-cognate'),
	fs 		= require('fs');

var symbolFile = fs.readFileSync('~/Flash/project/LIBRARY/mySymbol.xml');
var $ = cognate.load(symbolFile);

var result = $('textRuns').withCharacters('apple banana').segment().stringify();

That would produce the output:

<div id="apple banana"><span style="font-family: Times; color: #FFFFFF;">apple </span><span style="font-family: Tahoma; color: #FFE953;">banana</span></div>

You can then modify the output and then save it back into your file:

...
result = result.replace('banana', 'mango');
var newSegment = cognate.parse(result);
$('textRuns').withCharacters('apple banana').segment(newSegment);

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:

stringify: function() {
	return this.root().xml();
}
parse: function(xmlContent) {
	var $ = exp.load(xmlContent); // 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 = require('flash-cognate');

cognate.stringify = function() {
	var $ = cognate.load('');
	this.each(function(idx, elem){
		var $elem = $(elem);
		var cdata = '<![CDATA[' + $elem.xml() + ']]>';
		$elem.html(cdata);
	});
	return this.root().xml();
}

cognate.parse = function(xmlContent) {
	var $ = cognate.load(xmlContent);
	$('div').each(function(idx, elem){
		var $elem = $(elem);
		var cdata = $elem.contents().filter(function(i, e){
			return e.type === 'cdata';
		});
		$elem.html(cdata.text());
	});
	return $;
}