Skip to content

Commit

Permalink
Merge pull request #35 from SARDONYX-sard/feature/implement-custom-i18n
Browse files Browse the repository at this point in the history
Feature/implement custom i18n
  • Loading branch information
SARDONYX-sard authored Jan 16, 2024
2 parents 33f1033 + 4c6450c commit 0cda93c
Showing 20 changed files with 922 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -12,7 +12,8 @@ build
# misc
.DS_Store
*.pem
test/
test/data/*
!test/data/*.md
*.log

# Rust build cache
2 changes: 1 addition & 1 deletion dar2oar_core/benches/convert_n_thread.rs
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ use tokio::fs;
const REMOVE_TARGET: &str =
"../test/data/UNDERDOG Animations/meshes/actors/character/animations/OpenAnimationReplacer";
const TARGET: &str = "../test/data/UNDERDOG Animations";
const TABLE_PATH: &str = "../test/settings/UnderDog Animations_v1.9.6_mapping_table.txt";
const TABLE_PATH: &str = "../test/mapping_tables/UnderDog Animations_v1.9.6_mapping_table.txt";

fn criterion_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("dar2oar sequential vs parallel");
2 changes: 1 addition & 1 deletion dar2oar_core/src/fs/converter/mod.rs
Original file line number Diff line number Diff line change
@@ -116,7 +116,7 @@ mod test {
use anyhow::Result;

const DAR_DIR: &str = "../test/data/UNDERDOG Animations";
const TABLE_PATH: &str = "../test/settings/UnderDog Animations_v1.9.6_mapping_table.txt";
const TABLE_PATH: &str = "../test/mapping_tables/UnderDog Animations_v1.9.6_mapping_table.txt";

async fn create_options() -> Result<ConvertOptions> {
Ok(ConvertOptions {
2 changes: 1 addition & 1 deletion frontend/src/components/buttons/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @index('./*', f => `export * from '${f.path}'`)
export * from './convert_btn';
export * from './log_file_btn';
export * from './log_dir_btn';
export * from './log_file_btn';
export * from './path_selector';
export * from './remove_oar_btn';
export * from './unhide_dar_btn';
1 change: 1 addition & 0 deletions frontend/src/components/lists/translation_list.tsx
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@ export const TranslationList = () => {
<MenuItem value={'auto'}>Auto</MenuItem>
<MenuItem value={'en-US'}>English(US)</MenuItem>
<MenuItem value={'ja-JP'}>Japanese</MenuItem>
<MenuItem value={'custom'}>Custom</MenuItem>
</Select>
</FormControl>
</Tooltip>
3 changes: 2 additions & 1 deletion frontend/src/hooks/dyn_style.ts
Original file line number Diff line number Diff line change
@@ -45,7 +45,8 @@ export function useInjectScript(initialState = (() => localStorage.getItem('cust
const scriptElement = document.createElement('script');
if (pathname !== window.location.pathname) {
try {
scriptElement.innerText = script;
// comment remove script
scriptElement.innerHTML = script;
scriptElement.id = 'custom-script';
if (!document.getElementById('custom-script')) {
document.body.appendChild(scriptElement);
11 changes: 11 additions & 0 deletions frontend/src/utils/translation.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
'use client';
import { use, type Resource } from 'i18next';
import { toast } from 'react-hot-toast';
import { initReactI18next } from 'react-i18next';

import dictEnUS from '@/../../locales/en-US.json';
import dictJaJP from '@/../../locales/ja-JP.json';

function getCustomTranslationDict() {
try {
return JSON.parse(localStorage.getItem('custom-translation-dict') ?? '{}');
} catch (error) {
toast.error(`${error}`);
}
}

// The keys in RESOURCE are language tags according to the BCP-47 standard.
// See: https://partnerhub.warnermediagroup.com/metadata/languages
const resources = {
@@ -14,7 +23,9 @@ const resources = {
'ja-JP': {
translation: dictJaJP,
},
custom: { translation: getCustomTranslationDict() },
} as const satisfies Resource;

export type I18nKeys = keyof (typeof resources)['en-US']['translation'];

use(initReactI18next) // passes i18n down to react-i18next
29 changes: 29 additions & 0 deletions test/data/download-mods.ps1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Setup test mods

At this time, automatic installation is not possible and must be downloaded
manually.

```powershell
<# function Get-Mod([string]$dist, [string]$url) {
Invoke-WebRequest $url -OutFile "$dist.zip"
7zip "$dist.zip" -DestinationPath $dist
# Remove-Item "$dist.zip"
} #>
@(
@(
$dist = 'Animated Armoury DAR Modified Conditions'
$url = 'https://www.nexusmods.com/skyrimspecialedition/mods/74320?tab=files&file_id=395456'
),
@(
$dist = 'Modern Female Sitting Animations Overhaul'
$url = 'https://www.nexusmods.com/skyrimspecialedition/mods/85599?tab=files&file_id=444438'
),
@(
$dist = 'UNDERDOG - Animations'
$url = 'https://www.nexusmods.com/skyrimspecialedition/mods/51811?tab=files&file_id=461119'
)
)
# Get-Mod $dist $url
```
39 changes: 39 additions & 0 deletions test/generators/generate-from-dirname.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<#
How to use?
Execute this powershell file by double-clicking it in the root of the mod (where mesh, etc. are located).
PowerShell files written on someone else's PC may be blocked for security reasons.
In that case, you can create a new file by yourself and copy the contents of this file.
#>

$target = "." # target dir(. == current dir)
$mappingFile = "mapping_table.txt"

# Search for the path containing the "_CustomConditions" directory
$dirPath = $(Get-ChildItem -Path $target -Directory -Recurse -Filter "_CustomConditions").FullName

# Get the list of directories
$directories = Get-ChildItem -Path $dirPath -Directory | Sort-Object Name

# Define a regular expression pattern to extract the desired information
$pattern = '(\d+)\s*-\s*(.+)'

# Initialize an array to store the results
$results = @()

# Process each directory
foreach ($directory in $directories) {
$name = $directory.Name
if ($name -match $pattern) {
$number = $matches[1]
$name = $matches[2]
$results += "$number $name"
} else {
$results += $directory.Name
}
}

# Write the results to the mapping_table.txt file in UTF-8 encoding
$results | Out-File -FilePath $mappingFile -Encoding utf8

Write-Host "Mapping table has been written to $mappingFile"
39 changes: 39 additions & 0 deletions test/generators/generate_table_from_txt.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<#
- How to use?
Execute this powershell file by double-clicking it in the root of the mod (where mesh, etc. are located).
PowerShell files written on someone else's PC may be blocked for security reasons.
In that case, you can create a new file by yourself and copy the contents of this file.
- When use powershell command
powershell.exe -ExecutionPolicy Bypass -File "./generate_table_from_txt.ps1"
#>

$target = "." # target dir(. == current dir)
$mappingFile = "mapping_table.txt"
$renameFrom = "\s*\d+\s*" # Regexp
$renameTo = ""

# Search for the path containing the "_CustomConditions" directory
$dirPath = $(Get-ChildItem -Path $target -Directory -Recurse -Filter "_CustomConditions").FullName

# Get the list of directories
$directories = Get-ChildItem -Path $dirPath -Recurse -Filter '*.txt' | Sort-Object Name

# Initialize an array to store the results
$results = @()
foreach ($dir in $directories)
{
$number = Split-Path $dir -Parent | Split-Path -Leaf # Get DAR priority dirname
if ($dir.Name -match '\s*\d+\s*')
{
$name = $dir.BaseName -replace $renameFrom, $renameTo
$results += "$number $name"
}
}

# Write the results to the mapping_table.txt file in UTF-8 encoding
$results | Out-File -FilePath $mappingFile -Encoding utf8

Write-Host $results
Write-Host "Mapping table has been written to $mappingFile"
36 changes: 36 additions & 0 deletions test/generators/generate_table_from_txt2.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<#
How to use?
Execute this powershell file by double-clicking it in the root of the mod (where mesh, etc. are located).
PowerShell files written on someone else's PC may be blocked for security reasons.
In that case, you can create a new file by yourself and copy the contents of this file.
#>

$target = "." # target dir(. == current dir)
$mappingFile = "mapping_table.txt"
$renameFrom = "" # Regexp
$renameTo = ""

# Search for the path containing the "_CustomConditions" directory
$dirPath = $(Get-ChildItem -Path $target -Directory -Recurse -Filter "_CustomConditions").FullName

# Get the list of directories
$directories = Get-ChildItem -Path $dirPath -Recurse -Filter '*.txt' | Sort-Object Name

# Initialize an array to store the results
$results = @()
foreach ($dir in $directories)
{
$number = Split-Path $dir -Parent | Split-Path -Leaf # Get DAR priority dirname
if ($dir.Name -ne '_condition.txt')
{
$name = $dir.BaseName -replace $renameFrom, $renameTo
$results += "$number $name"
}
}

# Write the results to the mapping_table.txt file in UTF-8 encoding
$results | Out-File -FilePath $mappingFile -Encoding utf8

Write-Host $results
Write-Host "Mapping table has been written to $mappingFile"
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
10 Rapier
11 Pikes
12 Halberds
13 QuarterStaffs
14 Claw-in-Right-hand
15 Cestus
18 Whips
19 Katana-with-Something-in-Left-hand
29 Claw-in-Left-hand
30 Claws-in-both-hands
31 Whip-in-Left-hand
32 Whip-in-both-hands-left-hand
42 QuarterStaffs
43 Maces
44 Daggers-in-Right-Hand
45 Katana-with-Nothing-in-Left-hand
46 Claws-in-both-hands
47 Whip-in-Left-hand
48 Pikes
49 Halberds
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
10 Rapier
11 Pikes
12 Halberds
13 QuarterStaffs
14 Claw
15 Cestus
18 Whips
19 Katanas

29 Claw-in-Left-hand
30 Claws-in-both-hands
31 Whip-in-Left-hand
49 changes: 49 additions & 0 deletions test/mapping_tables/EVG Conditional Idles_v1.4.2_mapping_table.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// This file is generated by the following powershell script
// ```PowerShell
// # Search for the path containing the "_CustomConditions" directory
// $dirPath = $(Get-ChildItem -Path "." -Directory -Recurse -Filter "_CustomConditions").FullName
// $mappingFile = "mapping_table.txt"
// $renameFrom = "" # Regexp
// $renameTo = ""
//
// # Get the list of directories
// $directories = Get-ChildItem -Path $dirPath -Recurse -Filter '*.txt' | Sort-Object Name
//
// # Initialize an array to store the results
// $results = @()
// foreach ($dir in $directories)
// {
// $number = Split-Path $dir -Parent | Split-Path -Leaf # Get DAR priority dirname
// if ($dir.Name -ne '_conditions.txt')
// {
// $name = $dir.BaseName -replace $renameFrom, $renameTo
// $results += "$number $name"
// }
// }
//
// # Write the results to the mapping_table.txt file in UTF-8 encoding
// $results | Out-File -FilePath $mappingFile -Encoding utf8
//
// Write-Host $results
// Write-Host "Mapping table has been written to $mappingFile"
// ```

6002125 Cold Player
6002102 Female Modesty Player
6002121 Headache Alt 50 Percent Player
6002120 Headache Player
6002135 Injured Player
6002101 Male Modesty Player
6001925 NPC cold
6001902 NPC Female Modesty
6001921 NPC Headache 50 Alt
6001920 NPC Headache w Fist
6001935 NPC Injured
6001901 NPC Male Modesty
6001910 NPC Shield Cover
6001908 NPC Stamina Stage 1 at 50
6001926 NPC Stamina Stage 2 at 25
6002110 Shield Cover Player
6002108 Stamina Stage 1 at 50 Player
6002126 Stamina Stage 2 at 25 Player
6002090 Stretch 2 Percent
Loading
Oops, something went wrong.

0 comments on commit 0cda93c

Please sign in to comment.