Skip to content

Commit

Permalink
"
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoobes committed Feb 5, 2024
1 parent 3b4f9b9 commit 2c0d341
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 116 deletions.
6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
"discord.js": "^14.11.0",
"eslint": "8.39.0",
"prettier": "2.8.8",
"shrimple-locales": "^0.2.0",
"tsup": "^6.7.0",
"typescript": "5.0.2",
"vitest": "latest"
Expand Down Expand Up @@ -95,8 +94,5 @@
"type": "git",
"url": "git+https://github.com/sern-handler/handler.git"
},
"homepage": "https://sern.dev",
"peerDependencies": {
"shrimple-locales": "^0.2.0"
}
"homepage": "https://sern.dev"
}
1 change: 0 additions & 1 deletion src/core/contracts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ export * from './module-store';
export * from './init';
export * from './emitter';
export * from './disposable'
export * from './localization'
11 changes: 0 additions & 11 deletions src/core/contracts/localization.ts

This file was deleted.

46 changes: 0 additions & 46 deletions src/core/ioc/dependency-injection.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import assert from 'node:assert';
import type { IntoDependencies } from '../../types/ioc';
import { useContainerRaw } from './base';
import { fileURLToPath } from 'node:url';
import path from 'node:path';
import { requir } from '../module-loading';
import type { Localization } from '../contracts';

/**
* @__PURE__
Expand Down Expand Up @@ -59,45 +55,3 @@ export function useContainer<const T extends Dependencies>() {
keys.map(key => useContainerRaw().get(key as keyof Dependencies)) as IntoDependencies<V>;
}

/**
* Translates a string to its respective local
* Note: this method only works AFTER your container has been initiated
* @example
* ```ts
* assert.deepEqual(locals("salute.hello", "es"), "hola")
* ```
*/
export const local = (i: string, local: string) => {
return Service('@sern/localizer').translate(i, local)
}

/**
* Returns a record of locales to their respective translations.
* Note: this method only works AFTER your container has been initiated
* @example
* ```ts
* assert.deepEqual(localsFor("salute.hello"), { "en-US": "hello", "es": "hola" })
* ```
*/
export const localsFor = (path: string) => {
return Service('@sern/localizer').translationsFor(path)
}
/**
* A service which provides simple file based localization. Add this while making dependencies.
* @example
* ```ts
* await makeDependencies(({ add }) => {
* add('@sern/localizer', DefaultLocalization());
* });
* ```
**/
export const DefaultLocalization = (defaultLocale?: string) => {
const packageDirectory = fileURLToPath(import.meta.url);
const pathToLocalizer= path.resolve(packageDirectory, "../", "optional", "localizer");
const { ShrimpleLocalizer } = requir(pathToLocalizer);
const localizer = new ShrimpleLocalizer as Localization;
if (defaultLocale) {
localizer.currentLocale = defaultLocale;
}
return localizer;
}
2 changes: 1 addition & 1 deletion src/core/ioc/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { makeDependencies } from './base';
export { Service, Services, single, transient, local, localsFor, DefaultLocalization } from './dependency-injection';
export { Service, Services, single, transient } from './dependency-injection';
46 changes: 0 additions & 46 deletions src/optional/localizer.ts

This file was deleted.

6 changes: 3 additions & 3 deletions src/types/core-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ import type {
TextCommand,
UserSelectCommand,
} from './core-modules';
import { Args, Awaitable, Payload, SlashOptions } from './utility';
import { CommandType, Context, EventType, PluginType } from '../core';
import {
import type { Args, Awaitable, Payload, SlashOptions } from './utility';
import type { CommandType, Context, EventType, PluginType } from '../core';
import type {
ButtonInteraction,
ChannelSelectMenuInteraction,
ClientEvents,
Expand Down
4 changes: 3 additions & 1 deletion src/types/ioc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export interface CoreDependencies {
'@sern/modules': () => Contracts.ModuleManager;
'@sern/errors': () => Contracts.ErrorHandling;
'@sern/logger'?: () => Contracts.Logging;
'@sern/localizer'?: () => Contracts.Localization
}

export type DependencyFromKey<T extends keyof Dependencies> = Dependencies[T];
Expand All @@ -40,6 +39,9 @@ export type IntoDependencies<Tuple extends [...any[]]> = {
[Index in keyof Tuple]: UnpackFunction<NonNullable<DependencyFromKey<Tuple[Index]>>>; //Unpack and make NonNullable
} & { length: Tuple['length'] };

/**
* @deprecated This old signature will be incompatible with future versions of sern.
*/
export interface DependencyConfiguration {
/*
* @deprecated. Loggers will be opt-in the future
Expand Down
4 changes: 2 additions & 2 deletions tsup.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineConfig } from 'tsup';
const shared = {
entry: ['src/index.ts', 'src/optional/localizer.ts'],
external: ['discord.js', 'iti', 'shrimple-locales'],
entry: ['src/index.ts'],
external: ['discord.js', 'iti'],
platform: 'node',
clean: true,
sourcemap: true,
Expand Down

0 comments on commit 2c0d341

Please sign in to comment.