Skip to content

Commit

Permalink
refactor: change text domain to plugin slug
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaucau committed Jan 11, 2024
1 parent d5284ec commit 2c2f3ee
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<rule ref="WordPress.WP.I18n">
<properties>
<property name="text_domain" type="array">
<element value="acpl-ai-alt-generator"/>
<element value="alt-text-generator-gpt-vision"/>
</property>
</properties>
</rule>
Expand Down
8 changes: 4 additions & 4 deletions alt-text-generator-gpt-vision.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Author URI: https://android.com.pl/
* License: GPL v3
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
* Text Domain: acpl-ai-alt-generator
* Text Domain: alt-text-generator-gpt-vision
* @package ACPL\AIAltGenerator
*/

Expand Down Expand Up @@ -61,7 +61,7 @@ private function enqueue_script( string $file_name, array|bool $args = false ):
$asset_file = include ACPL_AI_ALT_PLUGIN_PATH . "build/$file_name.asset.php";
$handle = "acpl/ai-alt-generator/$file_name";
wp_enqueue_script( $handle, ACPL_AI_ALT_PLUGIN_URL . "build/$file_name.js", $asset_file['dependencies'], $asset_file['version'], $args );
wp_set_script_translations( $handle, 'acpl-ai-alt-generator' );
wp_set_script_translations( $handle, 'alt-text-generator-gpt-vision' );
}

private function enqueue_attachment_edit_page_script(): void {
Expand All @@ -77,13 +77,13 @@ public function plugin_row_meta( array $plugin_meta, string $plugin_file ): arra
$plugin_meta[] = sprintf(
'<a href="%s">%s</a>',
admin_url( 'options-media.php#' . Admin::SETTINGS_SECTION_ID ),
__( 'Settings', 'acpl-ai-alt-generator' )
__( 'Settings', 'alt-text-generator-gpt-vision' )
);

$plugin_meta[] = sprintf(
'<a href="%s" target="_blank" rel="noopener noreferrer">%s</a>',
'https://github.com/android-com-pl/wp-ai-alt-generator?sponsor=1',
__( 'Support Development', 'acpl-ai-alt-generator' )
__( 'Support Development', 'alt-text-generator-gpt-vision' )
);
}

Expand Down
20 changes: 10 additions & 10 deletions includes/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ public function add_plugin_settings(): void {

add_settings_section(
self::SETTINGS_SECTION_ID,
__( 'GPT Vision Alt Generator', 'acpl-ai-alt-generator' ),
__( 'GPT Vision Alt Generator', 'alt-text-generator-gpt-vision' ),
function () {
echo '<p>' .
esc_html__( 'This plugin uses the OpenAI API to generate alt text for images.', 'acpl-ai-alt-generator' )
esc_html__( 'This plugin uses the OpenAI API to generate alt text for images.', 'alt-text-generator-gpt-vision' )
. '</p>';
},
'media',
Expand All @@ -53,7 +53,7 @@ function () {

add_settings_field(
'acpl_ai_alt_generator_api_key',
__( 'OpenAI API Key', 'acpl-ai-alt-generator' ),
__( 'OpenAI API Key', 'alt-text-generator-gpt-vision' ),
function () use ( $options ) {
printf(
'<input type="password" id="openai_api_key" name="%1$s[api_key]" value="%2$s" class="regular-text" placeholder="sk-..." autocomplete="off"/>',
Expand All @@ -67,7 +67,7 @@ function () use ( $options ) {
// translators: %s is for link attributes.
__(
'Enter your OpenAI API key here. You can find it in your <a href="https://platform.openai.com/account/api-keys" %s>OpenAI account settings</a>.',
'acpl-ai-alt-generator'
'alt-text-generator-gpt-vision'
),
'target="_blank" rel="noopener noreferrer"'
),
Expand All @@ -90,7 +90,7 @@ function () use ( $options ) {

add_settings_field(
'acpl_ai_alt_generator_auto_generate',
__( 'Auto generate alt text on image upload', 'acpl-ai-alt-generator' ),
__( 'Auto generate alt text on image upload', 'alt-text-generator-gpt-vision' ),
function () use ( $options ) {
printf(
'<input type="checkbox" id="auto_generate_alt" name="%1$s[auto_generate]" %2$s/>',
Expand All @@ -101,7 +101,7 @@ function () use ( $options ) {
echo '<p class="description">' .
esc_html__(
'Enable this option to automatically generate alt text when images are uploaded. Please review generated alt texts as GPT can sometimes produce inaccurate descriptions.',
'acpl-ai-alt-generator'
'alt-text-generator-gpt-vision'
)
. '</p>';
},
Expand All @@ -114,11 +114,11 @@ function () use ( $options ) {

add_settings_field(
'acpl_ai_alt_generator_img_size',
__( 'Detail level', 'acpl-ai-alt-generator' ),
__( 'Detail level', 'alt-text-generator-gpt-vision' ),
function () use ( $options ) {
$detail_levels = [
'high' => _x( 'High', 'Detail level', 'acpl-ai-alt-generator' ),
'low' => _x( 'Low', 'Detail level', 'acpl-ai-alt-generator' ),
'high' => _x( 'High', 'Detail level', 'alt-text-generator-gpt-vision' ),
'low' => _x( 'Low', 'Detail level', 'alt-text-generator-gpt-vision' ),
];

printf( '<select id="detail_level" name="%s[detail]">', esc_attr( AltGeneratorPlugin::OPTION_NAME ) );
Expand All @@ -138,7 +138,7 @@ function () use ( $options ) {
// translators: %s is for link attributes.
__(
'Choose "Low" detail to minimize token usage and costs for image processing, which should be sufficient for most use cases and is significantly cheaper. "High" detail will use more tokens but provides finer detail. For precise token calculations and cost implications, refer to the <a href="https://platform.openai.com/docs/guides/vision/calculating-costs" %s>OpenAI documentation on calculating costs</a>.',
'acpl-ai-alt-generator'
'alt-text-generator-gpt-vision'
),
'target="_blank" rel="noopener noreferrer"'
),
Expand Down
2 changes: 1 addition & 1 deletion includes/AltGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static function generate_alt_text( int $attachment_id ): string|WP_Error
return new WP_Error(
$completion['error']['code'],
// translators: %s is the error message from OpenAI's API.
sprintf( __( "OpenAI's API error: %s", 'acpl-ai-alt-generator' ), $completion['error']['message'] )
sprintf( __( "OpenAI's API error: %s", 'alt-text-generator-gpt-vision' ), $completion['error']['message'] )
);
}

Expand Down
6 changes: 3 additions & 3 deletions includes/Enum/ErrorCodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ enum ErrorCodes: string {

public function get_label(): string {
return match ( $this ) {
self::Not_image => __( 'Attachment ID is not an image.', 'acpl-ai-alt-generator' ),
self::No_API_key => __( "OpenAI's API key is not configured.", 'acpl-ai-alt-generator' ),
self::Img_not_found => __( 'Image not found.', 'acpl-ai-alt-generator' ),
self::Not_image => __( 'Attachment ID is not an image.', 'alt-text-generator-gpt-vision' ),
self::No_API_key => __( "OpenAI's API key is not configured.", 'alt-text-generator-gpt-vision' ),
self::Img_not_found => __( 'Image not found.', 'alt-text-generator-gpt-vision' ),
};
}

Expand Down
8 changes: 4 additions & 4 deletions src/editor/components/GenerateAltButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default ({
!confirm(
__(
"Are you sure you want to overwrite the existing alt text?",
"acpl-ai-alt-generator",
"alt-text-generator-gpt-vision",
),
)
) {
Expand All @@ -36,7 +36,7 @@ export default ({
setAttributes({ alt });

await createSuccessNotice(
__("Alternative text generated", "acpl-ai-alt-generator"),
__("Alternative text generated", "alt-text-generator-gpt-vision"),
{
type: "snackbar",
id: "alt-text-generated",
Expand All @@ -49,7 +49,7 @@ export default ({
sprintf(
__(
"There was an error generating the alt text: %s",
"acpl-ai-alt-generator",
"alt-text-generator-gpt-vision",
),
error.message,
),
Expand All @@ -71,7 +71,7 @@ export default ({
isBusy={isGenerating}
disabled={isGenerating}
>
{__("Generate alternative text", "acpl-ai-alt-generator")}
{__("Generate alternative text", "alt-text-generator-gpt-vision")}
</Button>
);
};
5 changes: 4 additions & 1 deletion src/editor/components/ImageBlockInspectorControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ export default ({
<InspectorControls>
<Panel>
<PanelBody
title={__("GPT Vision Alt Generator", "acpl-ai-alt-generator")}
title={__(
"GPT Vision Alt Generator",
"alt-text-generator-gpt-vision",
)}
>
<GenerateAltButton
attributes={attributes}
Expand Down
6 changes: 3 additions & 3 deletions src/media/components/GenerateAltButon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ export default (

const button = createElement("button", {
class: "button",
text: __("Generate Alt Text", "acpl-ai-alt-generator"),
text: __("Generate Alt Text", "alt-text-generator-gpt-vision"),
onclick: async (e) => {
e.preventDefault();
if (
currentAlt?.length &&
!confirm(
__(
"Are you sure you want to overwrite the current alt text?",
"acpl-ai-alt-generator",
"alt-text-generator-gpt-vision",
),
)
) {
Expand All @@ -51,7 +51,7 @@ export default (
sprintf(
__(
"There was an error generating the alt text: %s",
"acpl-ai-alt-generator",
"alt-text-generator-gpt-vision",
),
error.message,
),
Expand Down

0 comments on commit 2c2f3ee

Please sign in to comment.