@bscotch/cl2-string-server-shared
TypeScript icon, indicating that this package has built-in type declarations

0.7.0 • Public • Published

Crashlands 2: String Server Utilities

⚠️ This package is only useful for Butterscotch Shenanigans developers! ⚠️

Purpose

For string management in Crashlands 2, we have a "String Server" for managing user-facing text strings. This server is primarily used for:

  • Auditing and spell-checking user-facing text to ensure it is correct
  • Creating a Glossary for use in spell-checking within various tools
  • Providing context to help translators accurately translate each string

This package provides shared utilities for use by the String Server and related tools.

Usage

Install:

  • pnpm: pnpm add @bscotch/cl2-string-server-shared
  • npm: npm install @bscotch/cl2-string-server-shared

Create a Client

import { Client } from '@bscotch/cl2-string-server-shared';

const client = new Client({
	baseUrl: process.env.CL2_STRING_SERVER_BASE_URL,
	user: process.env.CL2_STRING_SERVER_ROOT_USER,
	password: process.env.CL2_STRING_SERVER_ROOT_PASS,
});

// Load the strings to send off
const filePath = './path/to/exported/strings.json';
const strings = JSON.parse(await fs.readFile(filePath, 'utf8'));

Make a Commit

const filePath = './path/to/exported/strings.json';
const strings = JSON.parse(await fs.readFile(filePath, 'utf8'));

// (In this case the file's data has a different format than we need)
await client.commitStrings('crashlands-2', {
	branchId: file.branch_name,
	commitNumber: file.version,
	strings: file.strings.map((string) => ({
		id: string.key,
		sortKey: string.sort_key,
		text: string.text,
		immutable: !string.tags.includes('gamechanger'),
		maxCharacters:
			typeof string.character_limit === 'number'
				? string.character_limit
				: undefined,
	})),
});

Download as XLIFF

const xliff = await client.getXliff('crashlands-2', 'develop');
await fs.writeFile('crashlands-2.xliff', xliff);

Load the Glossary

import {Glossary, Client} from '@bscotch/cl2-string-server-shared';

const client = new Client({/* credentials */});
const glossary = await Glossary.create(client, 'crashlands-2');

Spellcheck a String

const words = glossary.parse("Some string with a bunch of user-facing game text");
const checkedWords = words.map(word=>glossary.checkWord(word));
console.log("Invalid words", checkedWords.filter(word=>!word.valid));

Add a new term to the Glossary

Glossary terms are synced to the String Server so that they are centralized!

Terms can be flagged as case-sensitive or case-insensitive, but other forms of the word (plurals, alternate spellings, etc) must be added as separate terms.

await glossary.addTerm("Norb", "Something that definitely is not an orb.")

Readme

Keywords

none

Package Sidebar

Install

npm i @bscotch/cl2-string-server-shared

Weekly Downloads

52

Version

0.7.0

License

ISC

Unpacked Size

1.38 MB

Total Files

90

Last publish

Collaborators

  • bscotchadam