2021-03-09 12:39:13 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2021 lingdocs.com
|
|
|
|
*
|
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
import {
|
|
|
|
translatePhonetics,
|
|
|
|
} from "../lib/translate-phonetics";
|
2021-06-24 08:22:19 +00:00
|
|
|
import { psJSXMap } from "../lib/jsx-map";
|
2021-03-09 12:39:13 +00:00
|
|
|
import * as T from "../types";
|
|
|
|
|
|
|
|
const Phonetics = ({ opts, children: text }: {
|
|
|
|
opts: T.TextOptions,
|
2021-06-24 08:22:19 +00:00
|
|
|
children: T.PsJSX | T.PsString | string,
|
2021-03-09 12:39:13 +00:00
|
|
|
}) => {
|
|
|
|
if (opts.phonetics === "none") {
|
|
|
|
return null;
|
|
|
|
}
|
2021-06-24 08:22:19 +00:00
|
|
|
const handleText = (f: string) => (
|
|
|
|
opts.phonetics === "lingdocs"
|
|
|
|
? f
|
|
|
|
: translatePhonetics(f, {
|
2021-03-09 12:39:13 +00:00
|
|
|
dialect: opts.dialect,
|
2021-06-24 08:22:19 +00:00
|
|
|
// @ts-ignore - weird TS not picking up the elimination of "none herre"
|
2021-03-09 12:39:13 +00:00
|
|
|
system: opts.phonetics,
|
2021-06-24 08:22:19 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
return <span className="f-text">
|
2021-06-24 08:51:52 +00:00
|
|
|
{(typeof text !== "string" && typeof text.f !== "string")
|
|
|
|
? psJSXMap(text as T.PsJSX, "f", ({f}) => handleText(f))
|
|
|
|
: handleText(typeof text === "string" ? text : text.f as string)}
|
2021-03-09 12:39:13 +00:00
|
|
|
</span>
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Phonetics;
|