Code Monkey home page Code Monkey logo

node-lokalise-api's Introduction

Lokalise API v2 official Node.js client

npm CI Coverage Status Downloads total

Official Node interface for the Lokalise API.

Quickstart

Please note that starting from version 9 this SDK is a pure ESM module. It does not provide a CommonJS export (require) anymore. Therefore you should either convert your project to ESM, use dynamic import (please find an example below), or stay on version 8.

Install the library:

npm install @lokalise/node-api

Obtain Lokalise API token in your personal profile, initialize and use the client:

import { LokaliseApi } from "@lokalise/node-api";

const lokaliseApi = new LokaliseApi({ apiKey: '<apiKey>'});
const projects = await lokaliseApi.projects().list();
projects.items[0].name;

process = await lokaliseApi.files().upload(project_id,
  {data: data_base64, filename: 'test1.json', lang_iso: 'en'})
process.status // => 'queued'

Alternatively, you can use tokens obtained via OAuth2 (don't forget that these tokens have expiration dates):

import { LokaliseApiOAuth } from "@lokalise/node-api";

const lokaliseApi = new LokaliseApiOAuth({ apiKey: '<apiKeyObtainedViaOauth2>' });

const projects = lokaliseApi.projects().list();

Here's an example using dynamic import:

(async function () {
  const LokaliseApi = await (import('@lokalise/node-api').then(m => m.LokaliseApi));
  const lokaliseApi = new LokaliseApi({ apiKey: LOKALISE_API_TOKEN});

  // use lokaliseApi here as usual...
})();

Usage

Detailed documentation can be found at lokalise.github.io/node-lokalise-api.

You can also check this repo containing some usage examples and this blog post with explanations. Finally, you might be interested in our free course "Lokalise for developers" that showcases Node SDK usage.

License

This library is licensed under the BSD 3 Clause. Prior to version 5.1.0 the license was MIT.

Copyright (c) Lokalise group and Ilya Krukowski

node-lokalise-api's People

Contributors

andrewlab-lokalise avatar arelstone avatar bodrovis avatar dependabot[bot] avatar dhensby avatar evangelion1204 avatar felixgraf avatar ihlokalise avatar kutanov avatar maribies avatar nickustinov avatar omonk avatar tenga avatar vlinder avatar xayer avatar yarlson avatar zoidc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-lokalise-api's Issues

Update translation values en masse and in different branches.

Hey there. Based on the docs, I am unsure on how to go about the bulk update of a given value in translation keys. Do I need to call each instance I want to update, update it locally and then push it back up?

Also, I am unsure how to select which branch I am pushing to from my local machine. I have successfully created to two branches with 100 keys each but need to update the translation values for both. The documentation is not too helpful here. Any suggestions?
Thank you so much in advance.
-Trevor

Browser Support

I'd like to consume Lokalise API endpoints from my browser client app

Additional context
I am working on a plugin for Figma which is basically going to run as a JavaScript code inside Chrome browser which is inside Electron app. Now I am trying to build a small PoC client app to run inside Chrome. I have problems with CORS - requests don't go through to Lokalise API from Chrome, but the same code runs find if I run it as a NodeJS app.

So, I wonder, if it's supposed to work in a similar way for both NodeJS and browser-based environments?

Here is my simple fetch example:

class LokaliseConnector {
    public async getProjects() {
        const result = await fetch(`https://api.lokalise.com/api2/projects/`,
            {
                headers: {
                    'x-api-token': 'abcdef'
                }
            }
        )
            .catch(console.error)
        console.log(result)
    }
}

Thank you!

Using this lib with Deno

Support Deno

It is possible to use this lib with Deno:

import { LokaliseApi } from "npm:@lokalise/node-api";

new LokaliseApi({ apiKey });

However, since you are importing package.json to get the current version. E.g. here:

const pkg = JSON.parse((await readFile("./package.json")).toString());
it is required to create a package.json file next to the Deno script to get this working.

It would be awesome to support Deno. Is it possible to get the version number in some other way?

Unable to use `9.0.0` Error [ERR_REQUIRE_ESM]: require() of ES Module not supported

Describe the bug
Unable to use latest version 9.0.01, getting following error.
Error [ERR_REQUIRE_ESM]: require() of ES Module node_modules/@lokalise/node-api/dist/main.js from lokalise.service.js not supported. Instead change the require of main.js in lokalise.service.js to a dynamic import() which is available in all CommonJS modules.

To Reproduce
Steps to reproduce the behavior.

  • Install "@lokalise/node-api": "^9.0.0"
import { LokaliseApi } from '@lokalise/node-api';
import { config } from 'somewhere';

export class LokaliseService {
  private lokaliseApi: LokaliseApi;

  constructor() {
    this.lokaliseApi = new LokaliseApi({ apiKey: config.apiKey });
  }

  async fetchLokaliseKeys(page: number, keys?: string[]) {
    try {
      const requestBody: any = { page, project_id: config.projectId, limit: 20 };

      if (keys?.length) {
        requestBody.include_translations = 1;
        requestBody.filter_keys = keys?.join();
      }

      return await this.lokaliseApi.keys().list(requestBody);
    } catch (error) {
      this.logger.error(error);
    }
  }
}

Expected behavior
Should work as mentioned in docs here.
https://lokalise.github.io/node-lokalise-api/api/getting-started#installation-and-requirements

Your environment:

  • Node version: v16.17.0

Additional context
Add any other context about the problem here.

Leaving the replace_breaks option enabled double-escapes line breaks in JSON export

Describe the bug
As per the documentation: replace_breaks: Enable to replace line breaks in exported translations with \n. Default: true. Instead, when I leave this option on, what I get is \\n, which then outputs actual ‘\n’s to the user, instead of a line break as intended.

To Reproduce
Including all my options in case any of them affects this in any way;

lokalise.files.download(<projectId>, {
    format: 'json',
    original_filenames: false,
    bundle_structure: '%LANG_ISO%.%FORMAT%',
    all_platforms: true,
    add_newline_eof: true,
    export_sort: 'a_z',
    export_empty_as: 'base',
    plural_format: 'icu',
    icu_numeric: true,
    placeholder_format: 'icu',
    indentation: '4sp'
})

Expected behavior
I expect line breaks added with Shift+Enter in the translation UI to appear as \n, instead they’re double-escaped to \\n.

If I instead specify replace_breaks: false in the options object, I get the desired result – but it feels accidental.

Your environment:

  • Node version: v12.16.3

Is this because line breaks aren’t supported in JSON, and so they are replaced implicitly no matter what the option is set to? If that’s the case, should this then be documented?

Downloading JSON flat fails with key collision

Describe the bug
When downloading translations as json format, I expect to have a flat JSON content like below

{
  "Patch": "some value",
  "Patch::permission": "another value"
}

but I receive an error message Following keys pairs would cause JSON collision, you need to fix them manually: Patch & Patch::permission;.

To Reproduce
Upload some keys like seen below:

  "Patch": "Patch",
  "Patch {{count}} fields_one": "Patch {{count}} fields",
  "Patch {{count}} fields_other": "Patch {{count}} fields",
  "Patch 1 field": "Patch 1 field",
  "Patch:::permission": "Patch:::permission",

Expected behavior
There should be no collision in flat JSON format as they are all at the same level

Your environment:

  • Node version: 16.14

Additional context

Add commit message field to files/download endpoint

The feature I'd like is...

Add the commit message field when using the github or other vcs provider as seen on the UI to export your translations.

We use this field because we want to specify a ticket number and a [skip ci] message in the commit message to stop the CI from running the build on an automated translation updated and to pass our ticket check.

Additional context

example query:

POST /projects/<id>/files/download

{
  ...,
  triggers: ['github'],
  // Does not exist yet
  commit_template: '[JIRA-123] [skip ci] Lokalise: Translations update'
}

X-Total-Count missing from `new LokaliseApi().keys.list`

Describe the bug
The total count of keys is missing from the response from new LokaliseApi().keys.list

To Reproduce
Call new LokaliseApi().keys.list

Expected behavior
Expose X-Total-Count to a property in the response from new LokaliseApi().keys.list

Your environment:

  • Node version: v12.13.0
  • "@lokalise/node-api": "^5.3.0",

Additional information:
From this issue we found some headers had been added, but not including X-Total-Count

CC @ycmjason

Lokalise download file seems to be broken

Describe the bug
Following the new update it seems that something has been broken on the package because using the download method always returns an error of the form:

(node:79054) ExperimentalWarning: The dns.promises API is experimental
(node:79054) ExperimentalWarning: Readable[Symbol.asyncIterator] is an experimental feature. This feature could change at any time
(node:79054) UnhandledPromiseRejectionWarning: SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at got.then (/foundation_lambda_node/lokalise_put_translation/node_modules/@lokalise/node-api/dist/http_client/base.js:37:43)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:79054) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:79054) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

To Reproduce
Basic use of the download method :

const response = await lokaliseApi.files.download(projectId, {format: 'json', "original_filenames": true});

Expected behavior
I expected the function to return with an object that contains the response of the api (200, with the bundle path or an HTTP error code)

Your environment:

  • Node version 10.16.3

Additional context
Working on a AWS lambda, testing locally by faking the trigger of the lokalise webhook.

Missing type definitions for webhook events

I'm trying to find type definitions for contents of the webhook events, but can't seem to find them.

Please point me in the right direction, or add them if they do not exist.

Thanks!

Create TypeScript definitions

Steps to reproduce

When I use TypeScript, this library has defined types

Expected behavior

TypeScript types declaration file to be included on NPM

Actual behavior

Is not there 😢

System configuration

Node version:

I wrote some, I hope it would work for you

declare module '@lokalise/node-api' {
  export interface UploadFileParams {
    data: string;
    filename: string;
    lang_iso: string;
    convert_placeholder?: string;
    detect_icu_plurals?: boolean;
    tags?: any[];
    replace_modified?: boolean;
    slashn_to_linebreak?: boolean;
    keys_to_values?: boolean;
    apply_tm?: boolean;
    hidden_from_contributors?: boolean;
    cleanup_mode?: boolean;
  }

  export interface StandartParams {
    page?: number;
    limit?: number;
    [paramName: string]: any;
  }

  export interface Project {
    project_id: number;
    name: string;
    description: string;
    team_id: number;
    created_by_email: string;
    created_at: string;
    created_by: number;
  }

  export interface Language {
    lang_id: number;
    lang_iso: string;
    lang_name: string;
    is_rtl: boolean;
    plural_forms: string[];
  }

  export interface Key {
    key_id: number;
    created_at: string;
    key_name: string;
    filenames: object;
    description: string;
    platforms: string[];
    tags: string[];
    comments: object;
    screenshots: object;
    translations: object | object[];
    is_plural: boolean;
    plural_name: string;
    is_hidden: boolean;
    is_archived: boolean;
    context: string;
    base_words: number;
    char_limit: number;
    custom_attributes: any[];
  }

  export interface FileParams extends StandartParams {
    filter_filename?: string;
  }

  export interface DownloadFileParams {
    format: string;
    original_filenames?: boolean;
    bundle_structure?: string;
    directory_prefix?: string;
    all_platforms?: string;
    filter_langs?: any[];
    filter_data?: any[];
    include_tags?: any[];
    exclude_tags?: any[];
    export_sort?: string;
    export_empty_as?: string;
    include_comments?: boolean;
    include_description?: boolean;
    include_pids?: any[];
    triggers?: string[];
    filter_repositories?: any[];
    replace_breaks?: boolean;
    disable_references?: boolean;
    plural_format?: string[];
    placeholder_format?: string;
    webhook_url?: string;
    language_mapping?: object;
    icu_numeric?: boolean;
    escape_percent?: boolean;
    indentation?: string;
    yaml_include_root?: boolean;
    json_unescaped_slashes?: boolean;
    java_properties_encoding?: string;
    java_properties_separator?: string;
  }

  export interface Comment {
    comment_id: number;
    key_id: number;
    comment: string;
    added_by: number;
    added_by_email: string;
    added_at: string;
  }

  export interface BulkUpdateKeysParams {
    keys: Key[];
  }

  export interface Headers {
    [paramName: string]: any;
  }

  export class ApiRequest {
    private urlRoot;
    promise: Promise<Object>;
    params: any;
    constructor(uri: any, method: any, body?: any, params?: {});
    createPromise(uri: any, method: any, body: any): Promise<{}>;
    protected composeURI(uri: any): any;
    protected mapUriParams(
      params: any,
    ): (entity: any, isMandaratory: any, paramName: any) => any;
    constructParameters(method: any, params: any): void;
  }

  export class UserGroups extends BaseCollection {
    protected static rootElementName: string;
    protected static prefixURI: string;
    protected static elementClass: Object;
    create(body: any, params?: StandartParams): Promise<any>;
    add_project_to_group(
      team_id: any,
      group_id: any,
      body: any,
      params: any,
    ): Promise<any>;
    remove_project_from_group(
      team_id: any,
      group_id: any,
      body: any,
      params: any,
    ): Promise<any>;
  }

  export class Translations extends BaseCollection {
    protected static rootElementName: string;
    protected static prefixURI: string;
  }
  export class Teams extends BaseCollection {
    protected static rootElementName: string;
    protected static prefixURI: string;
    protected static elementClass: Object;
  }

  export class TeamUsers extends BaseCollection {
    protected static rootElementName: string;
    protected static prefixURI: string;
    protected static elementClass: Object;
  }

  export class Tasks extends BaseCollection {
    protected static rootElementName: string;
    protected static prefixURI: string;
    protected static elementClass: Object;
  }
  export class Snapshots extends BaseCollection {
    protected static rootElementName: string;
    protected static prefixURI: string;
    restore(params: StandartParams): Promise<any>;
  }

  export class Screenshots extends BaseCollection {
    protected static rootElementName: string;
    protected static prefixURI: string;
    protected static elementClass: Object;
  }

  export class Projects extends BaseCollection {
    protected static rootElementName: string;
    protected static prefixURI: string;
    protected static elementClass: Object;
    empty(project_id: any): void;
  }
  export class Languages extends BaseCollection {
    protected static rootElementName: string;
    protected static prefixURI: string;
    protected static elementClass: Object;
    system_languages(params: StandartParams): Promise<any>;
    create(body: any, params?: StandartParams): Promise<any>;
  }

  export class Keys extends BaseCollection {
    protected static rootElementName: string;
    protected static prefixURI: string;
    protected static elementClass: Object;
    create(body: any, params?: StandartParams): Promise<any>;
    bulk_update(
      keys: BulkUpdateKeysParams,
      params: StandartParams,
    ): Promise<any>;
    bulk_delete(keys: number[] | string[], params: StandartParams): any;
  }

  export class Files extends BaseCollection {
    protected static rootElementName: string;
    protected static prefixURI: string;
    protected static elementClass: Object;
    list(params?: FileParams): Promise<this[]>;
    upload(project_id: string, upload: UploadFileParams): Promise<any>;
    download(project_id: string, download: DownloadFileParams): Promise<any>;
  }

  export class Contributors extends BaseCollection {
    protected static rootElementName: string;
    protected static prefixURI: string;
    protected static elementClass: Object;
    create(body: any, params?: StandartParams): Promise<any>;
  }

  export class Comments extends BaseCollection {
    protected static rootElementName: string;
    protected static prefixURI: string;
    protected static elementClass: Object;
    create(body: any, params?: StandartParams): Promise<any>;
    list_project_comments(params?: StandartParams): Promise<any[]>;
  }
  export class BaseCollection {
    protected static rootElementName: string;
    protected static endpoint: string;
    protected static prefixURI: string;
    protected static elementClass: any;
    get(id: any, params?: StandartParams, body?: any): Promise<any>;
    list(params?: StandartParams): Promise<any[]>;
    create(body: any, params?: StandartParams): Promise<any>;
    update(id: any, body: any, params?: StandartParams): Promise<any>;
    delete(id: any, params?: StandartParams): Promise<any>;
    protected populateObjectFromJson(json: Object): this;
    protected populateArrayFromJson(json: Array<any>): this[];
    protected returnBareJSON(json: any): any;
    protected handleReject(data: any): void;
    protected createPromise(
      method: any,
      params: any,
      resolveFn: any,
      rejectFn?: (data: any) => void,
      body?: any,
      uri?: any,
    ): Promise<any>;
  }

  export class LocaliseApiMethods {
    comments: Comments;
    contributors: Contributors;
    files: Files;
    keys: Keys;
    languages: Languages;
    projects: Projects;
    screenshots: Screenshots;
    snapshots: Snapshots;
    tasks: Tasks;
    teamUsers: TeamUsers;
    userGroups: UserGroups;
    translations: Translations;
  }

  export class LokaliseApi extends LocaliseApiMethods {
    static apiKey: string;
    private static _instance;
    apiKey: string;
    /**
     * Instantiate LokaliseApi to have access to methods
     * @param apiKey  text, mandaratory
     * @returns       LokaliseApi object to work with.
     */
    constructor(params?: Object);
  }
}

Cannot find module 'got' or its corresponding type declarations.

Describe the bug
Updated a project from v8 to v11.0.1. Implementation of the SDK is quite simple. When building the project we get the follwoing:

node_modules/@lokalise/node-api/dist/collections/base_collection.d.ts:1:25 - error TS2307: Cannot find module 'got' or its corresponding type declarations.

1 import { Options } from "got";
                          ~~~~~

node_modules/@lokalise/node-api/dist/http_client/base.d.ts:1:25 - error TS2307: Cannot find module 'got' or its corresponding type declarations.

1 import { Options } from "got";

To Reproduce
Build the project with TS

Expected behavior
Build the project

Your environment:

  • Node version 16.17.1

Additional context
Add any other context about the problem here.

Example lokalise-api-hello-world-app-with-node does not work

Describe the bug
Example from https://developers.lokalise.com/docs/lokalise-api-hello-world-app-with-node does not work with node v18

If i use import word, I see:

node --experimental-modules translations/upload.js
(node:16975) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
translations/upload.js:1
import { LokaliseApi } from "@lokalise/node-api";
^^^^^^

SyntaxError: Cannot use import statement outside a module

with require, as docs say:

const { LokaliseApi } = require('@lokalise/node-api');
                        ^

Error [ERR_REQUIRE_ESM]: require() of ES Module node_modules/@lokalise/node-api/dist/main.js from translations/upload.js not supported.
Instead change the require of main.js in translations/upload.js to a dynamic import() which is available in all CommonJS modules.

To Reproduce
Steps to reproduce the behavior.

Expected behavior
A clear and concise description of what you expected to happen.

Your environment:

  • Node version 18

Additional context
Add any other context about the problem here.

Support corporate proxy

Currently behind corporate firewall it is not possible to use any lokalise client, especially the this one in node. I've checked source code and tested proof of concept implementation and it is quite easy to implement. You are using 'got' http client which support proxies https://github.com/sindresorhus/got/blob/main/documentation/tips.md#proxying
You only need to extend configuration of of node-lokalise-api and pass proxy settings there.

Can you put such feature on roadmap?

A way to know if a dataset was changed since last request

Request an updated dataset only if it was changed

Additional context
Imagine, I retrieve translations for the project.
The dataset is retrieved and I save it locally.
Now, I pass this locally-stored dataset to to my logic.

Next, someone changes some translation via Lokalise interface.
I don't know if translations were changed or not until I retrieve the whole dataset again, so I tend to request it every time to make sure it's up-to-date.

It would be great to have some endpoint like /projects/<PROJECT_ID>/translations/summary which would have a timestamp of the last change so next time before deciding if need to fetch the whole dataset or not, I compare its timestamp to the local timestamp.

Any advice if it's possible now?

Thanks!

\n is escaped (\\n) in translations when downloading translation files

Hello there,
After downloading the translation files from our project, we have some translations containing \\n while \n is displayed on the web application.

I verified and we are using option replace_break to false as you can see here:

const { bundle_url: bundleUrl } = await lokaliseApi
.files()
.download(PROJECT_ID, {
replace_breaks: false,
format: 'json',
});

We are using version 7.3.1 I upgraded to 8.2.0 in case but issue is still happening.

Any idea how to solve this issue?

Regards

lokaliseApi.queuedProcesses.get

Describe the bug
This is my code

image

I get error "lokaliseApi.queuedProcesses.get is not a function"

If i change my code to process = await lokaliseApi.queuedProcesses().get(process.process_id, { project_id: projectId });

I will get

running upload success // should show: finish upload success?

in console

It looks like asynchronous functions don't work and the example on the official documentation has an error

https://lokalise.github.io/node-lokalise-api/api/files

To Reproduce
Steps to reproduce the behavior.

Expected behavior
A clear and concise description of what you expected to happen.

Your environment:

  • Node version

Additional context
Add any other context about the problem here.

Pluralise translation shown as a JSON string

Describe the bug
When a translation has is_plural: true, the translation will become a string of JSON

To Reproduce
Fetch a key that has pluralisation enabled

 const keys = await lokaliseApi.keys.list({
    ...
  })

console.log(keys.items[0].translation) // this becomes a string of JSON

Expected behavior
For the translation to be a parsed object

Your environment:

  • Node version 14

CC @ycmjason

Module not found: Can't resolve 'dns'

Describe the bug
The api has a dependency on got which subsequently has a dependency on cacheable-lookup. That package has a dependency on dns however, it's package.json doesn't include it. As a result, it never gets installed. This causes the following error.

info  - automatically enabled Fast Refresh for 1 custom loader
error - ../../node_modules/cacheable-lookup/source/index.js:10:2
Module not found: Can't resolve 'dns'

Import trace for requested module:
../../node_modules/got/dist/source/core/index.js
../../node_modules/got/dist/source/create.js
../../node_modules/got/dist/source/index.js
../../node_modules/@lokalise/node-api/dist/oauth2/auth_request.js
../../node_modules/@lokalise/node-api/dist/oauth2/lokalise_auth.js
../../node_modules/@lokalise/node-api/dist/main.js
../../node_modules/@lokalise/node-api/index.js
./components/Hero/Hero.tsx
./components/index.ts
./pages/_app.tsx

see:

https://github.com/szmarczak/cacheable-lookup/blob/master/source/index.js#L10

https://github.com/szmarczak/cacheable-lookup/blob/master/package.json

To Reproduce
Install the api, import it into your code, attempt to instantiate the class.

Expected behavior
It should not have any dependency errors.

Your environment:

  • Node version: v16.14.2

Support Remove Key from Task API

Currently, there is no API to remove keys from within a task. I want to automate task creation, but I need to put in a key every time, so I want to create a temporary key and remove it, but I can't remove the key once I'm inside the task.

Running a single instance client throws error "Your token is currently used to process another request. We do not support concurrent requests."

Describe the bug
I have a nodejs-based client which sends requests to Lokalise via node-lokalise-api library.

The code is as simple as this Express endpoint:

app.get('/project/:projectId', async (req, res) => {
    try {
        const project = await lokaliseApi.projects.get(req.params.projectId)
        res.json(project)
    } catch (err) {
        console.log(err)
        res.json(err)
    }

})

Returns this:

{ message: 'Your token is currently used to process another request. We do not support concurrent requests.',
  code: 423 }

To Reproduce
Call the same endpoint 5-10 times a minute.

Expected behavior
Error message seems to be wrong to me because I clearly run a single instance client, not multiple clients. I don't have a clear picture of what causes this error and how long to wait before it starts to return proper data again.

Your environment:

  • Node version 10.15.3
  • MacOs 10.14.6 (18G95)

Additional context
Thank you!

UploadFileParams uses old paramter: convert_placeholder

Describe the bug
File upload does not respect convert_placeholder parameter.

To Reproduce

  1. Use the node-js-api to upload a File.
  2. Set convert_placeholder to false.
await this.lokaliseApi.files.upload(this.projectId, {
  data: content,
  filename: fileName,
  lang_iso: languageISOCode,
  convert_placeholder: false,
  tags: ['Pushed'],
  replace_modified: this.replaceModified,
  skip_detect_lang_iso: true,
})
  1. File in Lokalise uses the Lokalise universal placeholder

Expected behavior
I expect the original placeholder to preserved.

Your environment:

  • Node version: 12.22.3

Additional context
UploadFileParams does not use convert_placeholders which is the correct param in the latest version of the API. https://app.lokalise.com/api2docs/curl/#transition-upload-a-file-post. Rather it uses convert_placeholder, without the s. I contacted someone on Lokalise support and they mentioned convert_placeholder is the V1 version of that param.

Very loose Typescript definitions

The provided typings are very loose, for example at DownloadFileParams for export_empty_as. Many fields are just string and no help about the values is provided.
I would recommend to strongly type them, like string replace by 'foo' | 'bar' or alternatively use TSDOC to document them:

export interface DownloadFileParams {
    
    /** Valid values: `foo`, `bar`.  */
    export_empty_as?: string;

https://github.com/lokalise/node-lokalise-api/blob/master/src/interfaces/download_file_params.ts

I do believe that improving the documentation will be a big gain for DX, otherwise working with the Node API is very painful.

ParamsWithPagination interface is not exported which is used in list()

Describe the bug
ParamsWithPagination interface is not exported but the parameter passed to lokaliseApi.keys().list(requestBody) expects this type.

To Reproduce
Steps to reproduce the behavior.

async fetchLokaliseKeysPage(page: number, keys?: string[]) {
      const requestBody: ParamsWithPagination = { page, project_id: projectId, limit: 20 };

      if (keys?.length) {
        requestBody.include_translations = 1;
        requestBody.filter_keys = keys?.join();
      }

      return await this.lokaliseApi.keys().list(requestBody);
}

Expected behavior
A clear and concise description of what you expected to happen.
interface ParamsWithPagination is exported

Your environment:

  • Node version: v16.17.0
  • "@lokalise/node-api": "^9.0.0"

Additional context
Add any other context about the problem here.
Screenshot 2022-10-13 at 2 00 45 PM

Typescript as a dependency

The feature I'd like is to move Typescript from a dependency to a devDependency. Is there a reason why it is listed as a dependency currently?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.