Skip to content
Open
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
79 changes: 79 additions & 0 deletions .github/workflows/validate-merge-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Validate @agape/i18n

on:
pull_request:

jobs:
test:
name: Unit Tests
runs-on: ubuntu-latest
env:
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}

steps:
- name: Checkout agape-i18n (this repo)
uses: actions/checkout@v4

- name: Extract branch name
id: extract_branch
run: echo "branch=${GITHUB_HEAD_REF}" >> $GITHUB_OUTPUT

- name: Configure Git to use PAT for submodules
run: |
git config --global url."https://${{ secrets.GH_PAT }}@github.com/".insteadOf "git@github.com:"

- name: Clone AgapeToolkit monorepo (with submodules)
run: |
git clone --recurse-submodules git@github.com:AgapeToolkit/AgapeToolkit.git ../AgapeToolkit
cd ../AgapeToolkit

# Try to switch top-level AgapeToolkit repo to matching branch
echo "🔍 Checking if top-level repo has branch: ${{ steps.extract_branch.outputs.branch }}"
git fetch origin
if git rev-parse --verify origin/${{ steps.extract_branch.outputs.branch }} >/dev/null 2>&1; then
echo "✅ Switching top-level repo to branch ${{ steps.extract_branch.outputs.branch }}"
git checkout ${{ steps.extract_branch.outputs.branch }}
git pull origin ${{ steps.extract_branch.outputs.branch }}
else
echo "🛑 No matching branch in top-level repo — leaving default"
fi

# Now handle submodules
git submodule foreach --quiet --recursive '
echo "🔍 Checking submodule: $name"
if [ "$name" = "libs/i18n" ]; then
echo "⚠️ Skipping $name (current module)"
exit 0
fi
cd "$toplevel/$name"
git fetch origin
if git rev-parse --verify origin/${{ steps.extract_branch.outputs.branch }} >/dev/null 2>&1; then
echo "✅ Switching $name to branch ${{ steps.extract_branch.outputs.branch }}"
git checkout ${{ steps.extract_branch.outputs.branch }}
git pull origin ${{ steps.extract_branch.outputs.branch }}
else
echo "🛑 No matching branch in $name — leaving on default"
fi
'

- name: Replace library code in monorepo
run: |
rm -rf ../AgapeToolkit/libs/i18n
cp -r . ../AgapeToolkit/libs/i18n

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '24'

- name: Install monorepo dependencies
working-directory: ../AgapeToolkit
run: npm ci

- name: Run lint for @agape/i18n
working-directory: ../AgapeToolkit
run: npx nx lint i18n

- name: Run tests for @agape/i18n
working-directory: ../AgapeToolkit
run: npx nx test i18n --no-watch --ci
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
2 changes: 2 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
npx nx lint i18n
npx nx test i18n --no-watch --ci
27 changes: 27 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
MIT License

Copyright (c) 2025 Maverik Minett

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the “Software”), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

### Attribution and Authorship Notice

Portions of this software were generated with the assistance of AI tools
(ChatGPT and/or Cursor) under the creative direction and supervision of
the author. The overall design, structure, and implementation decisions
are original works authored by Maverik Minett.
2 changes: 0 additions & 2 deletions README.md

This file was deleted.

Empty file added build-plans/build-plan-01.md
Empty file.
16 changes: 16 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* eslint-disable */
export default {
displayName: 'agape-i18n',
preset: '../../jest.preset.js',
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
},
},
testEnvironment: 'node',
transform: {
'^.+\\.[tj]s$': 'ts-jest',
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../../coverage/libs/i18n',
};
40 changes: 40 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "@agape/i18n",
"version": "0.0.0",
"description": "Internationalization utilities including locales, translated names for weekdays, languages, units, and other locale-specific data",
"main": "./cjs/index.js",
"module": "./es2022/index.js",
"author": {
"name": "Maverik Minett",
"email": "maverik.minett@gmail.com"
},
"license": "MIT",
"publishConfig": {
"access": "public"
},
"homepage": "https://agape.dev",
"repository": {
"type": "git",
"url": "https://github.com/AgapeToolkit/AgapeToolkit"
},
"keywords": [
"agape",
"i18n",
"localization",
"internationalization",
"locales",
"i18n",
"locale"
],
"exports": {
"./package.json": {
"default": "./package.json"
},
".": {
"node": "./cjs/index.js",
"default": "./es2022/index.js",
"require": "./cjs/index.js",
"import": "./es2022/index.js"
}
}
}
47 changes: 47 additions & 0 deletions project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "i18n",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/i18n/src",
"projectType": "library",
"targets": {
"build": {
"executor": "@nx/js:tsc",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/libs/i18n",
"main": "libs/i18n/src/index.ts",
"tsConfig": "libs/i18n/tsconfig.lib.json",
"assets": ["libs/agape/*.md"]
}
},
"publish": {
"executor": "nx:run-commands",
"options": {
"command": "node tools/scripts/publish.mjs i18n {args.ver} {args.tag}"
},
"dependsOn": ["build"]
},
"lint": {
"executor": "@nx/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["libs/i18n/**/*.ts"]
}
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "libs/i18n/jest.config.ts",
"passWithNoTests": true
},
"configurations": {
"ci": {
"ci": true,
"codeCoverage": true
}
}
}
},
"tags": []
}
Binary file added src/.DS_Store
Binary file not shown.
8 changes: 8 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

export * from './lib/i18n';
export * from './lib/localized';
export * from './lib/localized-ref';
export * from './lib/plural-ref';
export * from './lib/pluralized';
export * from './lib/translator';
export * from './lib/types';
3 changes: 3 additions & 0 deletions src/lib/i18n.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Translator } from './translator';

export const i18n = new Translator(null);
24 changes: 24 additions & 0 deletions src/lib/localized.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { LocalizedRef } from './localized-ref';
import { LocalizedForms } from './localized-ref';

/**
* Factory function for creating localized translation references.
*
* @param locales - Record of locale codes to their translations
* @returns A new LocalizedRef instance
*
* @example
* const userRef = localized({
* en: 'user',
* es: 'usuario',
* fr: 'utilisateur'
* });
*
* const pluralizedRef = localized({
* en: pluralized({ one: 'user', other: 'users' }),
* es: pluralized({ one: 'usuario', other: 'usuarios' })
* });
*/
export function localized(locales: LocalizedForms): LocalizedRef {
return new LocalizedRef(locales);
}
20 changes: 20 additions & 0 deletions src/lib/pluralized.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { PluralRef } from './plural-ref';
import { PluralForms } from './types';

/**
* Factory function for creating pluralized translation references.
*
* @param forms - Object containing plural form definitions
* @returns A new PluralRef instance
*
* @example
* const userRef = pluralized({ one: 'user', other: 'users' });
* const messageRef = pluralized({
* zero: 'no messages',
* one: 'one message',
* other: '{count} messages'
* });
*/
export function pluralized(forms: Partial<PluralForms>): PluralRef {
return new PluralRef(forms);
}
53 changes: 53 additions & 0 deletions src/lib/private/case-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { CasePattern } from '../types';

/**
* Detects the case pattern of a given text string.
*
* @param text - The text to analyze
* @returns The detected case pattern
*/
export function detectCasePattern(text: string): CasePattern {
if (text === text.toLowerCase()) {
return 'lowercase';
}

if (text === text.toUpperCase()) {
return 'uppercase';
}

// Check for title case (each word starts with capital letter)
const words = text.split(' ');
const titleCase = words.map(word =>
word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()
).join(' ');
if (text === titleCase) {
return 'titlecase';
}

return 'mixed';
}

/**
* Applies a case pattern to a given text string.
*
* @param text - The text to transform
* @param pattern - The case pattern to apply
* @returns The text with the applied case pattern
*/
export function applyCasePattern(text: string, pattern: CasePattern): string {
switch (pattern) {
case 'lowercase':
return text.toLowerCase();
case 'uppercase':
return text.toUpperCase();
case 'titlecase':
return text.split(' ').map(word =>
word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()
).join(' ');
case 'mixed':
// For mixed case, we can't reliably transform, so return as-is
return text;
default:
return text;
}
}
Loading
Loading