Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

86 lang #88

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions alexa/request/certificate.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,10 @@ public function verify_signature_certificate_url() {
} else if ( static::SIGNATURE_VALID_HOSTNAME !== $url['host'] ) {
throw new InvalidArgumentException( __( "Certificate isn't from Amazon. Request isn't from Alexa.", 'voicewp' ) );
} else if ( 0 !== strpos( $url['path'], static::SIGNATURE_VALID_PATH ) ) {
/* translators: %s: folder path */
throw new InvalidArgumentException( sprintf( esc_html__( "Certificate isn't in '%s' folder. Request isn't from Alexa.", 'voicewp' ), static::SIGNATURE_VALID_PATH ) );
} else if ( isset( $url['port'] ) && static::SIGNATURE_VALID_PORT !== $url['port'] ) {
/* translators: %s: port number */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't that be %d

throw new InvalidArgumentException( sprintf( esc_html__( "Port isn't %s. Request isn't from Alexa.", 'voicewp' ), static::SIGNATURE_VALID_PORT ) );
}
}
Expand Down
1 change: 1 addition & 0 deletions alexa/request/request.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public function from_data() {

$request_type = $data['request']['type'];
if ( ! class_exists( '\\Alexa\\Request\\' . $request_type ) ) {
/* translators: %s: type of Alexa request being made */
throw new RuntimeException( sprintf( esc_html__( 'Unknown request type: %s', 'voicewp' ), $request_type ) );
}

Expand Down
24 changes: 22 additions & 2 deletions alexa/skill/news.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,13 @@ public function news_request( $request, $response ) {
* unlike the case for all other numbers.
*/
$post_number = 2;
} elseif ( is_numeric( $maybe_post_number = substr( $post_number, 0, -2 ) ) ) {
$post_number = $maybe_post_number;
} else {
$post_number = substr( $post_number, 0, -2 );
$ordinals = array_flip( $this->get_ordinals() );
if ( isset( $ordinals[ $post_number ] ) ) {
$post_number = $ordinals[ $post_number ];
}
}
} else {
$post_number = $request->getSlot( 'PostNumber' );
Expand Down Expand Up @@ -218,6 +223,20 @@ private function message( $response, $case = 'missing' ) {
}
}

/**
* Returns an array of ordinal strings that correspond to their array keys
* @return array Array of translateable ordinal strings
*/
public function get_ordinals() {
return array(
1 => esc_html__( 'first', 'voicewp' ),
2 => esc_html__( 'second', 'voicewp' ),
3 => esc_html__( 'third', 'voicewp' ),
4 => esc_html__( 'fourth', 'voicewp' ),
5 => esc_html__( 'fifth', 'voicewp' ),
);
}

/**
* Creates output when a user asks for a list of posts.
* Delivers an array containing a numbered list of post titles
Expand All @@ -235,12 +254,13 @@ public function endpoint_content( $args ) {

$content = $card_content = '';
$ids = array();
$ordinals = $this->get_ordinals();
if ( ! empty( $news_posts ) && ! is_wp_error( $news_posts ) ) {

foreach ( $news_posts as $key => $news_post ) {
// Appending 'th' to any number results in proper ordinal pronunciation
// TODO: Sounds a little strange when there's only one result.
$content .= ( $key + 1 ) . 'th, ' . $news_post->post_title . '. ';
$content .= $ordinals[ $key + 1 ] . ', ' . $news_post->post_title . '. ';
$card_content .= ( $key + 1 ) . '. ' . $news_post->post_title . "\n";
$ids[] = $news_post->ID;
}
Expand Down
2 changes: 2 additions & 0 deletions inc/class-voicewp-setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ public function tiny_mce_before_init( $settings ) {
* @since 1.0.0
*/
public function plugins_loaded() {
// Load translation files
load_plugin_textdomain( 'voicewp', false, dirname( plugin_basename( __FILE__ ) ) . '/lang' );
// Determine if the database version and code version are the same.
$current_version = get_option( 'voicewp_version' );
if ( version_compare( $current_version, self::$version, '>=' ) ) {
Expand Down
14 changes: 12 additions & 2 deletions inc/fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,16 @@ function ( $taxonomy ) use ( $news_post_types ) {
),
) );

require_once( VOICEWP_PATH . '/speechAssets/utterances.php' );

$intent_schema = '';

foreach ( $news_utterances as $intent => $utterances ) {
foreach ( $utterances as $utterance ) {
$intent_schema .= $intent . ' ' . $utterance . "\n";
}
}

$interaction_model = array();

$interaction_model['news_intent_schema'] = new \Fieldmanager_TextArea( array(
Expand Down Expand Up @@ -331,7 +341,7 @@ function ( $taxonomy ) use ( $news_post_types ) {
) ),
new \Fieldmanager_TextArea( __( 'Values', 'voicewp' ), array(
'name' => 'VOICEWP_POST_NUMBER_WORD_values',
'default_value' => "first\nsecond\nthird\nfourth\nfifth",
'default_value' => implode( "\n", $ordinals ),
'attributes' => array_merge(
$readonly,
array( 'style' => 'width: 50%; height: 150px; font-family: monospace;' )
Expand Down Expand Up @@ -373,7 +383,7 @@ function ( $taxonomy ) use ( $news_post_types ) {
$interaction_model['news_utterances'] = new Fieldmanager_TextArea( array(
'label' => __( 'Here\'s a starting point for your skill\'s Sample Utterances. You can add these to your news skill in the <a href="https://developer.amazon.com" target="_blank">Amazon developer console</a>.', 'voicewp' ),
'escape' => array( 'label' => 'wp_kses_post' ),
'default_value' => file_get_contents( __DIR__ . '/../speechAssets/news/Utterances.txt', FILE_USE_INCLUDE_PATH ),
'default_value' => html_entity_decode( $intent_schema, ENT_QUOTES ),
'skip_save' => true,
'attributes' => array_merge(
$readonly,
Expand Down
Loading