Skip to content

Commit

Permalink
i18n fixes (#1377)
Browse files Browse the repository at this point in the history
* i18n fixes

* Removing unused lang, linting, etc

* lint
  • Loading branch information
HughParry authored Sep 19, 2024
1 parent 6d0e187 commit 78d37cf
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
5 changes: 3 additions & 2 deletions demos/client-example/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@ import { getServerUrl } from "@prosopo/server";
// See the License for the specific language governing permissions and
// limitations under the License.
import {
ProcaptchaConfigSchema,
type ProsopoClientConfigOutput,
ProsopoClientConfigSchema,
} from "@prosopo/types";

const config: ProsopoClientConfigOutput = ProsopoClientConfigSchema.parse({
const config: ProsopoClientConfigOutput = ProcaptchaConfigSchema.parse({
account: {
address: process.env.PROSOPO_SITE_KEY,
},
web2: process.env.PROSOPO_WEB2 !== "false",
defaultEnvironment: process.env.PROSOPO_DEFAULT_ENVIRONMENT,
dappName: "client-example",
serverUrl: getServerUrl(),
theme: "light",
});

export default config;
4 changes: 4 additions & 0 deletions packages/common/src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ const reactOptions: InitOptions = {
react: {
useSuspense: false,
},
detection: {
order: ["navigator", "htmlTag", "path", "subdomain"],
caches: ["localStorage", "cookie"],
},
};

const nodeOptions: InitOptions = {};
Expand Down
7 changes: 5 additions & 2 deletions packages/procaptcha-bundle/src/util/language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ export const setLanguage = (
config: ProcaptchaClientConfigInput,
) => {
const languageAttribute =
renderOptions?.language || element.getAttribute("data-language") || "en";
config.language = validateLanguage(languageAttribute);
renderOptions?.language || element.getAttribute("data-language");

if (languageAttribute) {
config.language = validateLanguage(languageAttribute);
}
};

const validateLanguage = (
Expand Down
2 changes: 0 additions & 2 deletions packages/procaptcha-react/src/components/ProcaptchaWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ const ProcaptchaWidget = (props: ProcaptchaProps) => {
if (config.language) {
i18n.changeLanguage(config.language);
}

console.log(config.language);
}, [config.language]);

return (
Expand Down
5 changes: 2 additions & 3 deletions packages/types/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@ export const ProsopoCaptchaSolutionConfigSchema = object({
captchaBlockRecency: number().positive().min(2),
});

export const LanguageSchema = z.enum(["en", "es", "pt"]);

export const ProsopoClientConfigSchema = ProsopoBasicConfigSchema.merge(
object({
userAccountAddress: string().optional(),
Expand Down Expand Up @@ -255,13 +253,14 @@ export type ProsopoClientConfigOutput = output<
>;

const ThemeType = union([literal("light"), literal("dark")]);
export const LanguageSchema = z.enum(["en", "pt", "es"]);

export const ProcaptchaConfigSchema = ProsopoClientConfigSchema.and(
object({
accountCreator: AccountCreatorConfigSchema.optional(),
theme: ThemeType.optional().default("light"),
captchas: CaptchaTimeoutSchema.optional().default(defaultCaptchaTimeouts),
language: LanguageSchema.optional().default("en"),
language: LanguageSchema.optional(),
}),
);

Expand Down

0 comments on commit 78d37cf

Please sign in to comment.