Skip to content

Commit

Permalink
fix: script translations
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaucau committed Nov 8, 2023
1 parent 3ea1869 commit e4190c2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
1 change: 0 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export const TEXT_DOMAIN = "gpt-vision-img-alt-generator";
export const API_PATH = "acp/ai-alt-generator";
21 changes: 13 additions & 8 deletions src/editor/components/GenerateAltButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { useState } from "@wordpress/element";
import { useDispatch } from "@wordpress/data";
import { store as noticesStore } from "@wordpress/notices";

import { TEXT_DOMAIN } from "../../constants";
import generateAltText from "../../utils/generateAltText";

export default ({
Expand All @@ -24,7 +23,7 @@ export default ({
confirmed = confirm(
__(
"Are you sure you want to overwrite the existing alt text?",
TEXT_DOMAIN,
"gpt-vision-img-alt-generator",
),
);
}
Expand All @@ -37,16 +36,22 @@ export default ({
const alt = await generateAltText(attributes.id);
setAttributes({ alt });

await createSuccessNotice(__("Alternative text generated", TEXT_DOMAIN), {
type: "snackbar",
id: "alt-text-generated",
});
await createSuccessNotice(
__("Alternative text generated", "gpt-vision-img-alt-generator"),
{
type: "snackbar",
id: "alt-text-generated",
},
);
//@ts-ignore
} catch (error: WPError) {
if (error.message) {
await createErrorNotice(
sprintf(
__("There was an error generating the alt text: %s", TEXT_DOMAIN),
__(
"There was an error generating the alt text: %s",
"gpt-vision-img-alt-generator",
),
error.message,
),
{
Expand All @@ -67,7 +72,7 @@ export default ({
isBusy={isGenerating}
disabled={isGenerating}
>
{__("Generate alternative text", TEXT_DOMAIN)}
{__("Generate alternative text", "gpt-vision-img-alt-generator")}
</Button>
);
};
5 changes: 3 additions & 2 deletions src/editor/components/ImageBlockInspectorControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { InspectorControls } from "@wordpress/block-editor";
import { Panel, PanelBody } from "@wordpress/components";
import { __ } from "@wordpress/i18n";

import { TEXT_DOMAIN } from "../../constants";
import GenerateAltButton from "./GenerateAltButton";

export default ({
Expand All @@ -17,7 +16,9 @@ export default ({
return (
<InspectorControls>
<Panel>
<PanelBody title={__("GPT Vision Alt Generator", TEXT_DOMAIN)}>
<PanelBody
title={__("GPT Vision Alt Generator", "gpt-vision-img-alt-generator")}
>
<GenerateAltButton
attributes={attributes}
setAttributes={setAttributes}
Expand Down
13 changes: 9 additions & 4 deletions src/media/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { createElement, qs } from "ts-dom-utils";
import { __, sprintf } from "@wordpress/i18n";

import { TEXT_DOMAIN } from "../constants";
import generateAltText from "../utils/generateAltText";

wp.media.view.Attachment.Details = wp.media.view.Attachment.Details.extend({
Expand Down Expand Up @@ -31,15 +30,18 @@ wp.media.view.Attachment.Details = wp.media.view.Attachment.Details.extend({

const button = createElement("button", {
class: "button",
text: __("Generate Alt Text using GPT Vision", TEXT_DOMAIN),
text: __(
"Generate Alt Text using GPT Vision",
"gpt-vision-img-alt-generator",
),
onclick: async (e) => {
const currentAlt = this.model.get("alt");
if (currentAlt?.length) {
if (
!confirm(
__(
"Are you sure you want to overwrite the current alt text?",
TEXT_DOMAIN,
"gpt-vision-img-alt-generator",
),
)
) {
Expand All @@ -59,7 +61,10 @@ wp.media.view.Attachment.Details = wp.media.view.Attachment.Details.extend({
} catch (error) {
alert(
sprintf(
__("There was an error generating the alt text: %s", TEXT_DOMAIN),
__(
"There was an error generating the alt text: %s",
"gpt-vision-img-alt-generator",
),
error.message,
),
);
Expand Down

0 comments on commit e4190c2

Please sign in to comment.