i18n: add createTranslator
This commit is contained in:
		
							parent
							
								
									8a9c788fe1
								
							
						
					
					
						commit
						4ae3def190
					
				
					 2 changed files with 11 additions and 7 deletions
				
			
		| 
						 | 
				
			
			@ -2,7 +2,6 @@ import {
 | 
			
		|||
  ParentComponent,
 | 
			
		||||
  createContext,
 | 
			
		||||
  createMemo,
 | 
			
		||||
  createRenderEffect,
 | 
			
		||||
  createResource,
 | 
			
		||||
  useContext,
 | 
			
		||||
} from "solid-js";
 | 
			
		||||
| 
						 | 
				
			
			@ -12,7 +11,7 @@ import { $settings } from "../settings/stores";
 | 
			
		|||
import { enGB } from "date-fns/locale/en-GB";
 | 
			
		||||
import { useStore } from "@nanostores/solid";
 | 
			
		||||
import type { Locale } from "date-fns";
 | 
			
		||||
import type { Template } from "@solid-primitives/i18n";
 | 
			
		||||
import { resolveTemplate, translator, type Template } from "@solid-primitives/i18n";
 | 
			
		||||
 | 
			
		||||
async function synchronised(
 | 
			
		||||
  name: string,
 | 
			
		||||
| 
						 | 
				
			
			@ -181,3 +180,9 @@ export function createStringResource<
 | 
			
		|||
    },
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function createTranslator<T extends ImportFn<Record<string, string | Template<any> | undefined>>[],>(...importFns: T) {
 | 
			
		||||
  const res = createStringResource(...importFns)
 | 
			
		||||
 | 
			
		||||
  return [translator(res[0], resolveTemplate), res] as const
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue