コード例 #1
0
ファイル: translation.php プロジェクト: akirk/GlotPress
 function export_translations_get($project_path, $locale_slug, $translation_set_slug)
 {
     $project = GP::$project->by_path($project_path);
     $locale = GP_Locales::by_slug($locale_slug);
     if (!$project || !$locale) {
         return $this->die_with_404();
     }
     $translation_set = GP::$translation_set->by_project_id_slug_and_locale($project->id, $translation_set_slug, $locale_slug);
     if (!$translation_set) {
         return $this->die_with_404();
     }
     $format = gp_array_get(GP::$formats, gp_get('format', 'po'), null);
     if (!$format) {
         return $this->die_with_404();
     }
     $export_locale = apply_filters('gp_export_locale', $locale->slug, $locale);
     $filename = sprintf('%s-%s.' . $format->extension, str_replace('/', '-', $project->path), $export_locale);
     $filename = apply_filters('gp_export_translations_filename', $filename, $format, $locale, $project, $translation_set);
     $entries = GP::$translation->for_export($project, $translation_set, gp_get('filters'));
     if (gp_has_translation_been_updated($translation_set)) {
         $last_modified = gmdate('D, d M Y H:i:s', gp_gmt_strtotime(GP::$translation->last_modified($translation_set))) . ' GMT';
         $this->headers_for_download($filename, $last_modified);
         echo $format->print_exported_file($project, $locale, $translation_set, $entries);
         // As has_translation_been_updated() compared against HTTP_IF_MODIFIED_SINCE here, send an appropriate header.
     } else {
         $this->header('HTTP/1.1 304 Not Modified');
     }
 }
コード例 #2
0
 function test_if_translation_has_been_updated_since_timestamp()
 {
     $set = $this->factory->translation_set->create_with_project_and_locale();
     $original = $this->factory->original->create(array('project_id' => $set->project_id));
     $this->factory->translation->create(array('original_id' => $original->id, 'translation_set_id' => $set->id, 'status' => 'current'));
     $this->assertTrue(gp_has_translation_been_updated($set));
     $_SERVER['HTTP_IF_MODIFIED_SINCE'] = 'Sat, 27 Apr 2012 15:49:29 GMT';
     $this->assertTrue(gp_has_translation_been_updated($set));
     $_SERVER['HTTP_IF_MODIFIED_SINCE'] = 'Wed, 2 Feb 2022 22:22:22 GMT';
     $this->assertFalse(gp_has_translation_been_updated($set));
 }
コード例 #3
0
 public function export_translations_get($project_path, $locale_slug, $translation_set_slug)
 {
     $project = GP::$project->by_path($project_path);
     $locale = GP_Locales::by_slug($locale_slug);
     if (!$project || !$locale) {
         return $this->die_with_404();
     }
     $translation_set = GP::$translation_set->by_project_id_slug_and_locale($project->id, $translation_set_slug, $locale_slug);
     if (!$translation_set) {
         return $this->die_with_404();
     }
     $format = gp_array_get(GP::$formats, gp_get('format', 'po'), null);
     if (!$format) {
         return $this->die_with_404();
     }
     /**
      * Filter the locale in the file name of the translation set export.
      *
      * @since 1.0.0
      *
      * @param string    $slug   Slug of the locale.
      * @param GP_Locale $locale The current locale.
      */
     $export_locale = apply_filters('gp_export_locale', $locale->slug, $locale);
     $filename = sprintf('%s-%s.' . $format->extension, str_replace('/', '-', $project->path), $export_locale);
     /**
      * Filter the filename of the translation set export.
      *
      * @since 1.0.0
      *
      * @param string             $filename        Filename of the exported translation set.
      * @param GP_Format          $format          Format of the export.
      * @param GP_Locale          $locale          Locale of the export.
      * @param GP_Project         $project         Project the translation set belongs to.
      * @param GP_Translation_Set $translation_set The translation set to be exported.
      */
     $filename = apply_filters('gp_export_translations_filename', $filename, $format, $locale, $project, $translation_set);
     $entries = GP::$translation->for_export($project, $translation_set, gp_get('filters'));
     if (gp_has_translation_been_updated($translation_set)) {
         $last_modified = gmdate('D, d M Y H:i:s', gp_gmt_strtotime(GP::$translation->last_modified($translation_set))) . ' GMT';
         $this->headers_for_download($filename, $last_modified);
         echo $format->print_exported_file($project, $locale, $translation_set, $entries);
         // As has_translation_been_updated() compared against HTTP_IF_MODIFIED_SINCE here, send an appropriate header.
     } else {
         $this->status_header(304);
     }
 }