Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"type": "module",
"name": "react-native-autolocalise",
"version": "0.2.0",
"version": "0.2.1",
"description": "Auto-translation SDK for React Native and Expo applications",
"main": "dist/index.js",
"module": "dist/index.esm.js",
Expand All @@ -24,9 +24,9 @@
"author": "AutoLocalise",
"license": "MIT",
"peerDependencies": {
"react": ">=18.0.0",
"react-native": ">=0.73.0",
"@react-native-async-storage/async-storage": ">=1.18.0"
"react": ">=16.8.0",
"react-native": ">=0.60.0",
"@react-native-async-storage/async-storage": ">=1.0.0"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^25.0.0",
Expand Down
4 changes: 3 additions & 1 deletion src/services/translation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
TranslationResponse,
} from "../types";
import { getStorageAdapter } from "../storage";
import { VERSION } from "../version";

export class TranslationService {
private config: TranslationConfig;
Expand Down Expand Up @@ -87,12 +88,13 @@ export class TranslationService {
this.pendingTranslations.clear();

if (allTexts.length > 0) {
// Modify API request to include context
// Modify API request to include context and version
const request: TranslationRequest = {
texts: allTexts,
sourceLocale: this.config.sourceLocale,
targetLocale: this.config.targetLocale,
apiKey: this.config.apiKey,
version: `react-native-v${VERSION}`,
};

try {
Expand Down
13 changes: 6 additions & 7 deletions src/storage/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
// import AsyncStorage from "@react-native-async-storage/async-storage";

interface StorageAdapter {
getItem: (key: string) => Promise<string | null>;
setItem: (key: string, value: string) => Promise<void>;
removeItem: (key: string) => Promise<void>;
}
import { StorageAdapter } from "../types";

export async function getStorageAdapter(): Promise<StorageAdapter> {
try {
Expand All @@ -14,6 +8,11 @@ export async function getStorageAdapter(): Promise<StorageAdapter> {
if (AsyncStorage?.default) {
return AsyncStorage.default;
}

// If AsyncStorage is not available, throw an error
throw new Error(
"No storage adapter available. Please install @react-native-async-storage/async-storage"
);
} catch (e) {
throw new Error(
"No storage adapter available. Please install @react-native-async-storage/async-storage"
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface TranslationRequest {
sourceLocale: string;
targetLocale: string;
apiKey: string;
version: string;
}

export interface TranslationResponse {
Expand Down
10 changes: 10 additions & 0 deletions src/types/async-storage.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
declare module "@react-native-async-storage/async-storage" {
interface AsyncStorageStatic {
getItem(key: string): Promise<string | null>;
setItem(key: string, value: string): Promise<void>;
removeItem(key: string): Promise<void>;
}

const AsyncStorage: AsyncStorageStatic;
export default AsyncStorage;
}
3 changes: 3 additions & 0 deletions src/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This file is auto-generated during build
// Update this manually or via build script
export const VERSION = "0.2.1";
Loading