Word finder and translation/csv utils
npm install word-file-utilsv2.0.3
utils-stuff
word-file-utils (including utils-stuff)
fast-js-excel (including exceljs, word-file-utils (including utils-stuff))
bash
npm install word-file-utils
`
The WordFileUtils extends a simple class with a simple function using the statickidz/node-google-translate-skidz api.
With this package comes the alessiovelluso/utils-stuff, a package of server/client utilities that can be helpful, be sure to check the library for all the different utilities you can use. This one has basically two different classes GenericUtils & ClientFilters, you can import them just as explained from the lib documentation but using "word-file-utils" like
`ts
import { GenericUtils } from "word-file-utils"
`
At the moment, the interface of the class is as it follows:
`ts
interface IWordFileUtils {
separator:string;
errorTranslationValue:string;
translationColumnName:string;
parseCsvToObjectList: = GenericObject>(csvFilepath:string, separator?:string) => T[];
parseObjectListToCsv:(data:T[], separator?:string) => string
writeCsv:(outputCsv:string, data:T[], separator?:string) => Promise
translateValue:(value:string, localeIn:string, localeOut:string) => Promise;
translateObjectList:(data:T[], { translatingCol, cultureFrom, cultureTo }:TranslationConfig) => Promise
translateCsv:(data:TranslateCsvConfig) => Promise;
findWords: (folderToRead:string, desiredExtensions:string[], excludeDir:string[], wordToFind:RegExp) => string[],
writeJson:(outputCsv:string, data:T[]) => void
}
`
Initialize the class
`ts
import { WordFileUtils } from "word-file-utils"
`
I raccomand you to initialize a new object every file that requires it.
The constructor of WordFileUtils follows this interface:
`ts
constructor(data?:TranslationMakerConstructor)
interface TranslationMakerConstructor { separator?:string, errorTranslationValue?:string, translationColumnName?:string }
`
The separator can be defined here or in any method that requires it as an optional parameter.
The errorTranslationValue and translationColumnName are specific to the translations method.
A brief explanation of the methods:
##### 1. Parse Csv To Object List
`js
parseCsvToObjectList: = GenericObject>(csvFilepath:string, separator?:string) => T[];
`
Parse a csv in an array of object, having the key as column name:
`
Col1,Col2
Value1,Value2
Value3,Value4
`
This is gonna be parsed as
`ts
[
{ Col1: Value1, Col2:Value2 },
{ Col1: Value3, Col2:Value4 },
]
`
##### 2. Parse Object List To Csv
`ts
parseObjectListToCsv:(data:T[], separator:string) => string
`
Returns a string ready to be written down with the specific writeCsvor passed in an api
##### 3. Write Csv
`ts
writeCsv:(outputCsv:string, data:T[], separator?:string) => Promise
`
Write a csv locally with an object list parameter, having the column as the object keys.
It uses the related parseObjectListToCsv method
##### 4. Translate Value
`ts
translateObjectList:(data:T[], { translatingCol, cultureFrom, cultureTo }:TranslationConfig) => Promise
`
Simply translating a word to the desired one
##### 5. Translate Object List
`ts
translateObjectList:(data:GenericObject[], { translatingCol, cultureFrom, cultureTo }:TranslationConfig) => Promise
`
After specifying the target column, the func return the same object list with an added key of the translation
##### 6. Translate Csv
`ts
translateCsv:(data:TranslateCsvConfig) => Promise
`
Take a csv as input and write the same csv with an added translated_value column.
It uses the related parseCsvToObjectList, translateObjectList and writeCsv methods
##### 7. Find Words
`ts
findWords: (folderToRead:string, desiredExtensions:string[], wordToFind:RegExp) => string[]
`
This will search along the whole project, in specified extensions files, and return a list of all the words matching a specified RegExp pattern.
##### 8. Write Json
`ts
writeJson:(outputCsv:string, data:T[]) => void
`
Easily write a local json
Types
`ts
import { GoogleTranslateLocales } from "./translate.types"
export interface TranslationConfig { translatingCol:string, cultureFrom:GoogleTranslateLocales, cultureTo:GoogleTranslateLocales }
export interface TranslateCsvConfig extends TranslationConfig { csvFilepath:string, outFilepath:string, separator?:string }
export interface TranslationMakerConstructor { separator?:string, errorTranslationValue?:string, translationColumnName?:string }
``