-
Notifications
You must be signed in to change notification settings - Fork 84
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
Added some features needed, when changing translation in production mode. #87
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,8 @@ | |
class CatalogueCompiler extends Nette\Object | ||
{ | ||
|
||
const TAG_TRANSLATION = 'Kdyby\\Translation\\Translator'; | ||
|
||
/** | ||
* @var \Nette\Caching\Cache | ||
*/ | ||
|
@@ -39,11 +41,16 @@ class CatalogueCompiler extends Nette\Object | |
*/ | ||
private $catalogueFactory; | ||
|
||
/** | ||
* @var Nette\Caching\IStorage | ||
*/ | ||
private $cacheStorage; | ||
|
||
|
||
public function __construct(Nette\Caching\IStorage $cacheStorage, FallbackResolver $fallbackResolver, | ||
CatalogueFactory $catalogueFactory) | ||
{ | ||
$this->cacheStorage = $cacheStorage; | ||
$this->cache = new Cache($cacheStorage, 'Kdyby\\Translation\\Translator'); | ||
$this->fallbackResolver = $fallbackResolver; | ||
$this->catalogueFactory = $catalogueFactory; | ||
|
@@ -60,10 +67,22 @@ public function enableDebugMode() | |
} | ||
|
||
|
||
/** | ||
* Replaces cache storage with simple memory storage (per-request). | ||
*/ | ||
public function disableDebugMode() | ||
{ | ||
$this->cache = new Cache($this->cacheStorage, 'Kdyby\\Translation\\Translator'); | ||
} | ||
|
||
|
||
public function invalidateCache() | ||
public function invalidateCache($onlyTranslation = FALSE) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tohle bych vubec nedělal, raději udělal mazani kdyz je filecache tak maznout složku, jinak maznout podle tagu... mazat všechno nechceš nikdy There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. proč bys to vůbec nedělal? Nechtěl jsem ti rozbít stávající chování (proto nepovinný parametr), a nevím, kde tam invaliduješ celou cache. Jestli nikdy nechceš mazat všechno, tak co tam ta metoda dělá? |
||
{ | ||
$this->cache->clean(array(Cache::ALL => TRUE)); | ||
if ($onlyTranslation) { | ||
$this->cache->clean(array(Cache::TAGS => static::TAG_TRANSLATION)); | ||
} else { | ||
$this->cache->clean(array(Cache::ALL => TRUE)); | ||
} | ||
} | ||
|
||
|
||
|
@@ -106,7 +125,7 @@ public function compile(Translator $translator, array &$availableCatalogues, $lo | |
} | ||
|
||
$this->catalogueFactory->createCatalogue($translator, $availableCatalogues, $locale); | ||
$this->cache->save($cacheKey, $availableCatalogues[$locale]->all()); | ||
$this->cache->save($cacheKey, $availableCatalogues[$locale]->all(), array(Cache::TAGS => array(static::TAG_TRANSLATION))); | ||
return $availableCatalogues; | ||
} | ||
|
||
|
@@ -115,7 +134,8 @@ public function compile(Translator $translator, array &$availableCatalogues, $lo | |
$cached = $compiled = $this->cache->load($cacheKey); | ||
if ($compiled === NULL) { | ||
$this->catalogueFactory->createCatalogue($translator, $availableCatalogues, $locale); | ||
$this->cache->save($cacheKey, $compiled = $this->compilePhpCache($translator, $availableCatalogues, $locale)); | ||
$this->cache->save($cacheKey, $compiled = $this->compilePhpCache($translator, $availableCatalogues, $locale), | ||
array(Cache::TAGS => array(static::TAG_TRANSLATION))); | ||
$cached = $this->cache->load($cacheKey); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[PHP] | ||
extension_dir = "./ext" | ||
extension=php_pdo_sqlite.dll | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. jak tohle souvisi s timto pullrq? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, tak, že nové nette má jako defaultní cache sqlite storage a když chci pustit testy na windows, tak se to bez tohoto neobejde. Mám to vyhodit? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tohle je realne na něco potřeba?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ano, potřebuji to tam.
Když není zapnutý debug mód, tak TranslationWriter nemá načtené resources.
Tedy musím zavolat enableDebugMode, aby měl TranslatonWriter resources, do kterých může zapsat.
Jenže pak se změna neprojeví u cache, jelikož mám zapnutou MemoryStorage a pro ostatní uživatele je stále klasickáPhpArrayStorage. Takže pokud chci, aby se automaticky projevily překlady i bez debug mode, musím těsně před zápisem přehodit zpět na persistentní storage (právě metodou disableDebugMode). Pak se překlady v celé aplikaci projeví hned po změně a nemusím kvůli tomu mazat cache celé aplikace.
A práci máme vyloženě na tohle usecase, když si klient překládá sám a z formu to cpeme do neon souborů a chceme, klient má production mode a chce, aby se překlady projevily hned.